@@ -701,11 +701,12 @@ class CWebWindow
701701 return E_FAIL;
702702 std::wstring url (resource[L" url" ].GetString ());
703703 std::wstring mimeType (resource[L" mimeType" ].GetString ());
704+ int64_t lastModified = resource.HasMember (L" lastModified" ) ? resource[L" lastModified" ].GetInt64 () : 0 ;
704705 std::wstring args = L" { \" frameId\" : \" " + frameId + L" \" , \" url\" : \" " + url + L" \" }" ;
705706 ComPtr<IWebDiffCallback> callback2 (callback);
706707 HRESULT hr = GetActiveWebView ()->CallDevToolsProtocolMethod (L" Page.getResourceContent" , args.c_str (),
707708 Callback<ICoreWebView2CallDevToolsProtocolMethodCompletedHandler>(
708- [this , dirname, url, mimeType, callback2](HRESULT errorCode, LPCWSTR returnObjectAsJson) -> HRESULT {
709+ [this , dirname, url, mimeType, lastModified, callback2](HRESULT errorCode, LPCWSTR returnObjectAsJson) -> HRESULT {
709710 std::filesystem::path path (dirname);
710711 if (SUCCEEDED (errorCode))
711712 {
@@ -756,6 +757,8 @@ class CWebWindow
756757 if (FAILED (errorCode = WriteToTextFile (path, document[L" content" ].GetString ())))
757758 WriteToErrorLog (dirname, url, errorCode);
758759 }
760+ if (lastModified > 0 )
761+ SetLastModifed (path, lastModified);
759762 }
760763 else
761764 {
@@ -1281,6 +1284,28 @@ class CWebWindow
12811284 return fp != nullptr ? S_OK : (GetLastError () == 0 ? E_FAIL : HRESULT_FROM_WIN32 (GetLastError ()));
12821285 }
12831286
1287+ static void TimetToFileTime (time_t t, LPFILETIME pft)
1288+ {
1289+ ULARGE_INTEGER time_value;
1290+ time_value.QuadPart = (t * 10000000LL ) + 116444736000000000LL ;
1291+ pft->dwLowDateTime = time_value.LowPart ;
1292+ pft->dwHighDateTime = time_value.HighPart ;
1293+ }
1294+
1295+ static bool SetLastModifed (const std::wstring& path, int64_t lastModified)
1296+ {
1297+ if (lastModified == 0 )
1298+ return false ;
1299+ wil::unique_hfile file (CreateFile (path.c_str (),
1300+ GENERIC_READ | GENERIC_WRITE, 0 , nullptr , OPEN_EXISTING,
1301+ FILE_ATTRIBUTE_NORMAL, nullptr ));
1302+ if (!file)
1303+ return false ;
1304+ FILETIME ft{};
1305+ TimetToFileTime (lastModified, &ft);
1306+ return SetFileTime (file.get (), nullptr , nullptr , &ft);
1307+ }
1308+
12841309 bool MyRegisterClass (HINSTANCE hInstance)
12851310 {
12861311 WNDCLASSEXW wcex = { 0 };
0 commit comments