diff --git a/ExplorerPatcher/GUI.c b/ExplorerPatcher/GUI.c index 12598dd..11905b3 100644 --- a/ExplorerPatcher/GUI.c +++ b/ExplorerPatcher/GUI.c @@ -6,6 +6,7 @@ DEFINE_GUID(LiveSetting_Property_GUID, 0xc12bcd8e, 0x2a8e, 0x4950, 0x8a, 0xe7, 0 TCHAR GUI_title[260]; FILE* AuditFile = NULL; LANGID locale; +WCHAR wszLanguage[MAX_PATH]; void* GUI_FileMapping = NULL; DWORD GUI_FileSize = 0; BOOL g_darkModeEnabled = FALSE; @@ -1030,6 +1031,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) wchar_t* lastHeading = calloc(MAX_LINE_LENGTH, sizeof(wchar_t)); while ((numChRd = getline(&line, &bufsiz, f)) != -1) { + hOldFont = NULL; if (currentSection == _this->section) { bWasSpecifiedSectionValid = TRUE; @@ -1236,6 +1238,42 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) text, MAX_LINE_LENGTH ); + if (!wcsncmp(text, L"%WEATHERLASTUPDATETEXT%", 23)) + { + BOOL bOk = FALSE; + DWORD bIsWeatherEnabled = 0, dwSize = sizeof(DWORD); + GUI_Internal_RegQueryValueExW(NULL, L"Virtualized_" _T(EP_CLSID) L"_PeopleBand", NULL, NULL, &bIsWeatherEnabled, &dwSize); + if (bIsWeatherEnabled) + { + IEPWeather* epw = NULL; + if (SUCCEEDED(CoCreateInstance(&CLSID_EPWeather, NULL, CLSCTX_LOCAL_SERVER, &IID_IEPWeather, &epw)) && epw) + { + SYSTEMTIME stLastUpdate; + ZeroMemory(&stLastUpdate, sizeof(SYSTEMTIME)); + if (SUCCEEDED(epw->lpVtbl->GetLastUpdateTime(epw, &stLastUpdate))) + { + WCHAR wszWeatherLanguage[10]; + ZeroMemory(wszWeatherLanguage, 10); + dwSize = sizeof(WCHAR) * 10; + RegGetValueW(HKEY_CURRENT_USER, _T(REGPATH), L"WeatherLanguage", RRF_RT_REG_SZ, NULL, wszWeatherLanguage, &dwSize); + WCHAR wszDate[MAX_PATH]; + ZeroMemory(wszDate, sizeof(WCHAR) * MAX_PATH); + if (GetDateFormatEx(wszWeatherLanguage[0] ? wszWeatherLanguage : wszLanguage, DATE_AUTOLAYOUT | DATE_LONGDATE, &stLastUpdate, NULL, wszDate, MAX_PATH, NULL)) + { + WCHAR wszTime[MAX_PATH]; + ZeroMemory(wszTime, sizeof(WCHAR) * MAX_PATH); + if (GetTimeFormatEx(wszWeatherLanguage[0] ? wszWeatherLanguage : wszLanguage, TIME_NOSECONDS, &stLastUpdate, NULL, wszTime, MAX_PATH)) + { + bOk = TRUE; + swprintf_s(text, MAX_LINE_LENGTH, L"Last updated on: %s, %s.", wszDate, wszTime); + } + } + } + epw->lpVtbl->Release(epw); + } + } + if (!bOk) continue; + } if (bResetLastHeading) { wcscpy_s(lastHeading, MAX_LINE_LENGTH, text); @@ -3087,6 +3125,10 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) tabOrder++; } } + if (hOldFont) + { + SelectObject(hdcPaint, hOldFont); + } } fclose(f); free(section); @@ -3102,7 +3144,6 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) InvalidateRect(hwnd, NULL, FALSE); } - SelectObject(hdcPaint, hOldFont); if (!hDC) { ReleaseDC(hwnd, hdcPaint); @@ -3822,6 +3863,26 @@ __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLin &dwSize ); } + BOOL bOk = FALSE; + ULONG ulNumLanguages = 0; + LPCWSTR wszLanguagesBuffer = NULL; + ULONG cchLanguagesBuffer = 0; + if (GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &ulNumLanguages, NULL, &cchLanguagesBuffer)) + { + if (wszLanguagesBuffer = malloc(cchLanguagesBuffer * sizeof(WCHAR))) + { + if (GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &ulNumLanguages, wszLanguagesBuffer, &cchLanguagesBuffer)) + { + wcscpy_s(wszLanguage, MAX_PATH, wszLanguagesBuffer); + bOk = TRUE; + } + free(wszLanguagesBuffer); + } + } + if (!bOk) + { + wcscpy_s(wszLanguage, MAX_PATH, L"en-US"); + } wchar_t wszPath[MAX_PATH]; ZeroMemory( diff --git a/ExplorerPatcher/GUI.h b/ExplorerPatcher/GUI.h index 333f7ec..2b14a88 100644 --- a/ExplorerPatcher/GUI.h +++ b/ExplorerPatcher/GUI.h @@ -25,6 +25,7 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #include "fmemopen.h" #include "utility.h" #include "../ep_weather_host/ep_weather.h" +#include "../ep_weather_host/ep_weather_host_h.h" #include #include diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index e50795c..889bd6e 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -497,9 +497,9 @@ ;x 500 500 % "WeatherZoomFactor"=dword:00000000 ;q -;t Weather data courtesy of Google, and weather.com. ;y Learn more about the Weather taskbar widget 🡕 ;https://github.com/valinet/ExplorerPatcher/wiki/Weather +;t %WEATHERLASTUPDATETEXT% ;u Update weather now ;update_weather ;u Clear weather widget local data diff --git a/ExplorerPatcher/settings10.reg b/ExplorerPatcher/settings10.reg index 509cfa3..fd66012 100644 --- a/ExplorerPatcher/settings10.reg +++ b/ExplorerPatcher/settings10.reg @@ -436,9 +436,9 @@ ;x 500 500 % "WeatherZoomFactor"=dword:00000000 ;q -;t Weather data courtesy of Google, and weather.com. ;y Learn more about the Weather taskbar widget 🡕 ;https://github.com/valinet/ExplorerPatcher/wiki/Weather +;t %WEATHERLASTUPDATETEXT% ;u Update weather now ;update_weather ;u Clear weather widget local data diff --git a/ep_weather_host/ep_weather_host.c b/ep_weather_host/ep_weather_host.c index 86c3c3a..67d3fa6 100644 --- a/ep_weather_host/ep_weather_host.c +++ b/ep_weather_host/ep_weather_host.c @@ -8,6 +8,7 @@ DWORD32 global_ubr; EPWeather* EPWeather_Instance = NULL; SRWLOCK Lock_EPWeather_Instance = { .Ptr = SRWLOCK_INIT }; FARPROC SHRegGetValueFromHKCUHKLMFunc; +SYSTEMTIME stLastUpdate; static DWORD epw_Weather_ReleaseBecauseClientDiedThread(EPWeather* _this) { @@ -589,6 +590,9 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted(ICoreWebView2Exec } else { + GetLocalTime(&stLastUpdate); + HWND hGUI = FindWindowW(L"ExplorerPatcher_GUI_" _T(EP_CLSID), NULL); + if (hGUI) InvalidateRect(hGUI, NULL, TRUE); InterlockedExchange64(&_this->bBrowserBusy, FALSE); printf("[General] Fetched data, requesting redraw.\n"); SetTimer(_this->hWnd, EP_WEATHER_TIMER_REQUEST_REPAINT, EP_WEATHER_TIMER_REQUEST_REPAINT_DELAY, NULL); @@ -1157,6 +1161,12 @@ HRESULT STDMETHODCALLTYPE epw_Weather_SetZoomFactor(EPWeather* _this, LONG64 dwZ return S_OK; } +HRESULT STDMETHODCALLTYPE epw_Weather_GetLastUpdateTime(EPWeather* _this, LPSYSTEMTIME lpLastUpdateTime) +{ + *lpLastUpdateTime = stLastUpdate; + return S_OK; +} + DWORD WINAPI epw_Weather_MainThread(EPWeather* _this) { HRESULT hr = S_OK; diff --git a/ep_weather_host/ep_weather_host.h b/ep_weather_host/ep_weather_host.h index 2883018..b9568b1 100644 --- a/ep_weather_host/ep_weather_host.h +++ b/ep_weather_host/ep_weather_host.h @@ -122,6 +122,7 @@ HRESULT STDMETHODCALLTYPE epw_Weather_SetWindowCornerPreference(EPWeather* _this HRESULT STDMETHODCALLTYPE epw_Weather_SetDevMode(EPWeather* _this, LONG64 dwDevMode, LONG64 bRefresh); HRESULT STDMETHODCALLTYPE epw_Weather_SetIconPack(EPWeather* _this, LONG64 dwIconPack, LONG64 bRefresh); HRESULT STDMETHODCALLTYPE epw_Weather_SetZoomFactor(EPWeather* _this, LONG64 dwZoomFactor); +HRESULT STDMETHODCALLTYPE epw_Weather_GetLastUpdateTime(EPWeather* _this, LPSYSTEMTIME lpLastUpdateTime); static const IEPWeatherVtbl IEPWeather_Vtbl = { .QueryInterface = epw_Weather_QueryInterface, @@ -151,6 +152,7 @@ static const IEPWeatherVtbl IEPWeather_Vtbl = { .SetDevMode = epw_Weather_SetDevMode, .SetIconPack = epw_Weather_SetIconPack, .SetZoomFactor = epw_Weather_SetZoomFactor, + .GetLastUpdateTime = epw_Weather_GetLastUpdateTime, }; static inline DWORD epw_Weather_GetTextScaleFactor(EPWeather* _this) { return InterlockedAdd64(&_this->dwTextScaleFactor, 0); } diff --git a/ep_weather_host_stub/ep_weather_host.idl b/ep_weather_host_stub/ep_weather_host.idl index 8408bd0..c1c7af1 100644 --- a/ep_weather_host_stub/ep_weather_host.idl +++ b/ep_weather_host_stub/ep_weather_host.idl @@ -85,4 +85,6 @@ import "unknwn.idl"; HRESULT SetIconPack([in] LONG64 dwIconPack, [in] LONG64 bRefresh); HRESULT SetZoomFactor([in] LONG64 dwZoomFactor); + + HRESULT GetLastUpdateTime([out] LPSYSTEMTIME lpLastUpdateTime); }; \ No newline at end of file