X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fenvironment.cpp;h=040335794d339fd627ce91c0924e804243883823;hb=7343cc1f7e4f83384fa175cb6c321cdaaea05265;hp=0656f8db8c447e1e07af85b04c5bb45d13df52a2;hpb=e647ac225ff9ac442dd1e6cd0aa7096299cc0418;p=xonotic%2Fnetradiant.git diff --git a/radiant/environment.cpp b/radiant/environment.cpp index 0656f8db..04033579 100644 --- a/radiant/environment.cpp +++ b/radiant/environment.cpp @@ -79,6 +79,28 @@ void gamedetect_found_game(char *game, char *path) g_argv = gamedetect_argv_buffer; } +bool gamedetect_check_game(char *gamefile, const char *checkfile1, const char *checkfile2, char *buf /* must have 64 bytes free after bufpos */, int bufpos) +{ + buf[bufpos] = '/'; + + strcpy(buf + bufpos + 1, checkfile1); + globalOutputStream() << "Checking for a game file in " << buf << "\n"; + if(!file_exists(buf)) + return false; + + if(checkfile2) + { + strcpy(buf + bufpos + 1, checkfile2); + globalOutputStream() << "Checking for a game file in " << buf << "\n"; + if(!file_exists(buf)) + return false; + } + + buf[bufpos + 1] = 0; + gamedetect_found_game(gamefile, buf); + return true; +} + void gamedetect() { // if we're inside a Nexuiz install @@ -104,25 +126,24 @@ void gamedetect() while(p != buf) { // TODO add more games to this + // try to detect Nexuiz installs - strcpy(p, "/data/common-spog.pk3"); - globalOutputStream() << "Checking for a game file in " << buf << "\n"; - if(file_exists(buf)) - { #if defined(WIN32) - strcpy(p, "/nexuiz.exe"); + if(gamedetect_check_game("nexuiz.game", "data/common-spog.pk3", "nexuiz.exe", buf, p - buf)) #elif defined(__APPLE__) - strcpy(p, "/Nexuiz.app/Contents/Info.plist"); + if(gamedetect_check_game("nexuiz.game", "data/common-spog.pk3", "Nexuiz.app/Contents/Info.plist", buf, p - buf)) #else - strcpy(p, "/nexuiz-linux-glx.sh"); + if(gamedetect_check_game("nexuiz.game", "data/common-spog.pk3", "nexuiz-linux-glx.sh", buf, p - buf)) #endif - if(file_exists(buf)) - { - p[1] = 0; - gamedetect_found_game("nexuiz.game", buf); - return; - } - } + return; + + // try to detect Q2World installs + if(gamedetect_check_game("q2w.game", "default/quake2world.version", NULL, buf, p - buf)) + return; + + // try to detect Warsow installs + if(gamedetect_check_game("warsow.game", "basewsw/dedicated_autoexec.cfg", NULL, buf, p - buf)) + return; // we found nothing // go backwards @@ -149,6 +170,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) @@ -212,17 +244,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(); } @@ -234,24 +268,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]; @@ -269,6 +285,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(); }