- Consider 'Program Files' a read only location without actually checking.

Due to virtualization the actual check may not produce correct results, plus writing there is bad style anyway.
This commit is contained in:
Christoph Oelckers 2021-09-15 00:39:18 +02:00
parent 8c715d48cd
commit 23a2ccec2b

View file

@ -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;