bool Sys_GetPath(sysPath_t type, idStr &path) { char buf[MAX_OSPATH]; struct _stat st; idStr s; switch(type) { case PATH_BASE: // try <path to exe>/base first if (Sys_GetPath(PATH_EXE, path)) { path.StripFilename(); s = path; s.AppendPath(BASE_GAMEDIR); if (_stat(s.c_str(), &st) != -1 && st.st_mode & _S_IFDIR) return true; common->Warning("base path '%s' does not exits", s.c_str()); } // fallback to vanilla doom3 cd install if (GetRegistryPath(buf, sizeof(buf), L"SOFTWARE\\id\\Doom 3", L"InstallPath") > 0) { path = buf; return true; } // fallback to steam doom3 install if (GetRegistryPath(buf, sizeof(buf), L"SOFTWARE\\Valve\\Steam", L"InstallPath") > 0) { path = buf; path.AppendPath("steamapps\\common\\doom 3"); if (_stat(path.c_str(), &st) != -1 && st.st_mode & _S_IFDIR) return true; } common->Warning("vanilla doom3 path not found"); return false; case PATH_CONFIG: case PATH_SAVE: if (GetHomeDir(buf, sizeof(buf)) < 1) { Sys_Error("ERROR: Couldn't get dir to home path"); return false; } path = buf; return true; case PATH_EXE: GetModuleFileName(NULL, buf, sizeof(buf) - 1); path = buf; path.BackSlashesToSlashes(); return true; } return false; }
bool Sys_GetPath(sysPath_t type, idStr &path) { const char *s; char buf[MAX_OSPATH]; char buf2[MAX_OSPATH]; struct stat st; size_t len; path.Clear(); switch(type) { case PATH_BASE: if (stat(BUILD_DATADIR, &st) != -1 && S_ISDIR(st.st_mode)) { path = BUILD_DATADIR; return true; } common->Warning("base path '" BUILD_DATADIR "' does not exist"); // try next to the executable.. if (Sys_GetPath(PATH_EXE, path)) { path = path.StripFilename(); // the path should have a base dir in it, otherwise it probably just contains the executable idStr testPath = path + "/" BASE_GAMEDIR; if (stat(testPath.c_str(), &st) != -1 && S_ISDIR(st.st_mode)) { common->Warning("using path of executable: %s", path.c_str()); return true; } else { path.Clear(); } } // fallback to vanilla doom3 install if (stat(LINUX_DEFAULT_PATH, &st) != -1 && S_ISDIR(st.st_mode)) { common->Warning("using hardcoded default base path: " LINUX_DEFAULT_PATH); path = LINUX_DEFAULT_PATH; return true; } return false; case PATH_CONFIG: s = getenv("XDG_CONFIG_HOME"); if (s) idStr::snPrintf(buf, sizeof(buf), "%s/dhewm3", s); else idStr::snPrintf(buf, sizeof(buf), "%s/.config/dhewm3", getenv("HOME")); path = buf; return true; case PATH_SAVE: s = getenv("XDG_DATA_HOME"); if (s) idStr::snPrintf(buf, sizeof(buf), "%s/dhewm3", s); else idStr::snPrintf(buf, sizeof(buf), "%s/.local/share/dhewm3", getenv("HOME")); path = buf; return true; case PATH_EXE: idStr::snPrintf(buf, sizeof(buf), "/proc/%d/exe", getpid()); len = readlink(buf, buf2, sizeof(buf2)); if (len != -1) { path = buf2; return true; } if (path_argv[0] != 0) { path = path_argv; return true; } return false; } return false; }