From becb99cdd3e540c126508b023d8b1f248345c1c8 Mon Sep 17 00:00:00 2001 From: StackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com> Date: Mon, 9 Mar 2020 16:25:56 +0100 Subject: [PATCH] Only save config if changes are made. --- source/init.cpp | 7 ++++++- source/screens/scriptlist.cpp | 3 +++ source/screens/settings.cpp | 15 ++++++++++++++- source/screens/unistore.cpp | 4 +++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/source/init.cpp b/source/init.cpp index bd91466..a321299 100644 --- a/source/init.cpp +++ b/source/init.cpp @@ -51,6 +51,7 @@ sound *bgm = NULL; bool songIsFound = false; bool UniStoreAutoboot = false; int AutobootWhat = 0; // 0 -> MainMenu ; 1 -> Store; 2 -> Script. +bool changesMade = false; // Include all spritesheet's. C2D_SpriteSheet sprites; @@ -193,7 +194,11 @@ Result Init::Exit() { // Free UniStore spritesheet, just in case. freeSheet(); - Config::save(); + // Only save config, if *any* changes are made. (To reduce SD Writes.) + if (changesMade) { + Config::save(); + } + Gui::exit(); Gui::unloadSheet(sprites); gfxExit(); diff --git a/source/screens/scriptlist.cpp b/source/screens/scriptlist.cpp index 6086383..76ccd81 100644 --- a/source/screens/scriptlist.cpp +++ b/source/screens/scriptlist.cpp @@ -40,6 +40,7 @@ extern bool checkWifiStatus(void); extern void notImplemented(void); bool isScriptSelected = false; +extern bool changesMade; // Parse the script for the list. ScriptInfo parseInfo(std::string fileName) { @@ -395,6 +396,7 @@ void ScriptList::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), {}); if (tempScript != "") { Config::ScriptPath = tempScript; + changesMade = true; } break; } @@ -430,6 +432,7 @@ void ScriptList::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), {}); if (tempScript != "") { Config::ScriptPath = tempScript; + changesMade = true; } } } diff --git a/source/screens/settings.cpp b/source/screens/settings.cpp index 2bc023e..0868b54 100644 --- a/source/screens/settings.cpp +++ b/source/screens/settings.cpp @@ -31,6 +31,7 @@ extern bool touching(touchPosition touch, Structs::ButtonPos button); int selectedLang; +extern bool changesMade; Settings::Settings() { selectedLang = Config::lang; @@ -220,10 +221,12 @@ void Settings::MiscSettingsLogic(u32 hDown, u32 hHeld, touchPosition touch) { std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), {"wav"}, 2); if (tempMusic != "") { Config::MusicPath = tempMusic; + changesMade = true; } } else if (Selection == 1) { if (Config::UseBars == true) Config::UseBars = false; else if (Config::UseBars == false) Config::UseBars = true; + changesMade = true; } else if (Selection == 2) { if (Msg::promptMsg(Lang::get("ENABLE_GODMODE_PROMPT"))) { Config::GodMode = true; @@ -236,10 +239,12 @@ void Settings::MiscSettingsLogic(u32 hDown, u32 hHeld, touchPosition touch) { std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), {"wav"}, 2); if (tempMusic != "") { Config::MusicPath = tempMusic; + changesMade = true; } } else if (touching(touch, mainButtons[1])) { if (Config::UseBars == true) Config::UseBars = false; else if (Config::UseBars == false) Config::UseBars = true; + changesMade = true; } else if (touching(touch, mainButtons[2])) { if (Msg::promptMsg(Lang::get("ENABLE_GODMODE_PROMPT"))) { Config::GodMode = true; @@ -273,7 +278,7 @@ void Settings::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { mode = 1; } else if (touching(touch, mainButtons[1])) { mode = 2; - } else if (touching(touch, mainButtons[2])) { + } else if (touching(touch, mainButtons[2])) { Gui::setScreen(std::make_unique()); } } @@ -297,6 +302,7 @@ void Settings::LanguageSelection(u32 hDown, touchPosition touch) { selectedLang = language; Config::lang = language; Lang::load(Config::lang); + changesMade = true; } } } @@ -306,6 +312,7 @@ void Settings::LanguageSelection(u32 hDown, touchPosition touch) { selectedLang--; Config::lang = selectedLang; Lang::load(Config::lang); + changesMade = true; } } @@ -314,6 +321,7 @@ void Settings::LanguageSelection(u32 hDown, touchPosition touch) { selectedLang++; Config::lang = selectedLang; Lang::load(Config::lang); + changesMade = true; } } @@ -323,6 +331,7 @@ void Settings::LanguageSelection(u32 hDown, touchPosition touch) { selectedLang -= 5; Config::lang = selectedLang; Lang::load(Config::lang); + changesMade = true; } } @@ -331,6 +340,7 @@ void Settings::LanguageSelection(u32 hDown, touchPosition touch) { selectedLang += 5; Config::lang = selectedLang; Lang::load(Config::lang); + changesMade = true; } } @@ -386,6 +396,7 @@ void Settings::colorChanging(u32 hDown, touchPosition touch) { } else if (colorMode == 6) { Config::progressbarColor = RGBA8(red, ColorHelper::getColorValue(Config::progressbarColor, 1), ColorHelper::getColorValue(Config::progressbarColor, 0), 255); } + changesMade = true; } @@ -408,6 +419,7 @@ void Settings::colorChanging(u32 hDown, touchPosition touch) { } else if (colorMode == 6) { Config::progressbarColor = RGBA8(ColorHelper::getColorValue(Config::progressbarColor, 2), green, ColorHelper::getColorValue(Config::progressbarColor, 0), 255); } + changesMade = true; } } else if (touching(touch, buttons[2])) { int temp = Input::getUint(255, Lang::get("ENTER_BLUE_RGB")); @@ -428,6 +440,7 @@ void Settings::colorChanging(u32 hDown, touchPosition touch) { } else if (colorMode == 6) { Config::progressbarColor = RGBA8(ColorHelper::getColorValue(Config::progressbarColor, 2), ColorHelper::getColorValue(Config::progressbarColor, 1), blue, 255); } + changesMade = true; } } } diff --git a/source/screens/unistore.cpp b/source/screens/unistore.cpp index 17ed589..407dc74 100644 --- a/source/screens/unistore.cpp +++ b/source/screens/unistore.cpp @@ -49,7 +49,7 @@ extern u32 selected; extern u32 unselected; extern int AutobootWhat; bool changeBackState = false; - +extern bool changesMade; C2D_SpriteSheet appStoreSheet; // Parse informations like URL, Title, Author, Description. @@ -515,6 +515,7 @@ void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), {}); if (tempStore != "") { Config::StorePath = tempStore; + changesMade = true; } break; } @@ -549,6 +550,7 @@ void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), {}); if (tempStore != "") { Config::StorePath = tempStore; + changesMade = true; } } }