diff --git a/src/modules/Workspaces/WorkspacesLauncher/main.cpp b/src/modules/Workspaces/WorkspacesLauncher/main.cpp index 4e3efc83810..38e88acd48c 100644 --- a/src/modules/Workspaces/WorkspacesLauncher/main.cpp +++ b/src/modules/Workspaces/WorkspacesLauncher/main.cpp @@ -1,12 +1,5 @@ #include "pch.h" -#include -#include - -#include - -#include - #include #include #include @@ -14,6 +7,13 @@ #include #include +#include +#include + +#include + +#include + const std::wstring moduleName = L"Workspaces\\WorkspacesLauncher"; const std::wstring internalPath = L""; @@ -28,6 +28,15 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cm return 0; } + std::wstring cmdLineStr{ GetCommandLineW() }; + auto cmdArgs = split(cmdLineStr, L" "); + if (cmdArgs.workspaceId.empty()) + { + Logger::warn("Incorrect command line arguments: no workspace id"); + MessageBox(NULL, GET_RESOURCE_STRING(IDS_INCORRECT_ARGS).c_str(), GET_RESOURCE_STRING(IDS_WORKSPACES).c_str(), MB_ICONERROR | MB_OK); + return 1; + } + if (is_process_elevated()) { Logger::warn("Workspaces Launcher is elevated, restart"); @@ -41,7 +50,9 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cm std::string cmdLineStr(cmdline); std::wstring cmdLineWStr(cmdLineStr.begin(), cmdLineStr.end()); - run_non_elevated(exe_path.get(), cmdLineWStr, nullptr, modulePath.c_str()); + std::wstring cmd = cmdArgs.workspaceId + L" " + std::to_wstring(cmdArgs.invokePoint); + + RunNonElevatedEx(exe_path.get(), cmd, modulePath); return 1; } @@ -54,50 +65,21 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cm SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); - std::wstring cmdLineStr{ GetCommandLineW() }; - auto cmdArgs = split(cmdLineStr, L" "); - if (cmdArgs.size() < 2) - { - Logger::warn("Incorrect command line arguments"); - MessageBox(NULL, GET_RESOURCE_STRING(IDS_INCORRECT_ARGS).c_str(), GET_RESOURCE_STRING(IDS_WORKSPACES).c_str(), MB_ICONERROR | MB_OK); - return 1; - } - - std::wstring id(cmdArgs[1].begin(), cmdArgs[1].end()); - if (id.empty()) - { - Logger::warn("Incorrect command line arguments: no workspace id"); - MessageBox(NULL, GET_RESOURCE_STRING(IDS_INCORRECT_ARGS).c_str(), GET_RESOURCE_STRING(IDS_WORKSPACES).c_str(), MB_ICONERROR | MB_OK); - return 1; - } - - InvokePoint invokePoint = InvokePoint::EditorButton; - if (cmdArgs.size() > 2) - { - try - { - invokePoint = static_cast(std::stoi(cmdArgs[2])); - } - catch (std::exception) - { - } - } - - Logger::trace(L"Invoke point: {}", invokePoint); + Logger::trace(L"Invoke point: {}", cmdArgs.invokePoint); // read workspaces std::vector workspaces; WorkspacesData::WorkspacesProject projectToLaunch{}; - if (invokePoint == InvokePoint::LaunchAndEdit) + if (cmdArgs.invokePoint == InvokePoint::LaunchAndEdit) { // check the temp file in case the project is just created and not saved to the workspaces.json yet auto file = WorkspacesData::TempWorkspacesFile(); auto res = JsonUtils::ReadSingleWorkspace(file); - if (res.isOk() && projectToLaunch.id == id) + if (res.isOk() && projectToLaunch.id == cmdArgs.workspaceId) { projectToLaunch = res.getValue(); } - else + else if (res.isError()) { std::wstring formattedMessage{}; switch (res.error()) @@ -150,7 +132,7 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cm for (const auto& proj : workspaces) { - if (proj.id == id) + if (proj.id == cmdArgs.workspaceId) { projectToLaunch = proj; break; @@ -160,13 +142,13 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cm if (projectToLaunch.id.empty()) { - Logger::critical(L"Workspace {} not found", id); - std::wstring formattedMessage = fmt::format(GET_RESOURCE_STRING(IDS_PROJECT_NOT_FOUND), id); + Logger::critical(L"Workspace {} not found", cmdArgs.workspaceId); + std::wstring formattedMessage = fmt::format(GET_RESOURCE_STRING(IDS_PROJECT_NOT_FOUND), cmdArgs.workspaceId); MessageBox(NULL, formattedMessage.c_str(), GET_RESOURCE_STRING(IDS_WORKSPACES).c_str(), MB_ICONERROR | MB_OK); return 1; } - Launcher launcher(projectToLaunch, workspaces, invokePoint); + Launcher launcher(projectToLaunch, workspaces, cmdArgs.invokePoint); Logger::trace("Finished"); CoUninitialize(); diff --git a/src/modules/Workspaces/WorkspacesLib/LaunchingStatus.cpp b/src/modules/Workspaces/WorkspacesLib/LaunchingStatus.cpp index 5c438f5cf04..46c4bb6e3f4 100644 --- a/src/modules/Workspaces/WorkspacesLib/LaunchingStatus.cpp +++ b/src/modules/Workspaces/WorkspacesLib/LaunchingStatus.cpp @@ -26,7 +26,6 @@ bool LaunchingStatus::AllLaunchedAndMoved() noexcept { if (data.state != LaunchingState::Failed && data.state != LaunchingState::LaunchedAndMoved) { - Logger::debug(data.state); return false; } } diff --git a/src/modules/Workspaces/WorkspacesLib/utils.h b/src/modules/Workspaces/WorkspacesLib/utils.h index 72492dda1ab..5aebd197b34 100644 --- a/src/modules/Workspaces/WorkspacesLib/utils.h +++ b/src/modules/Workspaces/WorkspacesLib/utils.h @@ -3,11 +3,22 @@ #include #include -std::vector split(std::wstring s, const std::wstring& delimiter) +#include +#include + +struct CommandLineArgs { - std::vector tokens; + std::wstring workspaceId; + InvokePoint invokePoint; +}; + +CommandLineArgs split(std::wstring s, const std::wstring& delimiter) +{ + CommandLineArgs cmdArgs{}; + size_t pos = 0; std::wstring token; + std::vector tokens; while ((pos = s.find(delimiter)) != std::wstring::npos) { token = s.substr(0, pos); @@ -16,5 +27,28 @@ std::vector split(std::wstring s, const std::wstring& delimiter) } tokens.push_back(s); - return tokens; + for (const auto& token : tokens) + { + if (!cmdArgs.workspaceId.empty()) + { + try + { + auto invokePoint = static_cast(std::stoi(token)); + cmdArgs.invokePoint = invokePoint; + } + catch (std::exception) + { + } + } + else + { + auto guid = GuidFromString(token); + if (guid.has_value()) + { + cmdArgs.workspaceId = token; + } + } + } + + return cmdArgs; } diff --git a/src/modules/Workspaces/WorkspacesWindowArranger/main.cpp b/src/modules/Workspaces/WorkspacesWindowArranger/main.cpp index c946848a190..1c6a72dae5a 100644 --- a/src/modules/Workspaces/WorkspacesWindowArranger/main.cpp +++ b/src/modules/Workspaces/WorkspacesWindowArranger/main.cpp @@ -35,17 +35,7 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cm } auto args = split(commandLine, L" "); - std::wstring id{}; - if (args.size() == 1) - { - id = args[0]; - } - else if (args.size() == 2) - { - id = args[1]; - } - - if (id.empty()) + if (args.workspaceId.empty()) { Logger::warn("Incorrect command line arguments: no workspace id"); return 1; @@ -60,11 +50,11 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cm { auto file = WorkspacesData::TempWorkspacesFile(); auto res = JsonUtils::ReadSingleWorkspace(file); - if (res.isOk() && res.value().id == id) + if (res.isOk() && res.value().id == args.workspaceId) { projectToLaunch = res.getValue(); } - else + else if (res.isError()) { Logger::error(L"Error reading temp file"); return 1; @@ -86,7 +76,7 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cm for (const auto& proj : workspaces) { - if (proj.id == id) + if (proj.id == args.workspaceId) { projectToLaunch = proj; break; @@ -96,7 +86,7 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cm if (projectToLaunch.id.empty()) { - Logger::critical(L"Workspace {} not found", id); + Logger::critical(L"Workspace {} not found", args.workspaceId); return 1; }