From 80592f666d6f1ad742984ce1fd1fe7d3d181b35d Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Mon, 13 May 2024 10:47:30 +0300 Subject: [PATCH] Updates: Support for ep_make --- ExplorerPatcher-L10N | 2 +- ExplorerPatcher/updates.c | 19 +++++++++++----- ExplorerPatcher/utility.c | 30 ++++++++++++++++++++++++++ ExplorerPatcher/utility.h | 2 ++ ep_gui/resources/EPSettingsResources.h | 1 + ep_gui/resources/lang/ep_gui.en-US.rc | 1 + ep_gui/resources/settings.reg | 2 ++ ep_gui/resources/settings10.reg | 2 ++ ep_setup/ep_setup.c | 19 ++++++++++++++-- 9 files changed, 70 insertions(+), 8 deletions(-) diff --git a/ExplorerPatcher-L10N b/ExplorerPatcher-L10N index a43a9d4..a57caf1 160000 --- a/ExplorerPatcher-L10N +++ b/ExplorerPatcher-L10N @@ -1 +1 @@ -Subproject commit a43a9d4cac99373f70526b13487a12b9c15ad72e +Subproject commit a57caf12f43374f53b7467cc7b1bc1b3aaa3edcf diff --git a/ExplorerPatcher/updates.c b/ExplorerPatcher/updates.c index d80a8bd..48a796d 100644 --- a/ExplorerPatcher/updates.c +++ b/ExplorerPatcher/updates.c @@ -421,8 +421,15 @@ BOOL IsUpdateAvailableHelper( BOOL bRet = DeleteFileW(wszPath); if (bRet || (!bRet && GetLastError() == ERROR_FILE_NOT_FOUND)) { + DWORD bIsUsingEpMake = 0, dwSize = sizeof(DWORD); + RegGetValueW(HKEY_CURRENT_USER, TEXT(REGPATH), L"UpdateUseLocal", RRF_RT_DWORD, NULL, &bIsUsingEpMake, &dwSize); + if (bIsUsingEpMake) { + GetSystemDirectoryW(wszPath, MAX_PATH); + wcscat_s(wszPath, MAX_PATH, L"\\WindowsPowerShell\\v1.0\\powershell.exe"); + } + FILE* f = NULL; - if (!_wfopen_s( + if (!bIsUsingEpMake && !_wfopen_s( &f, wszPath, L"wb" @@ -463,7 +470,7 @@ BOOL IsUpdateAvailableHelper( } fclose(f); } - if (bIsUpdateAvailable) + if (bIsUsingEpMake || bIsUpdateAvailable) { bIsUpdateAvailable = FALSE; #ifdef UPDATES_VERBOSE_OUTPUT @@ -572,9 +579,9 @@ BOOL IsUpdateAvailableHelper( ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; - ShExecInfo.lpVerb = L"runas"; + ShExecInfo.lpVerb = bIsUsingEpMake ? L"open" : L"runas"; ShExecInfo.lpFile = wszPath; - ShExecInfo.lpParameters = L"/update_silent"; + ShExecInfo.lpParameters = bIsUsingEpMake ? L"iex (irm 'https://raw.githubusercontent.com/valinet/ep_make/master/ep_make_safe.ps1')" : L"/update_silent"; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_SHOW; ShExecInfo.hInstApp = NULL; @@ -1063,7 +1070,9 @@ BOOL InstallUpdatesIfAvailable( CHAR hash[100]; ZeroMemory(hash, 100 * sizeof(CHAR)); - ComputeFileHash2(hModule, dllName, hash, 100); + GetHardcodedHash(dllName, hash, 100); + if (!strcmp(hash, "This")) ComputeFileHash2(hModule, dllName, hash, 100); + else printf("[Updates] Using hardcoded hash.\n"); BOOL bFail = FALSE, bReturnValue = FALSE; dwLeftMost = 0; dwSecondLeft = 0; dwSecondRight = 0; dwRightMost = 0; diff --git a/ExplorerPatcher/utility.c b/ExplorerPatcher/utility.c index 7ca5f01..3447a07 100644 --- a/ExplorerPatcher/utility.c +++ b/ExplorerPatcher/utility.c @@ -351,6 +351,36 @@ int ComputeFileHash2(HMODULE hModule, LPCWSTR filename, LPSTR hash, DWORD dwHash return ERROR_SUCCESS; } +void GetHardcodedHash(LPCWSTR wszPath, LPSTR hash, DWORD dwHash) +{ + HANDLE hFile = CreateFileW(wszPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + if (hFile == INVALID_HANDLE_VALUE) + { + return 1; + } + + HANDLE hFileMapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL); + if (hFileMapping == 0) + { + CloseHandle(hFile); + return 2; + } + + char* lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0); + if (lpFileBase == 0) + { + CloseHandle(hFileMapping); + CloseHandle(hFile); + return 3; + } + + memcpy_s(hash, MIN(32, dwHash), lpFileBase + DOSMODE_OFFSET, 32); + + UnmapViewOfFile(lpFileBase); + CloseHandle(hFileMapping); + CloseHandle(hFile); +} + void LaunchPropertiesGUI(HMODULE hModule) { //CreateThread(0, 0, ZZGUI, 0, 0, 0); diff --git a/ExplorerPatcher/utility.h b/ExplorerPatcher/utility.h index af8f5d7..45ef3eb 100644 --- a/ExplorerPatcher/utility.h +++ b/ExplorerPatcher/utility.h @@ -273,6 +273,8 @@ int ComputeFileHash(LPCWSTR filename, LPSTR hash, DWORD dwHash); int ComputeFileHash2(HMODULE hModule, LPCWSTR filename, LPSTR hash, DWORD dwHash); +void GetHardcodedHash(LPCWSTR wszPath, LPSTR hash, DWORD dwHash); + void LaunchPropertiesGUI(HMODULE hModule); BOOL SystemShutdown(BOOL reboot); diff --git a/ep_gui/resources/EPSettingsResources.h b/ep_gui/resources/EPSettingsResources.h index 4d1f34f..3cdc3c8 100644 --- a/ep_gui/resources/EPSettingsResources.h +++ b/ep_gui/resources/EPSettingsResources.h @@ -349,6 +349,7 @@ #define IDS_UPDATES_INSTALL 1814 #define IDS_UPDATES_CHANGES 1815 #define IDS_UPDATES_LEARN 1816 +#define IDS_UPDATES_USELOCAL 1817 #define IDS_ADV 1901 #define IDS_ADV_DISCLAIMER 1902 diff --git a/ep_gui/resources/lang/ep_gui.en-US.rc b/ep_gui/resources/lang/ep_gui.en-US.rc index b3370cf..8c548dd 100644 --- a/ep_gui/resources/lang/ep_gui.en-US.rc +++ b/ep_gui/resources/lang/ep_gui.en-US.rc @@ -391,6 +391,7 @@ BEGIN IDS_UPDATES_INSTALL "Update program and restart File Explorer" IDS_UPDATES_CHANGES "Read about changes in the latest releases" IDS_UPDATES_LEARN "Learn more" + IDS_UPDATES_USELOCAL "Build updates locally before installing" IDS_ADV "Advanced" diff --git a/ep_gui/resources/settings.reg b/ep_gui/resources/settings.reg index f1b575d..45e1fce 100644 --- a/ep_gui/resources/settings.reg +++ b/ep_gui/resources/settings.reg @@ -713,6 +713,8 @@ "UpdatePreferStaging"=dword:00000000 ;b %R:1807% "UpdateAllowDowngrades"=dword:00000000 +;b %R:1817% +"UpdateUseLocal"=dword:00000000 ;t %R:1808% ;w %R:1809% ;%R:1810% diff --git a/ep_gui/resources/settings10.reg b/ep_gui/resources/settings10.reg index e74e5f2..f197c70 100644 --- a/ep_gui/resources/settings10.reg +++ b/ep_gui/resources/settings10.reg @@ -524,6 +524,8 @@ "UpdatePreferStaging"=dword:00000000 ;b %R:1807% "UpdateAllowDowngrades"=dword:00000000 +;b %R:1817% +"UpdateUseLocal"=dword:00000000 ;t %R:1808% ;w %R:1809% ;%R:1810% diff --git a/ep_setup/ep_setup.c b/ep_setup/ep_setup.c index 2586c82..ceef457 100644 --- a/ep_setup/ep_setup.c +++ b/ep_setup/ep_setup.c @@ -354,10 +354,25 @@ BOOL InstallResourceHelper(BOOL bInstall, HMODULE hModule, HRSRC hRscr, WCHAR* w return FALSE; } DWORD dwNumberOfBytesWritten = 0; + int offset = 0; + wchar_t wszDxgi[MAX_PATH]; + if (GetWindowsDirectoryW(wszDxgi, MAX_PATH)) { + wcscat_s(wszDxgi, MAX_PATH, L"\\dxgi.dll"); + if (!wcscmp(wszPath, wszDxgi)) { + WCHAR wszOwnPath[MAX_PATH]; + GetModuleFileNameW(GetModuleHandle(NULL), wszOwnPath, MAX_PATH); + CHAR hash[100]; + GetHardcodedHash(wszOwnPath, hash, 100); + WriteFile(hFile, pRscr, DOSMODE_OFFSET, &dwNumberOfBytesWritten, NULL); + offset += dwNumberOfBytesWritten; + WriteFile(hFile, hash, 32, &dwNumberOfBytesWritten, NULL); + offset += dwNumberOfBytesWritten; + } + } if (!WriteFile( hFile, - pRscr, - cbRscr, + (char*)pRscr + offset, + cbRscr - offset, &dwNumberOfBytesWritten, NULL ))