From 7f9f098c7074d3556a7edcfc5ce0d01b11f9178d Mon Sep 17 00:00:00 2001 From: Malte Langkabel Date: Tue, 4 Feb 2020 20:24:59 +0100 Subject: [PATCH] logic: handled case when selected project location can not be written (issue #735) (#906) --- src/lib/settings/Settings.cpp | 16 ++++++++++------ src/lib/settings/Settings.h | 4 ++-- src/lib/utility/ConfigManager.cpp | 4 ++-- src/lib/utility/ConfigManager.h | 2 +- .../qt/project_wizard/QtProjectWizard.cpp | 18 ++++++++++++++++-- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/lib/settings/Settings.cpp b/src/lib/settings/Settings.cpp index eee66446..327a4b72 100644 --- a/src/lib/settings/Settings.cpp +++ b/src/lib/settings/Settings.cpp @@ -50,28 +50,32 @@ bool Settings::loadFromString(const std::string& text, bool readOnly) return true; } -void Settings::save() +bool Settings::save() { if (m_readOnly) { - return; + return false; } + bool success = false; if (m_config.get() && !m_filePath.empty()) { - m_config->save(m_filePath.str()); + success = m_config->save(m_filePath.str()); } - else + + if (!success) { LOG_WARNING(L"Settings were not saved: " + m_filePath.wstr()); } + + return success; } -void Settings::save(const FilePath& filePath) +bool Settings::save(const FilePath& filePath) { setFilePath(filePath); - save(); + return save(); } void Settings::clear() diff --git a/src/lib/settings/Settings.h b/src/lib/settings/Settings.h index cf82eaf2..550539f2 100644 --- a/src/lib/settings/Settings.h +++ b/src/lib/settings/Settings.h @@ -19,8 +19,8 @@ public: bool load(const FilePath& filePath, bool readOnly = false); bool loadFromString(const std::string& text, bool readOnly = false); - void save(); - void save(const FilePath& filePath); + bool save(); + bool save(const FilePath& filePath); void clear(); diff --git a/src/lib/utility/ConfigManager.cpp b/src/lib/utility/ConfigManager.cpp index 4efc530d..0ebf2a01 100644 --- a/src/lib/utility/ConfigManager.cpp +++ b/src/lib/utility/ConfigManager.cpp @@ -375,10 +375,10 @@ bool ConfigManager::load(const std::shared_ptr textAccess) return true; } -void ConfigManager::save(const std::string filepath) +bool ConfigManager::save(const std::string filepath) { std::string output(""); - createXmlDocument(true, filepath, output); + return createXmlDocument(true, filepath, output); } void ConfigManager::setWarnOnEmptyKey(bool warnOnEmptyKey) const diff --git a/src/lib/utility/ConfigManager.h b/src/lib/utility/ConfigManager.h index 58bbf5df..ff0243dc 100644 --- a/src/lib/utility/ConfigManager.h +++ b/src/lib/utility/ConfigManager.h @@ -59,7 +59,7 @@ public: std::vector getSublevelKeys(const std::string& key) const; bool load(const std::shared_ptr textAccess); - void save(const std::string filepath); + bool save(const std::string filepath); std::string toString(); void setWarnOnEmptyKey(bool warnOnEmptyKey) const; diff --git a/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp b/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp index 5557f215..8e881e09 100644 --- a/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp +++ b/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp @@ -1022,7 +1022,8 @@ void QtProjectWizard::removeSelectedSourceGroup() QMessageBox msgBox; msgBox.setText(QStringLiteral("Remove Source Group")); - msgBox.setInformativeText(QStringLiteral("Do you really want to remove this source group from the project?")); + msgBox.setInformativeText( + QStringLiteral("Do you really want to remove this source group from the project?")); msgBox.addButton(QStringLiteral("Yes"), QMessageBox::ButtonRole::YesRole); msgBox.addButton(QStringLiteral("No"), QMessageBox::ButtonRole::NoRole); msgBox.setIcon(QMessageBox::Icon::Question); @@ -1277,7 +1278,20 @@ void QtProjectWizard::createProject() m_projectSettings->setVersion(ProjectSettings::VERSION); m_projectSettings->setAllSourceGroupSettings(m_allSourceGroupSettings); - m_projectSettings->save(path); + if (!m_projectSettings->save(path)) + { + MessageStatus(L"Unable to save project to location: " + path.wstr()).dispatch(); + + QMessageBox msgBox; + msgBox.setText("Could not create Project"); + msgBox.setInformativeText(QString::fromStdWString( + L"

Sourcetrail was unable to save the project to the specified path. Please pick a " + L"different project location.

")); + msgBox.addButton("Ok", QMessageBox::ButtonRole::AcceptRole); + msgBox.exec(); + + return; + } bool settingsChanged = false; if (m_editing)