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:
Nicolas Arnaud-Cormos
2015-01-10 07:50:44 +01:00
parent 17b4525e60
commit e9300ca43f
6 changed files with 41 additions and 28 deletions

View File

@ -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);