Skip to content

Commit 3dff324

Browse files
committed
ResourceTree compare: Set last-modified date and time in resource files
1 parent 7413d39 commit 3dff324

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/WinWebDiffLib/WebWindow.hpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 };

src/gen-versioninfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//GIT-VS-VERSION-GEN.bat generated resource header.
2-
#define GEN_VER_VERSION_STRING "1.0.2.1.gb98a6.dirty\0"
3-
#define GEN_VER_DIGITAL_VERSION 1,0,2,1
4-
#define GEN_VER_VERSION_HEX 0x0001000000020001
2+
#define GEN_VER_VERSION_STRING "1.0.2.5.g7413d.dirty\0"
3+
#define GEN_VER_DIGITAL_VERSION 1,0,2,5
4+
#define GEN_VER_VERSION_HEX 0x0001000000020005
55
#define GEN_VER_COMMENT_STRING "Major Version Release\0"
66
#define GEN_VER_PRIVATE_FLAG VS_FF_PRIVATEBUILD
77
#define GEN_VER_PRIVATE_STRING "Custom Build\0"

0 commit comments

Comments
 (0)