1
0
mirror of synced 2025-02-17 18:59:21 +01:00

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.
This commit is contained in:
lorsanta 2023-08-16 23:18:16 +02:00 committed by GitHub
parent fc93f8bd66
commit 84ceb45129
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,10 @@
#include <nlohmann/json.hpp>
#if defined(OS_WINDOWS)
#include <windows.h>
#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();
}