From e6f246b94717f3d835d46e02e000f55ed59e6e41 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 7 Feb 2019 16:37:13 +0100 Subject: [PATCH] [CONFIG] Only load values from the SD Card at the beginning. Add a save to SD card when existing a application. --- src/myutils/ConfigInformation.cpp | 6 ++---- src/myutils/ConfigInformation.h | 6 +++--- src/myutils/ConfigUtils.cpp | 29 ++++++++++++++++++++++++++++- src/myutils/ConfigUtils.h | 12 +++++++++--- src/patcher/hooks_patcher.cpp | 1 + src/settings/ConfigSettings.cpp | 6 +++--- src/settings/ConfigSettings.h | 2 +- 7 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/myutils/ConfigInformation.cpp b/src/myutils/ConfigInformation.cpp index eb92259..72fb13b 100644 --- a/src/myutils/ConfigInformation.cpp +++ b/src/myutils/ConfigInformation.cpp @@ -25,12 +25,10 @@ ConfigInformation::ConfigInformation(WUPSConfig * config, std::string persistPat this->persistPath = persistPath; this->persistFileName = persistFileName; createConfigSettings(); - loadValuesFromSD(); } ConfigInformation::~ConfigInformation() { if(configSettings != NULL) { - updateAndSaveSettings(); delete configSettings; configSettings = NULL; } @@ -89,12 +87,12 @@ bool ConfigInformation::loadValuesFromSD() { return true; } -void ConfigInformation::updateAndSaveSettings() { +void ConfigInformation::updateAndSaveSettings(bool forceAll) { if(this->config == NULL || this->configSettings == NULL) { return; } updateConfigSettings(); - configSettings->Save(); + configSettings->Save(forceAll); } bool ConfigInformation::updateConfigSettings() { diff --git a/src/myutils/ConfigInformation.h b/src/myutils/ConfigInformation.h index 7100028..880a5f9 100644 --- a/src/myutils/ConfigInformation.h +++ b/src/myutils/ConfigInformation.h @@ -35,12 +35,13 @@ public: /** Deletes the given WUPSConfig - Calls updateAndSaveSettings Deletes the created ConfigSettings **/ ~ConfigInformation(); - void updateAndSaveSettings(); + void updateAndSaveSettings(bool forceAll); + + bool loadValuesFromSD(); WUPSConfig * getConfig() { return config; @@ -48,7 +49,6 @@ public: private: bool createConfigSettings(); - bool loadValuesFromSD(); bool updateConfigSettings(); WUPSConfig * config = NULL; diff --git a/src/myutils/ConfigUtils.cpp b/src/myutils/ConfigUtils.cpp index 3ea10ca..8ecd997 100644 --- a/src/myutils/ConfigUtils.cpp +++ b/src/myutils/ConfigUtils.cpp @@ -342,11 +342,34 @@ void ConfigUtils::deleteConfigInformation(std::vector confi } void ConfigUtils::loadConfigFromSD() { - deleteConfigInformation(getConfigInformation()); + std::vector configInfos = getConfigInformation(); + + for (auto & curConfig : configInfos) { + curConfig->loadValuesFromSD(); + } + + deleteConfigInformation(configInfos); +} + +void ConfigUtils::saveConfigToSD() { + std::vector configInfos = getConfigInformation(); + + for (auto & curConfig : configInfos) { + curConfig->updateAndSaveSettings(true); + } + + deleteConfigInformation(configInfos); } void ConfigUtils::openConfigMenu() { std::vector configInfos = getConfigInformation(); + + // We rely on the default values here. + //if(loadFromSD){ + // for (auto & curConfig : configInfos) { + // configs.loadValuesFromSD(); + // } + //} std::vector configs; @@ -363,6 +386,10 @@ void ConfigUtils::openConfigMenu() { for (auto & curConfig : configs) { DCFlushRange(curConfig, sizeof(WUPSConfig)); } + + for (auto & curConfig : configInfos) { + curConfig->updateAndSaveSettings(false); + } deleteConfigInformation(configInfos); } diff --git a/src/myutils/ConfigUtils.h b/src/myutils/ConfigUtils.h index b16c2b6..05cc848 100644 --- a/src/myutils/ConfigUtils.h +++ b/src/myutils/ConfigUtils.h @@ -26,15 +26,21 @@ class ConfigUtils { public: /** Loads the configuration files of all loaded plugins from the SDCard - and triggers the "loadValue" if they differ the default value. + and triggers the "callback" if they differ the default/current value. **/ static void loadConfigFromSD(); + + /** + Get the current values from all plugins via the WUPS_GET_CONFIG() hook and + save them to the SD Card. + **/ + static void saveConfigToSD(); /** Opens the configuration menu where plugins can be configured. Plugins need to implement the WUPS_GET_CONFIG() hook to show up in the menu. The menu will be rendered on the TV and DRC screen, with optimization for the DRC. - If the menu is low, the menu may be only rendered to the DRC. + If the memory is low, the menu may be only rendered to the DRC. **/ static void openConfigMenu(); @@ -66,7 +72,7 @@ private: default value. This behaviour may change in the future. See the ConfigInformation class for more information. **/ - static std::vector getConfigInformation(); + static std::vector getConfigInformation(); /** Delete a list of ConfigInformation. diff --git a/src/patcher/hooks_patcher.cpp b/src/patcher/hooks_patcher.cpp index b38d81f..44cd629 100644 --- a/src/patcher/hooks_patcher.cpp +++ b/src/patcher/hooks_patcher.cpp @@ -29,6 +29,7 @@ DECL(uint32_t, ProcUIProcessMessages, uint32_t u) { CallHook(WUPS_LOADER_HOOK_APP_STATUS_CHANGED); if(gAppStatus == WUPS_APP_STATUS_CLOSED) { CallHook(WUPS_LOADER_HOOK_ENDING_APPLICATION); + ConfigUtils::saveConfigToSD(); DeInit(); } } diff --git a/src/settings/ConfigSettings.cpp b/src/settings/ConfigSettings.cpp index ad1875a..8989f89 100644 --- a/src/settings/ConfigSettings.cpp +++ b/src/settings/ConfigSettings.cpp @@ -181,7 +181,7 @@ bool ConfigSettings::Reset() { this->SetDefault(); bChanged = true; - if (this->Save()) { + if (this->Save(true)) { return true; } @@ -197,8 +197,8 @@ int32_t ConfigSettings::getIdByName(std::string configID) { return -1; } -bool ConfigSettings::Save() { - if(!bChanged) { +bool ConfigSettings::Save(bool force) { + if(!force && !bChanged) { DEBUG_FUNCTION_LINE("Nothing has changed, we can skip\n"); return true; } diff --git a/src/settings/ConfigSettings.h b/src/settings/ConfigSettings.h index 57f8267..26ff0ab 100644 --- a/src/settings/ConfigSettings.h +++ b/src/settings/ConfigSettings.h @@ -37,7 +37,7 @@ public: //!Load Settings bool Load(); //!Save Settings - bool Save(); + bool Save(bool force); //!Reset Settings bool Reset();