int Tormat_Main::save() {
QString file_name
= QDir::toNativeSeparators( savePath
).
section( QDir::separator(),
-1 );
if( file_name.startsWith( "." ) ) { // the autosave starts with '.' so we want the user to save to a different location
savePath.clear();
}
if(savePath.isEmpty()) {
savePath
= QFileDialog::getSaveFileName(this, tr
("Save File"), baseFolder, tr
("TormatFiles (*.tormat)"));
}
if (savePath.isEmpty())
return -1;
try{
writeXmlFile(file);
QString fn
= QDir::toNativeSeparators( savePath
).
section( QDir::separator(),
-1 );
Ui::MainWindow::info->setText( tr( "Saved state to '%1'" ).arg( fn ) );
dialog->showOutput( tr( "Saved state to '%1'" ).arg( fn ) );
QString path_to_base
= QDir::toNativeSeparators( savePath
).
section( QDir::separator(),
0,
-2 );
// to get path of state QString autosave_filename
= QString( "%1\\.%2.autosave" ).
arg( path_to_base, fn
);
if( autosave_filename != _autosaver->filename() ) { // user has saved to a new state, so update the autosaver
_autosaver->deleteFile(); // delete old autosave file
_autosaver->setFilename( autosave_filename );
} else { // user has saved to same state name
_autosaver->deleteFile(); // delete obsolete autosave file
}
_state_manager->addState( savePath );
}catch(const std::exception &e) {
Logger
::LogMessage("Error Writing to File: " + QString(e.
what()));
QMessageBox::critical(this,
"Save File Error",e.
what());
return -2;
}
return 0;
}
int Tormat_Main::save() {
QString file_name = QDir::toNativeSeparators( savePath ).section( QDir::separator(), -1 );
if( file_name.startsWith( "." ) ) { // the autosave starts with '.' so we want the user to save to a different location
savePath.clear();
}
if(savePath.isEmpty()) {
savePath = QFileDialog::getSaveFileName(this, tr("Save File"), baseFolder, tr("TormatFiles (*.tormat)"));
}
if (savePath.isEmpty())
return -1;
try{
QFileInfo file(savePath);
writeXmlFile(file);
QString fn = QDir::toNativeSeparators( savePath ).section( QDir::separator(), -1 );
Ui::MainWindow::info->setText( tr( "Saved state to '%1'" ).arg( fn ) );
dialog->showOutput( tr( "Saved state to '%1'" ).arg( fn ) );
QString path_to_base = QDir::toNativeSeparators( savePath ).section( QDir::separator(), 0, -2 ); // to get path of state
QString autosave_filename = QString( "%1\\.%2.autosave" ).arg( path_to_base, fn );
if( autosave_filename != _autosaver->filename() ) { // user has saved to a new state, so update the autosaver
_autosaver->deleteFile(); // delete old autosave file
_autosaver->setFilename( autosave_filename );
} else { // user has saved to same state name
_autosaver->deleteFile(); // delete obsolete autosave file
}
_state_manager->addState( savePath );
}catch(const std::exception &e) {
Logger::LogMessage("Error Writing to File: " + QString(e.what()));
QMessageBox::critical(this,"Save File Error",e.what());
return -2;
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks