From f2c4846dcef9c87f86db2442b5cfa53034e9594d Mon Sep 17 00:00:00 2001 From: Hombre Date: Wed, 5 Feb 2014 18:29:23 +0100 Subject: [PATCH] Solving issue 2221: "Specifying the Settings and Cache path through environment variables" --- rtgui/main.cc | 8 +++++- rtgui/options.cc | 61 +++++++++++++++++++++++++++++-------------- rtgui/options.h | 2 +- rtgui/profilestore.cc | 3 +++ 4 files changed, 52 insertions(+), 22 deletions(-) diff --git a/rtgui/main.cc b/rtgui/main.cc index f0daad6ac..0e86fd0fc 100644 --- a/rtgui/main.cc +++ b/rtgui/main.cc @@ -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(); diff --git a/rtgui/options.cc b/rtgui/options.cc index 548e9f9e5..21be54704 100644 --- a/rtgui/options.cc +++ b/rtgui/options.cc @@ -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 () { diff --git a/rtgui/options.h b/rtgui/options.h index e77f98e22..070b726a9 100644 --- a/rtgui/options.h +++ b/rtgui/options.h @@ -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 diff --git a/rtgui/profilestore.cc b/rtgui/profilestore.cc index 6541e10ba..a2e4b0419 100644 --- a/rtgui/profilestore.cc +++ b/rtgui/profilestore.cc @@ -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);