Format and optimize last commit

This commit is contained in:
Urs Fleisch 2024-01-28 16:03:11 +01:00
parent e08d0395c6
commit cfae2039c8

View File

@ -49,10 +49,6 @@ namespace
const FileHandle InvalidFileHandle = INVALID_HANDLE_VALUE;
const std::wstring LongLocalPathPrefix = L"\\\\?\\";
const std::wstring UNCPathPrefix = L"\\\\";
const std::wstring LongUNCPathPrefix = L"\\\\?\\UNC\\";
FileHandle openFile(const FileName &path, bool readOnly)
{
const DWORD access = readOnly ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE);
@ -60,25 +56,21 @@ namespace
#if defined (PLATFORM_WINRT)
return CreateFile2(path.wstr().c_str(), access, FILE_SHARE_READ, OPEN_EXISTING, nullptr);
#else
std::wstring fixed_path;
if (path.wstr().length() > MAX_PATH && path.wstr().compare(0, LongLocalPathPrefix.length(), LongLocalPathPrefix) != 0 && path.wstr().compare(0, LongUNCPathPrefix.length(), LongUNCPathPrefix) != 0)
{
if (path.wstr().compare(0, UNCPathPrefix.length(), UNCPathPrefix) == 0)
{
fixed_path.append(LongUNCPathPrefix);
fixed_path.append(path.wstr().substr(2));
constexpr wchar_t LongLocalPathPrefix[] = L"\\\\?\\";
constexpr wchar_t UNCPathPrefix[] = L"\\\\";
constexpr wchar_t LongUNCPathPrefix[] = L"\\\\?\\UNC\\";
std::wstring pathWStr = path.wstr();
if(pathWStr.length() > MAX_PATH &&
pathWStr.compare(0, std::size(LongLocalPathPrefix) - 1, LongLocalPathPrefix) != 0 &&
pathWStr.compare(0, std::size(LongUNCPathPrefix) - 1, LongUNCPathPrefix) != 0) {
if(pathWStr.compare(0, std::size(UNCPathPrefix) - 1, UNCPathPrefix) == 0) {
pathWStr = LongUNCPathPrefix + pathWStr.substr(2);
}
else
{
fixed_path.append(LongLocalPathPrefix);
fixed_path.append(path.wstr());
else {
pathWStr = LongLocalPathPrefix + pathWStr;
}
}
else
{
fixed_path = path.wstr();
}
return CreateFileW(fixed_path.c_str(), access, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
return CreateFileW(pathWStr.c_str(), access, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
#endif
}