1
0
mirror of https://github.com/valinet/ExplorerPatcher.git synced 2024-11-27 17:00:59 +01:00

Updates: Support for ep_make

This commit is contained in:
Valentin Radu 2024-05-13 10:47:30 +03:00
parent c41b93b6b4
commit 80592f666d
9 changed files with 70 additions and 8 deletions

@ -1 +1 @@
Subproject commit a43a9d4cac99373f70526b13487a12b9c15ad72e
Subproject commit a57caf12f43374f53b7467cc7b1bc1b3aaa3edcf

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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"

View File

@ -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%

View File

@ -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%

View File

@ -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
))