[CONFIG] Only load values from the SD Card at the beginning. Add a save to SD card when existing a application.

This commit is contained in:
Maschell 2019-02-07 16:37:13 +01:00
parent 993b328f4c
commit e6f246b947
7 changed files with 47 additions and 15 deletions

View File

@ -25,12 +25,10 @@ ConfigInformation::ConfigInformation(WUPSConfig * config, std::string persistPat
this->persistPath = persistPath; this->persistPath = persistPath;
this->persistFileName = persistFileName; this->persistFileName = persistFileName;
createConfigSettings(); createConfigSettings();
loadValuesFromSD();
} }
ConfigInformation::~ConfigInformation() { ConfigInformation::~ConfigInformation() {
if(configSettings != NULL) { if(configSettings != NULL) {
updateAndSaveSettings();
delete configSettings; delete configSettings;
configSettings = NULL; configSettings = NULL;
} }
@ -89,12 +87,12 @@ bool ConfigInformation::loadValuesFromSD() {
return true; return true;
} }
void ConfigInformation::updateAndSaveSettings() { void ConfigInformation::updateAndSaveSettings(bool forceAll) {
if(this->config == NULL || this->configSettings == NULL) { if(this->config == NULL || this->configSettings == NULL) {
return; return;
} }
updateConfigSettings(); updateConfigSettings();
configSettings->Save(); configSettings->Save(forceAll);
} }
bool ConfigInformation::updateConfigSettings() { bool ConfigInformation::updateConfigSettings() {

View File

@ -35,12 +35,13 @@ public:
/** /**
Deletes the given WUPSConfig Deletes the given WUPSConfig
Calls updateAndSaveSettings
Deletes the created ConfigSettings Deletes the created ConfigSettings
**/ **/
~ConfigInformation(); ~ConfigInformation();
void updateAndSaveSettings(); void updateAndSaveSettings(bool forceAll);
bool loadValuesFromSD();
WUPSConfig * getConfig() { WUPSConfig * getConfig() {
return config; return config;
@ -48,7 +49,6 @@ public:
private: private:
bool createConfigSettings(); bool createConfigSettings();
bool loadValuesFromSD();
bool updateConfigSettings(); bool updateConfigSettings();
WUPSConfig * config = NULL; WUPSConfig * config = NULL;

View File

@ -342,11 +342,34 @@ void ConfigUtils::deleteConfigInformation(std::vector<ConfigInformation *> confi
} }
void ConfigUtils::loadConfigFromSD() { void ConfigUtils::loadConfigFromSD() {
deleteConfigInformation(getConfigInformation()); std::vector<ConfigInformation *> configInfos = getConfigInformation();
for (auto & curConfig : configInfos) {
curConfig->loadValuesFromSD();
}
deleteConfigInformation(configInfos);
}
void ConfigUtils::saveConfigToSD() {
std::vector<ConfigInformation *> configInfos = getConfigInformation();
for (auto & curConfig : configInfos) {
curConfig->updateAndSaveSettings(true);
}
deleteConfigInformation(configInfos);
} }
void ConfigUtils::openConfigMenu() { void ConfigUtils::openConfigMenu() {
std::vector<ConfigInformation *> configInfos = getConfigInformation(); std::vector<ConfigInformation *> configInfos = getConfigInformation();
// We rely on the default values here.
//if(loadFromSD){
// for (auto & curConfig : configInfos) {
// configs.loadValuesFromSD();
// }
//}
std::vector<WUPSConfig *> configs; std::vector<WUPSConfig *> configs;
@ -363,6 +386,10 @@ void ConfigUtils::openConfigMenu() {
for (auto & curConfig : configs) { for (auto & curConfig : configs) {
DCFlushRange(curConfig, sizeof(WUPSConfig)); DCFlushRange(curConfig, sizeof(WUPSConfig));
} }
for (auto & curConfig : configInfos) {
curConfig->updateAndSaveSettings(false);
}
deleteConfigInformation(configInfos); deleteConfigInformation(configInfos);
} }

View File

@ -26,15 +26,21 @@ class ConfigUtils {
public: public:
/** /**
Loads the configuration files of all loaded plugins from the SDCard 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(); 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. Opens the configuration menu where plugins can be configured.
Plugins need to implement the WUPS_GET_CONFIG() hook to show up in the menu. 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. 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(); static void openConfigMenu();
@ -66,7 +72,7 @@ private:
default value. This behaviour may change in the future. default value. This behaviour may change in the future.
See the ConfigInformation class for more information. See the ConfigInformation class for more information.
**/ **/
static std::vector<ConfigInformation *> getConfigInformation(); static std::vector<ConfigInformation *> getConfigInformation();
/** /**
Delete a list of ConfigInformation. Delete a list of ConfigInformation.

View File

@ -29,6 +29,7 @@ DECL(uint32_t, ProcUIProcessMessages, uint32_t u) {
CallHook(WUPS_LOADER_HOOK_APP_STATUS_CHANGED); CallHook(WUPS_LOADER_HOOK_APP_STATUS_CHANGED);
if(gAppStatus == WUPS_APP_STATUS_CLOSED) { if(gAppStatus == WUPS_APP_STATUS_CLOSED) {
CallHook(WUPS_LOADER_HOOK_ENDING_APPLICATION); CallHook(WUPS_LOADER_HOOK_ENDING_APPLICATION);
ConfigUtils::saveConfigToSD();
DeInit(); DeInit();
} }
} }

View File

@ -181,7 +181,7 @@ bool ConfigSettings::Reset() {
this->SetDefault(); this->SetDefault();
bChanged = true; bChanged = true;
if (this->Save()) { if (this->Save(true)) {
return true; return true;
} }
@ -197,8 +197,8 @@ int32_t ConfigSettings::getIdByName(std::string configID) {
return -1; return -1;
} }
bool ConfigSettings::Save() { bool ConfigSettings::Save(bool force) {
if(!bChanged) { if(!force && !bChanged) {
DEBUG_FUNCTION_LINE("Nothing has changed, we can skip\n"); DEBUG_FUNCTION_LINE("Nothing has changed, we can skip\n");
return true; return true;
} }

View File

@ -37,7 +37,7 @@ public:
//!Load Settings //!Load Settings
bool Load(); bool Load();
//!Save Settings //!Save Settings
bool Save(); bool Save(bool force);
//!Reset Settings //!Reset Settings
bool Reset(); bool Reset();