mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Juggle new/dat/old on symlink target
This commit is contained in:
parent
921cf0087c
commit
470850dd8c
2 changed files with 14 additions and 4 deletions
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
// C++ Standard Libraries
|
// C++ Standard Libraries
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <chrono>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
|
||||||
|
|
@ -427,7 +427,8 @@ void xivfixes::backup_userdata_save(bool bApply) {
|
||||||
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||||
DWORD dwCreationDisposition,
|
DWORD dwCreationDisposition,
|
||||||
DWORD dwFlagsAndAttributes,
|
DWORD dwFlagsAndAttributes,
|
||||||
HANDLE hTemplateFile)->HANDLE {
|
HANDLE hTemplateFile) noexcept {
|
||||||
|
|
||||||
if (dwDesiredAccess != GENERIC_WRITE)
|
if (dwDesiredAccess != GENERIC_WRITE)
|
||||||
return s_hookCreateFileW->call_original(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
|
return s_hookCreateFileW->call_original(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
|
||||||
|
|
||||||
|
|
@ -436,9 +437,17 @@ void xivfixes::backup_userdata_save(bool bApply) {
|
||||||
if (ext != ".dat" && ext != ".cfg")
|
if (ext != ".dat" && ext != ".cfg")
|
||||||
return s_hookCreateFileW->call_original(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
|
return s_hookCreateFileW->call_original(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
|
||||||
|
|
||||||
|
for (auto i = 0; i < 16; i++) {
|
||||||
|
std::error_code ec;
|
||||||
|
auto resolved = read_symlink(path, ec);
|
||||||
|
if (ec || resolved == path)
|
||||||
|
break;
|
||||||
|
path = std::move(resolved);
|
||||||
|
}
|
||||||
|
|
||||||
std::filesystem::path temporaryPath = path;
|
std::filesystem::path temporaryPath = path;
|
||||||
temporaryPath.replace_extension(path.extension().wstring() + L".new");
|
temporaryPath.replace_extension(std::format(L"{}.new.{:X}.{:X}", path.extension().c_str(), std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count(), GetCurrentProcessId()));
|
||||||
const auto handle = s_hookCreateFileW->call_original(temporaryPath.c_str(), GENERIC_READ | GENERIC_WRITE | DELETE, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
|
const auto handle = s_hookCreateFileW->call_original(temporaryPath.c_str(), GENERIC_READ | GENERIC_WRITE | DELETE, dwShareMode, lpSecurityAttributes, CREATE_ALWAYS, dwFlagsAndAttributes, hTemplateFile);
|
||||||
if (handle == INVALID_HANDLE_VALUE)
|
if (handle == INVALID_HANDLE_VALUE)
|
||||||
return handle;
|
return handle;
|
||||||
|
|
||||||
|
|
@ -448,7 +457,7 @@ void xivfixes::backup_userdata_save(bool bApply) {
|
||||||
return handle;
|
return handle;
|
||||||
});
|
});
|
||||||
|
|
||||||
s_hookCloseHandle->set_detour([](HANDLE handle) {
|
s_hookCloseHandle->set_detour([](HANDLE handle) noexcept {
|
||||||
const auto lock = std::lock_guard(s_mtx);
|
const auto lock = std::lock_guard(s_mtx);
|
||||||
if (const auto it = s_handles.find(handle); it != s_handles.end()) {
|
if (const auto it = s_handles.find(handle); it != s_handles.end()) {
|
||||||
std::filesystem::path tempPath(std::move(it->second.first));
|
std::filesystem::path tempPath(std::move(it->second.first));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue