From 88e1355ddf7562590c8447cb213c6635a5b9f2ad Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Mon, 6 Dec 2021 07:48:04 +0200 Subject: [PATCH] Possibility to uninstall by renaming `ep_setup.exe` to `ep_uninstall.exe` and running that --- CHANGELOG.md | 1 + ep_setup/ep_setup.c | 50 ++++++++++++++++++++++++++++----------------- version.h | 6 +++--- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 182dfea..b361a92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Tested on build 22000.348. * Fixed regression of [#161](https://github.com/valinet/ExplorerPatcher/issues/161#issuecomment-986234002) (.1) * Possibility to disable per-application window lists (`Alt`+`) ([#283](https://github.com/valinet/ExplorerPatcher/issues/283#issuecomment-986261712)) (.2) * Fixed bug that prevented proper loading of default settings (.3) +* Possibility to uninstall by renaming `ep_setup.exe` to `ep_uninstall.exe` and running that (.4) ## 22000.348.39 diff --git a/ep_setup/ep_setup.c b/ep_setup/ep_setup.c index 739ab70..895b57a 100644 --- a/ep_setup/ep_setup.c +++ b/ep_setup/ep_setup.c @@ -291,7 +291,7 @@ int WINAPI wWinMain( _In_ int nShowCmd ) { - BOOL bOk = TRUE, bInstall = TRUE, bWasShellExt = FALSE, bIsUpdate = FALSE; + BOOL bOk = TRUE, bInstall = TRUE, bWasShellExt = FALSE, bIsUpdate = FALSE, bForcePromptForUninstall = FALSE; SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); @@ -336,9 +336,26 @@ int WINAPI wWinMain( return 0; } + WCHAR wszOwnPath[MAX_PATH]; + ZeroMemory(wszOwnPath, ARRAYSIZE(wszOwnPath)); + if (!GetModuleFileNameW(NULL, wszOwnPath, ARRAYSIZE(wszOwnPath))) + { + exit(0); + } + bInstall = !(argc >= 1 && (!_wcsicmp(wargv[0], L"/uninstall") || !_wcsicmp(wargv[0], L"/uninstall_silent"))); + PathStripPathW(wszOwnPath); + if (!_wcsicmp(wszOwnPath, L"ep_uninstall.exe")) + { + bInstall = FALSE; + bForcePromptForUninstall = _wcsicmp(wargv[0], L"/uninstall_silent"); + } + if (!GetModuleFileNameW(NULL, wszOwnPath, ARRAYSIZE(wszOwnPath))) + { + exit(0); + } bIsUpdate = (argc >= 1 && !_wcsicmp(wargv[0], L"/update_silent")); - if (!bInstall && !_wcsicmp(wargv[0], L"/uninstall")) + if (!bInstall && (!_wcsicmp(wargv[0], L"/uninstall") || bForcePromptForUninstall)) { if (MessageBoxW( NULL, @@ -353,27 +370,22 @@ int WINAPI wWinMain( if (!IsAppRunningAsAdminMode()) { - WCHAR wszPath[MAX_PATH]; - ZeroMemory(wszPath, ARRAYSIZE(wszPath)); - if (GetModuleFileNameW(NULL, wszPath, ARRAYSIZE(wszPath))) + SHELLEXECUTEINFOW sei; + ZeroMemory(&sei, sizeof(SHELLEXECUTEINFOW)); + sei.cbSize = sizeof(sei); + sei.lpVerb = L"runas"; + sei.lpFile = wszOwnPath; + sei.lpParameters = !bInstall ? L"/uninstall_silent" : lpCmdLine; + sei.hwnd = NULL; + sei.nShow = SW_NORMAL; + if (!ShellExecuteExW(&sei)) { - SHELLEXECUTEINFOW sei; - ZeroMemory(&sei, sizeof(SHELLEXECUTEINFOW)); - sei.cbSize = sizeof(sei); - sei.lpVerb = L"runas"; - sei.lpFile = wszPath; - sei.lpParameters = !bInstall ? L"/uninstall_silent" : lpCmdLine; - sei.hwnd = NULL; - sei.nShow = SW_NORMAL; - if (!ShellExecuteExW(&sei)) + DWORD dwError = GetLastError(); + if (dwError == ERROR_CANCELLED) { - DWORD dwError = GetLastError(); - if (dwError == ERROR_CANCELLED) - { - } } - exit(0); } + exit(0); } SHGetFolderPathW(NULL, SPECIAL_FOLDER, NULL, SHGFP_TYPE_CURRENT, wszPath); diff --git a/version.h b/version.h index a793204..77dfef7 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define VER_MAJOR 22000 #define VER_MINOR 348 #define VER_BUILD_HI 40 -#define VER_BUILD_LO 3 +#define VER_BUILD_LO 4 #define VER_FLAGS VS_FF_PRERELEASE @@ -12,5 +12,5 @@ #define VER_STR(arg) #arg // The String form of the version numbers -#define VER_FILE_STRING VALUE "FileVersion", "22000.348.40.3" -#define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.348.40.3" +#define VER_FILE_STRING VALUE "FileVersion", "22000.348.40.4" +#define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.348.40.4"