Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
[CONFIG] Only load values from the SD Card at the beginning. Add a sa…
Browse files Browse the repository at this point in the history
…ve to SD card when existing a application.
  • Loading branch information
Maschell committed Feb 7, 2019
1 parent 993b328 commit e6f246b
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/myutils/ConfigInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions src/myutils/ConfigInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ class ConfigInformation {

/**
Deletes the given WUPSConfig
Calls updateAndSaveSettings
Deletes the created ConfigSettings
**/
~ConfigInformation();

void updateAndSaveSettings();
void updateAndSaveSettings(bool forceAll);

bool loadValuesFromSD();

WUPSConfig * getConfig() {
return config;
}

private:
bool createConfigSettings();
bool loadValuesFromSD();
bool updateConfigSettings();

WUPSConfig * config = NULL;
Expand Down
29 changes: 28 additions & 1 deletion src/myutils/ConfigUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -363,6 +386,10 @@ void ConfigUtils::openConfigMenu() {
for (auto & curConfig : configs) {
DCFlushRange(curConfig, sizeof(WUPSConfig));
}

for (auto & curConfig : configInfos) {
curConfig->updateAndSaveSettings(false);
}

deleteConfigInformation(configInfos);
}
12 changes: 9 additions & 3 deletions src/myutils/ConfigUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -66,7 +72,7 @@ class ConfigUtils {
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.
Expand Down
1 change: 1 addition & 0 deletions src/patcher/hooks_patcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/settings/ConfigSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ bool ConfigSettings::Reset() {
this->SetDefault();
bChanged = true;

if (this->Save()) {
if (this->Save(true)) {
return true;
}

Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/settings/ConfigSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ConfigSettings {
//!Load Settings
bool Load();
//!Save Settings
bool Save();
bool Save(bool force);
//!Reset Settings
bool Reset();

Expand Down

0 comments on commit e6f246b

Please sign in to comment.