mirror of https://github.com/vitalif/openscad
#665 support multiple open files with the same basename. Always clean up backups on window close
parent
3e6f659990
commit
0b8929cf1c
|
@ -1045,33 +1045,21 @@ void MainWindow::saveBackup()
|
|||
QString backupPath = QString::fromStdString(path);
|
||||
if (!backupPath.endsWith("/")) backupPath.append("/");
|
||||
|
||||
if (this->fileName.isEmpty()) {
|
||||
if (!this->tempFile) {
|
||||
this->tempFile = new QTemporaryFile(backupPath.append("unsaved-backup-XXXXXXXX.scad"));
|
||||
}
|
||||
|
||||
if ((!this->tempFile->isOpen()) && (! this->tempFile->open())) {
|
||||
PRINT("WARNING: Failed to create backup file");
|
||||
return;
|
||||
}
|
||||
return writeBackup(this->tempFile);
|
||||
QString basename = "unsaved";
|
||||
if (!this->fileName.isEmpty()) {
|
||||
QFileInfo fileInfo = QFileInfo(this->fileName);
|
||||
basename = fileInfo.baseName();
|
||||
}
|
||||
|
||||
QFileInfo fileInfo = QFileInfo(this->fileName);
|
||||
if (!this->tempFile) {
|
||||
this->tempFile = new QTemporaryFile(backupPath.append(basename + "-backup-XXXXXXXX.scad"));
|
||||
}
|
||||
|
||||
backupPath.append(fileInfo.baseName())
|
||||
.append("-backup.")
|
||||
.append(fileInfo.suffix());
|
||||
|
||||
QFile file(backupPath);
|
||||
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
PRINTB("WARNING: Failed to open backup file for writing: %s (%s)", backupPath.toLocal8Bit().constData() % file.errorString().toLocal8Bit().constData());
|
||||
if ((!this->tempFile->isOpen()) && (! this->tempFile->open())) {
|
||||
PRINT("WARNING: Failed to create backup file");
|
||||
return;
|
||||
}
|
||||
|
||||
writeBackup(&file);
|
||||
file.close();
|
||||
return writeBackup(this->tempFile);
|
||||
}
|
||||
|
||||
void MainWindow::actionSave()
|
||||
|
|
Loading…
Reference in New Issue