Skip to content

Commit

Permalink
Optimized away some string conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Dec 20, 2023
1 parent 0ba3ede commit 446421a
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions src/tabs/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1416,63 +1416,65 @@ RefreshRunningApps (void)
continue;
}

std::wstring fullPath;

bool accessDenied =
GetLastError ( ) == ERROR_ACCESS_DENIED;

// Get exit code to filter out zombie processes
DWORD dwExitCode = 0;
GetExitCodeProcess (hProcess, &dwExitCode);

WCHAR szExePath[MAX_PATH] = { };
DWORD szExePathLen = MAX_PATH;

if (! accessDenied)
{
// If the process is not active any longer, skip it (terminated or zombie process)
if (dwExitCode != STILL_ACTIVE)
continue;

WCHAR szExePath[MAX_PATH];
DWORD len = MAX_PATH;

// See if we can retrieve the full path of the executable
if (QueryFullProcessImageName (hProcess, 0, szExePath, &len))
fullPath = std::wstring (szExePath);
if (! QueryFullProcessImageName (hProcess, 0, szExePath, &szExePathLen))
szExePathLen = 0;
}

for (auto& app : apps)
{
// Steam games are covered through separate registry monitoring
if (app.second.store == app_record_s::Store::Steam)
{
if (! steamFallback)
continue;

if (fullPath == app.second.launch_configs[0].getExecutableFullPath ( )) // full patch
{
app.second._status.running = true;
break;
}
}

// Workaround for Xbox games that run under the virtual folder, e.g. H:\Games\Xbox Games\Hades\Content\Hades.exe
else if (app.second.store == app_record_s::Store::Xbox && (! wcscmp (pe32.szExeFile, app.second.launch_configs[0].executable.c_str())))
if (app.second.store == app_record_s::Store::Xbox && _wcsnicmp (app.second.launch_configs[0].executable.c_str(), pe32.szExeFile, MAX_PATH) == 0)
{
app.second._status.running = true;
break;
}

// Epic, GOG and SKIF Custom should be straight forward
else if (fullPath == app.second.launch_configs[0].getExecutableFullPath ( )) // full patch
else if (szExePathLen != 0)
{
app.second._status.running = true;
break;
// Steam games are covered through separate registry monitoring
if (app.second.store == app_record_s::Store::Steam)
{
if (! steamFallback)
continue;

if (_wcsnicmp (app.second.launch_configs[0].getExecutableFullPath ( ).c_str(), szExePath, szExePathLen) == 0)
{
app.second._status.running = true;
break;
}
}

// One can also perform a partial match with the below OR clause in the IF statement, however from testing
// PROCESS_QUERY_LIMITED_INFORMATION gives us GetExitCodeProcess() and QueryFullProcessImageName() rights
// even to elevated processes, meaning the below OR clause is unnecessary.
//
// (fullPath.empty() && ! wcscmp (pe32.szExeFile, app.second.launch_configs[0].executable.c_str()))
//
// Epic, GOG and SKIF Custom should be straight forward
else if (_wcsnicmp (app.second.launch_configs[0].getExecutableFullPath ( ).c_str(), szExePath, szExePathLen) == 0) // full patch
{
app.second._status.running = true;
break;

// One can also perform a partial match with the below OR clause in the IF statement, however from testing
// PROCESS_QUERY_LIMITED_INFORMATION gives us GetExitCodeProcess() and QueryFullProcessImageName() rights
// even to elevated processes, meaning the below OR clause is unnecessary.
//
// (fullPath.empty() && ! wcscmp (pe32.szExeFile, app.second.launch_configs[0].executable.c_str()))
//
}
}
}

Expand Down

0 comments on commit 446421a

Please sign in to comment.