summaryrefslogtreecommitdiff
path: root/src/spawn.cpp
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2013-03-22 18:57:45 +0100
committerTannin <devnull@localhost>2013-03-22 18:57:45 +0100
commitec0ea9df8dabe686d3256665c7ed638660309915 (patch)
tree39ff86ad325494c3531c159990ee695e84bee469 /src/spawn.cpp
parent24cc3861912cc33235af587d4f4feb538c1054dc (diff)
parent74c75e60d67b66a63225239c1f6b1403662857aa (diff)
Merge with default
Diffstat (limited to 'src/spawn.cpp')
-rw-r--r--src/spawn.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/spawn.cpp b/src/spawn.cpp
index 39bd2af9..e83c8e21 100644
--- a/src/spawn.cpp
+++ b/src/spawn.cpp
@@ -20,6 +20,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "spawn.h"
#include "report.h"
#include "utility.h"
+#include <boost/scoped_array.hpp>
#include <gameinfo.h>
#include <inject.h>
#include <appconfig.h>
@@ -31,6 +32,8 @@ using namespace MOBase;
using namespace MOShared;
+static const int BUFSIZE = 4096;
+
bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool suspended, HANDLE& processHandle, HANDLE& threadHandle)
{
STARTUPINFO si;
@@ -44,7 +47,25 @@ bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool sus
} else {
commandLine = new wchar_t[length];
_snwprintf(commandLine, length, L"\"%ls\"", binary);
+ }
+ QString moPath = QCoreApplication::applicationDirPath();
+
+ boost::scoped_array<TCHAR> oldPath(new TCHAR[BUFSIZE]);
+ DWORD offset = ::GetEnvironmentVariable(TEXT("PATH"), oldPath.get(), BUFSIZE);
+ if (offset > BUFSIZE) {
+ oldPath.reset(new TCHAR[offset]);
+ ::GetEnvironmentVariable(TEXT("PATH"), oldPath.get(), offset);
+ }
+
+ {
+ boost::scoped_array<TCHAR> newPath(new TCHAR[offset + moPath.length() + 2]);
+ _tcsncpy(newPath.get(), oldPath.get(), offset - 1);
+ newPath.get()[offset - 1] = L'\0';
+ _tcsncat(newPath.get(), TEXT(";"), 1);
+ _tcsncat(newPath.get(), ToWString(QDir::toNativeSeparators(moPath)).c_str(), moPath.length());
+
+ ::SetEnvironmentVariable(TEXT("PATH"), newPath.get());
}
PROCESS_INFORMATION pi;
@@ -58,6 +79,8 @@ bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool sus
&si, &pi // startup and process information
);
+ ::SetEnvironmentVariable(TEXT("PATH"), oldPath.get());
+
delete [] commandLine;
if (!success) {