diff options
author | Georg Zotti <Georg.Zotti@univie.ac.at> | 2024-02-26 15:08:37 +0100 |
---|---|---|
committer | Georg Zotti <Georg.Zotti@univie.ac.at> | 2024-02-26 15:08:37 +0100 |
commit | 25ffdd2b6d5da61307a8606ce8c4fa10fc621209 (patch) | |
tree | 4160e5336cb2accb8b984d5234146340236d92fe | |
parent | b3a6f2e0699c4ac6855650ae099dbe414bfdfd2d (diff) |
SSE plugin: allow overwrite if possible (Fix #3641)
-rw-r--r-- | plugins/SolarSystemEditor/src/SolarSystemEditor.cpp | 2 | ||||
-rw-r--r-- | plugins/SolarSystemEditor/src/gui/SolarSystemManagerWindow.cpp | 20 |
2 files changed, 20 insertions, 2 deletions
diff --git a/plugins/SolarSystemEditor/src/SolarSystemEditor.cpp b/plugins/SolarSystemEditor/src/SolarSystemEditor.cpp index 7e33b4b14b..a4be33cbd0 100644 --- a/plugins/SolarSystemEditor/src/SolarSystemEditor.cpp +++ b/plugins/SolarSystemEditor/src/SolarSystemEditor.cpp @@ -316,7 +316,7 @@ bool SolarSystemEditor::isFileEncodingValid(QString filePath) const if (state.invalidChars > 0) #endif { - qDebug() << "[Solar System Editor] Not a valid UTF-8 sequence in file " << filePath; + qCritical() << "[Solar System Editor] Not a valid UTF-8 sequence in file " << filePath; return false; } else diff --git a/plugins/SolarSystemEditor/src/gui/SolarSystemManagerWindow.cpp b/plugins/SolarSystemEditor/src/gui/SolarSystemManagerWindow.cpp index 11790104cc..0b23420310 100644 --- a/plugins/SolarSystemEditor/src/gui/SolarSystemManagerWindow.cpp +++ b/plugins/SolarSystemEditor/src/gui/SolarSystemManagerWindow.cpp @@ -36,6 +36,7 @@ #include "SolarSystem.hpp" #include <QFileDialog> +#include <QMessageBox> SolarSystemManagerWindow::SolarSystemManagerWindow() : StelDialog("SolarSystemEditor") @@ -211,7 +212,24 @@ void SolarSystemManagerWindow::copyConfiguration() QString filePath = QFileDialog::getSaveFileName(&StelMainView::getInstance(), q_("Save the minor Solar System bodies as..."), QDir::homePath() + "/ssystem_minor.ini"); - ssEditor->copySolarSystemConfigurationFileTo(filePath); + + const QFileInfo targetFile(filePath); + // We must remove an existing file because QFile::copy() does not overwrite. + // Note that at least on Windows, an existing and write-protected file has been identified by the previous dialog already, + // so these QMessageBoxes will never be seen here. + if (targetFile.exists() && targetFile.isWritable()) + { + if (!QFile::remove(targetFile.absoluteFilePath())) + { + QMessageBox::information(&StelMainView::getInstance(), q_("Cannot overwrite"), + q_("Cannot remove existing file. Do you have permissions?")); + return; + } + } + + if (!ssEditor->copySolarSystemConfigurationFileTo(filePath)) + QMessageBox::information(&StelMainView::getInstance(), q_("Cannot store"), + q_("File cannot be written. Do you have permissions?")); } void SolarSystemManagerWindow::replaceConfiguration() |