summaryrefslogtreecommitdiff
path: root/src/helper.cpp
diff options
context:
space:
mode:
authorSandro Jäckel <sandro.jaeckel@gmail.com>2018-02-22 16:54:34 +0100
committerSandro Jäckel <sandro.jaeckel@gmail.com>2018-02-22 16:54:34 +0100
commit5e5c9c07291f6b09623d31c92b1fb61c4ede576e (patch)
tree0684c123db375336e0e03f0240155a12e744db16 /src/helper.cpp
parent5ad912e1934061b38825801a27f7c12933878005 (diff)
Applied clang-format on source
Diffstat (limited to 'src/helper.cpp')
-rw-r--r--src/helper.cpp90
1 files changed, 40 insertions, 50 deletions
diff --git a/src/helper.cpp b/src/helper.cpp
index b7fc866c..172cf2a2 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 <report.h>
#include <LMCons.h>
+#include <report.h>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
@@ -29,71 +29,61 @@ 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);
-static bool helperExec(LPCWSTR moDirectory, LPCWSTR commandLine)
-{
- wchar_t fileName[MAX_PATH];
- _snwprintf(fileName, MAX_PATH, L"%ls\\helper.exe", moDirectory);
-
- SHELLEXECUTEINFOW execInfo = {0};
+ 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];
-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];
- if (!GetUserName(userName, &userNameLen)) {
- reportError(QObject::tr("failed to determine account name"));
- return false;
- }
- wchar_t *commandLine = new wchar_t[32768];
+ _snwprintf(commandLine, 32768, L"init \"%ls\" \"%ls\"", dataPath.c_str(), userName);
- _snwprintf(commandLine, 32768, L"init \"%ls\" \"%ls\"",
- dataPath.c_str(), userName);
+ bool res = helperExec(moPath.c_str(), commandLine);
+ delete[] commandLine;
- bool res = helperExec(moPath.c_str(), commandLine);
- delete [] commandLine;
-
- return res;
+ 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 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 res = helperExec(moPath.c_str(), commandLine);
+ delete[] commandLine;
- return res;
+ return res;
}
-
-} // namespace
+} // namespace Helper