Browse Source

Change user dir on Linux to $XDG_DATA_HOME/Rack2. Move old dir and show dialog.

tags/v2.5.0
Andrew Belt 7 months ago
parent
commit
1d5bf2f4be
2 changed files with 50 additions and 25 deletions
  1. +1
    -12
      adapters/standalone.cpp
  2. +49
    -13
      src/asset.cpp

+ 1
- 12
adapters/standalone.cpp View File

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


+ 49
- 13
src/asset.cpp View File

@@ -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() {


Loading…
Cancel
Save