tstring AppSettings::GetRelativeTexPath(LPCTSTR fname, LPCTSTR prefix) const
{
	TCHAR buffer[MAX_PATH];
	if (textureUseFullPath == 1) // full path name
	{
		GetFullPathName(fname, _countof(buffer), buffer, nullptr);
		return tstring(buffer);
	}
	else if (textureUseFullPath == -1) // only filename
	{
		return tstring(PathFindFileName(fname));
	}
	if (!PathIsRelative(fname))
	{
		TCHAR root[MAX_PATH];
		TCHAR file[MAX_PATH];
		GetFullPathName(fname, _countof(file), file, nullptr);
		PathMakePretty(file);

		for (tstringlist::const_iterator itr = textureRootPaths.begin(), end = textureRootPaths.end(); itr != end; ++itr) {
			GetFullPathName((*itr).c_str(), _countof(root), root, nullptr);
			PathAddBackslash(root);
			PathMakePretty(root);
			if (-1 != _taccess(root, 0)) {
				size_t len = _tcslen(root);
				if (0 == _tcsnicmp(root, file, len))
					return tstring(file + len);
			}
		}
	}
	else // Test if its relative to one of the specified root paths just return the texture 
	{
		for (tstringlist::const_iterator itr = textureRootPaths.begin(), end = textureRootPaths.end(); itr != end; ++itr) {
			PathCombine(buffer, itr->c_str(), fname);
			if (-1 != _taccess(buffer, 0)) {
				return fname;
			}
		}
	}

	// check if prefix is in place if so then just return fname as is
	for (LPCTSTR path = fname; path != nullptr; path = PathFindNextComponent(path))
	{
		if (_tcsnicmp(path, prefix, _tcslen(prefix)) == 0)
			return tstring(path);
	}

	// Now just combine prefix with file portion of the name
	PathCombine(buffer, prefix, PathFindFileName(fname));
	return tstring(buffer);
}
// Check whether the given file is a child of the root paths
bool AppSettings::IsFileInRootPaths(const std::string& fname)
{
   TCHAR root[MAX_PATH];
   TCHAR file[MAX_PATH];
   GetFullPathName(fname.c_str(), _countof(file), file, NULL);
   PathMakePretty(file);

   for (stringlist::iterator itr = rootPaths.begin(), end = rootPaths.end(); itr != end; ++itr ){
      GetFullPathName((*itr).c_str(), _countof(root), root, NULL);
      PathAddBackslash(root);
      PathMakePretty(root);
      if (-1 != _taccess(root,0)) {
         int len = _tcslen(root);
         if (0 == _tcsncmp(root, file, len))
            return true;
      }
   }
   return false;
}
HRESULT MassageOutputPath(const TCHAR* pathName, TCHAR* outPathName, int maxPathName)
{
	HRESULT hr = S_OK;

	if (SUCCEEDED(hr = StringCchCopy(outPathName, maxPathName, pathName)))
	{
		PathAddExtension(outPathName, ".x");
		PathMakePretty(outPathName);

		for (TCHAR* c=outPathName; *c; c++)
		{
			if (*c == '/')
			{
				*c = '\\';
			}
		}
	}

	return hr;
}
Example #4
0
CFilePath &CFilePath::MakePretty()
{
    CStringLock Buffer(msPath);
    PathMakePretty(Buffer);
    return *this;
}
	void make_pretty() { PathMakePretty(this->buf); }