summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2020-07-18 03:38:11 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2020-11-03 11:39:01 -0500
commitf121d92602772110b80ce8ee89fef82c475190d3 (patch)
tree44c7d3ff4d02cf3c298197c5c2aa02cf07664ebb /src/main.cpp
parent5e528fb4cf16ae208944d15d568c9140e3d741e4 (diff)
implemented `launch` as a command
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp69
1 files changed, 4 insertions, 65 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 8a006907..68dcfe11 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -174,60 +174,6 @@ void setUnhandledExceptionHandler()
prevTerminateHandler = std::set_terminate(terminateHandler);
}
-// Parses the first parseArgCount arguments of the current process command line and returns
-// them in parsedArgs, the rest of the command line is returned untouched.
-LPCWSTR UntouchedCommandLineArguments(int parseArgCount, std::vector<std::wstring>& parsedArgs)
-{
- LPCWSTR cmd = GetCommandLineW();
- LPCWSTR arg = nullptr; // to skip executable name
- for (; parseArgCount >= 0 && *cmd; ++cmd)
- {
- if (*cmd == '"') {
- int escaped = 0;
- for (++cmd; *cmd && (*cmd != '"' || escaped % 2 != 0); ++cmd)
- escaped = *cmd == '\\' ? escaped + 1 : 0;
- }
- if (*cmd == ' ') {
- if (arg)
- if (cmd-1 > arg && *arg == '"' && *(cmd-1) == '"')
- parsedArgs.push_back(std::wstring(arg+1, cmd-1));
- else
- parsedArgs.push_back(std::wstring(arg, cmd));
- arg = cmd + 1;
- --parseArgCount;
- }
- }
- return cmd;
-}
-
-
-static int SpawnWaitProcess(LPCWSTR workingDirectory, LPCWSTR commandLine) {
- PROCESS_INFORMATION pi{ 0 };
- STARTUPINFO si{ 0 };
- si.cb = sizeof(si);
- std::wstring commandLineCopy = commandLine;
-
- if (!CreateProcessW(NULL, &commandLineCopy[0], NULL, NULL, FALSE, 0, NULL, workingDirectory, &si, &pi)) {
- // A bit of a problem where to log the error message here, at least this way you can get the message
- // using a either DebugView or a live debugger:
- std::wostringstream ost;
- ost << L"CreateProcess failed: " << commandLine << ", " << GetLastError();
- OutputDebugStringW(ost.str().c_str());
- return -1;
- }
-
- WaitForSingleObject(pi.hProcess, INFINITE);
-
- DWORD exitCode = (DWORD)-1;
- ::GetExitCodeProcess(pi.hProcess, &exitCode);
- CloseHandle(pi.hThread);
- CloseHandle(pi.hProcess);
- return static_cast<int>(exitCode);
-}
-
-static DWORD WaitForProcess() {
-
-}
static bool HaveWriteAccess(const std::wstring &path)
{
@@ -879,13 +825,13 @@ void initLogging()
int main(int argc, char *argv[])
{
- TimeThis tt("main to runApplication()");
cl::CommandLine cl;
- const auto r = cl.run(argc, argv);
- if (r >= 0)
- return r;
+ const auto r = cl.run(GetCommandLineW());
+ if (r)
+ return *r;
+ TimeThis tt("main to runApplication()");
initLogging();
//Make sure the configured temp folder exists
@@ -896,13 +842,6 @@ int main(int argc, char *argv[])
//Should allow for better scaling of ui with higher resolution displays
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- if (argc >= 4) {
- std::vector<std::wstring> arg;
- auto args = UntouchedCommandLineArguments(2, arg);
- if (arg[0] == L"launch")
- return SpawnWaitProcess(arg[1].c_str(), args);
- }
-
MOApplication application(argc, argv);
QStringList arguments = application.arguments();