summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Belt <andrewpbelt@gmail.com>2024-04-02 19:35:45 -0400
committerAndrew Belt <andrewpbelt@gmail.com>2024-04-02 19:35:45 -0400
commit1d5bf2f4be82d346dfcc1b3ac5fdd9c2dd001d7f (patch)
treea68680b88436f3c8ac062ba6205a1763490a6b29
parent584f939f4d3befff9d1581cfcd75b1c4129f5484 (diff)
Change user dir on Linux to $XDG_DATA_HOME/Rack2. Move old dir and show dialog.
-rw-r--r--adapters/standalone.cpp13
-rw-r--r--src/asset.cpp62
2 files changed, 50 insertions, 25 deletions
diff --git a/adapters/standalone.cpp b/adapters/standalone.cpp
index e62153c2..720b4876 100644
--- a/adapters/standalone.cpp
+++ b/adapters/standalone.cpp
@@ -134,18 +134,7 @@ int main(int argc, char* argv[]) {
if (!settings::devMode) {
logger::logPath = asset::user("log.txt");
}
- if (!logger::init()) {
- std::string msg = "Cannot access VCV Rack's user folder:";
- msg += "\n" + asset::userDir;
-#if defined ARCH_MAC
- // The user likely clicked "Don't Allow" on the Documents Folder permissions dialog, so tell them how to allow it.
- msg += "\n\nGive permission to VCV Rack by opening Apple's System Settings and enabling Privacy & Security > Files and Folders > " + APP_NAME + " " + APP_VERSION_MAJOR + " " + APP_EDITION_NAME + " > Documents Folder.";
- // Launch Apple's Privacy & Security settings
- // std::system("open x-apple.systempreferences:com.apple.preference.security");
-#endif
- osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, msg.c_str());
- exit(1);
- }
+ logger::init();
random::init();
// Test code
diff --git a/src/asset.cpp b/src/asset.cpp
index 33bf2612..40fdda4f 100644
--- a/src/asset.cpp
+++ b/src/asset.cpp
@@ -23,6 +23,7 @@
#include <plugin/Plugin.hpp>
#include <engine/Module.hpp>
#include <app/common.hpp>
+#include <osdialog.h>
namespace rack {
@@ -39,9 +40,9 @@ static void initSystemDir() {
}
// Environment variable overrides
- const char* env = getenv("RACK_SYSTEM_DIR");
- if (env) {
- systemDir = env;
+ const char* envSystem = getenv("RACK_SYSTEM_DIR");
+ if (envSystem) {
+ systemDir = envSystem;
return;
}
@@ -93,35 +94,70 @@ static void initUserDir() {
}
// Environment variable overrides
- const char* env = getenv("RACK_USER_DIR");
- if (env) {
- userDir = env;
+ const char* envUser = getenv("RACK_USER_DIR");
+ if (envUser) {
+ userDir = envUser;
return;
}
+ std::string oldUserDir;
+
#if defined ARCH_WIN
// Get "My Documents" path
wchar_t documentsBufW[MAX_PATH] = L".";
HRESULT result = SHGetFolderPathW(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsBufW);
assert(result == S_OK);
- userDir = system::join(string::UTF16toUTF8(documentsBufW), "Rack" + APP_VERSION_MAJOR);
+
+ // Rack <2.5.0 used "My Documents/Rack2"
+ oldUserDir = system::join(string::UTF16toUTF8(documentsBufW), "Rack" + APP_VERSION_MAJOR);
+
+ // TODO new userDir
#endif
+
#if defined ARCH_MAC
// Get home directory
struct passwd* pw = getpwuid(getuid());
assert(pw);
- userDir = system::join(pw->pw_dir, "Documents", "Rack" + APP_VERSION_MAJOR);
+
+ // Rack <2.5.0 used ~/Documents/Rack2
+ oldUserDir = system::join(pw->pw_dir, "Documents", "Rack" + APP_VERSION_MAJOR);
+
+ // TODO new userDir
#endif
+
#if defined ARCH_LIN
- // Get home directory
- const char* homeBuf = getenv("HOME");
- if (!homeBuf) {
+ // Get home path
+ const char* envHome = getenv("HOME");
+ if (!envHome) {
struct passwd* pw = getpwuid(getuid());
assert(pw);
- homeBuf = pw->pw_dir;
+ envHome = pw->pw_dir;
+ }
+ std::string homeDir = envHome;
+
+ // Get XDG data path
+ const char* envData = getenv("XDG_DATA_HOME");
+ if (envData) {
+ userDir = envData;
+ }
+ else {
+ userDir = system::join(homeDir, ".local", "share");
}
- userDir = system::join(homeBuf, ".Rack" + APP_VERSION_MAJOR);
+ userDir = system::join(userDir, "Rack" + APP_VERSION_MAJOR);
+
+ // Rack <2.5.0 used ~/.Rack2
+ oldUserDir = system::join(homeDir, ".Rack" + APP_VERSION_MAJOR);
#endif
+
+ // If userDir doesn't exist but oldUserDir does, move it.
+ if (!system::isDirectory(userDir) && system::isDirectory(oldUserDir)) {
+ std::string msg = "Your Rack user folder has been moved from";
+ msg += "\n" + oldUserDir;
+ msg += "\nto";
+ msg += "\n" + userDir;
+ osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, msg.c_str());
+ system::rename(oldUserDir, userDir);
+ }
}
void init() {