示例#1
0
/*
================
Sys_DefaultBasePath

Get the default base path
- binary image path
- current directory
- hardcoded
Try to be intelligent: if there is no BASE_GAMEDIR, try the next path
================
*/
const char *Sys_DefaultBasePath( void ) {
	struct stat st;
	idStr testbase;
	basepath = Sys_EXEPath();
	if( basepath.Length() ) {
		basepath.StripFilename();
		testbase = basepath;
		testbase += "/";
		testbase += BASE_GAMEDIR;
		if( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) {
			return basepath.c_str();
		} else {
			common->Printf( "no '%s' directory in exe path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() );
		}
	}
	if( basepath != Posix_Cwd() ) {
		basepath = Posix_Cwd();
		testbase = basepath;
		testbase += "/";
		testbase += BASE_GAMEDIR;
		if( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) {
			return basepath.c_str();
		} else {
			common->Printf( "no '%s' directory in cwd path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() );
		}
	}
	common->Printf( "WARNING: using hardcoded default base path\n" );
	return LINUX_DEFAULT_PATH;
}
示例#2
0
文件: win_main.cpp 项目: kevindqc/utl
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;
}
示例#3
0
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;
}