Skip to content

Commit 15d5618

Browse files
authored
Merge pull request #2988 from daxgames/fix_launcher_overwrite-2
Development BUG - Fixes launcher overwriting or not backing up terminal emulator settings in development branch.
2 parents a1a6a02 + b412036 commit 15d5618

File tree

2 files changed

+51
-42
lines changed

2 files changed

+51
-42
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Fixes #2940
8+
39
## [1.3.20](https://github.com/cmderdev/cmder/tree/v1.3.20) (2022-03-18)
410

511
### Changes

launcher/src/CmderLauncher.cpp

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -289,57 +289,60 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
289289
// Set path to Cmder user ConEmu config file
290290
PathCombine(userCfgPath, userConfigDirPath, L"user-ConEmu.xml");
291291
}
292-
293-
if (wcscmp(cpuCfgPath, L"") == 0 && (PathFileExists(cpuCfgPath) || use_user_cfg == false)) // config/ConEmu-%COMPUTERNAME%.xml file exists or /m was specified on command line, use machine specific config.
292+
293+
if (wcscmp(cpuCfgPath, L"") != 0 && (PathFileExists(cpuCfgPath) || use_user_cfg == false)) // config/[host specific terminal emulator config] file exists or /m was specified on command line, use machine specific config.
294294
{
295295
if (cfgRoot.length() == 0) // '/c [path]' was NOT specified
296296
{
297-
if (!CopyFile(cfgPath, cpuCfgPath, FALSE))
297+
if (PathFileExists(cfgPath)) // [terminal emulator config] file exists, copy [terminal emulator config] to config/user_[terminal emulator config] file to backup any settings changes from previous sessions.
298298
{
299-
if (PathFileExists(windowsTerminalDir)) {
300-
MessageBox(NULL,
301-
(GetLastError() == ERROR_ACCESS_DENIED)
302-
? L"Failed to copy vendor/windows-terminal/settings/settings.json file to config/windows_terminal_%COMPUTERNAME%_settings.json! Access Denied."
303-
: L"Failed to copy vendor/windows-terminal/settings/settings.json file to config/windows_teerminal_%COMPUTERNAME%_settigns.json!", MB_TITLE, MB_ICONSTOP);
304-
exit(1);
305-
}
306-
else if (PathFileExists(conEmuDir))
299+
if (!CopyFile(cfgPath, cpuCfgPath, FALSE))
307300
{
308-
MessageBox(NULL,
309-
(GetLastError() == ERROR_ACCESS_DENIED)
310-
? L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/ConEmu-%COMPUTERNAME%.xml! Access Denied."
311-
: L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/ConEmu-%COMPUTERNAME%.xml!", MB_TITLE, MB_ICONSTOP);
312-
exit(1);
301+
if (PathFileExists(windowsTerminalDir)) {
302+
MessageBox(NULL,
303+
(GetLastError() == ERROR_ACCESS_DENIED)
304+
? L"Failed to copy vendor/windows-terminal/settings/settings.json file to config/windows_terminal_%COMPUTERNAME%_settings.json! Access Denied."
305+
: L"Failed to copy vendor/windows-terminal/settings/settings.json file to config/windows_teerminal_%COMPUTERNAME%_settigns.json!", MB_TITLE, MB_ICONSTOP);
306+
exit(1);
307+
}
308+
else if (PathFileExists(conEmuDir))
309+
{
310+
MessageBox(NULL,
311+
(GetLastError() == ERROR_ACCESS_DENIED)
312+
? L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/ConEmu-%COMPUTERNAME%.xml! Access Denied."
313+
: L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/ConEmu-%COMPUTERNAME%.xml!", MB_TITLE, MB_ICONSTOP);
314+
exit(1);
315+
}
313316
}
314317
}
315-
}
316-
else // vendor/conemu-maximus5/ConEmu.xml config file does not exist, copy config/ConEmu-%COMPUTERNAME%.xml to vendor/conemu-maximus5/ConEmu.xml file
317-
{
318-
if (!CopyFile(cpuCfgPath, cfgPath, FALSE))
318+
else // [terminal emulator config] file does not exist, copy config/[host specific terminal emulator config] file to [terminal emulator config] file
319319
{
320-
if (PathFileExists(windowsTerminalDir)) {
321-
MessageBox(NULL,
322-
(GetLastError() == ERROR_ACCESS_DENIED)
323-
? L"Failed to copy config/windows_terminal_%COMPUTERNAME%_settings.json file to vendor/windows-terminal/settings/settings.json! Access Denied."
324-
: L"Failed to copy config/windows_terminal_%COMPUTERNAME%_settings.json file to vendor/windows-terminal/settings/settings.json!", MB_TITLE, MB_ICONSTOP);
325-
exit(1);
326-
}
327-
else if (PathFileExists(conEmuDir))
320+
if (!CopyFile(cpuCfgPath, cfgPath, FALSE))
328321
{
329-
MessageBox(NULL,
330-
(GetLastError() == ERROR_ACCESS_DENIED)
331-
? L"Failed to copy config/ConEmu-%COMPUTERNAME%.xml file to vendor/conemu-maximus5/ConEmu.xml! Access Denied."
332-
: L"Failed to copy config/ConEmu-%COMPUTERNAME%.xml file to vendor/conemu-maximus5/ConEmu.xml!", MB_TITLE, MB_ICONSTOP);
333-
exit(1);
322+
if (PathFileExists(windowsTerminalDir)) {
323+
MessageBox(NULL,
324+
(GetLastError() == ERROR_ACCESS_DENIED)
325+
? L"Failed to copy config/windows_terminal_%COMPUTERNAME%_settings.json file to vendor/windows-terminal/settings/settings.json! Access Denied."
326+
: L"Failed to copy config/windows_terminal_%COMPUTERNAME%_settings.json file to vendor/windows-terminal/settings/settings.json!", MB_TITLE, MB_ICONSTOP);
327+
exit(1);
328+
}
329+
else if (PathFileExists(conEmuDir))
330+
{
331+
MessageBox(NULL,
332+
(GetLastError() == ERROR_ACCESS_DENIED)
333+
? L"Failed to copy config/ConEmu-%COMPUTERNAME%.xml file to vendor/conemu-maximus5/ConEmu.xml! Access Denied."
334+
: L"Failed to copy config/ConEmu-%COMPUTERNAME%.xml file to vendor/conemu-maximus5/ConEmu.xml!", MB_TITLE, MB_ICONSTOP);
335+
exit(1);
336+
}
334337
}
335338
}
336339
}
337340
}
338-
else if (wcscmp(userCfgPath, L"") == 0 && PathFileExists(userCfgPath)) // config/user_conemu.xml exists, use it.
341+
else if (wcscmp(userCfgPath, L"") != 0 && PathFileExists(userCfgPath)) // config/user[terminal emulator config] file exists, use it.
339342
{
340343
if (cfgRoot.length() == 0) // '/c [path]' was NOT specified
341344
{
342-
if (PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml exists, copy vendor/conemu-maximus5/ConEmu.xml to config/user_conemu.xml.
345+
if (PathFileExists(cfgPath)) // [terminal emulator config] file exists, copy [terminal emulator config] to config/user_[terminal emulator config] file to backup any settings changes from previous sessions.
343346
{
344347
if (!CopyFile(cfgPath, userCfgPath, FALSE))
345348
{
@@ -360,7 +363,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
360363
}
361364
}
362365
}
363-
else // vendor/conemu-maximus5/ConEmu.xml does not exist, copy config/user-conemu.xml to vendor/conemu-maximus5/ConEmu.xml
366+
else // [terminal emulator config] file does not exist, copy config/user_[terminal emulator config] file to [terminal emulator config] file
364367
{
365368
if (!CopyFile(userCfgPath, cfgPath, FALSE))
366369
{
@@ -382,13 +385,13 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
382385
}
383386
}
384387
}
385-
else if (!PathFileExists(windowsTerminalDir)) { // '/c [path]' was specified, don't copy anything and use existing user_conemu.xml to start comemu.
388+
else if (!PathFileExists(windowsTerminalDir)) { // '/c [path]' was specified, don't copy anything and use existing user_[terminal emulator config] file.
386389
PathCombine(userConEmuCfgPath, userConfigDirPath, L"user-ConEmu.xml");
387390
}
388391
}
389392
else if (cfgRoot.length() == 0) // '/c [path]' was NOT specified
390393
{
391-
if (PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml exists, copy vendor/conemu-maximus5/ConEmu.xml to config/user_conemu.xml
394+
if (PathFileExists(cfgPath)) // [terminal emulator config] file exists, copy [terminal emulator config] file to config/user_[terminal emulator config] file.
392395
{
393396
if (!CopyFile(cfgPath, userCfgPath, FALSE))
394397
{
@@ -408,7 +411,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
408411
exit(1);
409412
}
410413
}
411-
else // vendor/ConEmu.xml.default config exists, copy Cmder vendor/ConEmu.xml.default file to vendor/conemu-maximus5/ConEmu.xml.
414+
else // vendor/[terminal emulator config].default config exists, copy Cmder vendor/[terminal emulator config].default file to [terminal emulator config] file.
412415
{
413416
if (!CopyFile(defaultCfgPath, cfgPath, FALSE))
414417
{
@@ -436,10 +439,10 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
436439
(GetLastError() == ERROR_ACCESS_DENIED)
437440
? L"Failed to copy vendor/ConEmu.xml.default file to vendor/conemu-maximus5/ConEmu.xml! Access Denied."
438441
: L"Failed to copy vendor/ConEmu.xml.default file to vendor/conemu-maximus5/ConEmu.xml!", MB_TITLE, MB_ICONSTOP);
439-
exit(1);
442+
exit(1);
440443
}
441444
}
442-
else if (wcscmp(cfgPath, L"") == 0 && PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml exists, copy vendor/conemu-maximus5/ConEmu.xml to config/user_conemu.xml
445+
else if (wcscmp(cfgPath, L"") != 0 && PathFileExists(cfgPath)) // This is a first time Cmder.exe run and [terminal emulator config] file exists, copy [terminal emulator config] file to config/user_[terminal emulator config] file.
443446
{
444447
if (!CopyFile(cfgPath, userCfgPath, FALSE))
445448
{
@@ -462,7 +465,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
462465

463466
PathCombine(userConEmuCfgPath, userConfigDirPath, L"user-ConEmu.xml");
464467
}
465-
else if (wcscmp(defaultCfgPath, L"") == 0) // '/c [path]' was specified and 'vendor/ConEmu.xml.default' config exists, copy Cmder 'vendor/ConEmu.xml.default' file to '[user specified path]/config/user_ConEmu.xml'.
468+
else if (wcscmp(defaultCfgPath, L"") != 0) // '/c [path]' was specified and 'vendor/[terminal emulator config].default' config exists, copy Cmder 'vendor/[terminal emulator config].default' file to '[user specified path]/config/user_[terminal emulator config]'.
466469
{
467470
if ( ! CopyFile(defaultCfgPath, userCfgPath, FALSE))
468471
{

0 commit comments

Comments
 (0)