Browse Source

Weather: Download and install WebView2 Runtime when not available on the system

pull/899/head
Valentin Radu 4 years ago
parent
commit
d3d11ff67d
  1. 33
      ExplorerPatcher/dllmain.c
  2. 88
      ExplorerPatcher/utility.c
  3. 2
      ExplorerPatcher/utility.h

33
ExplorerPatcher/dllmain.c

@ -3964,13 +3964,36 @@ SIZE WINAPI PeopleButton_CalculateMinimumSizeHook(void* _this, SIZE* pSz) @@ -3964,13 +3964,36 @@ SIZE WINAPI PeopleButton_CalculateMinimumSizeHook(void* _this, SIZE* pSz)
rcWeatherFlyoutWindow.top = mi.rcWork.top;
rcWeatherFlyoutWindow.right = rcWeatherFlyoutWindow.left + MulDiv(MulDiv(EP_WEATHER_WIDTH, dpiX, 96), dwTextScaleFactor, 100);
rcWeatherFlyoutWindow.bottom = rcWeatherFlyoutWindow.top + MulDiv(MulDiv(EP_WEATHER_HEIGHT, dpiX, 96), dwTextScaleFactor, 100);
if (FAILED(epw->lpVtbl->Initialize(epw, wszEPWeatherKillswitch, bAllocConsole, EP_WEATHER_PROVIDER_GOOGLE, rt, rt, dwWeatherTemperatureUnit, dwWeatherUpdateSchedule * 1000, rcWeatherFlyoutWindow, dwWeatherTheme, dwWeatherGeolocationMode, &hWndWeatherFlyout)))
int k = 0;
while (FAILED(hr = epw->lpVtbl->Initialize(epw, wszEPWeatherKillswitch, bAllocConsole, EP_WEATHER_PROVIDER_GOOGLE, rt, rt, dwWeatherTemperatureUnit, dwWeatherUpdateSchedule * 1000, rcWeatherFlyoutWindow, dwWeatherTheme, dwWeatherGeolocationMode, &hWndWeatherFlyout)))
{
epw->lpVtbl->Release(epw);
epw = NULL;
prev_total_h = 0;
BOOL bFailed = FALSE;
if (k == 0 && hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
{
if (DownloadAndInstallWebView2Runtime())
{
k++;
}
else
{
bFailed = TRUE;
}
}
else
{
bFailed = TRUE;
}
if (bFailed)
{
epw->lpVtbl->Release(epw);
epw = NULL;
prev_total_h = 0;
PostMessageW(FindWindowW(L"Shell_TrayWnd", NULL), WM_COMMAND, 435, 0);
PostMessageW(FindWindowW(L"ExplorerPatcher_GUI_" _T(EP_CLSID), NULL), WM_USER + 1, 0, 0);
break;
}
}
else
if (SUCCEEDED(hr))
{
epw->lpVtbl->SetWindowCornerPreference(epw, dwWeatherWindowCornerPreference);
}

88
ExplorerPatcher/utility.c

@ -1,4 +1,6 @@ @@ -1,4 +1,6 @@
#include "utility.h"
#include <Wininet.h>
#pragma comment(lib, "Wininet.lib")
#pragma region "Weird stuff"
INT64 STDMETHODCALLTYPE nimpl4_1(INT64 a1, DWORD* a2)
@ -1279,4 +1281,90 @@ LRESULT CALLBACK PleaseWait_HookProc(int code, WPARAM wParam, LPARAM lParam) @@ -1279,4 +1281,90 @@ LRESULT CALLBACK PleaseWait_HookProc(int code, WPARAM wParam, LPARAM lParam)
PleaseWaitHook = NULL;
}
return result;
BOOL DownloadAndInstallWebView2Runtime()
{
BOOL bOK = FALSE;
HINTERNET hInternet = NULL;
if (hInternet = InternetOpenA(
L"ExplorerPatcher",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
0
))
{
HINTERNET hConnect = InternetOpenUrlA(
hInternet,
"https://go.microsoft.com/fwlink/p/?LinkId=2124703",
NULL,
0,
INTERNET_FLAG_RAW_DATA |
INTERNET_FLAG_RELOAD |
INTERNET_FLAG_RESYNCHRONIZE |
INTERNET_FLAG_NO_COOKIES |
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_DONT_CACHE,
NULL
);
if (hConnect)
{
char* exe_buffer = NULL;
DWORD dwSize = 2 * 1024 * 1024;
DWORD dwRead = dwSize;
exe_buffer = calloc(dwSize, sizeof(char));
if (exe_buffer)
{
BOOL bRet = FALSE;
if (bRet = InternetReadFile(
hConnect,
exe_buffer,
dwSize - 1,
&dwRead
))
{
WCHAR wszPath[MAX_PATH];
ZeroMemory(wszPath, MAX_PATH * sizeof(WCHAR));
SHGetFolderPathW(NULL, SPECIAL_FOLDER_LEGACY, NULL, SHGFP_TYPE_CURRENT, wszPath);
wcscat_s(wszPath, MAX_PATH, _T(APP_RELATIVE_PATH));
BOOL bRet = CreateDirectoryW(wszPath, NULL);
if (bRet || (!bRet && GetLastError() == ERROR_ALREADY_EXISTS))
{
wcscat_s(wszPath, MAX_PATH, L"\\MicrosoftEdgeWebview2Setup.exe");
FILE* f = NULL;
_wfopen_s(&f, wszPath, L"wb");
if (f)
{
fwrite(exe_buffer, 1, dwRead, f);
fclose(f);
SHELLEXECUTEINFOW sei;
ZeroMemory(&sei, sizeof(SHELLEXECUTEINFOW));
sei.cbSize = sizeof(sei);
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
sei.hwnd = NULL;
sei.hInstApp = NULL;
sei.lpVerb = NULL;
sei.lpFile = wszPath;
sei.lpParameters = L"";
sei.hwnd = NULL;
sei.nShow = SW_SHOWMINIMIZED;
if (ShellExecuteExW(&sei) && sei.hProcess)
{
WaitForSingleObject(sei.hProcess, INFINITE);
CloseHandle(sei.hProcess);
Sleep(100);
DeleteFileW(wszPath);
bOK = TRUE;
}
}
}
}
free(exe_buffer);
}
InternetCloseHandle(hConnect);
}
InternetCloseHandle(hInternet);
}
return bOK;
}

2
ExplorerPatcher/utility.h

@ -562,4 +562,6 @@ extern BOOL (*PleaseWaitCallbackFunc)(void* data); @@ -562,4 +562,6 @@ extern BOOL (*PleaseWaitCallbackFunc)(void* data);
BOOL PleaseWait_UpdateTimeout(int timeout);
VOID CALLBACK PleaseWait_TimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime);
LRESULT CALLBACK PleaseWait_HookProc(int code, WPARAM wParam, LPARAM lParam);
BOOL DownloadAndInstallWebView2Runtime();
#endif

Loading…
Cancel
Save