mirror of
https://github.com/cmderdev/cmder.git
synced 2025-09-16 19:23:13 +08:00
Enhance cmder start directory.
The start directory of cmder is defined in that order: 1. The directory passed as parameter to the cmder executable 2. The `CMDER_START` environment variable 3. The `HOME` environment variable 4. The current user directory (`USERPROFILE` environment variable) This commit also fix two issues: * stating cmder with a path in parameter would set CMDER_START (whereas it may just be temporary) * fix new line in cmd when starting cmder (this one was buggin me)
This commit is contained in:
@ -79,6 +79,33 @@ optpair GetOption()
|
||||
return pair;
|
||||
}
|
||||
|
||||
void ComputeStartDirectory(std::wstring path)
|
||||
{
|
||||
if (path.empty()) {
|
||||
wchar_t buffer[MAX_PATH];
|
||||
if (GetEnvironmentVariable(L"CMDER_START", buffer, MAX_PATH))
|
||||
{
|
||||
SetEnvironmentVariable(L"CMDER_SESSION_START", buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GetEnvironmentVariable(L"HOME", buffer, MAX_PATH))
|
||||
{
|
||||
SetEnvironmentVariable(L"CMDER_SESSION_START", buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetEnvironmentVariable(L"USERPROFILE", buffer, MAX_PATH);
|
||||
SetEnvironmentVariable(L"CMDER_SESSION_START", buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetEnvironmentVariable(L"CMDER_SESSION_START", path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void StartCmder(std::wstring path, bool is_single_mode)
|
||||
{
|
||||
#if USE_TASKBAR_API
|
||||
@ -112,7 +139,7 @@ void StartCmder(std::wstring path, bool is_single_mode)
|
||||
}
|
||||
|
||||
SetEnvironmentVariable(L"CMDER_ROOT", exeDir);
|
||||
SetEnvironmentVariable(L"CMDER_START", path.c_str());
|
||||
ComputeStartDirectory(path);
|
||||
|
||||
STARTUPINFO si = { 0 };
|
||||
si.cb = sizeof(STARTUPINFO);
|
||||
|
Reference in New Issue
Block a user