Skip to content

Commit 7962eda

Browse files
committed
Merge pull request #803 from cmderdev/MartiUK-patch-1
Set tasks to always use CMDER_START
2 parents fccba92 + 97cae2b commit 7962eda

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

Diff for: config/ConEmu.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@
527527
<value name="Flags" type="dword" data="00000000"/>
528528
<value name="Hotkey" type="dword" data="00000000"/>
529529
<value name="GuiArgs" type="string" data="/icon &quot;%ConEmuDir%\..\git-for-windows\usr\share\git\git-for-windows.ico&quot;"/>
530-
<value name="Cmd1" type="string" data="*%ConEmuDir%\..\git-for-windows\usr\bin\mintty.exe /bin/bash -l -new_console:d:%userProfile%"/>
530+
<value name="Cmd1" type="string" data="*%ConEmuDir%\..\git-for-windows\usr\bin\mintty.exe /bin/bash -l -new_console:d:%USERPROFILE%"/>
531531
<value name="Active" type="dword" data="00000000"/>
532532
<value name="Count" type="dword" data="00000001"/>
533533
</key>

Diff for: launcher/src/CmderLauncher.cpp

+25-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <Shlwapi.h>
44
#include "resource.h"
55
#include <vector>
6+
#include <Shlobj.h>
7+
68

79
#pragma comment(lib, "Shlwapi.lib")
810

@@ -153,17 +155,26 @@ void StartCmder(std::wstring path, bool is_single_mode)
153155
swprintf_s(args, L"/Icon \"%s\" /Title Cmder", icoPath);
154156
}
155157

156-
SetEnvironmentVariable(L"CMDER_ROOT", exeDir);
157-
if (!streqi(path.c_str(), L""))
158-
{
159-
SetEnvironmentVariable(L"CMDER_START", path.c_str());
158+
SetEnvironmentVariable(L"CMDER_ROOT", exeDir);
159+
if (!streqi(path.c_str(), L""))
160+
{
161+
if (!SetEnvironmentVariable(L"CMDER_START", path.c_str())) {
162+
MessageBox(NULL, _T("Error trying to set CMDER_START to given path!"), _T("Error"), MB_OK);
160163
}
161-
162-
// Send out the Settings Changed message - Once using ANSII...
163-
//SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, NULL);
164-
165-
// ...and once using UniCode (because Windows 8 likes it that way).
166-
//SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) L"Environment", SMTO_ABORTIFHUNG, 5000, NULL);
164+
}
165+
else
166+
{
167+
wchar_t* homeProfile = 0;
168+
SHGetKnownFolderPath(FOLDERID_Profile, 0, NULL, &homeProfile);
169+
if (!SetEnvironmentVariable(L"CMDER_START", homeProfile)) {
170+
MessageBox(NULL, _T("Error trying to set CMDER_START to USER_PROFILE!"), _T("Error"), MB_OK);
171+
}
172+
CoTaskMemFree(static_cast<void*>(homeProfile));
173+
}
174+
175+
// Ensure EnvironmentVariables are propagated.
176+
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, NULL);
177+
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) L"Environment", SMTO_ABORTIFHUNG, 5000, NULL); // For Windows >= 8
167178

168179
STARTUPINFO si = { 0 };
169180
si.cb = sizeof(STARTUPINFO);
@@ -173,8 +184,10 @@ void StartCmder(std::wstring path, bool is_single_mode)
173184
#endif
174185

175186
PROCESS_INFORMATION pi;
176-
177-
CreateProcess(conEmuPath, args, NULL, NULL, false, 0, NULL, NULL, &si, &pi);
187+
if (!CreateProcess(conEmuPath, args, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) {
188+
MessageBox(NULL, _T("Unable to create the ConEmu Process!"), _T("Error"), MB_OK);
189+
return;
190+
}
178191
}
179192

180193
bool IsUserOnly(std::wstring opt)

0 commit comments

Comments
 (0)