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


C++ OsPath类代码示例

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


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

示例1: fi

OsStatus MpCodecFactory::loadAllDynCodecs(const char* path, const char* regexFilter)
{
   OsPath ospath = path;
   OsPath module;
   OsFileIterator fi(ospath);

   OsSysLog::add(FAC_MP, PRI_INFO, "MpCodecFactory::loadAllDynCodecs(\"%s\", \"%s\")",
                 path, regexFilter);

   OsStatus res;
   res = fi.findFirst(module, regexFilter);

   if (res != OS_SUCCESS) 
      return OS_NOT_FOUND;

   do {
      UtlString str = path;
      str += OsPathBase::separator;
      str += module.data();
      res = loadDynCodec(str.data());
      OsSysLog::add(FAC_MP, PRI_INFO, "MpCodecFactory::loadDynCodec(\"%s\") returned %d",
                    str.data(), res);
   } while (fi.findNext(module) == OS_SUCCESS);

   return OS_SUCCESS;
}
开发者ID:,项目名称:,代码行数:26,代码来源:

示例2: wdll_ver_Append

void wdll_ver_Append(const OsPath& pathname, VersionList& list)
{
	if(pathname.empty())
		return;	// avoid error in ReadVersionString

	// pathname may not have an extension (e.g. driver names from the
	// registry). note that always appending ".dll" would be incorrect
	// since some have ".sys" extension.
	OsPath modulePathname(pathname);
	if(modulePathname.Extension() == "")
		modulePathname = modulePathname.ChangeExtension(L".dll");
	const OsPath moduleName(modulePathname.Filename());

	// read file version. try this with and without FS redirection since
	// pathname might assume both.
	wchar_t versionString[500];	// enclosed in () below
	if(ReadVersionString(modulePathname, versionString, ARRAY_SIZE(versionString)) != INFO::OK)
	{
		WinScopedDisableWow64Redirection s;
		// still failed; avoid polluting list with DLLs that don't exist
		// (requiring callers to check for their existence beforehand would be
		// onerous and unreliable)
		if(ReadVersionString(modulePathname, versionString, ARRAY_SIZE(versionString)) != INFO::OK)
			return;
	}

	if(!list.empty())
		list += L", ";
	
	list += moduleName.Filename().string();
	list += L" (";
	list += versionString;
	list += L")";
}
开发者ID:Marlinc,项目名称:0ad,代码行数:34,代码来源:wdll_ver.cpp

示例3: CreateDirectories

Status CreateDirectories(const OsPath& path, mode_t mode, bool breakpoint)
{
	if(path.empty())
		return INFO::OK;

	struct stat s;
	if(wstat(path, &s) == 0)
	{
		if(!S_ISDIR(s.st_mode))	// encountered a file
			WARN_RETURN(ERR::FAIL);
		return INFO::OK;
	}

	// If we were passed a path ending with '/', strip the '/' now so that
	// we can consistently use Parent to find parent directory names
	if(path.IsDirectory())
		return CreateDirectories(path.Parent(), mode, breakpoint);

	RETURN_STATUS_IF_ERR(CreateDirectories(path.Parent(), mode));

	errno = 0;
	if(wmkdir(path, mode) != 0)
	{
		debug_printf("CreateDirectories: failed to mkdir %s (mode %d)\n", path.string8().c_str(), mode);
		if (breakpoint)
			WARN_RETURN(StatusFromErrno());
		else
			return StatusFromErrno();
	}

	return INFO::OK;
}
开发者ID:krichter722,项目名称:0ad,代码行数:32,代码来源:file_system.cpp

示例4: remove

//: Removes the directory or file specified by path
OsStatus OsFileSystem::remove(const OsPath& path, UtlBoolean bRecursive, UtlBoolean bForce)
{
    OsStatus retval = OS_INVALID;
    OsFileInfo info;
    OsPath testpath = path;
    getFileInfo(testpath,info);

    if (info.isDir())
    {
        if (bRecursive)
        {
            retval = removeTree(path,bForce);
        }
        else
        {
            if (rmdir((char *)path.data()) != -1)
                retval = OS_SUCCESS;
        }
    }
    else
    {
        if (bForce)
            setReadOnly(path,FALSE);
        if (::remove(path.data()) != -1)
            retval = OS_SUCCESS;
    }

    return retval;
}
开发者ID:Konnekt,项目名称:lib-sipx,代码行数:30,代码来源:OsFileSystem.cpp

示例5: psLogDir

void CProfileViewer::SaveToFile()
{
    // Open the file, if necessary. If this method is called several times,
    // the profile results will be appended to the previous ones from the same
    // run.
    if (! m->outputStream.is_open())
    {
        // Open the file. (It will be closed when the CProfileViewer
        // destructor is called.)
        OsPath path = psLogDir()/"profile.txt";
        m->outputStream.open(OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc);

        if (m->outputStream.fail())
        {
            LOGERROR(L"Failed to open profile log file");
            return;
        }
        else
        {
            LOGMESSAGERENDER(L"Profiler snapshot saved to '%ls'", path.string().c_str());
        }
    }

    time_t t;
    time(&t);
    m->outputStream << "================================================================\n\n";
    m->outputStream << "PS profiler snapshot - " << asctime(localtime(&t));

    std::vector<AbstractProfileTable*> tables = m->rootTables;
    sort(tables.begin(), tables.end(), SortByName);
    for_each(tables.begin(), tables.end(), WriteTable(m->outputStream));

    m->outputStream << "\n\n================================================================\n";
    m->outputStream.flush();
}
开发者ID:Marlinc,项目名称:0ad,代码行数:35,代码来源:ProfileViewer.cpp

示例6: PROFILE

void CSimulation2Impl::DumpState()
{
	PROFILE("DumpState");

	std::stringstream pid;
	pid << getpid();
	std::stringstream name;\
	name << std::setw(5) << std::setfill('0') << m_TurnNumber << ".txt";
	OsPath path = psLogDir() / "sim_log" / pid.str() / name.str();
	CreateDirectories(path.Parent(), 0700);
	std::ofstream file (OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc);

	file << "State hash: " << std::hex;
	std::string hashRaw;
	m_ComponentManager.ComputeStateHash(hashRaw, false);
	for (size_t i = 0; i < hashRaw.size(); ++i)
		file << std::setfill('0') << std::setw(2) << (int)(unsigned char)hashRaw[i];
	file << std::dec << "\n";

	file << "\n";

	m_ComponentManager.DumpDebugState(file, true);

	std::ofstream binfile (OsString(path.ChangeExtension(L".dat")).c_str(), std::ofstream::out | std::ofstream::trunc | std::ofstream::binary);
	m_ComponentManager.SerializeState(binfile);
}
开发者ID:,项目名称:,代码行数:26,代码来源:

示例7: setLogPriority

void SipXecsService::setLogPriority(const char* configSettingsFile, // path to configuration file
                                    const char* servicePrefix, /* the string "_LOG_LEVEL" is
                                                                * appended to this prefix to find
                                                                * the config directive that sets
                                                                * the level */
                                    OsSysLogPriority defaultLevel /* used if no directive
                                                                   * is found, or the value
                                                                   * found is not a valid
                                                                   * level name */
                                   )
{
    OsConfigDb configuration;

    OsPath configPath = SipXecsService::Path(SipXecsService::ConfigurationDirType,
                        configSettingsFile);

    if (OS_SUCCESS == configuration.loadFromFile(configPath.data()))
    {
        setLogPriority(configuration, servicePrefix, defaultLevel);
    }
    else
    {
        OsSysLog::add(FAC_KERNEL, PRI_WARNING,
                      "SipXecsService::setLogPriority: Failed to open config file at '%s'\n"
                      "  setting %s%s to %s",
                      configPath.data(),
                      servicePrefix, LogLevelSuffix, OsSysLog::priorityName(defaultLevel)
                     );

        OsSysLog::setLoggingPriority(defaultLevel);
    }
}
开发者ID:,项目名称:,代码行数:32,代码来源:

示例8: OsPath

/*static*/ OsPath Paths::Root(const OsPath& argv0)
{
#if OS_ANDROID
	return OsPath("/sdcard/0ad"); // TODO: this is kind of bogus
#else

	// get full path to executable
	OsPath pathname = sys_ExecutablePathname();	// safe, but requires OS-specific implementation
	if(pathname.empty())	// failed, use argv[0] instead
	{
		errno = 0;
		pathname = wrealpath(argv0);
		if(pathname.empty())
			WARN_IF_ERR(StatusFromErrno());
	}

	// make sure it's valid
	if(!FileExists(pathname))
	{
		LOGERROR(L"Cannot find executable (expected at '%ls')", pathname.string().c_str());
		WARN_IF_ERR(StatusFromErrno());
	}

	for(size_t i = 0; i < 2; i++)	// remove "system/name.exe"
		pathname = pathname.Parent();
	return pathname;

#endif
}
开发者ID:Valvador,项目名称:PyroSpaceFork,代码行数:29,代码来源:Paths.cpp

示例9: Initialise

		bool Initialise(bool callConstructor)
		{
			if (!LoadScripts(m_AIName))
				return false;

			OsPath path = L"simulation/ai/" + m_AIName + L"/data.json";
			CScriptValRooted metadata = m_Worker.LoadMetadata(path);
			if (metadata.uninitialised())
			{
				LOGERROR(L"Failed to create AI player: can't find %ls", path.string().c_str());
				return false;
			}

			// Get the constructor name from the metadata
			std::string constructor;
			if (!m_ScriptInterface.GetProperty(metadata.get(), "constructor", constructor))
			{
				LOGERROR(L"Failed to create AI player: %ls: missing 'constructor'", path.string().c_str());
				return false;
			}

			// Get the constructor function from the loaded scripts
			CScriptVal ctor;
			if (!m_ScriptInterface.GetProperty(m_ScriptInterface.GetGlobalObject(), constructor.c_str(), ctor)
				|| ctor.undefined())
			{
				LOGERROR(L"Failed to create AI player: %ls: can't find constructor '%hs'", path.string().c_str(), constructor.c_str());
				return false;
			}

			CScriptVal obj;

			if (callConstructor)
			{
				// Set up the data to pass as the constructor argument
				CScriptVal settings;
				m_ScriptInterface.Eval(L"({})", settings);
				m_ScriptInterface.SetProperty(settings.get(), "player", m_Player, false);
				ENSURE(m_Worker.m_HasLoadedEntityTemplates);
				m_ScriptInterface.SetProperty(settings.get(), "templates", m_Worker.m_EntityTemplates, false);

				obj = m_ScriptInterface.CallConstructor(ctor.get(), settings.get());
			}
			else
			{
				// For deserialization, we want to create the object with the correct prototype
				// but don't want to actually run the constructor again
				// XXX: actually we don't currently use this path for deserialization - maybe delete it?
				obj = m_ScriptInterface.NewObjectFromConstructor(ctor.get());
			}

			if (obj.undefined())
			{
				LOGERROR(L"Failed to create AI player: %ls: error calling constructor '%hs'", path.string().c_str(), constructor.c_str());
				return false;
			}

			m_Obj = CScriptValRooted(m_ScriptInterface.GetContext(), obj);
			return true;
		}
开发者ID:Gallaecio,项目名称:0ad,代码行数:60,代码来源:CCmpAIManager.cpp

示例10: sys_ExecutablePathname

OsPath sys_ExecutablePathname()
{
	OsPath path;

	// On OS X we might be a bundle, return the bundle path as the executable name,
	//	i.e. /path/to/0ad.app instead of /path/to/0ad.app/Contents/MacOS/pyrogenesis
	if (osx_IsAppBundleValid())
	{
		path = osx_GetBundlePath();
		ENSURE(!path.empty());
	}
	else
	{
		char temp[PATH_MAX];
		u32 size = PATH_MAX;
		if (_NSGetExecutablePath(temp, &size) == 0)
		{
			char name[PATH_MAX];
			realpath(temp, name);
			path = OsPath(name);
		}
	}

	return path;
}
开发者ID:righnatios,项目名称:0ad,代码行数:25,代码来源:osx.cpp

示例11: GetVirtualPath

	virtual Status GetVirtualPath(const OsPath& realPathname, VfsPath& pathname)
	{
		ScopedLock s;
		const OsPath realPath = realPathname.Parent()/"";
		VfsPath path;
		RETURN_STATUS_IF_ERR(FindRealPathR(realPath, m_rootDirectory, L"", path));
		pathname = path / realPathname.Filename();
		return INFO::OK;
	}
开发者ID:,项目名称:,代码行数:9,代码来源:

示例12: defaultDir

OsPath SipXecsService::Path(DirectoryType pathType, const char* fileName)
{
    OsPath path;

    const char* dirPath;
    if ( (dirPath = getenv(pathType)) )
    {
        OsSysLog::add(FAC_KERNEL, PRI_NOTICE,
                      "SipXecsService::Path type '%s' overridden by environment to '%s'",
                      pathType, dirPath);
    }
    else
    {
        dirPath = defaultDir(pathType);
    }
    path.append(dirPath);

    const char slash = OsPath::separator(0);
    const char lastPathChar = path(path.length()-1);
    if (fileName && *fileName != '\000')
    {
        // Add the file name
        //   make sure there is exactly one separator between the directory and the file
        if (   slash != lastPathChar
                && slash != fileName[0]
           )
        {
            // neither has separator - add one
            path.append(OsPath::separator);
        }
        else if (   slash == lastPathChar
                    && slash == fileName[0]
                )
        {
            // both have the separator - take one off so there's only one
            path.remove(path.length()-1);
        }

        path.append(fileName);
    }
    // There is no file name, so make sure the returned directory name does not
    // end in a separator
    else if ( slash == lastPathChar )
    {
        path.remove(path.length()-1);
    }

    OsSysLog::add(FAC_KERNEL, PRI_DEBUG,
                  "SipXecsService::Path('%s', '%s') returning '%s'",
                  pathType, fileName ? fileName : "", path.data() );
    return path;
}
开发者ID:,项目名称:,代码行数:52,代码来源:

示例13: WriteScreenshot

// <extension> identifies the file format that is to be written
// (case-insensitive). examples: "bmp", "png", "jpg".
// BMP is good for quick output at the expense of large files.
void WriteScreenshot(const VfsPath& extension)
{
    // get next available numbered filename
    // note: %04d -> always 4 digits, so sorting by filename works correctly.
    const VfsPath basenameFormat(L"screenshots/screenshot%04d");
    const VfsPath filenameFormat = basenameFormat.ChangeExtension(extension);
    VfsPath filename;
    vfs::NextNumberedFilename(g_VFS, filenameFormat, s_nextScreenshotNumber, filename);

    const size_t w = (size_t)g_xres, h = (size_t)g_yres;
    const size_t bpp = 24;
    GLenum fmt = GL_RGB;
    int flags = TEX_BOTTOM_UP;
    // we want writing BMP to be as fast as possible,
    // so read data from OpenGL in BMP format to obviate conversion.
    if(extension == L".bmp")
    {
#if !CONFIG2_GLES // GLES doesn't support BGR
        fmt = GL_BGR;
        flags |= TEX_BGR;
#endif
    }

    // Hide log messages and re-render
    RenderLogger(false);
    Render();
    RenderLogger(true);

    const size_t img_size = w * h * bpp/8;
    const size_t hdr_size = tex_hdr_size(filename);
    shared_ptr<u8> buf;
    AllocateAligned(buf, hdr_size+img_size, maxSectorSize);
    GLvoid* img = buf.get() + hdr_size;
    Tex t;
    if(t.wrap(w, h, bpp, flags, buf, hdr_size) < 0)
        return;
    glReadPixels(0, 0, (GLsizei)w, (GLsizei)h, fmt, GL_UNSIGNED_BYTE, img);

    if (tex_write(&t, filename) == INFO::OK)
    {
        OsPath realPath;
        g_VFS->GetRealPath(filename, realPath);

        LOGMESSAGERENDER(g_L10n.Translate("Screenshot written to '%s'"), realPath.string8());

        debug_printf(
            CStr(g_L10n.Translate("Screenshot written to '%s'") + "\n").c_str(),
            realPath.string8().c_str());
    }
    else
        LOGERROR("Error writing screenshot to '%s'", filename.string8());
}
开发者ID:krichter722,项目名称:0ad,代码行数:55,代码来源:Util.cpp

示例14: testPathInfo

    void testPathInfo()
    {
        UtlString testDir = "../../filename.ext";
        OsPath testPath = testDir;

        UtlString parentPath;
        parentPath.append("..").append(OsPath::separator).append("..").append(OsPath::separator);

        ASSERT_STR_EQUAL_MESSAGE("Extension", ".ext", testPath.getExt().data());
        ASSERT_STR_EQUAL_MESSAGE("Parent Path", parentPath, testPath.getDirName().data());
        ASSERT_STR_EQUAL_MESSAGE("Volume", "", testPath.getVolume().data());
        ASSERT_STR_EQUAL_MESSAGE("Filename no extension", "filename",
                                     testPath.getFilename().data());

        // little risky, may not have permissions, but '../../' is too
        // good a test to not try. Refactor if this is bad assumption
        OsFile file(testPath);
        file.touch();

        OsPath nativePath;
        testPath.getNativePath(nativePath);

        // dont' know what's right, but know whats wrong
        CPPUNIT_ASSERT_MESSAGE("Resolved relative path", !nativePath.contains(".."));
        //printf("Native path is %s\n", nativePath.data());

        file.remove();
    }
开发者ID:Jaroslav23,项目名称:sipxtapi,代码行数:28,代码来源:OsPathTest.cpp

示例15: path

SipConfigServerAgent* SipConfigServerAgent::getSipConfigServerAgent()
{
   UtlBoolean isStarted ;

   // If the task object already exists, and the corresponding low-level task
   // has been started, then use it
   if (spInstance != NULL && spInstance->isStarted())
      return spInstance;

   // If the task does not yet exist or hasn't been started, then acquire
   // the lock to ensure that only one instance of the task is started
   sLock.acquire();
   if (spInstance == NULL)
   {
      OsPath workingDirectory ;
      if ( OsFileSystem::exists( CONFIG_ETC_DIR ) )
      {
         workingDirectory = CONFIG_ETC_DIR;
         OsPath path(workingDirectory);
         path.getNativePath(workingDirectory);
      }
      else
      {
         OsPath path;
         OsFileSystem::getWorkingDirectory(path);
         path.getNativePath(workingDirectory);
      }

      UtlString ConfigfileName =  workingDirectory +
         OsPathBase::separator +
         CONFIG_SETTINGS_FILE  ;

      // Initialize the OsSysLog
      OsConfigDb configDb ;
      configDb.loadFromFile(ConfigfileName) ;
      initializeLog(&configDb) ;

      spInstance = startAgents(ConfigfileName);
   }

   isStarted = spInstance->isStarted();
   if (!isStarted)
   {
      isStarted = spInstance->start();
      // assert(isStarted);
   }
   sLock.release();

   return spInstance;
}
开发者ID:mranga,项目名称:sipxecs,代码行数:50,代码来源:SipConfigServerAgent.cpp


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