Skip to content

Commit

Permalink
Updates: Support for ep_make
Browse files Browse the repository at this point in the history
  • Loading branch information
valinet committed May 13, 2024
1 parent c41b93b commit 80592f6
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 8 deletions.
19 changes: 14 additions & 5 deletions ExplorerPatcher/updates.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -463,7 +470,7 @@ BOOL IsUpdateAvailableHelper(
}
fclose(f);
}
if (bIsUpdateAvailable)
if (bIsUsingEpMake || bIsUpdateAvailable)
{
bIsUpdateAvailable = FALSE;
#ifdef UPDATES_VERBOSE_OUTPUT
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions ExplorerPatcher/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions ExplorerPatcher/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions ep_gui/resources/EPSettingsResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ep_gui/resources/lang/ep_gui.en-US.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions ep_gui/resources/settings.reg
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Expand Down
2 changes: 2 additions & 0 deletions ep_gui/resources/settings10.reg
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Expand Down
19 changes: 17 additions & 2 deletions ep_setup/ep_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
))
Expand Down

0 comments on commit 80592f6

Please sign in to comment.