mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Windows: Avoid loading shell libraries during startup.
This commit is contained in:
@@ -168,6 +168,34 @@ namespace W32Util
|
||||
ExitProcess(0);
|
||||
}
|
||||
|
||||
bool ExecuteAndGetReturnCode(const wchar_t *executable, const wchar_t *cmdline, const wchar_t *currentDirectory, DWORD *exitCode) {
|
||||
PROCESS_INFORMATION processInformation = { 0 };
|
||||
STARTUPINFO startupInfo = { 0 };
|
||||
startupInfo.cb = sizeof(startupInfo);
|
||||
|
||||
std::wstring cmdlineW;
|
||||
cmdlineW += L"PPSSPP "; // could also put the executable name as first argument, but concerned about escaping.
|
||||
cmdlineW += cmdline;
|
||||
|
||||
// Create the process
|
||||
bool result = CreateProcess(executable, (LPWSTR)cmdlineW.c_str(),
|
||||
NULL, NULL, FALSE,
|
||||
NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW,
|
||||
NULL, currentDirectory, &startupInfo, &processInformation);
|
||||
|
||||
if (!result) {
|
||||
// We failed.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Successfully created the process. Wait for it to finish.
|
||||
WaitForSingleObject(processInformation.hProcess, INFINITE);
|
||||
result = GetExitCodeProcess(processInformation.hProcess, exitCode);
|
||||
CloseHandle(processInformation.hProcess);
|
||||
CloseHandle(processInformation.hThread);
|
||||
return result != 0;
|
||||
}
|
||||
|
||||
void SpawnNewInstance(bool overrideArgs, const std::string &args) {
|
||||
// This preserves arguments (for example, config file) and working directory.
|
||||
std::wstring workingDirectory;
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace W32Util
|
||||
void MakeTopMost(HWND hwnd, bool topMost);
|
||||
void ExitAndRestart(bool overrideArgs = false, const std::string &args = "");
|
||||
void SpawnNewInstance(bool overrideArgs = false, const std::string &args = "");
|
||||
bool ExecuteAndGetReturnCode(const wchar_t *executable, const wchar_t *cmdline, const wchar_t *currentDirectory, DWORD *exitCode);
|
||||
void GetSelfExecuteParams(std::wstring &workingDirectory, std::wstring &moduleFilename);
|
||||
|
||||
void GetWindowRes(HWND hWnd, int *xres, int *yres);
|
||||
|
||||
+4
-19
@@ -694,28 +694,13 @@ static bool DetectVulkanInExternalProcess() {
|
||||
|
||||
const wchar_t *cmdline = L"--vulkan-available-check";
|
||||
|
||||
SHELLEXECUTEINFO info{ sizeof(SHELLEXECUTEINFO) };
|
||||
info.fMask = SEE_MASK_NOCLOSEPROCESS;
|
||||
info.lpFile = moduleFilename.c_str();
|
||||
info.lpParameters = cmdline;
|
||||
info.lpDirectory = workingDirectory.c_str();
|
||||
info.nShow = SW_HIDE;
|
||||
if (ShellExecuteEx(&info) != TRUE) {
|
||||
return false;
|
||||
}
|
||||
if (info.hProcess == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD result = WaitForSingleObject(info.hProcess, 10000);
|
||||
DWORD exitCode = 0;
|
||||
if (result == WAIT_FAILED || GetExitCodeProcess(info.hProcess, &exitCode) == 0) {
|
||||
CloseHandle(info.hProcess);
|
||||
if (W32Util::ExecuteAndGetReturnCode(moduleFilename.c_str(), cmdline, workingDirectory.c_str(), &exitCode)) {
|
||||
return exitCode == EXIT_CODE_VULKAN_WORKS;
|
||||
} else {
|
||||
ERROR_LOG(G3D, "Failed to detect Vulkan in external process somehow");
|
||||
return false;
|
||||
}
|
||||
CloseHandle(info.hProcess);
|
||||
|
||||
return exitCode == EXIT_CODE_VULKAN_WORKS;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user