summaryrefslogtreecommitdiff
path: root/src/spawn.cpp
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2014-04-05 15:36:42 +0200
committerTannin <devnull@localhost>2014-04-05 15:36:42 +0200
commitcabed9b268c9f095d5e3b98a6797b0bcdcd38b1f (patch)
tree454b03b0c5664e90fe586e7b39603e34a526d35b /src/spawn.cpp
parent98e5e57a845541acddf519a81957261f58008cb9 (diff)
parentc017f4a0d50b67a44e276bd5ae8929ed3990c62c (diff)
Merge with branch1.1
Diffstat (limited to 'src/spawn.cpp')
-rw-r--r--src/spawn.cpp38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/spawn.cpp b/src/spawn.cpp
index ab43b687..6adafba0 100644
--- a/src/spawn.cpp
+++ b/src/spawn.cpp
@@ -36,10 +36,23 @@ using namespace MOShared;
static const int BUFSIZE = 4096;
-bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool suspended, HANDLE& processHandle, HANDLE& threadHandle)
+bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool suspended,
+ HANDLE stdOut, HANDLE stdErr,
+ HANDLE& processHandle, HANDLE& threadHandle)
{
+ BOOL inheritHandles = FALSE;
STARTUPINFO si;
::ZeroMemory(&si, sizeof(si));
+ if (stdOut != INVALID_HANDLE_VALUE) {
+ si.hStdOutput = stdOut;
+ inheritHandles = TRUE;
+ si.dwFlags |= STARTF_USESTDHANDLES;
+ }
+ if (stdErr != INVALID_HANDLE_VALUE) {
+ si.hStdError = stdErr;
+ inheritHandles = TRUE;
+ si.dwFlags |= STARTF_USESTDHANDLES;
+ }
si.cb = sizeof(si);
int length = wcslen(binary) + wcslen(arguments) + 4;
wchar_t *commandLine = NULL;
@@ -74,7 +87,7 @@ bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool sus
BOOL success = ::CreateProcess(NULL,
commandLine,
NULL, NULL, // no special process or thread attributes
- FALSE, // don't inherit handle
+ inheritHandles, // inherit handles if we plan to use stdout or stderr reroute
suspended ? CREATE_SUSPENDED : 0, // create suspended so I have time to inject the DLL
NULL, // same environment as parent
currentDirectory, // current directory
@@ -95,14 +108,22 @@ bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool sus
}
-HANDLE startBinary(const QFileInfo &binary, const QString &arguments, const QString& profileName, int logLevel, const QDir &currentDirectory, bool hooked)
+HANDLE startBinary(const QFileInfo &binary,
+ const QString &arguments,
+ const QString& profileName,
+ int logLevel,
+ const QDir &currentDirectory,
+ bool hooked,
+ HANDLE stdOut,
+ HANDLE stdErr)
{
HANDLE processHandle, threadHandle;
std::wstring binaryName = ToWString(QDir::toNativeSeparators(binary.absoluteFilePath()));
std::wstring currentDirectoryName = ToWString(QDir::toNativeSeparators(currentDirectory.absolutePath()));
try {
- if (!spawn(binaryName.c_str(), ToWString(arguments).c_str(), currentDirectoryName.c_str(), hooked, processHandle, threadHandle)) {
+ if (!spawn(binaryName.c_str(), ToWString(arguments).c_str(), currentDirectoryName.c_str(), hooked,
+ stdOut, stdErr, processHandle, threadHandle)) {
reportError(QObject::tr("failed to spawn \"%1\"").arg(binary.fileName()));
return INVALID_HANDLE_VALUE;
}
@@ -117,9 +138,10 @@ HANDLE startBinary(const QFileInfo &binary, const QString &arguments, const QStr
"can be installed to work without elevation.\n\n"
"Start elevated anyway? "
"(you will be asked if you want to allow ModOrganizer.exe to make changes to the system)").arg(
- QDir::toNativeSeparators(binary.absoluteFilePath()))) == QMessageBox::Yes) {
+ QDir::toNativeSeparators(binary.absoluteFilePath())),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
::ShellExecuteW(NULL, L"runas", ToWString(QCoreApplication::applicationFilePath()).c_str(),
- (binaryName + L" " + ToWString(arguments)).c_str(), currentDirectoryName.c_str(), SW_SHOWNORMAL);
+ (std::wstring(L"\"") + binaryName + L"\" " + ToWString(arguments)).c_str(), currentDirectoryName.c_str(), SW_SHOWNORMAL);
return INVALID_HANDLE_VALUE;
} else {
return INVALID_HANDLE_VALUE;
@@ -156,7 +178,7 @@ HANDLE startBinary(const QFileInfo &binary, const QString &arguments, const QStr
return processHandle;
}
-
+/*
ExitProxy *ExitProxy::s_Instance = NULL;
ExitProxy *ExitProxy::instance()
@@ -170,4 +192,4 @@ ExitProxy *ExitProxy::instance()
void ExitProxy::emitExit()
{
emit exit();
-}
+}*/