diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-10-29 11:34:06 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-11-06 07:44:55 -0500 |
| commit | 4d269c2e1a625e6d50b7e6272b4f474a921c6bfa (patch) | |
| tree | cd43db6b19152e98dd219de3350f8dbe6911662d /src/processrunner.h | |
| parent | 8c72077febaea485200adcf1e9f615902e930def (diff) | |
split to processrunner
added IUserInterface::qtWidget()
put back IUserInterface in OrganizerCore now that there's a way to get the widget
Diffstat (limited to 'src/processrunner.h')
| -rw-r--r-- | src/processrunner.h | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/processrunner.h b/src/processrunner.h new file mode 100644 index 00000000..38e79ca8 --- /dev/null +++ b/src/processrunner.h @@ -0,0 +1,104 @@ +#ifndef PROCESSRUNNER_H +#define PROCESSRUNNER_H + +#include "spawn.h" +#include <executableinfo.h> + +class OrganizerCore; +class ILockedWaitingForProcess; +class IUserInterface; +class Executable; +class MOShortcut; + +class SpawnedProcess +{ +public: + SpawnedProcess(HANDLE handle, spawn::SpawnParameters sp); + + SpawnedProcess(const SpawnedProcess&) = delete; + SpawnedProcess& operator=(const SpawnedProcess&) = delete; + SpawnedProcess(SpawnedProcess&& other); + SpawnedProcess& operator=(SpawnedProcess&& other); + ~SpawnedProcess(); + + HANDLE releaseHandle(); + void wait(); + +private: + HANDLE m_handle; + spawn::SpawnParameters m_parameters; + + void destroy(); +}; + + +class ProcessRunner +{ +public: + ProcessRunner(OrganizerCore& core); + + void setUserInterface(IUserInterface* ui); + + bool runFile(QWidget* parent, const QFileInfo& targetInfo); + + bool runExecutableFile( + const QFileInfo &binary, const QString &arguments, + const QDir ¤tDirectory, const QString &steamAppID={}, + const QString &customOverwrite={}, + const QList<MOBase::ExecutableForcedLoadSetting> &forcedLibraries={}, + bool refresh=true); + + bool runExecutable(const Executable& exe, bool refresh=true); + + bool runShortcut(const MOShortcut& shortcut); + + HANDLE runExecutableOrExecutableFile( + const QString &executable, const QStringList &args, const QString &cwd, + const QString &profile, const QString &forcedCustomOverwrite = "", + bool ignoreCustomOverwrite = false); + + bool waitForApplication(HANDLE processHandle, LPDWORD exitCode = nullptr); + + bool waitForAllUSVFSProcessesWithLock(); + +private: + OrganizerCore& m_core; + IUserInterface* m_ui; + + HANDLE spawnAndWait( + const QFileInfo &binary, const QString &arguments, + const QString &profileName, + const QDir ¤tDirectory, + const QString &steamAppID, + const QString &customOverwrite, + const QList<MOBase::ExecutableForcedLoadSetting> &forcedLibraries={}, + LPDWORD exitCode = nullptr); + + SpawnedProcess spawn(spawn::SpawnParameters sp); + + void withLock(std::function<void (ILockedWaitingForProcess*)> f); + + bool waitForProcessCompletionWithLock(HANDLE handle, LPDWORD exitCode); + + bool waitForProcessCompletion( + HANDLE handle, LPDWORD exitCode, ILockedWaitingForProcess* uilock); + + bool waitForAllUSVFSProcesses(ILockedWaitingForProcess* uilock); +}; + + +enum class WaitResults +{ + Completed = 1, + Error, + Cancelled +}; + +WaitResults waitForProcess( + HANDLE handle, DWORD* exitCode, std::function<bool ()> progress); + +WaitResults waitForProcesses( + const std::vector<HANDLE>& handles, std::vector<DWORD>& exitCodes, + std::function<bool ()> progress); + +#endif // PROCESSRUNNER_H |
