Solving issue 2221: "Specifying the Settings and Cache path through environment variables"

This commit is contained in:
Hombre
2014-02-05 18:29:23 +01:00
parent aa986a4c76
commit f2c4846dce
4 changed files with 52 additions and 22 deletions

View File

@@ -140,7 +140,13 @@ int main(int argc, char **argv)
mainThread = Glib::Thread::self();
Options::load ();
if (!Options::load ()) {
Gtk::Main m(&argc, &argv);
Gtk::MessageDialog msgd ("Fatal error!\nThe RT_SETTINGS and/or RT_PATH environment variables are set, but use a relative path. The path must be absolute!", true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
msgd.run ();
return -2;
}
extProgStore->init();
SoundManager::init();

View File

@@ -1094,28 +1094,34 @@ int Options::saveToFile (Glib::ustring fname) {
}
}
void Options::load () {
bool Options::load () {
// Find the application data path
// Find the application data path
#ifdef WIN32
const gchar* dataPath;
Glib::ustring dPath;
const gchar* path;
Glib::ustring dPath;
dataPath = g_getenv("RT_CACHE");
if (dataPath != NULL)
rtdir = Glib::ustring(dataPath);
else {
path = g_getenv("RT_SETTINGS");
if (path != NULL) {
rtdir = Glib::ustring(path);
if (!Glib::path_is_absolute(rtdir))
return false;
}
else {
#ifdef WIN32
WCHAR pathW[MAX_PATH]={0}; char pathA[MAX_PATH];
if (SHGetSpecialFolderPathW(NULL,pathW,CSIDL_LOCAL_APPDATA,false)) {
WideCharToMultiByte(CP_UTF8,0,pathW,-1,pathA,MAX_PATH,0,0);
rtdir = Glib::build_filename(Glib::ustring(pathA), Glib::ustring(CACHEFOLDERNAME));
}
}
#else
rtdir = Glib::build_filename(Glib::ustring(g_get_user_config_dir ()), Glib::ustring(CACHEFOLDERNAME));
#endif
}
#else
rtdir = Glib::build_filename(Glib::ustring(g_get_user_config_dir ()), Glib::ustring(CACHEFOLDERNAME));
#endif
}
if (options.rtSettings.verbose)
printf("Settings directory (rtdir) = %s\n", rtdir.c_str());
// Set the cache folder in RT's base folder
cacheBaseDir = Glib::build_filename(argv0, "cache");
@@ -1123,6 +1129,22 @@ void Options::load () {
// Read the global option file (the one located in the application's base folder)
options.readFromFile (Glib::build_filename(argv0, "options"));
// Modify the path of the cache folder to the one provided in RT_CACHE environment variable
path = g_getenv("RT_CACHE");
if (path != NULL) {
cacheBaseDir = Glib::ustring(path);
if (!Glib::path_is_absolute(cacheBaseDir))
return false;
}
// No environment variable provided, so falling back to the multi user mode, is enabled
else if (options.multiUser) {
#ifdef WIN32
cacheBaseDir = Glib::build_filename(rtdir, "cache");
#else
cacheBaseDir = Glib::build_filename(Glib::ustring(g_get_user_cache_dir()), Glib::ustring(CACHEFOLDERNAME));
#endif
}
// Check if RT is installed in Multi-User mode
if (options.multiUser) {
// Read the user option file (the one located somewhere in the user's home folder)
@@ -1133,12 +1155,6 @@ void Options::load () {
// Save the option file
options.saveToFile (Glib::build_filename(rtdir, "options"));
}
// Modify the path of the cache folder to the user's personal folder
#ifdef WIN32
cacheBaseDir = Glib::build_filename(rtdir, "cache");
#else
cacheBaseDir = Glib::build_filename(Glib::ustring(g_get_user_cache_dir()), Glib::ustring(CACHEFOLDERNAME));
#endif
#ifdef __APPLE__
// make sure .local/share exists on OS X so we don't get problems with recently-used.xbel
@@ -1146,6 +1162,9 @@ void Options::load () {
#endif
}
if (options.rtSettings.verbose)
printf("Cache directory (cacheBaseDir) = %s\n", cacheBaseDir.c_str());
// Update profile's path and recreate it if necessary
options.updatePaths();
@@ -1212,6 +1231,8 @@ void Options::load () {
langMgr.load(localeTranslation, new MultiLangMgr(languageTranslation, new MultiLangMgr(defaultTranslation)));
rtengine::init (&options.rtSettings, argv0, rtdir);
return true;
}
void Options::save () {

View File

@@ -266,7 +266,7 @@ class Options {
void setDefaults ();
int readFromFile (Glib::ustring fname);
int saveToFile (Glib::ustring fname);
static void load ();
static bool load ();
static void save ();
// if multiUser=false, send back the global profile path

View File

@@ -46,6 +46,9 @@ bool ProfileStore::init () {
ProfileStore::~ProfileStore () {
if (storeState == STORESTATE_NOTINITIALIZED)
return;
// This lock prevent object's suppression while scanning the directories
storeState = STORESTATE_DELETED;
MyMutex::MyLock lock(*parseMutex);