From 30c941fcf884566ac9be2fbfa7ebb634b1f0ed96 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Fri, 7 Aug 2015 00:17:41 +0200 Subject: [PATCH] logic: crash fixes --- src/lib/Application.cpp | 38 ++++++++++++++++++++++++-------------- src/lib/Application.h | 2 ++ src/lib/data/Storage.cpp | 2 +- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 4169e70d..c805034f 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -64,20 +64,7 @@ void Application::loadProject(const std::string& projectSettingsFilePath) m_project->loadProjectSettings(projectSettingsFilePath); m_project->parseCode(); - std::vector recentProjects = ApplicationSettings::getInstance()->getRecentProjects(); - if (recentProjects.size()) - { - recentProjects.erase(std::find(recentProjects.begin(), recentProjects.end(), projectSettingsFilePath)); - } - - recentProjects.insert(recentProjects.begin(), projectSettingsFilePath); - if (recentProjects.size() > 7) - { - recentProjects.pop_back(); - } - - ApplicationSettings::getInstance()->setRecentProjects(recentProjects); - ApplicationSettings::getInstance()->save("data/ApplicationSettings.xml"); + updateRecentProjects(projectSettingsFilePath); } void Application::loadSource(const std::string& sourceDirectoryPath) @@ -176,3 +163,26 @@ void Application::handleMessage(MessageSaveProject* message) { saveProject(message->projectSettingsFilePath); } + +void Application::updateRecentProjects(const std::string& projectSettingsFilePath) +{ + ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); + std::vector recentProjects = appSettings->getRecentProjects(); + if (recentProjects.size()) + { + std::vector::iterator it = std::find(recentProjects.begin(), recentProjects.end(), projectSettingsFilePath); + if (it != recentProjects.end()) + { + recentProjects.erase(it); + } + } + + recentProjects.insert(recentProjects.begin(), projectSettingsFilePath); + if (recentProjects.size() > 7) + { + recentProjects.pop_back(); + } + + appSettings->setRecentProjects(recentProjects); + appSettings->save("data/ApplicationSettings.xml"); +} diff --git a/src/lib/Application.h b/src/lib/Application.h index b34823b3..0508ea90 100644 --- a/src/lib/Application.h +++ b/src/lib/Application.h @@ -43,6 +43,8 @@ private: virtual void handleMessage(MessageRefresh* message); virtual void handleMessage(MessageSaveProject* message); + void updateRecentProjects(const std::string& projectSettingsFilePath); + std::shared_ptr m_project; std::shared_ptr m_storageCache; diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index c59c2896..549513ee 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -114,7 +114,7 @@ std::set Storage::getDependingFilePathsAndRemoveFileNodes(const std::s { Node* fileNode = findFileNode(filePath); - if (!fileNode->getComponent() || + if (!fileNode || !fileNode->getComponent() || fileNode->getComponent()->getFilePath() != filePath) { LOG_ERROR("Node is not resolving to the same file.");