[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->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() {

View File

@ -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;

View File

@ -342,11 +342,34 @@ void ConfigUtils::deleteConfigInformation(std::vector<ConfigInformation *> confi
}
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() {
std::vector<ConfigInformation *> configInfos = getConfigInformation();
// We rely on the default values here.
//if(loadFromSD){
// for (auto & curConfig : configInfos) {
// configs.loadValuesFromSD();
// }
//}
std::vector<WUPSConfig *> 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);
}

View File

@ -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<ConfigInformation *> getConfigInformation();
static std::vector<ConfigInformation *> getConfigInformation();
/**
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);
if(gAppStatus == WUPS_APP_STATUS_CLOSED) {
CallHook(WUPS_LOADER_HOOK_ENDING_APPLICATION);
ConfigUtils::saveConfigToSD();
DeInit();
}
}

View File

@ -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;
}

View File

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