[TASKMGR] Process page: Improve readability of command line string formatting code

This commit is contained in:
Thamatip Chitpong 2024-04-22 20:48:42 +07:00
parent 018264f38f
commit 6d16d27462

View file

@ -1222,6 +1222,7 @@ void ProcessPage_OnOpenFileLocation(void)
DWORD dwProcessId;
DWORD dwLength;
LPWSTR pszExePath;
static const WCHAR szCmdFormat[] = L"/select,\"%s\"";
LPWSTR pszCmdLine = NULL;
dwProcessId = GetSelectedProcessId();
@ -1240,11 +1241,12 @@ void ProcessPage_OnOpenFileLocation(void)
goto Cleanup;
/* Build the shell command line */
pszCmdLine = HeapAlloc(GetProcessHeap(), 0, (dwLength + CONST_STR_LEN(L"/select,\"\"")) * sizeof(WCHAR));
dwLength += CONST_STR_LEN(szCmdFormat) - CONST_STR_LEN(L"%s");
pszCmdLine = HeapAlloc(GetProcessHeap(), 0, dwLength * sizeof(WCHAR));
if (!pszCmdLine)
goto Cleanup;
StringCchPrintfW(pszCmdLine, dwLength + CONST_STR_LEN(L"/select,\"\""), L"/select,\"%s\"", pszExePath);
StringCchPrintfW(pszCmdLine, dwLength, szCmdFormat, pszExePath);
/* Call the shell to open the file location and select it */
ShellExecuteW(NULL, L"open", L"explorer.exe", pszCmdLine, NULL, SW_SHOWNORMAL);