From 444af8c46aa588c8d21f1efe61624008cfc7b865 Mon Sep 17 00:00:00 2001 From: divverent Date: Thu, 2 Apr 2009 17:07:17 +0000 Subject: [PATCH] "Portable" Radiant support: when a subdirectory "settings" of the directory with radiant.exe exists, the configuration data is stored in there. git-svn-id: svn://svn.icculus.org/netradiant/trunk@242 61c419a2-8eb2-4b30-bcec-8cead039b335 --- radiant/environment.cpp | 60 +++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/radiant/environment.cpp b/radiant/environment.cpp index 16aba7f7..58a405dd 100644 --- a/radiant/environment.cpp +++ b/radiant/environment.cpp @@ -163,6 +163,17 @@ const char* environment_get_app_path() return app_path.c_str(); } +bool portable_app_setup() +{ + StringOutputStream confdir(256); + confdir << app_path.c_str() << "settings/"; + if(file_exists(confdir.c_str())) + { + home_path = confdir.c_str(); + return true; + } + return false; +} #if defined(POSIX) @@ -226,17 +237,19 @@ void environment_init(int argc, char* argv[]) args_init(argc, argv); + { + char real[PATH_MAX]; + app_path = getexename(real); + ASSERT_MESSAGE(!string_empty(app_path.c_str()), "failed to deduce app path"); + } + + if(!portable_app_setup()) { StringOutputStream home(256); home << DirectoryCleaned(g_get_home_dir()) << ".netradiant/"; Q_mkdir(home.c_str()); home_path = home.c_str(); } - { - char real[PATH_MAX]; - app_path = getexename(real); - ASSERT_MESSAGE(!string_empty(app_path.c_str()), "failed to deduce app path"); - } gamedetect(); } @@ -248,24 +261,6 @@ void environment_init(int argc, char* argv[]) { args_init(argc, argv); - { - char *appdata = getenv("APPDATA"); - - StringOutputStream home(256); - if(!appdata || string_empty(appdata)) - { - ERROR_MESSAGE("Application Data folder not available.\n" - "Radiant will use C:\\ for user preferences.\n"); - home << "C:"; - } - else - { - home << PathCleaned(appdata); - } - home << "/NetRadiantSettings/"; - Q_mkdir(home.c_str()); - home_path = home.c_str(); - } { // get path to the editor char filename[MAX_PATH+1]; @@ -283,6 +278,25 @@ void environment_init(int argc, char* argv[]) app << PathCleaned(filename); app_path = app.c_str(); } + + if(!portable_app_setup()) + { + char *appdata = getenv("APPDATA"); + StringOutputStream home(256); + if(!appdata || string_empty(appdata)) + { + ERROR_MESSAGE("Application Data folder not available.\n" + "Radiant will use C:\\ for user preferences.\n"); + home << "C:"; + } + else + { + home << PathCleaned(appdata); + } + home << "/NetRadiantSettings/"; + Q_mkdir(home.c_str()); + home_path = home.c_str(); + } gamedetect(); } -- 2.39.2