diff --git a/CMakeLists.txt b/CMakeLists.txt index cadde579..3ceaf0f5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,7 @@ add_executable(Bloom # Project & application configuration src/ProjectConfig.cpp + src/ProjectSettings.cpp # Events src/EventManager/EventListener.cpp diff --git a/src/Application.cpp b/src/Application.cpp index 4d62ba75..41eb19ea 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -49,7 +49,8 @@ int Application::run(const std::vector& arguments) { this->eventManager, this->projectConfig.value(), this->environmentConfig.value(), - this->insightConfig.value() + this->insightConfig.value(), + this->projectSettings.value().insightSettings ); /* @@ -94,6 +95,7 @@ void Application::startup() { std::bind(&Application::onShutdownApplicationRequest, this, std::placeholders::_1) ); + this->loadProjectSettings(); this->loadProjectConfiguration(); Logger::configure(this->projectConfig.value()); @@ -153,6 +155,28 @@ void Application::shutdown() { Thread::setThreadState(ThreadState::STOPPED); } +void Application::loadProjectSettings() { + const auto projectSettingsPath = Paths::projectSettingsPath(); + auto jsonSettingsFile = QFile(QString::fromStdString(projectSettingsPath)); + + if (jsonSettingsFile.exists()) { + auto jsonObject = QJsonDocument::fromJson(jsonSettingsFile.readAll()).object(); + jsonSettingsFile.close(); + + try { + this->projectSettings = ProjectSettings(jsonObject); + return; + + } catch (const std::exception& exception) { + Logger::error( + "Failed to load project settings from " + projectSettingsPath + " - " + exception.what() + ); + } + } + + this->projectSettings = ProjectSettings(); +} + void Application::loadProjectConfiguration() { auto jsonConfigFile = QFile(QString::fromStdString(Paths::projectConfigPath())); diff --git a/src/Application.hpp b/src/Application.hpp index 48986f86..fe974837 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -16,6 +16,7 @@ #include "src/Logger/Logger.hpp" #include "src/ProjectConfig.hpp" +#include "src/ProjectSettings.hpp" #include "src/VersionNumber.hpp" #include "src/EventManager/EventListener.hpp" @@ -147,6 +148,11 @@ namespace Bloom std::optional debugServerConfig; std::optional insightConfig; + /** + * Settings extracted from the settings file in the user's project root. + */ + std::optional projectSettings; + /** * The project environment selected by the user. * @@ -201,6 +207,12 @@ namespace Bloom */ void shutdown(); + /** + * Extracts or generates project settings. + * + */ + void loadProjectSettings(); + /** * Extracts the project config from the user's JSON config file and populates the following members: * - this->projectConfig diff --git a/src/Helpers/Paths.hpp b/src/Helpers/Paths.hpp index 6cf6b876..0123455f 100644 --- a/src/Helpers/Paths.hpp +++ b/src/Helpers/Paths.hpp @@ -41,6 +41,25 @@ namespace Bloom static std::string projectConfigPath() { return std::filesystem::current_path().string() + "/bloom.json"; } + + /** + * Returns the path to the current project's settings directory. + * + * @return + */ + static std::string projectSettingsDirPath() { + return std::filesystem::current_path().string() + "/.bloom"; + } + + /** + * Returns the path to the current project's settings file. + * + * @return + */ + static std::string projectSettingsPath() { + return std::filesystem::current_path().string() + "/.bloom/settings.json"; + } + /** * Returns the path to Bloom's compiled resources. * diff --git a/src/Insight/Insight.hpp b/src/Insight/Insight.hpp index 1ded24e7..be51974b 100644 --- a/src/Insight/Insight.hpp +++ b/src/Insight/Insight.hpp @@ -7,6 +7,7 @@ #include "src/TargetController/TargetControllerConsole.hpp" #include "src/Helpers/Paths.hpp" #include "src/ProjectConfig.hpp" +#include "src/ProjectSettings.hpp" #include "src/EventManager/EventManager.hpp" #include "src/EventManager/EventListener.hpp" @@ -41,12 +42,14 @@ namespace Bloom EventManager& eventManager, const ProjectConfig& projectConfig, const EnvironmentConfig& environmentConfig, - const InsightConfig& insightConfig + const InsightConfig& insightConfig, + const InsightProjectSettings& insightProjectSettings ): eventManager(eventManager), projectConfig(projectConfig), environmentConfig(environmentConfig), insightConfig(insightConfig), + insightProjectSettings(insightProjectSettings), application( ( QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, false), @@ -71,6 +74,8 @@ namespace Bloom EnvironmentConfig environmentConfig; InsightConfig insightConfig; + InsightProjectSettings insightProjectSettings; + EventManager& eventManager; EventListenerPointer eventListener = std::make_shared("InsightEventListener"); diff --git a/src/ProjectSettings.cpp b/src/ProjectSettings.cpp new file mode 100644 index 00000000..be8b766f --- /dev/null +++ b/src/ProjectSettings.cpp @@ -0,0 +1,9 @@ +#include "ProjectSettings.hpp" + +#include "src/Logger/Logger.hpp" + +using namespace Bloom; + +ProjectSettings::ProjectSettings(const QJsonObject& jsonObject) { + +} diff --git a/src/ProjectSettings.hpp b/src/ProjectSettings.hpp new file mode 100644 index 00000000..8c399e14 --- /dev/null +++ b/src/ProjectSettings.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include +#include + +#include "src/Targets/TargetMemory.hpp" +#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp" + +namespace Bloom +{ + struct InsightProjectSettings + { + std::map< + Targets::TargetMemoryType, + Widgets::TargetMemoryInspectionPaneSettings + > memoryInspectionPaneSettingsByMemoryType; + + InsightProjectSettings() = default; + InsightProjectSettings(const QJsonObject& jsonObject); + }; + + struct ProjectSettings + { + InsightProjectSettings insightSettings; + + ProjectSettings() = default; + explicit ProjectSettings(const QJsonObject& jsonObject); + }; +}