MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / spawn

Function spawn

src/spawn.cpp:418–480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

416}
417
418DWORD spawn(const SpawnParameters& sp, HANDLE& processHandle)
419{
420 BOOL inheritHandles = FALSE;
421
422 STARTUPINFO si = {};
423 si.cb = sizeof(si);
424
425 // inherit handles if we plan to use stdout or stderr reroute
426 if (sp.stdOut != INVALID_HANDLE_VALUE) {
427 si.hStdOutput = sp.stdOut;
428 inheritHandles = TRUE;
429 si.dwFlags |= STARTF_USESTDHANDLES;
430 }
431
432 if (sp.stdErr != INVALID_HANDLE_VALUE) {
433 si.hStdError = sp.stdErr;
434 inheritHandles = TRUE;
435 si.dwFlags |= STARTF_USESTDHANDLES;
436 }
437
438 const auto bin = QDir::toNativeSeparators(sp.binary.absoluteFilePath());
439 const auto cwd = QDir::toNativeSeparators(sp.currentDirectory.absolutePath());
440
441 QString commandLine = "\"" + bin + "\"";
442 if (!sp.arguments.isEmpty()) {
443 commandLine += " " + sp.arguments;
444 }
445
446 const QString moPath = QCoreApplication::applicationDirPath();
447 const auto oldPath = env::appendToPath(QDir::toNativeSeparators(moPath));
448
449 PROCESS_INFORMATION pi = {};
450 BOOL success = FALSE;
451
452 logSpawning(sp, commandLine);
453
454 const auto wcommandLine = commandLine.toStdWString();
455 const auto wcwd = cwd.toStdWString();
456
457 const DWORD flags = CREATE_BREAKAWAY_FROM_JOB;
458
459 if (sp.hooked) {
460 success = ::usvfsCreateProcessHooked(
461 nullptr, const_cast<wchar_t*>(wcommandLine.c_str()), nullptr, nullptr,
462 inheritHandles, flags, nullptr, wcwd.c_str(), &si, &pi);
463 } else {
464 success = ::CreateProcess(nullptr, const_cast<wchar_t*>(wcommandLine.c_str()),
465 nullptr, nullptr, inheritHandles, flags, nullptr,
466 wcwd.c_str(), &si, &pi);
467 }
468
469 const auto e = GetLastError();
470 env::setPath(oldPath);
471
472 if (!success) {
473 return e;
474 }
475

Callers 2

startSteamFunction · 0.85
startBinaryFunction · 0.85

Calls 5

appendToPathFunction · 0.85
logSpawningFunction · 0.85
setPathFunction · 0.85
absolutePathMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected