summaryrefslogtreecommitdiff
path: root/src/spawn.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/spawn.cpp')
-rw-r--r--src/spawn.cpp198
1 files changed, 0 insertions, 198 deletions
diff --git a/src/spawn.cpp b/src/spawn.cpp
index 0ea60641..c8d7c76a 100644
--- a/src/spawn.cpp
+++ b/src/spawn.cpp
@@ -772,50 +772,6 @@ bool checkBlacklist(
}
}
-
-void adjustForVirtualized(
- const IPluginGame* game, SpawnParameters& sp, const Settings& settings)
-{
- const QString modsPath = settings.paths().mods();
-
- // Check if this a request with either an executable or a working directory
- // under our mods folder then will start the process in a virtualized
- // "environment" with the appropriate paths fixed:
- // (i.e. mods\FNIS\path\exe => game\data\path\exe)
- QString cwdPath = sp.currentDirectory.absolutePath();
- bool virtualizedCwd = cwdPath.startsWith(modsPath, Qt::CaseInsensitive);
- QString binPath = sp.binary.absoluteFilePath();
- bool virtualizedBin = binPath.startsWith(modsPath, Qt::CaseInsensitive);
- if (virtualizedCwd || virtualizedBin) {
- if (virtualizedCwd) {
- int cwdOffset = cwdPath.indexOf('/', modsPath.length() + 1);
- QString adjustedCwd = cwdPath.mid(cwdOffset, -1);
- cwdPath = game->dataDirectory().absolutePath();
- if (cwdOffset >= 0)
- cwdPath += adjustedCwd;
-
- }
-
- if (virtualizedBin) {
- int binOffset = binPath.indexOf('/', modsPath.length() + 1);
- QString adjustedBin = binPath.mid(binOffset, -1);
- binPath = game->dataDirectory().absolutePath();
- if (binOffset >= 0)
- binPath += adjustedBin;
- }
-
- QString cmdline
- = QString("launch \"%1\" \"%2\" %3")
- .arg(QDir::toNativeSeparators(cwdPath),
- QDir::toNativeSeparators(binPath), sp.arguments);
-
- sp.binary = QFileInfo(QCoreApplication::applicationFilePath());
- sp.arguments = cmdline;
- sp.currentDirectory.setPath(QCoreApplication::applicationDirPath());
- }
-}
-
-
HANDLE startBinary(QWidget* parent, const SpawnParameters& sp)
{
HANDLE handle = INVALID_HANDLE_VALUE;
@@ -842,80 +798,6 @@ HANDLE startBinary(QWidget* parent, const SpawnParameters& sp)
}
}
-
-
-SpawnedProcess::SpawnedProcess(HANDLE handle, SpawnParameters sp)
- : m_handle(handle), m_parameters(std::move(sp))
-{
-}
-
-SpawnedProcess::SpawnedProcess(SpawnedProcess&& other)
- : m_handle(other.m_handle), m_parameters(std::move(other.m_parameters))
-{
- other.m_handle = INVALID_HANDLE_VALUE;
-}
-
-SpawnedProcess& SpawnedProcess::operator=(SpawnedProcess&& other)
-{
- if (this != &other) {
- destroy();
-
- m_handle = other.m_handle;
- other.m_handle = INVALID_HANDLE_VALUE;
-
- m_parameters = std::move(other.m_parameters);
- }
-
- return *this;
-}
-
-SpawnedProcess::~SpawnedProcess()
-{
- destroy();
-}
-
-HANDLE SpawnedProcess::releaseHandle()
-{
- const auto h = m_handle;
- m_handle = INVALID_HANDLE_VALUE;
- return h;
-}
-
-void SpawnedProcess::destroy()
-{
- if (m_handle != INVALID_HANDLE_VALUE) {
- ::CloseHandle(m_handle);
- m_handle = INVALID_HANDLE_VALUE;
- }
-}
-
-
-SpawnedProcess Spawner::spawn(
- QWidget* parent, const IPluginGame* game,
- SpawnParameters sp, Settings& settings)
-{
- if (!checkBinary(parent, sp)) {
- return {INVALID_HANDLE_VALUE, sp};
- }
-
- if (!checkSteam(parent, sp, game->gameDirectory(), sp.steamAppID, settings)) {
- return {INVALID_HANDLE_VALUE, sp};
- }
-
- if (!checkEnvironment(parent, sp)) {
- return {INVALID_HANDLE_VALUE, sp};
- }
-
- if (!checkBlacklist(parent, sp, settings)) {
- return {INVALID_HANDLE_VALUE, sp};
- }
-
- adjustForVirtualized(game, sp, settings);
-
- return {startBinary(parent, sp), sp};
-}
-
-
QString getExecutableForJarFile(const QString& jarFile)
{
const std::wstring jarFileW = jarFile.toStdWString();
@@ -1094,86 +976,6 @@ FileExecutionContext getFileExecutionContext(
return {{}, {}, FileExecutionTypes::Other};
}
-WaitResults waitForProcess(
- HANDLE handle, DWORD* exitCode, std::function<bool ()> progress)
-{
- if (handle == INVALID_HANDLE_VALUE) {
- return WaitResults::Error;
- }
-
- log::debug("waiting for completion on pid {}", ::GetProcessId(handle));
-
- std::vector<HANDLE> handles;
- handles.push_back(handle);
-
- std::vector<DWORD> exitCodes;
-
- const auto r = waitForProcesses(handles, exitCodes, progress);
-
- if (r == WaitResults::Completed) {
- if (exitCode && !exitCodes.empty()) {
- *exitCode = exitCodes[0];
- }
- }
-
- return r;
-}
-
-WaitResults waitForProcesses(
- const std::vector<HANDLE>& handles, std::vector<DWORD>& exitCodes,
- std::function<bool ()> progress)
-{
- if (handles.empty()) {
- return WaitResults::Completed;
- }
-
- const auto WAIT_OBJECT_N = static_cast<DWORD>(WAIT_OBJECT_0 + handles.size());
-
- for (;;) {
- // Wait for a an event on the handle, a key press, mouse click or timeout
- const auto res = MsgWaitForMultipleObjects(
- static_cast<DWORD>(handles.size()), &handles[0],
- TRUE, 50, QS_KEY | QS_MOUSEBUTTON);
-
- if (res == WAIT_FAILED) {
- // error
- const auto e = ::GetLastError();
-
- log::error(
- "failed waiting for process completion, {}", formatSystemMessage(e));
-
- return WaitResults::Error;
- } else if (res >= WAIT_OBJECT_0 && res < WAIT_OBJECT_N) {
- // completed
- exitCodes.resize(handles.size());
- std::fill(exitCodes.begin(), exitCodes.end(), 0);
-
- for (std::size_t i=0; i<handles.size(); ++i) {
- DWORD exitCode = 0;
-
- if (::GetExitCodeProcess(handles[i], &exitCode)) {
- exitCodes[i] = exitCode;
- } else {
- const auto e = ::GetLastError();
- log::warn(
- "failed to get exit code of process, {}",
- formatSystemMessage(e));
- }
- }
-
- return WaitResults::Completed;
- }
-
- // keep processing events so the app doesn't appear dead
- QCoreApplication::sendPostedEvents();
- QCoreApplication::processEvents();
-
- if (progress && progress()) {
- return WaitResults::Cancelled;
- }
- }
-}
-
} // namespace