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:
parent
fc93f8bd66
commit
84ceb45129
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user