From 449502977cc032022cd735b41fec2cf2a23fe3d4 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 30 Apr 2024 04:50:15 -0400 Subject: [PATCH] After moving user dir, update recent patches inside old user dir to new dir. --- include/asset.hpp | 1 + src/asset.cpp | 11 +++++++---- src/settings.cpp | 8 ++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/asset.hpp b/include/asset.hpp index e5482498..fb0cb171 100644 --- a/include/asset.hpp +++ b/include/asset.hpp @@ -39,6 +39,7 @@ std::string plugin(plugin::Plugin* plugin, std::string filename = ""); // Set these before calling init() to override the default paths extern std::string systemDir; extern std::string userDir; +extern std::string oldUserDir; // Only defined on Mac extern std::string bundlePath; diff --git a/src/asset.cpp b/src/asset.cpp index df820239..6611239c 100644 --- a/src/asset.cpp +++ b/src/asset.cpp @@ -105,8 +105,6 @@ static void initUserDir() { return; } - std::string oldUserDir; - #if defined ARCH_WIN // Get AppData/Local path WCHAR localBufW[MAX_PATH] = {}; @@ -166,7 +164,7 @@ static void initUserDir() { #endif // If userDir doesn't exist but oldUserDir does, attempt to move it and inform user. - if (!oldUserDir.empty() && !system::isDirectory(userDir) && system::isDirectory(oldUserDir)) { + if (oldUserDir != "" && !system::isDirectory(userDir) && system::isDirectory(oldUserDir)) { if (system::rename(oldUserDir, userDir)) { std::string msg = APP_NAME + "'s user folder has been moved from"; msg += "\n" + oldUserDir; @@ -179,12 +177,16 @@ static void initUserDir() { msg += "\n" + oldUserDir; msg += "\nto"; msg += "\n" + userDir; - msg += "\ndue to insufficient access permissions. Consider moving this folder manually to ensure compatibility with future versions."; + msg += "\nConsider moving this folder manually to ensure compatibility with future versions."; osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, msg.c_str()); // Move failed, just use the old dir instead userDir = oldUserDir; + oldUserDir = ""; } } + else { + oldUserDir = ""; + } // Create user dir if it doesn't exist system::createDirectory(userDir); @@ -215,6 +217,7 @@ std::string plugin(plugin::Plugin* plugin, std::string filename) { std::string systemDir; std::string userDir; +std::string oldUserDir; std::string bundlePath; diff --git a/src/settings.cpp b/src/settings.cpp index c75bac99..361d7124 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -416,6 +416,14 @@ void fromJson(json_t* rootJ) { recentPatchPaths.push_back(path); } } + // Update recent patches to use new dir + if (asset::oldUserDir != "") { + for (std::string& path : recentPatchPaths) { + if (string::startsWith(path, asset::oldUserDir)) { + path.replace(0, asset::oldUserDir.size(), asset::userDir); + } + } + } cableColors.clear(); json_t* cableColorsJ = json_object_get(rootJ, "cableColors");