summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Belt <andrewpbelt@gmail.com>2024-04-30 04:50:15 -0400
committerAndrew Belt <andrewpbelt@gmail.com>2024-04-30 04:50:15 -0400
commit449502977cc032022cd735b41fec2cf2a23fe3d4 (patch)
tree3a1702141ae3cfdde45ab2079da7ce2aa28230db
parent45113452eb9b61650c3c08fe02a5663bf12696c8 (diff)
After moving user dir, update recent patches inside old user dir to new dir.
-rw-r--r--include/asset.hpp1
-rw-r--r--src/asset.cpp11
-rw-r--r--src/settings.cpp8
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");