@@ -701,11 +701,12 @@ class CWebWindow
701
701
return E_FAIL;
702
702
std::wstring url (resource[L" url" ].GetString ());
703
703
std::wstring mimeType (resource[L" mimeType" ].GetString ());
704
+ int64_t lastModified = resource.HasMember (L" lastModified" ) ? resource[L" lastModified" ].GetInt64 () : 0 ;
704
705
std::wstring args = L" { \" frameId\" : \" " + frameId + L" \" , \" url\" : \" " + url + L" \" }" ;
705
706
ComPtr<IWebDiffCallback> callback2 (callback);
706
707
HRESULT hr = GetActiveWebView ()->CallDevToolsProtocolMethod (L" Page.getResourceContent" , args.c_str (),
707
708
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 {
709
710
std::filesystem::path path (dirname);
710
711
if (SUCCEEDED (errorCode))
711
712
{
@@ -756,6 +757,8 @@ class CWebWindow
756
757
if (FAILED (errorCode = WriteToTextFile (path, document[L" content" ].GetString ())))
757
758
WriteToErrorLog (dirname, url, errorCode);
758
759
}
760
+ if (lastModified > 0 )
761
+ SetLastModifed (path, lastModified);
759
762
}
760
763
else
761
764
{
@@ -1281,6 +1284,28 @@ class CWebWindow
1281
1284
return fp != nullptr ? S_OK : (GetLastError () == 0 ? E_FAIL : HRESULT_FROM_WIN32 (GetLastError ()));
1282
1285
}
1283
1286
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
+
1284
1309
bool MyRegisterClass (HINSTANCE hInstance)
1285
1310
{
1286
1311
WNDCLASSEXW wcex = { 0 };
0 commit comments