From 4dc1249881f5ad3e2c5c64f685e7a9320f3840fc Mon Sep 17 00:00:00 2001 From: Martin Kemp Date: Fri, 15 Jan 2016 11:47:54 +0000 Subject: [PATCH 1/8] Set tasks to always user CMDER_START CMDER_START should always be set as a result of either: 1. The user passes a directory to cmder.exe using `/START $DIR` - or - 2. Sets CMDER_START as a default environment variable. Fixes #772 --- config/ConEmu.xml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/config/ConEmu.xml b/config/ConEmu.xml index ae1fd5d..979a469 100644 --- a/config/ConEmu.xml +++ b/config/ConEmu.xml @@ -488,7 +488,7 @@ - + @@ -497,7 +497,7 @@ - + @@ -507,7 +507,7 @@ - + @@ -516,7 +516,7 @@ - + @@ -527,7 +527,7 @@ - + @@ -536,10 +536,10 @@ - + - + @@ -548,14 +548,14 @@ - + - + From 9c7a0379485946e120db841ed10d75c578a5224b Mon Sep 17 00:00:00 2001 From: Martin Kemp Date: Fri, 15 Jan 2016 12:10:24 +0000 Subject: [PATCH 2/8] Set CMDER_START to USER_PROFILE if no path given. --- launcher/src/CmderLauncher.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index a29617e..bf616ad 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -153,17 +153,15 @@ void StartCmder(std::wstring path, bool is_single_mode) swprintf_s(args, L"/Icon \"%s\" /Title Cmder", icoPath); } - SetEnvironmentVariable(L"CMDER_ROOT", exeDir); - if (!streqi(path.c_str(), L"")) - { - SetEnvironmentVariable(L"CMDER_START", path.c_str()); - } - - // Send out the Settings Changed message - Once using ANSII... - //SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, NULL); - - // ...and once using UniCode (because Windows 8 likes it that way). - //SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) L"Environment", SMTO_ABORTIFHUNG, 5000, NULL); + SetEnvironmentVariable(L"CMDER_ROOT", exeDir); + if (!streqi(path.c_str(), L"")) + { + SetEnvironmentVariable(L"CMDER_START", path.c_str()); + } + else + { + SetEnvironmentVariable(L"CMDER_START", GetEnvironmentVariable(L"USER_PROFILE")); + } STARTUPINFO si = { 0 }; si.cb = sizeof(STARTUPINFO); From df7a6629659ece3c9af23ef8076f964e9a49c866 Mon Sep 17 00:00:00 2001 From: Martin Kemp Date: Fri, 15 Jan 2016 12:44:10 +0000 Subject: [PATCH 3/8] Get the environment variable correctly. --- launcher/src/CmderLauncher.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index bf616ad..eeff868 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -160,7 +160,9 @@ void StartCmder(std::wstring path, bool is_single_mode) } else { - SetEnvironmentVariable(L"CMDER_START", GetEnvironmentVariable(L"USER_PROFILE")); + static char buff[MAX_PATH]; + GetEnvironmentVariable(L"USER_PROFILE", buff, MAX_PATH); + SetEnvironmentVariable(L"CMDER_START", buff); } STARTUPINFO si = { 0 }; From fabcd468a797937a670c906b4e78442c9374529e Mon Sep 17 00:00:00 2001 From: Martin Kemp Date: Fri, 15 Jan 2016 13:01:55 +0000 Subject: [PATCH 4/8] Use the correct type and initialise it. --- 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 eeff868..be99de7 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -160,7 +160,7 @@ void StartCmder(std::wstring path, bool is_single_mode) } else { - static char buff[MAX_PATH]; + static wchar_t buff[MAX_PATH] = { 0 }; GetEnvironmentVariable(L"USER_PROFILE", buff, MAX_PATH); SetEnvironmentVariable(L"CMDER_START", buff); } From 73e1eb2a8bea93d4759f07cbb3a3145203c682fe Mon Sep 17 00:00:00 2001 From: Martin Kemp Date: Fri, 15 Jan 2016 13:13:16 +0000 Subject: [PATCH 5/8] Ensure Environment Variables are propagated. --- launcher/src/CmderLauncher.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index be99de7..6ac22e5 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -164,6 +164,10 @@ void StartCmder(std::wstring path, bool is_single_mode) GetEnvironmentVariable(L"USER_PROFILE", buff, MAX_PATH); SetEnvironmentVariable(L"CMDER_START", buff); } + + // Ensure EnvironmentVariables are propagated. + SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, NULL); + SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) L"Environment", SMTO_ABORTIFHUNG, 5000, NULL); // For Windows >= 8 STARTUPINFO si = { 0 }; si.cb = sizeof(STARTUPINFO); From c055ce1c13ac25565673b81a8fdb44172b059fa8 Mon Sep 17 00:00:00 2001 From: Martin Kemp Date: Sun, 31 Jan 2016 21:35:57 +0000 Subject: [PATCH 6/8] Get USER_PROFILE differently USER_PROFILE is a known folder, so use that functionality to get it. --- launcher/src/CmderLauncher.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index 6ac22e5..510d8ad 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -3,6 +3,8 @@ #include #include "resource.h" #include +#include + #pragma comment(lib, "Shlwapi.lib") @@ -156,13 +158,18 @@ void StartCmder(std::wstring path, bool is_single_mode) SetEnvironmentVariable(L"CMDER_ROOT", exeDir); if (!streqi(path.c_str(), L"")) { - SetEnvironmentVariable(L"CMDER_START", path.c_str()); + if (!SetEnvironmentVariable(L"CMDER_START", path.c_str())) { + MessageBox(NULL, _T("Error trying to set CMDER_START to given path!"), _T("Error"), MB_OK); + } } else { - static wchar_t buff[MAX_PATH] = { 0 }; - GetEnvironmentVariable(L"USER_PROFILE", buff, MAX_PATH); - SetEnvironmentVariable(L"CMDER_START", buff); + wchar_t* homeProfile = 0; + SHGetKnownFolderPath(FOLDERID_Profile, 0, NULL, &homeProfile); + if (!SetEnvironmentVariable(L"CMDER_START", homeProfile)) { + MessageBox(NULL, _T("Error trying to set CMDER_START to USER_PROFILE!"), _T("Error"), MB_OK); + } + CoTaskMemFree(static_cast(homeProfile)); } // Ensure EnvironmentVariables are propagated. @@ -177,8 +184,10 @@ void StartCmder(std::wstring path, bool is_single_mode) #endif PROCESS_INFORMATION pi; - - CreateProcess(conEmuPath, args, NULL, NULL, false, 0, NULL, NULL, &si, &pi); + if (!CreateProcess(conEmuPath, args, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) { + MessageBox(NULL, _T("Unable to create the ConEmu Process!"), _T("Error"), MB_OK); + return; + } } bool IsUserOnly(std::wstring opt) From 6bb07d9b196623a2472427b63fd027e900a4f0b2 Mon Sep 17 00:00:00 2001 From: Martin Kemp Date: Mon, 8 Feb 2016 18:19:58 +0000 Subject: [PATCH 7/8] Revert "Set tasks to always user CMDER_START" This reverts commit 4dc1249881f5ad3e2c5c64f685e7a9320f3840fc. --- config/ConEmu.xml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/config/ConEmu.xml b/config/ConEmu.xml index 979a469..ae1fd5d 100644 --- a/config/ConEmu.xml +++ b/config/ConEmu.xml @@ -488,7 +488,7 @@ - + @@ -497,7 +497,7 @@ - + @@ -507,7 +507,7 @@ - + @@ -516,7 +516,7 @@ - + @@ -527,7 +527,7 @@ - + @@ -536,10 +536,10 @@ - + - + @@ -548,14 +548,14 @@ - + - + From 97cae2bdc7970558708903851a25d14bc82442f1 Mon Sep 17 00:00:00 2001 From: Martin Kemp Date: Mon, 8 Feb 2016 18:26:57 +0000 Subject: [PATCH 8/8] Bring variable into line --- config/ConEmu.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/ConEmu.xml b/config/ConEmu.xml index ae1fd5d..bd520e2 100644 --- a/config/ConEmu.xml +++ b/config/ConEmu.xml @@ -527,7 +527,7 @@ - +