コード例 #1
0
ファイル: cvtname.cpp プロジェクト: johnd0e/farmanager
// try to replace volume GUID (if present) with drive letter
// used by ConvertNameToReal() only
static string TryConvertVolumeGuidToDrivePath(string_view const Path, const string_view AbsPath = {})
{
	string Result(Path);
	size_t DirectoryOffset;
	if (ParsePath(Path, &DirectoryOffset) == root_type::volume)
	{
		if (imports.GetVolumePathNamesForVolumeNameW)
		{
			string VolumePathNames;
			if (os::fs::GetVolumePathNamesForVolumeName(ExtractPathRoot(Path), VolumePathNames))
			{
				for(const auto& i: enum_substrings(VolumePathNames.c_str()))
				{
					if (!AbsPath.empty() && starts_with_icase(AbsPath, i))
						return string(i);

					if (IsRootPath(i))
					{
						Result.replace(0, DirectoryOffset, i.data(), i.size());
						break;
					}
				}
			}

			if (!AbsPath.empty())
				Result.clear();
		}

		else if (!AbsPath.empty())
			Result.clear();

		else
		{
			string strVolumeGuid;
			const os::fs::enum_drives Enumerator(os::fs::get_logical_drives());
			const auto ItemIterator = std::find_if(ALL_CONST_RANGE(Enumerator), [&](const auto& i)
			{
				return os::fs::GetVolumeNameForVolumeMountPoint(os::fs::get_root_directory(i), strVolumeGuid) && starts_with(Path, string_view(strVolumeGuid).substr(0, DirectoryOffset));
			});
			if (ItemIterator != Enumerator.cend())
			{
				Result.replace(0, DirectoryOffset, os::fs::get_drive(*ItemIterator));
			}
		}
	}

	else if (!AbsPath.empty())
		Result.clear();

	return Result;
}
コード例 #2
0
ファイル: flink.cpp プロジェクト: alexlav/conemu
void GetPathRoot(const wchar_t *Path, string &strRoot)
{
	string RealPath;
	ConvertNameToReal(Path, RealPath);
	strRoot = ExtractPathRoot(RealPath);
}
コード例 #3
0
ファイル: flink.cpp プロジェクト: johnd0e/farmanager
string GetPathRoot(string_view const Path)
{
	return ExtractPathRoot(ConvertNameToReal(Path));
}
コード例 #4
0
ファイル: pathmix.cpp プロジェクト: alexlav/conemu
			{
				TargetPath.Copy(LinkTarget.Buffer, LinkTarget.Length / sizeof(wchar_t));
			}

			ifn.NtClose(hSymLink);

			if (PathStartsWith(NtPath, TargetPath))
				return static_cast<int>(TargetPath.GetLength());
		}
	}

	return 0;
}

SELF_TEST(
    assert(ExtractPathRoot(L"") == L"");
    assert(ExtractPathRoot(L"\\") == L"");
    assert(ExtractPathRoot(L"file") == L"");
    assert(ExtractPathRoot(L"path\\file") == L"");
    assert(ExtractPathRoot(L"C:") == L"C:\\");
    assert(ExtractPathRoot(L"C:\\") == L"C:\\");
    assert(ExtractPathRoot(L"C:\\path\\file") == L"C:\\");
    assert(ExtractPathRoot(L"\\\\?\\Volume{01e45c83-9ce4-11db-b27f-806d6172696f}") == L"\\\\?\\Volume{01e45c83-9ce4-11db-b27f-806d6172696f}\\");
    assert(ExtractPathRoot(L"\\\\?\\Volume{01e45c83-9ce4-11db-b27f-806d6172696f}\\") == L"\\\\?\\Volume{01e45c83-9ce4-11db-b27f-806d6172696f}\\");
    assert(ExtractPathRoot(L"\\\\?\\Volume{01e45c83-9ce4-11db-b27f-806d6172696f}\\path\\file") == L"\\\\?\\Volume{01e45c83-9ce4-11db-b27f-806d6172696f}\\");
    assert(ExtractPathRoot(L"\\\\server\\share") == L"\\\\server\\share\\");
    assert(ExtractPathRoot(L"\\\\server\\share\\") == L"\\\\server\\share\\");
    assert(ExtractPathRoot(L"\\\\server\\share\\path\\file") == L"\\\\server\\share\\");
    assert(ExtractPathRoot(L"\\\\?\\UNC\\server\\share") == L"\\\\?\\UNC\\server\\share\\");
    assert(ExtractPathRoot(L"\\\\?\\UNC\\server\\share\\") == L"\\\\?\\UNC\\server\\share\\");
    assert(ExtractPathRoot(L"\\\\?\\UNC\\server\\share\\path\\file") == L"\\\\?\\UNC\\server\\share\\");