Browse Source

After moving user dir, update recent patches inside old user dir to new dir.

tags/v2.5.2
Andrew Belt 6 months ago
parent
commit
449502977c
3 changed files with 16 additions and 4 deletions
  1. +1
    -0
      include/asset.hpp
  2. +7
    -4
      src/asset.cpp
  3. +8
    -0
      src/settings.cpp

+ 1
- 0
include/asset.hpp View File

@@ -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;



+ 7
- 4
src/asset.cpp View File

@@ -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;



+ 8
- 0
src/settings.cpp View File

@@ -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");


Loading…
Cancel
Save