better command line error handling

This commit is contained in:
Dax T. Games 2018-11-12 08:30:44 -05:00
parent d8e8fc8adb
commit b16aa7a29e

View File

@ -247,6 +247,18 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
} }
else // '/c [path]' was specified, don't copy anything and use existing conemu-%COMPUTERNAME%.xml to start comemu. else // '/c [path]' was specified, don't copy anything and use existing conemu-%COMPUTERNAME%.xml to start comemu.
{ {
if (use_user_cfg == false && PathFileExists(cfgPath) && !PathFileExists(cpuCfgPath)) // vendor/conemu-maximus5/ConEmu.xml file exists, copy vendor/conemu-maximus5/ConEmu.xml to config/ConEmu-%COMPUTERNAME%.xml.
{
if (!CopyFile(cfgPath, cpuCfgPath, FALSE))
{
MessageBox(NULL,
(GetLastError() == ERROR_ACCESS_DENIED)
? L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/ConEmu-%COMPUTERNAME%.xml! Access Denied."
: L"Failed to copy vendor/conemu-maximus5/ConEmu.xml file to config/ConEmu-%COMPUTERNAME%.xml!", MB_TITLE, MB_ICONSTOP);
exit(1);
}
}
PathCombine(userConEmuCfgPath, userConfigDirPath, L"ConEmu-%COMPUTERNAME%.xml"); PathCombine(userConEmuCfgPath, userConfigDirPath, L"ConEmu-%COMPUTERNAME%.xml");
ExpandEnvironmentStrings(userConEmuCfgPath, userConEmuCfgPath, sizeof(userConEmuCfgPath) / sizeof(userConEmuCfgPath[0])); ExpandEnvironmentStrings(userConEmuCfgPath, userConEmuCfgPath, sizeof(userConEmuCfgPath) / sizeof(userConEmuCfgPath[0]));
} }
@ -504,6 +516,7 @@ cmderOptions GetOption()
{ {
// MessageBox(NULL, szArgList[i], L"Arglist contents", MB_OK); // MessageBox(NULL, szArgList[i], L"Arglist contents", MB_OK);
if (cmderOptions.error == false) {
if (_wcsicmp(L"/c", szArgList[i]) == 0) if (_wcsicmp(L"/c", szArgList[i]) == 0)
{ {
TCHAR userProfile[MAX_PATH]; TCHAR userProfile[MAX_PATH];
@ -592,7 +605,8 @@ cmderOptions GetOption()
} }
else else
{ {
MessageBox(NULL, szArgList[i], L"Folder does not exist!", MB_OK); MessageBox(NULL, L"Unrecognized parameter.\n\nValid options:\n\n /c [CMDER User Root Path]\n\n /task [ConEmu Task Name]\n\n [/start [Start in Path] | [Start in Path]]\n\n /single\n\n /m\n\nor\n\n /register [USER | ALL]\n\nor\n\n /unregister [USER | ALL]\n", MB_TITLE, MB_OK);
cmderOptions.error = true;
} }
} }
else else
@ -601,6 +615,7 @@ cmderOptions GetOption()
cmderOptions.error = true; cmderOptions.error = true;
} }
} }
}
LocalFree(szArgList); LocalFree(szArgList);