当前位置: 首页>>代码示例>>C++>>正文


C++ idStr::StripFilename方法代码示例

本文整理汇总了C++中idStr::StripFilename方法的典型用法代码示例。如果您正苦于以下问题:C++ idStr::StripFilename方法的具体用法?C++ idStr::StripFilename怎么用?C++ idStr::StripFilename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在idStr的用法示例。


在下文中一共展示了idStr::StripFilename方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

/*
================
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;
}
开发者ID:revelator,项目名称:Revelation,代码行数:40,代码来源:main.cpp

示例2: Sys_GetPath

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;
}
开发者ID:kevindqc,项目名称:utl,代码行数:57,代码来源:win_main.cpp

示例3: Sys_GetPath

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;
}
开发者ID:BielBdeLuna,项目名称:dhewm3,代码行数:79,代码来源:main.cpp


注:本文中的idStr::StripFilename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。