bool readCelloi_file(const QString &qs_filename,QList<QString> &ql_celloi) { //check paras if(qs_filename.isEmpty()) { printf("ERROR: Invalid input file name.\n"); return false; } if(!ql_celloi.isEmpty()) { printf("WARNING: ql_celloi is not empty, original data will be deleted.\n"); ql_celloi.clear(); } QFile qf_file(qs_filename); if(!qf_file.open(QIODevice::ReadOnly | QIODevice::Text)) { printf("ERROR: open file error!\n"); return false; } while(!qf_file.atEnd()) { char curline[2000]; qf_file.readLine(curline, sizeof(curline)); QString qs_cellname=QString(curline).simplified().toUpper(); if(qs_cellname.isEmpty()) continue; if(qs_cellname.contains("#")) continue; ql_celloi.push_back(qs_cellname); } return true; }
bool RS_Graphic::saveAs(const QString &filename, RS2::FormatType type, bool force) { RS_DEBUG->print("RS_Graphic::saveAs: Entering..."); // Set to "failed" by default. bool ret = false; // Check/memorize if file name we want to use as new file // name is the same as the actual file name. bool fn_is_same = filename == this->filename; auto const filenameSaved=this->filename; auto const autosaveFilenameSaved=this->autosaveFilename; auto const formatTypeSaved=this->formatType; this->filename = filename; this->formatType = type; // QString const oldAutosaveName = this->autosaveFilename; QFileInfo finfo(filename); // Construct new autosave filename by prepending # to the filename // part, using the same directory as the destination file. this->autosaveFilename = finfo.path() + "/#" + finfo.fileName(); // When drawing is saved using a different name than the actual // drawing file name, make LibreCAD think that drawing file // has been modified, to make sure the drawing file saved. if (!fn_is_same || force) setModified(true); ret = save(); // Save file. if (ret) { // Save was successful, remove old autosave file. QFile qf_file(autosaveFilenameSaved); if (qf_file.exists()) { RS_DEBUG->print("RS_Graphic::saveAs: Removing old autosave file %s", autosaveFilenameSaved.toLatin1().data()); qf_file.remove(); } }else{ //do not modify filenames: this->filename=filenameSaved; this->autosaveFilename=autosaveFilenameSaved; this->formatType=formatTypeSaved; } return ret; }
bool RS_Graphic::save(bool isAutoSave) { bool ret = false; RS_DEBUG->print("RS_Graphic::save: Entering..."); /* - Save drawing file only if it has been modifed. * - Notes: Potentially dangerous in case of an internal * coding error that make LibreCAD not aware of modification * when some kind of drawing modification is done. * ----------------------------------------------------------- */ if (isModified()) { QString actualName; RS2::FormatType actualType; actualType = formatType; if (isAutoSave) { actualName = autosaveFilename; if (formatType == RS2::FormatUnknown) actualType = RS2::FormatDXFRW; } else { // - This is not an AutoSave operation. This is a manual // save operation. So, ... // - Set working file name to the drawing file name. // - Backup drawing file (if necessary). // ------------------------------------------------------ QFileInfo finfo(filename); QDateTime m=finfo.lastModified(); //bug#3414993 //modifiedTime should only be used for the same filename // DEBUG_HEADER // qDebug()<<"currentFileName= "<<currentFileName; // qDebug()<<"Checking file: filename= "<<filename; // qDebug()<<"Checking file: "<<filename; // qDebug()<<"modifiedTime.isValid()="<<modifiedTime.isValid(); // qDebug()<<"Previous timestamp: "<<modifiedTime; // qDebug()<<"Current timestamp: "<<m; if ( currentFileName == QString(filename) && modifiedTime.isValid() && m != modifiedTime ) { //file modified by others // qDebug()<<"detected on disk change"; RS_DIALOGFACTORY->commandMessage(QObject::tr("File on disk modified. Please save to another file to avoid data loss! File modified: %1").arg(filename)); return false; } actualName = filename; if (RS_SETTINGS->readNumEntry("/AutoBackupDocument", 1)!=0) BackupDrawingFile(filename); } /* Save drawing file if able to created associated object. * ------------------------------------------------------- */ if (!actualName.isEmpty()) { RS_DEBUG->print("RS_Graphic::save: File: %s", actualName.toLatin1().data()); RS_DEBUG->print("RS_Graphic::save: Format: %d", (int) actualType); RS_DEBUG->print("RS_Graphic::save: Export..."); ret = RS_FileIO::instance()->fileExport(*this, actualName, actualType); QFileInfo finfo(actualName); modifiedTime=finfo.lastModified(); currentFileName=actualName; } else { RS_DEBUG->print("RS_Graphic::save: Can't create object!"); RS_DEBUG->print("RS_Graphic::save: File not saved!"); } /* Remove AutoSave file after user has successfully saved file. * ------------------------------------------------------------ */ if (ret && !isAutoSave) { /* Autosave file object. * */ QFile qf_file(autosaveFilename); /* Tell that drawing file is no more modified. * ------------------------------------------- */ setModified(false); layerList.setModified(false); blockList.setModified(false); /* - Remove autosave file, if able to create associated object, * and if autosave file exist. * ------------------------------------------------------------ */ if (qf_file.exists()) { RS_DEBUG->print( "RS_Graphic::save: Removing old autosave file %s", autosaveFilename.toLatin1().data()); qf_file.remove(); } } RS_DEBUG->print("RS_Graphic::save: Done!"); } else { RS_DEBUG->print("RS_Graphic::save: File not modified, not saved"); ret = true; } RS_DEBUG->print("RS_Graphic::save: Exiting..."); return ret; }