Skip to content

Commit

Permalink
Merge pull request #1109 from daxgames/user_conemu_cfg
Browse files Browse the repository at this point in the history
User conemu cfg
  • Loading branch information
daxgames authored Nov 2, 2016
2 parents 2b292f9 + 4c522aa commit 104033e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cmder.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@echo off
SET CMDER_ROOT=%~dp0

:: Remove trailing '\'
:: Remove Trailing '\'
@if "%CMDER_ROOT:~-1%" == "\" SET CMDER_ROOT=%CMDER_ROOT:~0,-1%

if exist "%~1" (
Expand Down
39 changes: 29 additions & 10 deletions launcher/src/CmderLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ void StartCmder(std::wstring path, bool is_single_mode)
wchar_t exeDir[MAX_PATH] = { 0 };
wchar_t icoPath[MAX_PATH] = { 0 };
wchar_t cfgPath[MAX_PATH] = { 0 };
wchar_t backupCfgPath[MAX_PATH] = { 0 };
wchar_t cpuCfgPath[MAX_PATH] = { 0 };
wchar_t userCfgPath[MAX_PATH] = { 0 };
wchar_t oldCfgPath[MAX_PATH] = { 0 };
wchar_t conEmuPath[MAX_PATH] = { 0 };
wchar_t args[MAX_PATH * 2 + 256] = { 0 };
Expand All @@ -117,19 +120,27 @@ void StartCmder(std::wstring path, bool is_single_mode)

PathCombine(icoPath, exeDir, L"icons\\cmder.ico");

// Check for machine-specific config file.
PathCombine(oldCfgPath, exeDir, L"config\\ConEmu-%COMPUTERNAME%.xml");
ExpandEnvironmentStrings(oldCfgPath, oldCfgPath, sizeof(oldCfgPath) / sizeof(oldCfgPath[0]));
if (!PathFileExists(oldCfgPath)) {
// Check for machine-specific then user config source file.
PathCombine(cpuCfgPath, exeDir, L"config\\ConEmu-%COMPUTERNAME%.xml");
ExpandEnvironmentStrings(cpuCfgPath, cpuCfgPath, sizeof(cpuCfgPath) / sizeof(cpuCfgPath[0]));

PathCombine(userCfgPath, exeDir, L"config\\user-ConEmu.xml");

if (PathFileExists(cpuCfgPath)) {
wcsncpy_s(oldCfgPath, cpuCfgPath, sizeof(cpuCfgPath));
wcsncpy_s(backupCfgPath, cpuCfgPath, sizeof(cpuCfgPath));
}
else if (PathFileExists(userCfgPath)) {
wcsncpy_s(oldCfgPath, userCfgPath,sizeof(userCfgPath));
wcsncpy_s(backupCfgPath, userCfgPath, sizeof(userCfgPath));
}
else {
PathCombine(oldCfgPath, exeDir, L"config\\ConEmu.xml");
wcsncpy_s(backupCfgPath, userCfgPath, sizeof(userCfgPath));
}

// Check for machine-specific config file.
PathCombine(cfgPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu-%COMPUTERNAME%.xml");
ExpandEnvironmentStrings(cfgPath, cfgPath, sizeof(cfgPath) / sizeof(cfgPath[0]));
if (!PathFileExists(cfgPath)) {
PathCombine(cfgPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu.xml");
}
// Set path to vendored ConEmu config file
PathCombine(cfgPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu.xml");

SYSTEM_INFO sysInfo;
GetNativeSystemInfo(&sysInfo);
Expand All @@ -151,6 +162,14 @@ void StartCmder(std::wstring path, bool is_single_mode)
exit(1);
}
}
else if (!CopyFile(cfgPath, backupCfgPath, FALSE))
{
MessageBox(NULL,
(GetLastError() == ERROR_ACCESS_DENIED)
? L"Failed to backup ConEmu.xml file to ./config folder!"
: L"Failed to backup ConEmu.xml file to ./config folder!", MB_TITLE, MB_ICONSTOP);
exit(1);
}

if (is_single_mode)
{
Expand Down

0 comments on commit 104033e

Please sign in to comment.