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
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
--p;
- while(p != buf && *p != '/')
+ while(p != buf && *p != '/' && *p != '\\')
--p;
}
}
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)
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();
}
{
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];
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();
}