diff options
Diffstat (limited to 'src/helper.cpp')
| -rw-r--r-- | src/helper.cpp | 90 |
1 files changed, 50 insertions, 40 deletions
diff --git a/src/helper.cpp b/src/helper.cpp index 172cf2a2..b7fc866c 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -19,8 +19,8 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "helper.h"
#include "utility.h"
-#include <LMCons.h>
#include <report.h>
+#include <LMCons.h>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
@@ -29,61 +29,71 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. using MOBase::reportError;
+
namespace Helper {
-static bool helperExec(LPCWSTR moDirectory, LPCWSTR commandLine) {
- wchar_t fileName[MAX_PATH];
- _snwprintf(fileName, MAX_PATH, L"%ls\\helper.exe", moDirectory);
- SHELLEXECUTEINFOW execInfo = {0};
+static bool helperExec(LPCWSTR moDirectory, LPCWSTR commandLine)
+{
+ wchar_t fileName[MAX_PATH];
+ _snwprintf(fileName, MAX_PATH, L"%ls\\helper.exe", moDirectory);
+
+ SHELLEXECUTEINFOW execInfo = {0};
- execInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
- execInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
- execInfo.hwnd = nullptr;
- execInfo.lpVerb = L"runas";
- execInfo.lpFile = fileName;
- execInfo.lpParameters = commandLine;
- execInfo.lpDirectory = moDirectory;
- execInfo.nShow = SW_SHOW;
+ execInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
+ execInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
+ execInfo.hwnd = nullptr;
+ execInfo.lpVerb = L"runas";
+ execInfo.lpFile = fileName;
+ execInfo.lpParameters = commandLine;
+ execInfo.lpDirectory = moDirectory;
+ execInfo.nShow = SW_SHOW;
- ::ShellExecuteExW(&execInfo);
+ ::ShellExecuteExW(&execInfo);
- if ((execInfo.hProcess == 0) || (::WaitForSingleObject(execInfo.hProcess, INFINITE) != WAIT_OBJECT_0)) {
- reportError(QObject::tr("helper failed"));
- return false;
- }
+ if ((execInfo.hProcess == 0) || (::WaitForSingleObject(execInfo.hProcess, INFINITE) != WAIT_OBJECT_0)) {
+ reportError(QObject::tr("helper failed"));
+ return false;
+ }
- DWORD exitCode;
- GetExitCodeProcess(execInfo.hProcess, &exitCode);
- return exitCode == NOERROR;
+ DWORD exitCode;
+ GetExitCodeProcess(execInfo.hProcess, &exitCode);
+ return exitCode == NOERROR;
}
-bool init(const std::wstring& moPath, const std::wstring& dataPath) {
- DWORD userNameLen = UNLEN + 1;
- wchar_t userName[UNLEN + 1];
- if (!GetUserName(userName, &userNameLen)) {
- reportError(QObject::tr("failed to determine account name"));
- return false;
- }
- wchar_t* commandLine = new wchar_t[32768];
+bool init(const std::wstring &moPath, const std::wstring &dataPath)
+{
+ DWORD userNameLen = UNLEN + 1;
+ wchar_t userName[UNLEN + 1];
- _snwprintf(commandLine, 32768, L"init \"%ls\" \"%ls\"", dataPath.c_str(), userName);
+ if (!GetUserName(userName, &userNameLen)) {
+ reportError(QObject::tr("failed to determine account name"));
+ return false;
+ }
+ wchar_t *commandLine = new wchar_t[32768];
- bool res = helperExec(moPath.c_str(), commandLine);
- delete[] commandLine;
+ _snwprintf(commandLine, 32768, L"init \"%ls\" \"%ls\"",
+ dataPath.c_str(), userName);
- return res;
+ bool res = helperExec(moPath.c_str(), commandLine);
+ delete [] commandLine;
+
+ return res;
}
-bool backdateBSAs(const std::wstring& moPath, const std::wstring& dataPath) {
- wchar_t* commandLine = new wchar_t[32768];
- _snwprintf(commandLine, 32768, L"backdateBSA \"%ls\"", dataPath.c_str());
- bool res = helperExec(moPath.c_str(), commandLine);
- delete[] commandLine;
+bool backdateBSAs(const std::wstring &moPath, const std::wstring &dataPath)
+{
+ wchar_t *commandLine = new wchar_t[32768];
+ _snwprintf(commandLine, 32768, L"backdateBSA \"%ls\"",
+ dataPath.c_str());
+
+ bool res = helperExec(moPath.c_str(), commandLine);
+ delete [] commandLine;
- return res;
+ return res;
}
-} // namespace Helper
+
+} // namespace
|
