From 787ac3773cab86d31f477abd1a31808a7c39dfe5 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Mon, 12 Nov 2018 09:22:05 -0500 Subject: [PATCH] make /register work with /c --- README.md | 15 +++++++++------ launcher/src/CmderLauncher.cpp | 19 +++++++++++++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b56c05b..46d8dfd 100644 --- a/README.md +++ b/README.md @@ -41,12 +41,15 @@ The Cmder's user interface is also designed to be more eye pleasing, and you can ## Cmder.exe Command Line Arguments -| Argument | Description | -| ------------------- | ----------------------------------------------------------------------- | -| `/C [user_root_path]` | Individual user Cmder root folder. Example: `%userprofile%\cmder_config` | -| `/SINGLE` | Start Cmder in single mode. | -| `/START [start_path]` | Folder path to start in. | -| `/TASK [task_name]` | Task to start after launch. | +| Argument | Description | +| ------------------- | ----------------------------------------------------------------------- | +| `/C [user_root_path]` | Individual user Cmder root folder. Example: `%userprofile%\cmder_config` | +| `/M` | Use `conemu-%computername%.xml` for ConEmu settings storage instead of `user_conemu.xml` | +| `/REGISTER [ALL, USER]` | Register a Windows Shell Menu shortcut. | +| `/UNREGISTER [ALL, USER]` | Un-register a Windows Shell Menu shortcut. | +| `/SINGLE` | Start Cmder in single mode. | +| `/START [start_path]` | Folder path to start in. | +| `/TASK [task_name]` | Task to start after launch. | ## Context Menu Integration diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index 2a2c937..438a6d2 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -442,8 +442,10 @@ HKEY GetRootKey(std::wstring opt) return root; } -void RegisterShellMenu(std::wstring opt, wchar_t* keyBaseName) +void RegisterShellMenu(std::wstring opt, wchar_t* keyBaseName, std::wstring cfgRoot = L"") { + wchar_t userConfigDirPath[MAX_PATH] = { 0 }; + // First, get the paths we will use wchar_t exePath[MAX_PATH] = { 0 }; @@ -452,7 +454,16 @@ void RegisterShellMenu(std::wstring opt, wchar_t* keyBaseName) GetModuleFileName(NULL, exePath, sizeof(exePath)); wchar_t commandStr[MAX_PATH + 20] = { 0 }; - swprintf_s(commandStr, L"\"%s\" \"%%V\"", exePath); + + if (cfgRoot.length() == 0) // '/c [path]' was NOT specified + { + swprintf_s(commandStr, L"\"%s\" \"%%V\"", exePath); + } + else { + std::copy(cfgRoot.begin(), cfgRoot.end(), userConfigDirPath); + userConfigDirPath[cfgRoot.length()] = 0; + swprintf_s(commandStr, L"\"%s\" /c \"%s\" \"%%V\"", exePath, userConfigDirPath); + } // Now that we have `commandStr`, it's OK to change `exePath`... PathRemoveFileSpec(exePath); @@ -635,8 +646,8 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, if (cmderOptions.registerApp == true) { - RegisterShellMenu(cmderOptions.cmderRegScope, SHELL_MENU_REGISTRY_PATH_BACKGROUND); - RegisterShellMenu(cmderOptions.cmderRegScope, SHELL_MENU_REGISTRY_PATH_LISTITEM); + RegisterShellMenu(cmderOptions.cmderRegScope, SHELL_MENU_REGISTRY_PATH_BACKGROUND, cmderOptions.cmderCfgRoot); + RegisterShellMenu(cmderOptions.cmderRegScope, SHELL_MENU_REGISTRY_PATH_LISTITEM, cmderOptions.cmderCfgRoot); } else if (cmderOptions.unRegisterApp == true) {