From 84ceb45129be352f752c02adf88e66bb62d79a60 Mon Sep 17 00:00:00 2001 From: lorsanta <48159385+lorsanta@users.noreply.github.com> Date: Wed, 16 Aug 2023 23:18:16 +0200 Subject: [PATCH] impr: Update timestamp when saving a file in windows (#1248) ### Problem description Ref #1210 ### Implementation description Call [`SetFileTime()`](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfiletime) everytime `FileProvider::save()` is called. ### Additional things I moved the call to `File::close()` from `FileProvider::open()` to `FileProvider::close()` because `SetFileTime()` requires a file handler as input, so I need `File::m_file` to be valid. --- .../content/providers/file_provider.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index 41f55f818..6b253f614 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -16,6 +16,10 @@ #include +#if defined(OS_WINDOWS) + #include +#endif + namespace hex::plugin::builtin { bool FileProvider::isAvailable() const { @@ -75,6 +79,21 @@ namespace hex::plugin::builtin { void FileProvider::save() { this->applyPatches(); + + #if defined(OS_WINDOWS) + FILETIME ft; + SYSTEMTIME st; + + wolv::io::File file(this->m_path, wolv::io::File::Mode::Write); + if (file.isValid()) { + GetSystemTime(&st); + if (SystemTimeToFileTime(&st, &ft)) { + auto fileHandle = (HANDLE)_get_osfhandle(_fileno(file.getHandle())); + SetFileTime(fileHandle, (LPFILETIME) NULL, (LPFILETIME) NULL, &ft); + } + } + #endif + Provider::save(); }