From e904ebce72b6b612c37269298b8b831b2d1d4311 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sat, 10 Nov 2018 17:25:17 -0500 Subject: [PATCH 1/8] use user_conemu.xml or conemu-%computername%.xml directly if '-c [path]' is used to start cmder. --- launcher/src/CmderLauncher.cpp | 148 ++++++++++++++++++++------------- vendor/init.bat | 2 + 2 files changed, 91 insertions(+), 59 deletions(-) diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index 318ef61..b7d3868 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -91,6 +91,8 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr wchar_t userAliasesPath[MAX_PATH] = { 0 }; wchar_t legacyUserAliasesPath[MAX_PATH] = { 0 }; wchar_t args[MAX_PATH * 2 + 256] = { 0 }; + wchar_t userConEmuCfgPath[MAX_PATH] = { 0 }; + std::wstring cmderStart = path; std::wstring cmderTask = taskName; @@ -218,32 +220,72 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr if (PathFileExists(cpuCfgPath)) // config/ConEmu-%COMPUTERNAME%.xml file exists, use it. { - if (PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml file exists, copy vendor/conemu-maximus5/ConEmu.xml to config/ConEmu-%COMPUTERNAME%.xml. + if (cfgRoot.length() == 0) // '-C [PATH]' was NOT specified { - if (!CopyFile(cfgPath, cpuCfgPath, FALSE)) + if (PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml file exists, copy vendor/conemu-maximus5/ConEmu.xml to config/ConEmu-%COMPUTERNAME%.xml. { - MessageBox(NULL, - (GetLastError() == ERROR_ACCESS_DENIED) - ? L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/ConEmu-%COMPUTERNAME%.xml! Access Denied." - : L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/ConEmu-%COMPUTERNAME%.xml!", MB_TITLE, MB_ICONSTOP); - exit(1); + if (!CopyFile(cfgPath, cpuCfgPath, FALSE)) + { + MessageBox(NULL, + (GetLastError() == ERROR_ACCESS_DENIED) + ? L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/ConEmu-%COMPUTERNAME%.xml! Access Denied." + : L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/ConEmu-%COMPUTERNAME%.xml!", MB_TITLE, MB_ICONSTOP); + exit(1); + } + } + else // vendor/conemu-maximus5/ConEmu.xml config file does not exist, copy config/ConEmu-%COMPUTERNAME%.xml to vendor/conemu-maximus5/ConEmu.xml file + { + if (!CopyFile(cpuCfgPath, cfgPath, FALSE)) + { + MessageBox(NULL, + (GetLastError() == ERROR_ACCESS_DENIED) + ? L"Failed to copy conig/ConEmu-%COMPUTERNAME%.xml file to vendor/conemu-maximus5/ConEmu.xml! Access Denied." + : L"Failed to copy config/ConEmu-%COMPUTERNAME%.xml file to vendor/conemu-maximus5/ConEmu.xml!", MB_TITLE, MB_ICONSTOP); + exit(1); + } } } - else // vendor/conemu-maximus5/ConEmu.xml config file does not exist, copy config/ConEmu-%COMPUTERNAME%.xml to vendor/conemu-maximus5/ConEmu.xml file + else // '-C [PATH]' was specified, don't copy anything and use existing conemu-%COMPUTERNAME%.xml to start comemu. { - if (!CopyFile(cpuCfgPath, cfgPath, FALSE)) - { - MessageBox(NULL, - (GetLastError() == ERROR_ACCESS_DENIED) - ? L"Failed to copy conig/ConEmu-%COMPUTERNAME%.xml file to vendor/conemu-maximus5/ConEmu.xml! Access Denied." - : L"Failed to copy config/ConEmu-%COMPUTERNAME%.xml file to vendor/conemu-maximus5/ConEmu.xml!", MB_TITLE, MB_ICONSTOP); - exit(1); - } + PathCombine(userConEmuCfgPath, userConfigDirPath, L"ConEmu-%COMPUTERNAME%.xml"); + ExpandEnvironmentStrings(userConEmuCfgPath, userConEmuCfgPath, sizeof(userConEmuCfgPath) / sizeof(userConEmuCfgPath[0])); } } else if (PathFileExists(userCfgPath)) // config/user_conemu.xml exists, use it. { - if (PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml exists, copy vendor/conemu-maximus5/ConEmu.xml to config/user_conemu.xml. + if (cfgRoot.length() == 0) // '-C [PATH]' was NOT specified + { + if (PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml exists, copy vendor/conemu-maximus5/ConEmu.xml to config/user_conemu.xml. + { + if (!CopyFile(cfgPath, userCfgPath, FALSE)) + { + MessageBox(NULL, + (GetLastError() == ERROR_ACCESS_DENIED) + ? L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/user-conemu.xml! Access Denied." + : L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/user-conemu.xml!", MB_TITLE, MB_ICONSTOP); + exit(1); + } + } + else // vendor/conemu-maximus5/ConEmu.xml does not exist, copy config/user-conemu.xml to vendor/conemu-maximus5/ConEmu.xml + { + if (!CopyFile(userCfgPath, cfgPath, FALSE)) + { + MessageBox(NULL, + (GetLastError() == ERROR_ACCESS_DENIED) + ? L"Failed to copy config/user-conemu.xml file to vendor/conemu-maximus5/ConEmu.xml! Access Denied." + : L"Failed to copy config/user-conemu.xml file to vendor/conemu-maximus5/ConEmu.xml!", MB_TITLE, MB_ICONSTOP); + exit(1); + } + } + } + else // '-C [PATH]' was specified, don't copy anything and use existing user_conemu.xml to start comemu. + { + PathCombine(userConEmuCfgPath, userConfigDirPath, L"user-ConEmu.xml"); + } + } + else if (cfgRoot.length() == 0) // '-C [PATH]' was NOT specified + { + if (PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml exists, copy vendor/conemu-maximus5/ConEmu.xml to config/user_conemu.xml { if (!CopyFile(cfgPath, userCfgPath, FALSE)) { @@ -253,41 +295,30 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr : L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/user-conemu.xml!", MB_TITLE, MB_ICONSTOP); exit(1); } - } - else // vendor/conemu-maximus5/ConEmu.xml does not exist, copy config/user-conemu.xml to vendor/conemu-maximus5/ConEmu.xml - { - if (!CopyFile(userCfgPath, cfgPath, FALSE)) + else // vendor/ConEmu.xml config exists, copy Cmder vendor/ConEmu.xml file to vendor/conemu-maximus5/ConEmu.xml. { - MessageBox(NULL, - (GetLastError() == ERROR_ACCESS_DENIED) - ? L"Failed to copy config/user-conemu.xml file to vendor/conemu-maximus5/ConEmu.xml! Access Denied." - : L"Failed to copy config/user-conemu.xml file to vendor/conemu-maximus5/ConEmu.xml!", MB_TITLE, MB_ICONSTOP); - exit(1); + if (!CopyFile(defaultCfgPath, cfgPath, FALSE)) + { + MessageBox(NULL, + (GetLastError() == ERROR_ACCESS_DENIED) + ? L"Failed to copy vendor/ConEmu.xml.default file to vendor/conemu-maximus5/ConEmu.xml! Access Denied." + : L"Failed to copy vendor/ConEmu.xml.default file to vendor/conemu-maximus5/ConEmu.xml!", MB_TITLE, MB_ICONSTOP); + exit(1); + } } } } - else if (PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml exists, copy vendor/conemu-maximus5/ConEmu.xml to config/user_conemu.xml + else // '-C [PATH]' was specified and 'vendor/ConEmu.xml.default' config exists, copy Cmder 'vendor/ConEmu.xml.default' file to '[user specified path]/config/user_ConEmu.xml'. { - if (!CopyFile(cfgPath, userCfgPath, FALSE)) + if ( ! CopyFile(defaultCfgPath, userCfgPath, FALSE)) { MessageBox(NULL, (GetLastError() == ERROR_ACCESS_DENIED) - ? L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/user-conemu.xml! Access Denied." - : L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/user-conemu.xml!", MB_TITLE, MB_ICONSTOP); - exit(1); - } - } - else // vendor/ConEmu.xml config exists, copy Cmder vendor/ConEmu.xml file to vendor/conemu-maximus5/ConEmu.xml. - { - if ( ! CopyFile(defaultCfgPath, cfgPath, FALSE)) - { - ShowErrorAndExit(GetLastError(), __WFUNCTION__, __LINE__); - MessageBox(NULL, - (GetLastError() == ERROR_ACCESS_DENIED) - ? L"Failed to copy vendor/ConEmu.xml.default file to vendor/conemu-maximus5/ConEmu.xml! Access Denied." - : L"Failed to copy vendor/ConEmu.xml.default file to vendor/conemu-maximus5/ConEmu.xml!", MB_TITLE, MB_ICONSTOP); + ? L"Failed to copy vendor/ConEmu.xml.default file to [user specified path]/config/user_ConEmu.xml! Access Denied." + : L"Failed to copy vendor/ConEmu.xml.default file to [user specified path]/config/user_ConEmu.xml!", MB_TITLE, MB_ICONSTOP); exit(1); } + PathCombine(userConEmuCfgPath, userConfigDirPath, L"user-ConEmu.xml"); } SYSTEM_INFO sysInfo; @@ -301,27 +332,26 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr PathCombine(conEmuPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu.exe"); } + swprintf_s(args, L"%s /Icon \"%s\" /Title Cmder", args, icoPath); + + if (!streqi(cmderStart.c_str(), L"")) + { + swprintf_s(args, L"%s /dir \"%s\"", args, cmderStart.c_str()); + } + if (is_single_mode) { - if (!streqi(cmderTask.c_str(), L"")) - { - swprintf_s(args, L"%s /single /Icon \"%s\" /Title Cmder /dir \"%s\" /run {%s}", args, icoPath, cmderStart.c_str(), cmderTask.c_str()); - } - else - { - swprintf_s(args, L"%s /single /Icon \"%s\" /Title Cmder /dir \"%s\"", args, icoPath, cmderStart.c_str()); - } + swprintf_s(args, L"%s /single", args); } - else + + if (!streqi(cmderTask.c_str(), L"")) { - if (!streqi(cmderTask.c_str(), L"")) - { - swprintf_s(args, L"/Icon \"%s\" /Title Cmder /dir \"%s\" /run {%s}", icoPath, cmderStart.c_str(), cmderTask.c_str()); - } - else - { - swprintf_s(args, L"%s /Icon \"%s\" /Title Cmder /dir \"%s\"", args, icoPath, cmderStart.c_str()); - } + swprintf_s(args, L"%s /run {%s}", args, cmderTask.c_str()); + } + + if (cfgRoot.length() != 0) + { + swprintf_s(args, L"%s -loadcfgfile \"%s\"", args, userConEmuCfgPath); } SetEnvironmentVariable(L"CMDER_ROOT", exeDir); diff --git a/vendor/init.bat b/vendor/init.bat index 8a4d71a..a7452a1 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -346,6 +346,7 @@ if not defined HOME set "HOME=%USERPROFILE%" set "initialConfig=%CMDER_ROOT%\config\user_profile.cmd" if exist "%CMDER_ROOT%\config\user_profile.cmd" ( REM Create this file and place your own command in there + %lib_console% debug_output init.bat "Calling - %CMDER_ROOT%\config\user_profile.cmd" call "%CMDER_ROOT%\config\user_profile.cmd" ) @@ -353,6 +354,7 @@ if defined CMDER_USER_CONFIG ( set "initialConfig=%CMDER_USER_CONFIG%\user_profile.cmd" if exist "%CMDER_USER_CONFIG%\user_profile.cmd" ( REM Create this file and place your own command in there + %lib_console% debug_output init.bat "Calling - %CMDER_USER_CONFIG%\user_profile.cmd call "%CMDER_USER_CONFIG%\user_profile.cmd" ) ) From e17b04cbb941561cececd36aca9914c251d0cb3c Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sat, 10 Nov 2018 18:49:33 -0500 Subject: [PATCH 2/8] cleanup --- launcher/src/CmderLauncher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index b7d3868..37f8a81 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -295,7 +295,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr : L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/user-conemu.xml!", MB_TITLE, MB_ICONSTOP); exit(1); } - else // vendor/ConEmu.xml config exists, copy Cmder vendor/ConEmu.xml file to vendor/conemu-maximus5/ConEmu.xml. + else // vendor/ConEmu.xml config exists, copy Cmder vendor/ConEmu.xml.default file to vendor/conemu-maximus5/ConEmu.xml. { if (!CopyFile(defaultCfgPath, cfgPath, FALSE)) { From 8c0817941e6c4bac6e17de191f3d10b0a76e8182 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sun, 11 Nov 2018 07:55:14 -0500 Subject: [PATCH 3/8] added /c [path] use vendored conemu.xml as a default starting point if it exists --- launcher/src/CmderLauncher.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index 37f8a81..b4f43be 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -295,7 +295,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr : L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/user-conemu.xml!", MB_TITLE, MB_ICONSTOP); exit(1); } - else // vendor/ConEmu.xml config exists, copy Cmder vendor/ConEmu.xml.default file to vendor/conemu-maximus5/ConEmu.xml. + else // vendor/ConEmu.xml.default config exists, copy Cmder vendor/ConEmu.xml.default file to vendor/conemu-maximus5/ConEmu.xml. { if (!CopyFile(defaultCfgPath, cfgPath, FALSE)) { @@ -308,6 +308,19 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr } } } + else if (PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml exists, copy vendor/conemu-maximus5/ConEmu.xml to config/user_conemu.xml + { + if (!CopyFile(cfgPath, userCfgPath, FALSE)) + { + MessageBox(NULL, + (GetLastError() == ERROR_ACCESS_DENIED) + ? L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/user-conemu.xml! Access Denied." + : L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/user-conemu.xml!", MB_TITLE, MB_ICONSTOP); + exit(1); + } + + PathCombine(userConEmuCfgPath, userConfigDirPath, L"user-ConEmu.xml"); + } else // '-C [PATH]' was specified and 'vendor/ConEmu.xml.default' config exists, copy Cmder 'vendor/ConEmu.xml.default' file to '[user specified path]/config/user_ConEmu.xml'. { if ( ! CopyFile(defaultCfgPath, userCfgPath, FALSE)) From 0efeaa91fad426a12031b3c1bc0249d004c5629e Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sun, 11 Nov 2018 08:04:35 -0500 Subject: [PATCH 4/8] cleanup --- launcher/src/CmderLauncher.cpp | 14 +++++++------- vendor/init.bat | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index b4f43be..453a750 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -149,7 +149,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr } /* - Was -c [path] specified? + Was /c [path] specified? */ if (wcscmp(userConfigDirPath, L"") == 0) { @@ -220,7 +220,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr if (PathFileExists(cpuCfgPath)) // config/ConEmu-%COMPUTERNAME%.xml file exists, use it. { - if (cfgRoot.length() == 0) // '-C [PATH]' was NOT specified + if (cfgRoot.length() == 0) // '/c [path]' was NOT specified { if (PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml file exists, copy vendor/conemu-maximus5/ConEmu.xml to config/ConEmu-%COMPUTERNAME%.xml. { @@ -245,7 +245,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr } } } - else // '-C [PATH]' was specified, don't copy anything and use existing conemu-%COMPUTERNAME%.xml to start comemu. + else // '/c [path]' was specified, don't copy anything and use existing conemu-%COMPUTERNAME%.xml to start comemu. { PathCombine(userConEmuCfgPath, userConfigDirPath, L"ConEmu-%COMPUTERNAME%.xml"); ExpandEnvironmentStrings(userConEmuCfgPath, userConEmuCfgPath, sizeof(userConEmuCfgPath) / sizeof(userConEmuCfgPath[0])); @@ -253,7 +253,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr } else if (PathFileExists(userCfgPath)) // config/user_conemu.xml exists, use it. { - if (cfgRoot.length() == 0) // '-C [PATH]' was NOT specified + if (cfgRoot.length() == 0) // '/c [path]' was NOT specified { if (PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml exists, copy vendor/conemu-maximus5/ConEmu.xml to config/user_conemu.xml. { @@ -278,12 +278,12 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr } } } - else // '-C [PATH]' was specified, don't copy anything and use existing user_conemu.xml to start comemu. + else // '/c [path]' was specified, don't copy anything and use existing user_conemu.xml to start comemu. { PathCombine(userConEmuCfgPath, userConfigDirPath, L"user-ConEmu.xml"); } } - else if (cfgRoot.length() == 0) // '-C [PATH]' was NOT specified + else if (cfgRoot.length() == 0) // '/c [path]' was NOT specified { if (PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml exists, copy vendor/conemu-maximus5/ConEmu.xml to config/user_conemu.xml { @@ -321,7 +321,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr PathCombine(userConEmuCfgPath, userConfigDirPath, L"user-ConEmu.xml"); } - else // '-C [PATH]' was specified and 'vendor/ConEmu.xml.default' config exists, copy Cmder 'vendor/ConEmu.xml.default' file to '[user specified path]/config/user_ConEmu.xml'. + else // '/c [path]' was specified and 'vendor/ConEmu.xml.default' config exists, copy Cmder 'vendor/ConEmu.xml.default' file to '[user specified path]/config/user_ConEmu.xml'. { if ( ! CopyFile(defaultCfgPath, userCfgPath, FALSE)) { diff --git a/vendor/init.bat b/vendor/init.bat index a7452a1..30384ed 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -1,6 +1,6 @@ @echo off -set cmder_init_start=%time% +set CMDER_INIT_START=%time% :: Init Script for cmd.exe :: Created as part of cmder project @@ -400,9 +400,9 @@ if "%CMDER_ALIASES%" == "1" if exist "%CMDER_ROOT%\bin\alias.bat" if exist "%CMD set initialConfig= set CMDER_CONFIGURED=1 -set cmder_init_end=%time% +set CMDER_INIT_END=%time% if %time_init% gtr 0 ( - "%cmder_root%\vendor\bin\timer.cmd" %cmder_init_start% %cmder_init_end% + "%cmder_root%\vendor\bin\timer.cmd" %CMDER_INIT_START% %CMDER_INIT_END% ) exit /b From d8e8fc8adb03129658d4dad6eb012d30c2f5729e Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Mon, 12 Nov 2018 07:56:55 -0500 Subject: [PATCH 5/8] add /m command line argument to use machine config rather than user config for conemu. --- .gitignore | 2 ++ launcher/src/CmderLauncher.cpp | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index ac64e10..4a75750 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ vendor/*/* config/* !config/Readme.md +config_user/* + Thumbs.db *.exe *.dll diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index 453a750..33e2f41 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -69,7 +69,7 @@ bool FileExists(const wchar_t * filePath) return false; } -void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstring taskName = L"", std::wstring cfgRoot = L"") +void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstring taskName = L"", std::wstring cfgRoot = L"", bool use_user_cfg = true) { #if USE_TASKBAR_API wchar_t appId[MAX_PATH] = { 0 }; @@ -218,7 +218,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr // Set path to Cmder user ConEmu config file PathCombine(userCfgPath, userConfigDirPath, L"user-ConEmu.xml"); - if (PathFileExists(cpuCfgPath)) // config/ConEmu-%COMPUTERNAME%.xml file exists, use it. + if ( PathFileExists(cpuCfgPath) || use_user_cfg == false ) // config/ConEmu-%COMPUTERNAME%.xml file exists or /m was specified on command line, use machine specific config. { if (cfgRoot.length() == 0) // '/c [path]' was NOT specified { @@ -486,6 +486,7 @@ struct cmderOptions std::wstring cmderTask = L""; std::wstring cmderRegScope = L"USER"; bool cmderSingle = false; + bool cmderUserCfg = true; bool registerApp = false; bool unRegisterApp = false; bool error = false; @@ -546,6 +547,10 @@ cmderOptions GetOption() { cmderOptions.cmderSingle = true; } + else if (_wcsicmp(L"/m", szArgList[i]) == 0) + { + cmderOptions.cmderUserCfg = false; + } else if (_wcsicmp(L"/register", szArgList[i]) == 0) { cmderOptions.registerApp = true; @@ -592,7 +597,7 @@ cmderOptions GetOption() } else { - MessageBox(NULL, L"Unrecognized parameter.\n\nValid options:\n\n /c [CMDER User Root Path]\n\n /task [ConEmu Task Name]\n\n [/start [Start in Path] | [Start in Path]]\n\n /single\n\nor\n\n /register [USER | ALL]\n\nor\n\n /unregister [USER | ALL]\n", MB_TITLE, MB_OK); + MessageBox(NULL, L"Unrecognized parameter.\n\nValid options:\n\n /c [CMDER User Root Path]\n\n /task [ConEmu Task Name]\n\n [/start [Start in Path] | [Start in Path]]\n\n /single\n\n /m\n\nor\n\n /register [USER | ALL]\n\nor\n\n /unregister [USER | ALL]\n", MB_TITLE, MB_OK); cmderOptions.error = true; } } @@ -629,7 +634,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, } else { - StartCmder(cmderOptions.cmderStart, cmderOptions.cmderSingle, cmderOptions.cmderTask, cmderOptions.cmderCfgRoot); + StartCmder(cmderOptions.cmderStart, cmderOptions.cmderSingle, cmderOptions.cmderTask, cmderOptions.cmderCfgRoot, cmderOptions.cmderUserCfg); } return 0; From b16aa7a29e777c6d3a9240ffbb3ce96708ac14ca Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Mon, 12 Nov 2018 08:30:44 -0500 Subject: [PATCH 6/8] better command line error handling --- launcher/src/CmderLauncher.cpp | 169 ++++++++++++++++++--------------- 1 file changed, 92 insertions(+), 77 deletions(-) diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index 33e2f41..2a2c937 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -247,6 +247,18 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr } else // '/c [path]' was specified, don't copy anything and use existing conemu-%COMPUTERNAME%.xml to start comemu. { + if (use_user_cfg == false && PathFileExists(cfgPath) && !PathFileExists(cpuCfgPath)) // vendor/conemu-maximus5/ConEmu.xml file exists, copy vendor/conemu-maximus5/ConEmu.xml to config/ConEmu-%COMPUTERNAME%.xml. + { + if (!CopyFile(cfgPath, cpuCfgPath, FALSE)) + { + MessageBox(NULL, + (GetLastError() == ERROR_ACCESS_DENIED) + ? L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/ConEmu-%COMPUTERNAME%.xml! Access Denied." + : L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/ConEmu-%COMPUTERNAME%.xml!", MB_TITLE, MB_ICONSTOP); + exit(1); + } + } + PathCombine(userConEmuCfgPath, userConfigDirPath, L"ConEmu-%COMPUTERNAME%.xml"); ExpandEnvironmentStrings(userConEmuCfgPath, userConEmuCfgPath, sizeof(userConEmuCfgPath) / sizeof(userConEmuCfgPath[0])); } @@ -504,102 +516,105 @@ cmderOptions GetOption() { // MessageBox(NULL, szArgList[i], L"Arglist contents", MB_OK); - if (_wcsicmp(L"/c", szArgList[i]) == 0) - { - TCHAR userProfile[MAX_PATH]; - const DWORD ret = GetEnvironmentVariable(L"USERPROFILE", userProfile, MAX_PATH); + if (cmderOptions.error == false) { + if (_wcsicmp(L"/c", szArgList[i]) == 0) + { + TCHAR userProfile[MAX_PATH]; + const DWORD ret = GetEnvironmentVariable(L"USERPROFILE", userProfile, MAX_PATH); - wchar_t cmderCfgRoot[MAX_PATH] = { 0 }; - PathCombine(cmderCfgRoot, userProfile, L"cmder_cfg"); + wchar_t cmderCfgRoot[MAX_PATH] = { 0 }; + PathCombine(cmderCfgRoot, userProfile, L"cmder_cfg"); - cmderOptions.cmderCfgRoot = cmderCfgRoot; + cmderOptions.cmderCfgRoot = cmderCfgRoot; - if (szArgList[i + 1] != NULL && szArgList[i + 1][0] != '/') - { - cmderOptions.cmderCfgRoot = szArgList[i + 1]; - i++; - } - } - else if (_wcsicmp(L"/start", szArgList[i]) == 0) - { - int len = wcslen(szArgList[i + 1]); - if (wcscmp(&szArgList[i + 1][len - 1], L"\"") == 0) - { - szArgList[i + 1][len - 1] = '\0'; - } - - if (PathFileExists(szArgList[i + 1])) - { - cmderOptions.cmderStart = szArgList[i + 1]; - i++; - } - else - { - MessageBox(NULL, szArgList[i + 1], L"/START - Folder does not exist!", MB_OK); - } - } - else if (_wcsicmp(L"/task", szArgList[i]) == 0) - { - cmderOptions.cmderTask = szArgList[i + 1]; - i++; - } - else if (_wcsicmp(L"/single", szArgList[i]) == 0) - { - cmderOptions.cmderSingle = true; - } - else if (_wcsicmp(L"/m", szArgList[i]) == 0) - { - cmderOptions.cmderUserCfg = false; - } - else if (_wcsicmp(L"/register", szArgList[i]) == 0) - { - cmderOptions.registerApp = true; - cmderOptions.unRegisterApp = false; - if (szArgList[i + 1] != NULL) - { - if (_wcsicmp(L"all", szArgList[i + 1]) == 0 || _wcsicmp(L"user", szArgList[i + 1]) == 0) + if (szArgList[i + 1] != NULL && szArgList[i + 1][0] != '/') { - cmderOptions.cmderRegScope = szArgList[i + 1]; + cmderOptions.cmderCfgRoot = szArgList[i + 1]; i++; } } - } - else if (_wcsicmp(L"/unregister", szArgList[i]) == 0) - { - cmderOptions.unRegisterApp = true; - cmderOptions.registerApp = false; - if (szArgList[i + 1] != NULL) + else if (_wcsicmp(L"/start", szArgList[i]) == 0) { - if (_wcsicmp(L"all", szArgList[i + 1]) == 0 || _wcsicmp(L"user", szArgList[i + 1]) == 0) + int len = wcslen(szArgList[i + 1]); + if (wcscmp(&szArgList[i + 1][len - 1], L"\"") == 0) { - cmderOptions.cmderRegScope = szArgList[i + 1]; + szArgList[i + 1][len - 1] = '\0'; + } + + if (PathFileExists(szArgList[i + 1])) + { + cmderOptions.cmderStart = szArgList[i + 1]; i++; } + else + { + MessageBox(NULL, szArgList[i + 1], L"/START - Folder does not exist!", MB_OK); + } } - } - else if (cmderOptions.cmderStart == L"") - { - int len = wcslen(szArgList[i]); - if (wcscmp(&szArgList[i][len - 1], L"\"") == 0) + else if (_wcsicmp(L"/task", szArgList[i]) == 0) { - szArgList[i][len - 1] = '\0'; - } - - if (PathFileExists(szArgList[i])) - { - cmderOptions.cmderStart = szArgList[i]; + cmderOptions.cmderTask = szArgList[i + 1]; i++; } + else if (_wcsicmp(L"/single", szArgList[i]) == 0) + { + cmderOptions.cmderSingle = true; + } + else if (_wcsicmp(L"/m", szArgList[i]) == 0) + { + cmderOptions.cmderUserCfg = false; + } + else if (_wcsicmp(L"/register", szArgList[i]) == 0) + { + cmderOptions.registerApp = true; + cmderOptions.unRegisterApp = false; + if (szArgList[i + 1] != NULL) + { + if (_wcsicmp(L"all", szArgList[i + 1]) == 0 || _wcsicmp(L"user", szArgList[i + 1]) == 0) + { + cmderOptions.cmderRegScope = szArgList[i + 1]; + i++; + } + } + } + else if (_wcsicmp(L"/unregister", szArgList[i]) == 0) + { + cmderOptions.unRegisterApp = true; + cmderOptions.registerApp = false; + if (szArgList[i + 1] != NULL) + { + if (_wcsicmp(L"all", szArgList[i + 1]) == 0 || _wcsicmp(L"user", szArgList[i + 1]) == 0) + { + cmderOptions.cmderRegScope = szArgList[i + 1]; + i++; + } + } + } + else if (cmderOptions.cmderStart == L"") + { + int len = wcslen(szArgList[i]); + if (wcscmp(&szArgList[i][len - 1], L"\"") == 0) + { + szArgList[i][len - 1] = '\0'; + } + + if (PathFileExists(szArgList[i])) + { + cmderOptions.cmderStart = szArgList[i]; + i++; + } + else + { + MessageBox(NULL, L"Unrecognized parameter.\n\nValid options:\n\n /c [CMDER User Root Path]\n\n /task [ConEmu Task Name]\n\n [/start [Start in Path] | [Start in Path]]\n\n /single\n\n /m\n\nor\n\n /register [USER | ALL]\n\nor\n\n /unregister [USER | ALL]\n", MB_TITLE, MB_OK); + cmderOptions.error = true; + } + } else { - MessageBox(NULL, szArgList[i], L"Folder does not exist!", MB_OK); + MessageBox(NULL, L"Unrecognized parameter.\n\nValid options:\n\n /c [CMDER User Root Path]\n\n /task [ConEmu Task Name]\n\n [/start [Start in Path] | [Start in Path]]\n\n /single\n\n /m\n\nor\n\n /register [USER | ALL]\n\nor\n\n /unregister [USER | ALL]\n", MB_TITLE, MB_OK); + cmderOptions.error = true; } } - else - { - MessageBox(NULL, L"Unrecognized parameter.\n\nValid options:\n\n /c [CMDER User Root Path]\n\n /task [ConEmu Task Name]\n\n [/start [Start in Path] | [Start in Path]]\n\n /single\n\n /m\n\nor\n\n /register [USER | ALL]\n\nor\n\n /unregister [USER | ALL]\n", MB_TITLE, MB_OK); - cmderOptions.error = true; - } } LocalFree(szArgList); From 787ac3773cab86d31f477abd1a31808a7c39dfe5 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Mon, 12 Nov 2018 09:22:05 -0500 Subject: [PATCH 7/8] 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) { From 7203671fc9fe2922c4de6e3c484b1c347855b2eb Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sat, 17 Nov 2018 19:55:24 -0500 Subject: [PATCH 8/8] fix powershell profile.d --- vendor/profile.ps1 | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/vendor/profile.ps1 b/vendor/profile.ps1 index 995b745..159ebe2 100644 --- a/vendor/profile.ps1 +++ b/vendor/profile.ps1 @@ -128,20 +128,30 @@ if (-not (test-path "$ENV:CMDER_ROOT\config\profile.d")) { } pushd $ENV:CMDER_ROOT\config\profile.d -foreach ($x in Get-ChildItem *.ps1) { +foreach ($x in Get-ChildItem *.psm1) { # write-host write-host Sourcing $x Import-Module $x } + +foreach ($x in Get-ChildItem *.ps1) { + # write-host write-host Sourcing $x + . $x +} popd # Drop *.ps1 files into "$ENV:CMDER_USER_CONFIG\config\profile.d" # to source them at startup. Requires using cmder.exe /C [cmder_user_root_path] argument if ($ENV:CMDER_USER_CONFIG -ne "" -and (test-path "$ENV:CMDER_USER_CONFIG\profile.d")) { pushd $ENV:CMDER_USER_CONFIG\profile.d - foreach ($x in Get-ChildItem *.ps1) { + foreach ($x in Get-ChildItem *.psm1) { # write-host write-host Sourcing $x Import-Module $x } + + foreach ($x in Get-ChildItem *.ps1) { + # write-host write-host Sourcing $x + . $x + } popd } @@ -153,7 +163,7 @@ if (test-path "$env:CMDER_ROOT\config\user-profile.ps1") { $CmderUserProfilePath = Join-Path $env:CMDER_ROOT "config\user_profile.ps1" if (Test-Path $CmderUserProfilePath) { # Create this file and place your own command in there. - Import-Module "$CmderUserProfilePath" + . "$CmderUserProfilePath" # user_profile.ps1 is not a module DO NOT USE import-module } if ($ENV:CMDER_USER_CONFIG) { @@ -166,7 +176,7 @@ if ($ENV:CMDER_USER_CONFIG) { $CmderUserProfilePath = Join-Path $ENV:CMDER_USER_CONFIG "user_profile.ps1" if (Test-Path $CmderUserProfilePath) { - Import-Module "$CmderUserProfilePath" + . "$CmderUserProfilePath" # user_profile.ps1 is not a module DO NOT USE import-module } }