FileSystem: Fix GetProgramPath() sometimes returning stale paths
See https://social.msdn.microsoft.com/Forums/windowshardware/en-US/4b7b3884-d0bb-4812-bc18-2078c61d4b90/queryfullprocessimagename-gives-wrong-path-for-renamed-directory?forum=windowsgeneraldevelopmentissues
This commit is contained in:
parent
ffc840d909
commit
3950d80771
|
@ -1114,16 +1114,13 @@ bool FileSystem::DeleteDirectory(const char* Path, bool Recursive)
|
|||
|
||||
std::string GetProgramPath()
|
||||
{
|
||||
const HANDLE hProcess = GetCurrentProcess();
|
||||
|
||||
std::wstring buffer;
|
||||
buffer.resize(MAX_PATH);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
DWORD nChars = static_cast<DWORD>(buffer.size());
|
||||
if (!QueryFullProcessImageNameW(GetCurrentProcess(), 0, buffer.data(), &nChars) &&
|
||||
GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||
DWORD nChars = GetModuleFileNameW(nullptr, buffer.data(), static_cast<DWORD>(buffer.size()));
|
||||
if (nChars == static_cast<DWORD>(buffer.size()) && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
buffer.resize(buffer.size() * 2);
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue