Skip to content

Commit

Permalink
- Consider 'Program Files' a read only location without actually chec…
Browse files Browse the repository at this point in the history
…king.

Due to virtualization the actual check may not produce correct results, plus writing there is bad style anyway.
  • Loading branch information
coelckers committed Sep 14, 2021
1 parent 8c715d4 commit 23a2cce
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/common/platform/win32/i_specialpaths.cpp
Expand Up @@ -74,16 +74,36 @@ bool UseKnownFolders()
{
return !iswritable;
}
std::wstring testpath = progdir.WideString() + L"writest";
file = CreateFile(testpath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL);
if (file != INVALID_HANDLE_VALUE)
// Consider 'Program Files' read only without actually checking.
bool found = false;
for (auto p : { L"ProgramFiles", L"ProgramFiles(x86)" })
{
CloseHandle(file);
if (!batchrun) Printf("Using program directory for storage\n");
iswritable = true;
return false;
wchar_t buffer1[256];
if (GetEnvironmentVariable(p, buffer1, 256))
{
FString envpath(buffer1);
FixPathSeperator(envpath);
if (progdir.MakeLower().IndexOf(envpath.MakeLower()) == 0)
{
found = true;
break;
}
}
}

if (!found)
{
std::wstring testpath = progdir.WideString() + L"writest";
file = CreateFile(testpath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL);
if (file != INVALID_HANDLE_VALUE)
{
CloseHandle(file);
if (!batchrun) Printf("Using program directory for storage\n");
iswritable = true;
return false;
}
}
if (!batchrun) Printf("Using known folders for storage\n");
iswritable = false;
Expand Down

0 comments on commit 23a2cce

Please sign in to comment.