add Cmder for win

This commit is contained in:
Dax T. Games 2023-11-24 11:35:24 -05:00
parent 67b62784c8
commit 99b4e66c47
2 changed files with 69 additions and 38 deletions

View File

@ -1,4 +1,4 @@
#include <windows.h> #include <windows.h>/
#include <tchar.h> #include <tchar.h>
#include <Shlwapi.h> #include <Shlwapi.h>
#include "resource.h" #include "resource.h"
@ -130,6 +130,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
wchar_t userConEmuCfgPath[MAX_PATH] = { 0 }; wchar_t userConEmuCfgPath[MAX_PATH] = { 0 };
wchar_t windowsTerminalDir[MAX_PATH] = { 0 }; wchar_t windowsTerminalDir[MAX_PATH] = { 0 };
wchar_t conEmuDir[MAX_PATH] = { 0 }; wchar_t conEmuDir[MAX_PATH] = { 0 };
wchar_t winDir[MAX_PATH] = { 0 };
wchar_t emulatorPath[MAX_PATH] = { 0 }; wchar_t emulatorPath[MAX_PATH] = { 0 };
@ -256,6 +257,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
PathCombine(windowsTerminalDir, exeDir, L"vendor\\windows-terminal"); PathCombine(windowsTerminalDir, exeDir, L"vendor\\windows-terminal");
PathCombine(conEmuDir, exeDir, L"vendor\\conemu-maximus5"); PathCombine(conEmuDir, exeDir, L"vendor\\conemu-maximus5");
GetEnvironmentVariable(L"WINDIR", winDir, MAX_PATH);
if (PathFileExists(windowsTerminalDir)) if (PathFileExists(windowsTerminalDir))
{ {
@ -272,7 +274,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
// Set path to Cmder user ConEmu config file // Set path to Cmder user ConEmu config file
PathCombine(userCfgPath, userConfigDirPath, L"user_windows_terminal_settings.json"); PathCombine(userCfgPath, userConfigDirPath, L"user_windows_terminal_settings.json");
} }
else else if (PathFileExists(conEmuDir))
{ {
// Set path to vendored ConEmu config file // Set path to vendored ConEmu config file
PathCombine(cfgPath, conEmuDir, L"ConEmu.xml"); PathCombine(cfgPath, conEmuDir, L"ConEmu.xml");
@ -288,7 +290,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
PathCombine(userCfgPath, userConfigDirPath, L"user-ConEmu.xml"); PathCombine(userCfgPath, userConfigDirPath, L"user-ConEmu.xml");
} }
if (PathFileExists(cpuCfgPath) || use_user_cfg == false) // config/ConEmu-%COMPUTERNAME%.xml file exists or /m was specified on command line, use machine specific config. 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.
{ {
if (cfgRoot.length() == 0) // '/c [path]' was NOT specified if (cfgRoot.length() == 0) // '/c [path]' was NOT specified
{ {
@ -301,7 +303,8 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
: L"Failed to copy vendor/windows-terminal/settings/settings.json file to config/windows_teerminal_%COMPUTERNAME%_settigns.json!", MB_TITLE, MB_ICONSTOP); : L"Failed to copy vendor/windows-terminal/settings/settings.json file to config/windows_teerminal_%COMPUTERNAME%_settigns.json!", MB_TITLE, MB_ICONSTOP);
exit(1); exit(1);
} }
else { else if (PathFileExists(conEmuDir))
{
MessageBox(NULL, MessageBox(NULL,
(GetLastError() == ERROR_ACCESS_DENIED) (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! Access Denied."
@ -321,7 +324,8 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
: L"Failed to copy config/windows_terminal_%COMPUTERNAME%_settings.json file to vendor/windows-terminal/settings/settings.json!", MB_TITLE, MB_ICONSTOP); : L"Failed to copy config/windows_terminal_%COMPUTERNAME%_settings.json file to vendor/windows-terminal/settings/settings.json!", MB_TITLE, MB_ICONSTOP);
exit(1); exit(1);
} }
else { else if (PathFileExists(conEmuDir))
{
MessageBox(NULL, MessageBox(NULL,
(GetLastError() == ERROR_ACCESS_DENIED) (GetLastError() == ERROR_ACCESS_DENIED)
? L"Failed to copy config/ConEmu-%COMPUTERNAME%.xml file to vendor/conemu-maximus5/ConEmu.xml! Access Denied." ? L"Failed to copy config/ConEmu-%COMPUTERNAME%.xml file to vendor/conemu-maximus5/ConEmu.xml! Access Denied."
@ -331,7 +335,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
} }
} }
} }
else if (PathFileExists(userCfgPath)) // config/user_conemu.xml exists, use it. else if (wcscmp(userCfgPath, L"") == 0 && PathFileExists(userCfgPath)) // config/user_conemu.xml exists, use it.
{ {
if (cfgRoot.length() == 0) // '/c [path]' was NOT specified if (cfgRoot.length() == 0) // '/c [path]' was NOT specified
{ {
@ -346,7 +350,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
: L"Failed to copy vendor/windows-terminal/settings/settings.json file to config/windows_teerminal_settigns.json!", MB_TITLE, MB_ICONSTOP); : L"Failed to copy vendor/windows-terminal/settings/settings.json file to config/windows_teerminal_settigns.json!", MB_TITLE, MB_ICONSTOP);
exit(1); exit(1);
} }
else else if (PathFileExists(conEmuDir))
{ {
MessageBox(NULL, MessageBox(NULL,
(GetLastError() == ERROR_ACCESS_DENIED) (GetLastError() == ERROR_ACCESS_DENIED)
@ -367,7 +371,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
: L"Failed to copy config/user_windows_terminal_settings.json file to vendor/windows-terminal/settings/settings.json!", MB_TITLE, MB_ICONSTOP); : L"Failed to copy config/user_windows_terminal_settings.json file to vendor/windows-terminal/settings/settings.json!", MB_TITLE, MB_ICONSTOP);
exit(1); exit(1);
} }
else else if (PathFileExists(conEmuDir))
{ {
MessageBox(NULL, MessageBox(NULL,
(GetLastError() == ERROR_ACCESS_DENIED) (GetLastError() == ERROR_ACCESS_DENIED)
@ -395,7 +399,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
: L"Failed to copy vendor/windows-terminal/settings/settings.json file to config/user_windows_terminal_settigns.json!", MB_TITLE, MB_ICONSTOP); : L"Failed to copy vendor/windows-terminal/settings/settings.json file to config/user_windows_terminal_settigns.json!", MB_TITLE, MB_ICONSTOP);
exit(1); exit(1);
} }
else else if (PathFileExists(conEmuDir))
{ {
MessageBox(NULL, MessageBox(NULL,
(GetLastError() == ERROR_ACCESS_DENIED) (GetLastError() == ERROR_ACCESS_DENIED)
@ -415,7 +419,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
: L"Failed to copy vendor/windows-terminal_default_settings_settings.json file to vendor/windows-terminal/settings/settigns.json!", MB_TITLE, MB_ICONSTOP); : L"Failed to copy vendor/windows-terminal_default_settings_settings.json file to vendor/windows-terminal/settings/settigns.json!", MB_TITLE, MB_ICONSTOP);
exit(1); exit(1);
} }
else else if (PathFileExists(conEmuDir))
{ {
MessageBox(NULL, MessageBox(NULL,
(GetLastError() == ERROR_ACCESS_DENIED) (GetLastError() == ERROR_ACCESS_DENIED)
@ -426,8 +430,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
} }
} }
} }
else { else if (!CopyFile(defaultCfgPath, cfgPath, FALSE) && PathFileExists(conEmuDir))
if (!CopyFile(defaultCfgPath, cfgPath, FALSE))
{ {
MessageBox(NULL, MessageBox(NULL,
(GetLastError() == ERROR_ACCESS_DENIED) (GetLastError() == ERROR_ACCESS_DENIED)
@ -436,8 +439,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
exit(1); exit(1);
} }
} }
} 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
else if (PathFileExists(cfgPath)) // vendor/conemu-maximus5/ConEmu.xml exists, copy vendor/conemu-maximus5/ConEmu.xml to config/user_conemu.xml
{ {
if (!CopyFile(cfgPath, userCfgPath, FALSE)) if (!CopyFile(cfgPath, userCfgPath, FALSE))
{ {
@ -460,7 +462,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
PathCombine(userConEmuCfgPath, userConfigDirPath, L"user-ConEmu.xml"); PathCombine(userConEmuCfgPath, userConfigDirPath, L"user-ConEmu.xml");
} }
else // '/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'. 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'.
{ {
if ( ! CopyFile(defaultCfgPath, userCfgPath, FALSE)) if ( ! CopyFile(defaultCfgPath, userCfgPath, FALSE))
{ {
@ -488,10 +490,14 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
if (PathFileExists(windowsTerminalDir)) { if (PathFileExists(windowsTerminalDir)) {
PathCombine(terminalPath, exeDir, L"vendor\\windows-terminal\\WindowsTerminal.exe"); PathCombine(terminalPath, exeDir, L"vendor\\windows-terminal\\WindowsTerminal.exe");
} }
else else if (PathFileExists(conEmuDir))
{ {
PathCombine(terminalPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu64.exe"); PathCombine(terminalPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu64.exe");
} }
else
{
PathCombine(terminalPath, winDir, L"system32\\cmd.exe");
}
if (!PathFileExists(windowsTerminalDir)) { if (!PathFileExists(windowsTerminalDir)) {
swprintf_s(args, L"%s /Icon \"%s\"", args, icoPath); swprintf_s(args, L"%s /Icon \"%s\"", args, icoPath);
@ -542,10 +548,14 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
if (PathFileExists(windowsTerminalDir)) { if (PathFileExists(windowsTerminalDir)) {
swprintf_s(args, L"%s -p \"%s\"", args, cmderTask.c_str()); swprintf_s(args, L"%s -p \"%s\"", args, cmderTask.c_str());
} }
else else if (PathFileExists(conEmuDir))
{ {
swprintf_s(args, L"%s /run {%s}", args, cmderTask.c_str()); swprintf_s(args, L"%s /run {%s}", args, cmderTask.c_str());
} }
else
{
swprintf_s(args, L"%s %s", args, cmderTask.c_str());
}
} }
SetEnvironmentVariable(L"CMDER_ROOT", exeDir); SetEnvironmentVariable(L"CMDER_ROOT", exeDir);
@ -565,14 +575,23 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
si.dwFlags = STARTF_TITLEISAPPID; si.dwFlags = STARTF_TITLEISAPPID;
#endif #endif
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
if (!CreateProcess(terminalPath, args, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) {
// MessageBox(NULL, terminalPath, _T("Error"), MB_OK);
// MessageBox(NULL, args, _T("Error"), MB_OK);
if (!CreateProcess(terminalPath, args, NULL, NULL, false, 0, NULL, NULL, &si, &pi))
{
if (PathFileExists(windowsTerminalDir)) { if (PathFileExists(windowsTerminalDir)) {
MessageBox(NULL, _T("Unable to create the Windows Terminal process!"), _T("Error"), MB_OK); MessageBox(NULL, _T("Unable to create the Windows Terminal process!"), _T("Error"), MB_OK);
} }
else else if (PathFileExists(conEmuDir))
{ {
MessageBox(NULL, _T("Unable to create the ConEmu process!"), _T("Error"), MB_OK); MessageBox(NULL, _T("Unable to create the ConEmu process!"), _T("Error"), MB_OK);
} }
else
{
MessageBox(NULL, _T("Unable to create the Cmd process!"), _T("Error"), MB_OK);
}
return; return;
} }
} }
@ -704,18 +723,23 @@ cmderOptions GetOption()
int argCount; int argCount;
wchar_t windowsTerminalDir[MAX_PATH] = { 0 }; wchar_t windowsTerminalDir[MAX_PATH] = { 0 };
wchar_t conEmuDir[MAX_PATH] = { 0 };
wchar_t vendorDir[MAX_PATH] = { 0 };
wchar_t exeDir[MAX_PATH] = { 0 }; wchar_t exeDir[MAX_PATH] = { 0 };
wchar_t cmdInit[MAX_PATH] = { 0 };
GetModuleFileName(NULL, exeDir, sizeof(exeDir)); GetModuleFileName(NULL, exeDir, sizeof(exeDir));
PathRemoveFileSpec(exeDir); PathRemoveFileSpec(exeDir);
PathCombine(windowsTerminalDir, exeDir, L"vendor\\windows-terminal"); PathCombine(vendorDir, exeDir, L"vendor");
PathCombine(windowsTerminalDir, vendorDir, L"windows-terminal");
PathCombine(conEmuDir, vendorDir, L"ConEmu-Maximus5");
PathCombine(cmdInit, vendorDir, L"init.bat");
szArgList = CommandLineToArgvW(GetCommandLine(), &argCount); szArgList = CommandLineToArgvW(GetCommandLine(), &argCount);
for (int i = 1; i < argCount; i++) for (int i = 1; i < argCount; i++)
{ {
// MessageBox(NULL, szArgList[i], L"Arglist contents", MB_OK); // MessageBox(NULL, szArgList[i], L"Arglist contents", MB_OK);
if (cmderOptions.error == false) { if (cmderOptions.error == false) {
if (_wcsicmp(L"/c", szArgList[i]) == 0) if (_wcsicmp(L"/c", szArgList[i]) == 0)
@ -752,26 +776,26 @@ cmderOptions GetOption()
MessageBox(NULL, szArgList[i + 1], L"/START - Folder does not exist!", MB_OK); MessageBox(NULL, szArgList[i + 1], L"/START - Folder does not exist!", MB_OK);
} }
} }
else if (_wcsicmp(L"/task", szArgList[i]) == 0) else if (_wcsicmp(L"/task", szArgList[i]) == 0 || PathFileExists(windowsTerminalDir) || PathFileExists(conEmuDir))
{ {
cmderOptions.cmderTask = szArgList[i + 1]; cmderOptions.cmderTask = szArgList[i + 1];
i++; i++;
} }
else if (_wcsicmp(L"/title", szArgList[i]) == 0 && !PathFileExists(windowsTerminalDir)) else if (_wcsicmp(L"/title", szArgList[i]) == 0 && !PathFileExists(windowsTerminalDir) && PathFileExists(conEmuDir))
{ {
cmderOptions.cmderTitle = szArgList[i + 1]; cmderOptions.cmderTitle = szArgList[i + 1];
i++; i++;
} }
else if (_wcsicmp(L"/icon", szArgList[i]) == 0 && !PathFileExists(windowsTerminalDir)) else if (_wcsicmp(L"/icon", szArgList[i]) == 0 && !PathFileExists(windowsTerminalDir) && PathFileExists(conEmuDir))
{ {
cmderOptions.cmderIcon = szArgList[i + 1]; cmderOptions.cmderIcon = szArgList[i + 1];
i++; i++;
} }
else if (_wcsicmp(L"/single", szArgList[i]) == 0 && !PathFileExists(windowsTerminalDir)) else if (_wcsicmp(L"/single", szArgList[i]) == 0 && !PathFileExists(windowsTerminalDir) && PathFileExists(conEmuDir))
{ {
cmderOptions.cmderSingle = true; cmderOptions.cmderSingle = true;
} }
else if (_wcsicmp(L"/m", szArgList[i]) == 0 && !PathFileExists(windowsTerminalDir)) else if (_wcsicmp(L"/m", szArgList[i]) == 0 && !PathFileExists(windowsTerminalDir) && PathFileExists(conEmuDir))
{ {
cmderOptions.cmderUserCfg = false; cmderOptions.cmderUserCfg = false;
} }
@ -844,6 +868,13 @@ cmderOptions GetOption()
} }
if (!PathFileExists(windowsTerminalDir) && !PathFileExists(conEmuDir))
{
cmderOptions.cmderTask = L"/k \"";
cmderOptions.cmderTask += cmdInit;
cmderOptions.cmderTask += L"\"";
}
if (cmderOptions.error == true) if (cmderOptions.error == true)
{ {
wchar_t validOptions[512]; wchar_t validOptions[512];

View File

@ -46,9 +46,9 @@ Ensure-Executable "7z"
if ($terminal -eq "none") { if ($terminal -eq "none") {
$targets = @{ $targets = @{
"cmder_slim.7z" = "-t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -myx=7 -mqs=on -xr!`"vendor\conemu-maximus5`" -xr!`"vendor\windows-terminal`""; "cmder_win.7z" = "-t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -myx=7 -mqs=on -xr!`"vendor\conemu-maximus5`" -xr!`"vendor\windows-terminal`"";
"cmder_slim.zip" = "-mm=Deflate -mfb=128 -mpass=3 -xr!`"vendor\conemu-maximus5`" -xr!`"vendor\windows-terminal`""; "cmder_win.zip" = "-mm=Deflate -mfb=128 -mpass=3 -xr!`"vendor\conemu-maximus5`" -xr!`"vendor\windows-terminal`"";
"cmder_slim_mini.zip" = "-xr!`"vendor\git-for-windows`" -xr!`"vendor\conemu-maximus5`" -xr!`"vendor\windows-terminal`""; "cmder_win.mini.zip" = "-xr!`"vendor\git-for-windows`" -xr!`"vendor\conemu-maximus5`" -xr!`"vendor\windows-terminal`"";
} }
} elseif ($terminal -eq "windows-terminal") { } elseif ($terminal -eq "windows-terminal") {
$targets = @{ $targets = @{
@ -64,9 +64,9 @@ if ($terminal -eq "none") {
} }
} else { } else {
$targets = @{ $targets = @{
"cmder_slim.7z" = "-t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -myx=7 -mqs=on -xr!`"vendor\conemu-maximus5`" -xr!`"vendor\windows-terminal`""; "cmder_win.7z" = "-t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -myx=7 -mqs=on -xr!`"vendor\conemu-maximus5`" -xr!`"vendor\windows-terminal`"";
"cmder_slim.zip" = "-mm=Deflate -mfb=128 -mpass=3 -xr!`"vendor\conemu-maximus5`" -xr!`"vendor\windows-terminal`""; "cmder_win.zip" = "-mm=Deflate -mfb=128 -mpass=3 -xr!`"vendor\conemu-maximus5`" -xr!`"vendor\windows-terminal`"";
"cmder_slim_mini.zip" = "-xr!`"vendor\git-for-windows`" -xr!`"vendor\conemu-maximus5`" -xr!`"vendor\windows-terminal`""; "cmder_win.mini.zip" = "-xr!`"vendor\git-for-windows`" -xr!`"vendor\conemu-maximus5`" -xr!`"vendor\windows-terminal`"";
"cmder_wt.7z" = "-t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -myx=7 -mqs=on -xr!`"vendor\conemu-maximus5`""; "cmder_wt.7z" = "-t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -myx=7 -mqs=on -xr!`"vendor\conemu-maximus5`"";
"cmder_wt.zip" = "-mm=Deflate -mfb=128 -mpass=3 -xr!`"vendor\conemu-maximus5`""; "cmder_wt.zip" = "-mm=Deflate -mfb=128 -mpass=3 -xr!`"vendor\conemu-maximus5`"";
"cmder_wt_mini.zip" = "-xr!`"vendor\git-for-windows`" -xr!`"vendor\conemu-maximus5`""; "cmder_wt_mini.zip" = "-xr!`"vendor\git-for-windows`" -xr!`"vendor\conemu-maximus5`"";