diff --git a/Cmder.bat b/Cmder.bat index 18d9ff0..6a95148 100644 --- a/Cmder.bat +++ b/Cmder.bat @@ -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" ( diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index acfd6eb..42f2902 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -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 }; @@ -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); @@ -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) {