示例#1
0
function Printer_getFileFromModel($type_model, $id_model, &$gcode_path, $filename = NULL, &$array_info = NULL)
{
    $model_path = NULL;
    $bz2_path = NULL;
    $command = '';
    $output = array();
    $ret_val = 0;
    $filename_json = NULL;
    $filename_bz2 = NULL;
    $filename_gcode = NULL;
    $CI =& get_instance();
    switch ($type_model) {
        case PRINTER_TYPE_MODELLIST:
            $CI->load->helper('printlist');
            $filename_json = PRINTLIST_FILE_JSON;
            $filename_bz2 = PRINTLIST_FILE_GCODE_BZ2;
            $filename_gcode = PRINTLIST_FILE_GCODE;
            $model_cr = ModelList__find($id_model, $model_path);
            // get json info
            if (is_array($array_info)) {
                $json_data = array();
                try {
                    $json_data = json_read($model_path . $filename_json, TRUE);
                    if ($json_data['error']) {
                        throw new Exception('read json error');
                    }
                } catch (Exception $e) {
                    return ERROR_INTERNAL;
                }
                $array_info = $json_data['json'];
            }
            break;
        case PRINTER_TYPE_GCODELIB:
            $CI->load->helper('printerstoring');
            $tmp_array = NULL;
            $filename_json = PRINTERSTORING_FILE_INFO_JSON;
            $filename_bz2 = PRINTERSTORING_FILE_GCODE_BZ2;
            $filename_gcode = PRINTERSTORING_FILE_GCODE_EXT;
            $array_info = PrinterStoring_getInfo('gcode', $id_model, $model_path);
            if (is_null($array_info)) {
                $model_cr = ERROR_WRONG_PRM;
            } else {
                $model_cr = ERROR_OK;
            }
    }
    if ($model_cr == ERROR_OK && $model_path) {
        $ret_val = 0;
        //		//if we don't fix the filename of gcode
        // 		try {
        // 			$json_data = json_read($model_path . PRINTLIST_FILE_JSON);
        // 			if ($json_data['error']) {
        // 				throw new Exception('read json error');
        // 			}
        // 		} catch (Exception $e) {
        // 			return ERROR_INTERNAL;
        // 		}
        // 		$gcode_path = $json_data['json'][PRINTLIST_TITLE_GCODE];
        $bz2_path = $model_path . $filename_bz2;
        $filename = is_null($filename) ? $filename_gcode : $filename;
        $gcode_path = $CI->config->item('temp') . $filename;
        $command = 'bzip2 -dkcf ' . $bz2_path . ' > ' . $gcode_path;
        @unlink($gcode_path);
        // delete old file
        exec($command, $output, $ret_val);
        if ($ret_val != ERROR_NORMAL_RC_OK) {
            return ERROR_INTERNAL;
        }
        return ERROR_OK;
    } else {
        return ERROR_UNKNOWN_MODEL;
    }
    return ERROR_OK;
    // never reach here
}
示例#2
0
function ModelList__getDetailAsArray($id_model, &$array_data, $set_localization = FALSE)
{
    $array_data = NULL;
    $tmp_array = NULL;
    $json_path = NULL;
    $model_path = NULL;
    $model_cr = ModelList__find($id_model, $model_path);
    if ($model_cr == ERROR_OK && $model_path) {
        $json_path = $model_path . PRINTLIST_FILE_JSON;
        $tmp_array = json_read($json_path, TRUE);
        if ($tmp_array['error']) {
            return ERROR_INTERNAL;
        }
        $array_data = $tmp_array['json'];
        ModelList__blindUrl($array_data);
        if ($set_localization) {
            ModelList__setLocalization($array_data);
        }
        return ERROR_OK;
    } else {
        return ERROR_UNKNOWN_MODEL;
    }
    return;
}