コード例 #1
0
ファイル: rest.php プロジェクト: Jaesin/zim-web
 public function libdeletegcode()
 {
     $cr = ERROR_OK;
     $id = NULL;
     $this->load->helper('printerstoring');
     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
         if ($id = $this->input->get('id')) {
             if (intval($id) < 1) {
                 $cr = ERROR_WRONG_PRM;
             } else {
                 $cr = PrinterStoring_deleteGcode(intval($id));
             }
         } else {
             $cr = ERROR_MISS_PRM;
         }
         $this->_return_cr($cr);
     }
     return;
 }
コード例 #2
0
function PrinterStoring_storeGcode($name)
{
    global $CFG;
    $CI =& get_instance();
    $gcode_library_path = $CFG->config['gcode_library'];
    $data_json = NULL;
    $array_length = array();
    $array_material = array();
    $nb_models = 0;
    $preset_id = NULL;
    // check if library folder exist
    if (@is_dir($gcode_library_path) == false) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('gcode library folder does not exist', __FILE__, __LINE__);
        return ERROR_INTERNAL;
    }
    // get last unused ID
    if (($model_id = PrinterStoring__getLastId($gcode_library_path)) < 0) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('could not get the last id from gcode library', __FILE__, __LINE__);
        return ERROR_INTERNAL;
    }
    // create model folder
    $model_folder = $gcode_library_path . sprintf('%06d', $model_id) . '/';
    if (@mkdir($model_folder) == false) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('could not create the model folder', __FILE__, __LINE__);
        return ERROR_DISK_FULL;
    }
    // get length and material info
    $CI->load->helper('printerstate');
    if (ERROR_OK != PrinterState_getSlicedJson($data_json)) {
        return ERROR_INTERNAL;
    }
    foreach (array('r', 'l') as $abb_cartridge) {
        if (array_key_exists($abb_cartridge, $data_json) && array_key_exists(PRINTERSTATE_TITLE_NEED_L, $data_json[$abb_cartridge]) && $data_json[$abb_cartridge][PRINTERSTATE_TITLE_NEED_L] > 0) {
            $array_length[$abb_cartridge] = $data_json[$abb_cartridge][PRINTERSTATE_TITLE_NEED_L];
            $array_material[$abb_cartridge] = $data_json[$abb_cartridge][PRINTERSTATE_TITLE_MATERIAL];
            ++$nb_models;
        } else {
            $array_length[$abb_cartridge] = 0;
            $array_material[$abb_cartridge] = NULL;
        }
    }
    // get preset id
    $CI->load->helper('zimapi');
    if (!ZimAPI_getPreset($preset_id)) {
        $preset_id = NULL;
    }
    // create info file
    $info_file = $model_folder . PRINTERSTORING_FILE_INFO_JSON;
    $info = array("id" => $model_id, "name" => $name, PRINTERSTORING_TITLE_CREATE_TIME => time(), PRINTERSTORING_TITLE_LENG_R => $array_length['r'], PRINTERSTORING_TITLE_LENG_L => $array_length['l'], PRINTERSTORING_TITLE_MATER_R => $array_material['r'], PRINTERSTORING_TITLE_MATER_L => $array_material['l'], PRINTERSTORING_TITLE_PRESET_ID => $preset_id);
    if (!PrinterStoring__createInfoFile($info_file, $info)) {
        PrinterStoring_deleteGcode($model_id);
        $CI->load->helper('printerlog');
        PrinterLog_logError('could not create the model info file', __FILE__, __LINE__);
        return ERROR_DISK_FULL;
    }
    // store captured image
    $CI->load->helper('zimapi');
    $image_path = ZIMAPI_FILEPATH_CAPTURE;
    if (file_exists($image_path) === false) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('could not find the captured image', __FILE__, __LINE__);
        return ERROR_IMG_NOTFOUND;
    } elseif (!copy($image_path, $model_folder . PRINTERSTORING_FILE_IMG_JPG)) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('could not store the captured image', __FILE__, __LINE__);
        return ERROR_DISK_FULL;
    }
    // store file(s)
    $CI->load->helper('slicer');
    $file_path = $CI->config->item('temp') . SLICER_FILE_MODEL;
    if (@file_exists($file_path) == false) {
        PrinterStoring_deleteGcode($model_id);
        $CI->load->helper('printerlog');
        PrinterLog_logError('could not find the gcode model', __FILE__, __LINE__);
        return ERROR_GCODE_NOTFOUND;
    } elseif (!PrinterStoring__storeModelFile($model_folder . PRINTERSTORING_FILE_GCODE_BZ2, $file_path)) {
        PrinterStoring_deleteGcode($model_id);
        $CI->load->helper('printerlog');
        PrinterLog_logError('disk full, could not store the gcode file', __FILE__, __LINE__);
        return ERROR_DISK_FULL;
    }
    // check disk free space
    if (!PrinterStoring__checkFreeSpace()) {
        PrinterStoring_deleteGcode($model_id);
        $CI->load->helper('printerlog');
        PrinterLog_logError('overpass user library minimum free space limit', __FILE__, __LINE__);
        return ERROR_DISK_FULL;
    }
    // stats info
    $CI->load->helper('printerlog');
    PrinterLog_statsLibraryGcode(PRINTERLOG_STATS_LABEL_LOAD, $nb_models);
    return ERROR_OK;
}