From cae6dc51602359b9975d1a751ff17094ca21e3df Mon Sep 17 00:00:00 2001 From: StackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com> Date: Thu, 26 Mar 2020 23:11:42 +0100 Subject: [PATCH] Properly refresh `SelectFilePath(...);`. --- include/utils/fileBrowse.hpp | 2 +- source/screens/scriptCreator.cpp | 2 +- source/screens/scriptlist.cpp | 4 ++-- source/screens/settings.cpp | 4 ++-- source/screens/unistore.cpp | 4 ++-- source/utils/fileBrowse.cpp | 20 +++++++++++++++----- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/utils/fileBrowse.hpp b/include/utils/fileBrowse.hpp index a38a7e8..70cbebe 100644 --- a/include/utils/fileBrowse.hpp +++ b/include/utils/fileBrowse.hpp @@ -22,7 +22,7 @@ std::vector getContents(const std::string &name, const std::vector< bool returnIfExist(const std::string &path, const std::vector &extensionList); -std::string selectFilePath(std::string selectText, const std::vector &extensionList, int selectionMode = 1); +std::string selectFilePath(std::string selectText, std::string initialPath, const std::vector &extensionList, int selectionMode = 1); void dirCopy(DirEntry* entry, int i, const char *destinationPath, const char *sourcePath); int fcopy(const char *sourcePath, const char *destinationPath); diff --git a/source/screens/scriptCreator.cpp b/source/screens/scriptCreator.cpp index c68e919..46fdcfb 100644 --- a/source/screens/scriptCreator.cpp +++ b/source/screens/scriptCreator.cpp @@ -303,7 +303,7 @@ void ScriptCreator::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { } break; case 1: - std::string tempScript = selectFilePath("Select the Script file.", {"json"}, 2); + std::string tempScript = selectFilePath("Select the Script file.", Config::ScriptPath, {"json"}, 2); if (tempScript != "") { jsonFileName = tempScript; if(access(jsonFileName.c_str(), F_OK) != -1 ) { diff --git a/source/screens/scriptlist.cpp b/source/screens/scriptlist.cpp index da22d5e..82c1b7f 100644 --- a/source/screens/scriptlist.cpp +++ b/source/screens/scriptlist.cpp @@ -431,7 +431,7 @@ void ScriptList::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { } break; case 3: - std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), {}); + std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), Config::ScriptPath, {}); if (tempScript != "") { Config::ScriptPath = tempScript; changesMade = true; @@ -467,7 +467,7 @@ void ScriptList::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { notImplemented(); } } else if (touching(touch, subPos[3])) { - std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), {}); + std::string tempScript = selectFilePath(Lang::get("SELECT_SCRIPT_PATH"), Config::ScriptPath, {}); if (tempScript != "") { Config::ScriptPath = tempScript; changesMade = true; diff --git a/source/screens/settings.cpp b/source/screens/settings.cpp index d3ba732..b110059 100644 --- a/source/screens/settings.cpp +++ b/source/screens/settings.cpp @@ -246,7 +246,7 @@ void Settings::MiscSettingsLogic(u32 hDown, u32 hHeld, touchPosition touch) { if (hDown & KEY_A) { if (Selection == 0) { - std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), {"wav"}, 2); + std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), "sdmc:/", {"wav"}, 2); if (tempMusic != "") { Config::MusicPath = tempMusic; changesMade = true; @@ -264,7 +264,7 @@ void Settings::MiscSettingsLogic(u32 hDown, u32 hHeld, touchPosition touch) { if (hDown & KEY_TOUCH) { if (touching(touch, mainButtons[0])) { - std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), {"wav"}, 2); + std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), "sdmc:/", {"wav"}, 2); if (tempMusic != "") { Config::MusicPath = tempMusic; changesMade = true; diff --git a/source/screens/unistore.cpp b/source/screens/unistore.cpp index 4a30e06..558d8ab 100644 --- a/source/screens/unistore.cpp +++ b/source/screens/unistore.cpp @@ -549,7 +549,7 @@ void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { } break; case 2: - std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), {}); + std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), Config::StorePath, {}); if (tempStore != "") { Config::StorePath = tempStore; changesMade = true; @@ -584,7 +584,7 @@ void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { notConnectedMsg(); } } else if (touching(touch, subPos[2])) { - std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), {}); + std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), Config::StorePath, {}); if (tempStore != "") { Config::StorePath = tempStore; changesMade = true; diff --git a/source/utils/fileBrowse.cpp b/source/utils/fileBrowse.cpp index 9e9593e..f3c6c78 100644 --- a/source/utils/fileBrowse.cpp +++ b/source/utils/fileBrowse.cpp @@ -141,17 +141,27 @@ bool returnIfExist(const std::string &path, const std::vector &exte // returns a Path or file to 'std::string'. // selectText is the Text which is displayed on the bottom bar of the top screen. // selectionMode is how you select it. 1 -> Path, 2 -> File. -std::string selectFilePath(std::string selectText, const std::vector &extensionList, int selectionMode) { - static uint selectedFile = 0; +std::string selectFilePath(std::string selectText, std::string initialPath, const std::vector &extensionList, int selectionMode) { + uint selectedFile = 0; std::string selectedPath = ""; - static int keyRepeatDelay = 4; - static bool dirChanged = true; - static bool fastMode = false; + int keyRepeatDelay = 4; + bool dirChanged = true; + bool fastMode = false; uint screenPos = 0; uint screenPosList = 0; std::vector dirContents; std::string dirs; + // Initial dir change. + dirContents.clear(); + chdir(initialPath.c_str()); + std::vector dirContentsTemp; + getDirectoryContents(dirContentsTemp, extensionList); + for(uint i=0;i