VFS: ReplaceFileW is redirected #59
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/60"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by gefydev on 2026-11-22T23:07:43Z.
ReplaceFileWis the usual way to save safely: writesave.tmp, then replacesave.datwith it, optionally keepingsave.bak.vfs_hooks.rsdoesn't hook it, so:T:\, the PLS driveS:\), the call goes to the PC's own drive and fails, leaving the old save and the temporary file.The new hook:
source_offor the two existing files,dest_offor the backup) and calls the original.CopyFileWand the replacement withMoveFileExW. Both go through their own hooks (the guard is dropped first), so the write lands in the overlay the same way a move does today.CopyFileWis only hooked in #59; without it the backup copy is still the right call, it just isn't redirected yet. The two PRs don't conflict.Validation
The hooks are process-wide and need an initialized VFS (a global
OnceLock), so this isn't a unit test. I ran a probe alone, with a VFS that mountsG:(the game) andT:on temp folders and the real hooks installed. Under Wine:mainReplaceFileW(T:\save.dat, T:\save.tmp, T:\save.bak)save.datstill old, no backup,save.tmpleftsave.datnew,save.bakold,save.tmpgoneReplaceFileW(G:\save.dat, T:\save.tmp, null)G:\save.datstill the originalG:\save.datreads the new data fromoverlay\save.dat; the file in the game folder is still the original (checked outside Wine)cargo test -p xcl --lib: 343 passed, 0 failed, on Windows GNU under Wine.Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T09:45:18Z.
Merged (
533187c). Verified on Windows 11 with the real hooks:ReplaceFileWandReplaceFileA(which reachesReplaceFileW) onT:– new data, backup with the old, temp gone;ReplaceFileW(G:\save.dat, T:\save.tmp, G:\save.bak)–G:\save.datreads the new data from the overlay, the backup is in the overlay, the game folder's file is unchanged (checked from outside the process).Tested on Windows 11 (RX 9070):
cargo test --workspacegreen (lib 351, e2e), and a 45 s Unicorn Overlord run on the release build (VFS hooks active, ~60 fps, clean exit). Thanks!