Repository navigation
Launcher: roll back and the Engine.ini revert change only WrongGPU's bytes, through one handle - #209
Merged
Merged
Conversation
…bytes, through one handle Roll back (#184): every payload file is held (PinnedFile: one handle, no write, rename or delete sharing), hashed through that handle and compared with the hash the record says WrongGPU installed. The current files are copied out for a later update and the earlier ones written through the same held handles. A file with other bytes, a hard-linked file, a link, or a file that appears where a payload file was missing stops the roll back before anything changes; the result names it and the file stays. A missing payload file is created only where nothing is (CREATE_NEW, held). Engine.ini revert (#186): Engine.ini is opened once, read, compared and then rewritten or deleted through that same handle. A missing file is created only with CREATE_NEW; a file another program created meanwhile stays, the player's copy is kept in wronggpu-setup\rr-config and the result says where. Hard-linked or linked files are not written. New PinnedFile primitives (Create, ReadBytes, CopyOut, SetReadOnly) and WriteFileNew; RestoreStep is shared so the tests can act at the new steps. launcher-core gains 13 checks: player-changed, hard-linked, held, missing and appeared payload files at roll back; Engine.ini replaced or written while held, replaced before the open, created before the absent-file restore (on disk and in-memory copy), restored when gone, hard-linked. Fixes #184 Fixes #186 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…ni-ownership Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
phantoslayer21
marked this pull request as ready for review
November 14, 2026 22:17
Roll back: - Every earlier file is held and hashed before the first write and copied through that handle. - A write that fails part way puts the files already changed back from their swap copies, through their held handles; the record changes only after every file is in (a failed record save is undone the same way). - previous and a left-over previous.swap folder go only after the writes, file by file: a file previous.txt lists is deleted only while its bytes are the stated hash, through one handle; anything else stays and is named; a folder goes only when empty. The new swap folder is always a fresh one. - A payload file missing at a roll back is recorded as absent in previous.txt (file=absent:<hash>|<name>); the second roll back removes the recreated file only while its bytes are the recorded ones, and refuses otherwise. Engine.ini revert: - Policy (documented): only WrongGPU's own line goes, also from a file changed elsewhere. A file WrongGPU created is deleted only while it is byte for byte what WrongGPU wrote. - The corrected bytes go into a new file in the same folder (flushed, read back), the held original is checked again, then ReplaceFileW (attributes and ACL kept). A change by another program in the moment before the replace is put back and said. - The rr-config backup is deleted only while it matches the hash recorded when it was made (new record line rrconfig-backup), through one handle; otherwise it stays and is named. - The read-only attribute result is checked; a failure is said and the backup stays. Tests: launcher-core gains 17 checks (write fault mid roll back through a new test seam, absent round trip, list-only cleanup, Engine.ini policy, torn write, the replace window, backup hash, read-only failure). Refs #184 Refs #186 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…ni-ownership Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
phantoslayer21
marked this pull request as draft
November 14, 2026 23:16
phantoslayer21
marked this pull request as ready for review
November 14, 2026 23:34
…fter the replace) - The corrected copy is closed before ReplaceFileW, so it is not trusted after it: the live Engine.ini is then held (no write, rename or delete sharing) and must hash to the corrected bytes. Otherwise it is left as it is, the file it replaced stays beside it as Engine.ini.wronggpu-old, the backup is kept and the result says so. - The race recovery no longer moves the old file over Engine.ini by name: a change made before the replace is written back through the held, verified live file; a change made after it is never overwritten. - When taking out WrongGPU's line leaves nothing, the file stays empty; the backup from before the fix is never put back over it. - A failed replace puts the read-only attribute back and the warning names a failure to do so; PinnedFile::Close and a failed Open now report a read-only bit they could not put back. Tests: launcher-core gains 5 checks (copy swapped before the replace, a second change after it, an emptied file, a failed replace with and without a failed read-only restore, through the fault seams). Refs #184 Refs #186 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
… replace - The live Engine.ini counts as WrongGPU's corrected file only when it is the copy itself (its volume and file index, taken while the copy was held) and holds the corrected bytes; equal bytes in another file are not enough. - The recovery no longer writes anything into the live file: a version another program wrote just before the replace is kept beside it as Engine.ini.wronggpu-their-change (moved only into a free name), the backups stay, and the warning names both files. - The verification opens the live file without write access, so another program's read-only file is never changed; a read-only bit that could not be put back (ReadOnlyLost, the Close result) is still checked and said, and the backups stay. Tests: launcher-core gains 3 checks (a distinct file with identical bytes swapped in after the replace is left untouched; the verification's mismatch path with a read-only file, with and without a read-only restore failure). Refs #184 Refs #186 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
3 tasks done
j0nsh1n
added a commit
to j0nsh1n/wronggpu
that referenced
this pull request
Nov 15, 2026
Brings the launcher branch up to upstream main (217 commits: phantoslayer21#47, phantoslayer21#105, phantoslayer21#196, phantoslayer21#197, phantoslayer21#209, Model K/L, frame generation, ...). Changes beyond resolving the three conflicts (CMakeLists.txt project(), util.h's includes, the restorer test): - POSIX layer: the Win32 calls main's handle-based restore uses (SetFileInformationByHandle with FileBasicInfo, FileDispositionInfo and FileDispositionInfoEx's POSIX delete, GetFileInformationByHandleEx FileBasicInfo, SetEndOfFile, ExitProcess, GetProcessHeap/HeapFree, CDECL, ERROR_TOO_MANY_LINKS/FILE_CORRUPT/READ_FAULT), with posix-layer tests. - run_launcher_tests.py stays below the 256 KB source limit: the edition section moves unchanged to launcher_edition_cases.py and the Linux run's plumbing to native_linux.NativeT. - launcher-native runs only in a -DWRONGGPU_PRESET_K=OFF build (like CI's launcher build: the suite expects no seeded wronggpu-asi.ini); its two checks that fail on main's own launcher too (phantoslayer21#219) are skipped while they fail (native_linux.KNOWN_ON_MAIN). Verified: fresh build, ctest 22/22 (launcher-native 365 passed, 0 failed, 6 skipped: 4 Windows-only sections, the 2 phantoslayer21#219 checks); reuse lint passes. Signed-off-by: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Roll back and the Engine.ini revert now follow the ownership rule from #47. A file is changed only through one handle:
open it, hash or read it, then write, replace or delete it from that handle, with no write, rename or delete sharing in
between. It is changed only when its bytes are WrongGPU's. Otherwise the file is kept and the result names it. A missing
file is created only with fail-if-present (
CREATE_NEW).Fixes #184
Fixes #186
One PR for both issues because they share the new primitives in
util.h/util.cpp:PinnedFile::Create(heldCREATE_NEW),ReadBytes,CopyOut,SetReadOnly,OverwriteFrom,Flush, andWriteFileNew. They also share thetest seams:
RestoreStepis no longer file-local, andSetFaultHook/TestFaultinject a write fault at named steps.Review fixes
One line per review item (line numbers of the reviewed head 28dbde8). All tests are in
tests/launcher_core_tests.cpp.previous/previous.swapcleanup.RemoveTreeis gone from roll back.RemoveListeddeletes only the filesprevious.txtlists, each only while its bytes are the stated hash (DeleteIfSha: hashed and deleted through one heldhandle, never through a link in the path).
previous.txtitself goes last, only while it is the list that was read.Folders go only when empty. Anything else stays and is named in the result. The cleanup runs after the writes and the
record. The new swap folder is always fresh (
previous.swap, elseprevious.swap-2, ...). An earlier swap folder isnever cleared before the writes; afterwards it goes by its own list. Tests: "previous\ goes only by its list..." and
"an earlier swap folder is never cleared before the writes...". Negative control: putting
RemoveTree(prev)back failsthe first of these.
Partial roll back. Every earlier file is held and hashed before the first write, and written through that handle
(
OverwriteFrom). A damaged one stops the roll back before any write. If a write fails after the writes have started,every file already changed is put back from its swap copy through its held handle. That includes the torn file, a file
the roll back created (deleted again) and a file it removed (created again). The record is saved only after every file
is in. A failed save is undone the same way. Tests: "a write that fails on the second file..." (fault seam
rollback-write; record bytes andprevious\unchanged), "...a file the roll back created goes again...", "an earlierfile with other bytes...", "the earlier files are held from their check to the write". Negative control: skipping the
undo fails the write-fault test.
Double roll back after a missing payload file. The new
previous.txtrecords it asfile=absent:<record hash>|<name>.The second roll back removes the recreated file through its held handle, only while its bytes are the ones the record
names. Other bytes stop that roll back with a clear message ("...had no such file..."), and nothing changes. An older
launcher reads
absent:...as a hash no kept file has, so it refuses ("damaged") rather than mixing two versions.Tests: "a payload file missing at the roll back is recorded as absent; the second roll back takes the recreated file
out...", "...a third roll back creates it again", "...a file there with other bytes stops the second roll back...".
Engine.ini policy and crash-safe write. Policy, now stated in the README: only WrongGPU's own line goes, also from an
Engine.inithe player changed elsewhere. A file WrongGPU created is deleted only while its bytes are exactly the onesWrongGPU wrote; a changed one stays, without the line (before, it was also deleted when only whitespace was left).
The write never goes over the file in place:
CREATE_NEW), which is flushed (result checked) andhashed back;
ReplaceFileW, with a backup name and no ignore flags, which keeps attributes, ACL and creation time.The remaining window (documented in the README): the handle closes just before the replace. Another program's change in
that moment ends up at the backup name, is compared with the bytes read, and is put back at the name if it differs.
The result says so. Tests: "from a file the player changed elsewhere only WrongGPU's line goes (policy); a corrected copy
replaces the file (its attributes kept, nothing left beside it)...", "a write fault part way leaves Engine.ini byte for
byte as it was..." (seam
rrconfig-write), "a change by another program in the moment before the replace is not lost..."(step
rrconfig-replace), "a file WrongGPU created and something changed since stays...". Negative control: writing inplace again (with the seam at that write) fails the policy test (the file id check) and, with that check left out, the
torn-write test.
rr-config backup deletion. The backup's SHA-256 is recorded when it is made, in a new record line
rrconfig-backup\t<sha>. An older launcher keeps it as a line it does not know. The revert deletes the backup only whileits bytes are that hash (a record from before this line: the bytes this revert read), through
DeleteIfSha. Otherwise itstays and the result names it. A backup that is not the recorded copy is also never used to recreate a missing
Engine.ini. Tests: "a backup with other bytes than the recorded hash is not deleted...", "the backup's hash is kept in aline of its own (rrconfig-backup) and read back".
Read-only restore. The result of putting back the read-only attribute is checked (in-place, replaced and recreated
file). A failure is said in the result and the backup is not deleted. Test: "a read-only attribute that cannot be put back
is said, and the backup stays" (seam
rrconfig-readonly).Re-check fixes (REVIEW-209b)
a. The corrected copy is verified after the replace. The copy is closed before
ReplaceFileW(the replace needs itunshared), so it is not trusted afterwards. The live
Engine.iniis then held (no write, rename or delete sharing) andmust hash to the corrected bytes. If it doesn't, it is left as it is and never overwritten. The file it replaced stays
beside it as
Engine.ini.wronggpu-old, the backup is kept, and the result says so. Test: "a corrected copy swappedbefore the replace is caught after it..." (the copy is replaced at step
rrconfig-replace). Negative control: droppingthe hash check fails it.
b. The race recovery never overwrites an unverified destination. The old file is no longer moved over
Engine.inibyname (
MoveFileExW(REPLACE_EXISTING)is gone). A change made just before the replace is written back through the heldlive file, and only after that file is verified as WrongGPU's own copy. A change made after the replace fails that
check, so it is left as it is, the earlier change is kept beside it, and the player is told. Test: "a second change
after the replace is never overwritten by the recovery..." (changes at
rrconfig-replaceand at a new steprrconfig-replaced).c. Empty content stays empty. When taking out WrongGPU's line leaves nothing, the empty file is written. The backup from
before the fix is never put back. A file is deleted only if WrongGPU created it and it is still byte for byte what
WrongGPU wrote. Test: "taking out WrongGPU's line from a file the player emptied of their own settings leaves it
empty...". Negative control: putting the backup fallback back fails it.
d. Read-only after a failed replace. The read-only attribute is put back, the result is checked, and the warning names
any failure.
PinnedFile::Closeand a failedPinnedFile::Opennow report a read-only bit they could not put back(
ReadOnlyLost), and the Engine.ini open-failure messages include it. Tests: "a failed replace puts the read-only bitback..." and "a failed replace whose read-only restore fails says so in the warning..." (fault seams
rrconfig-replacefile,rrconfig-readonly).Re-check 2 fixes (REVIEW-209c)
Engine.iniisWrongGPU's corrected file only if it is the copy itself: the same volume and file index, captured while the copy was
held. It must also hold the corrected bytes. The recovery write is gone. When another program wrote
Engine.inijustbefore the replace, its version is kept beside the corrected file as
Engine.ini.wronggpu-their-change(moved onlyinto a free name), the backups stay, and the warning names both files. Nothing after the replace writes into a file
WrongGPU did not just create. Test: "a distinct file with the corrected bytes swapped in after the replace is not taken
for WrongGPU's...": a new file with identical bytes is swapped in at
rrconfig-replaced, and its file id and bytes stayuntouched. The earlier "change before the replace" test now expects the their-change file. Negative control: dropping
the identity check fails the new test.
is never cleared there.
ReadOnlyLost()and theClose()result are still checked on the open-failure and mismatchpath; a failure is said in the warning, and the backups stay. Tests: "the verification opens another program's
read-only file without changing its attribute..." and "on the verification's mismatch path a read-only restore failure
is said in the warning..." (fault seam
rrconfig-verify-readonly).#184: Roll back (
launcher.cppRollback), as it is nowprevious\is opened withPinnedFile::Open(path, false)and hashed through its handle. Each mustmatch
previous.txt.PinnedFile::Open(path, forWrite)and hashed through the handle,then compared with the record's
instfor that path. A fileprevious.txtlists as absent must be WrongGPU's too; it isremoved at the end.
PinnedFile::Create(CREATE_NEW) and held like theothers.
warnings name each file. This covers other bytes, a hard link (
ERROR_TOO_MANY_LINKS), a link or folder, and a filethat appeared where one was missing. Files created in step 3 are deleted again through their handles.
CopyOut,CREATE_NEW), withprevious.txt(absent ones listed as such).earlier version did not have are deleted last. A failure undoes everything (Review fix 2).
previous\is removed by its list, the swap folder takes its place, andolder swap folders go by their lists.
#186: Engine.ini revert (
rrconfig.cppRevertRrConfig, called from uninstall,=off, and relocation)PinnedFile::Open(path, true)) and read through that handle, and the edit is computed fromthose bytes. Then either a corrected copy replaces it (
ReplaceEngineIni, Review fix 4), or the file WrongGPU created isdeleted through the handle (
Delete). Read-only goes back as the player had it (wasReadOnly), and the result is checked.CREATE_NEWthrough a held handle. A file another programcreated in the meantime stays. The player's copy is kept in
wronggpu-setup\rr-config(in a newEngine.ini.kept-<time>file when the caller held the copy only in memory, as relocation does). The result names that location, and the backup is
not deleted.
What is guaranteed, and what is not
Guaranteed, within the limits of the
PinnedFilemodel described in #47 and inutil.h:equal the record's hash. If any file fails that check, nothing is changed. The earlier files are held and checked before
the first write.
file is in.
wronggpu-setup\previousand swap folders only files their list names with the stated bytes, andonly empty folders.
that name.
replaced.
After the replace, the live file counts as done only when it is held, is the copy WrongGPU wrote (same file identity),
and holds the corrected bytes.
Not guaranteed (remaining narrow races and limits):
parent folder between operations can make the open reach a different file. For roll back, that file is still compared
with the record's hash. For Engine.ini, a different file at that path is the one read and edited, but only WrongGPU's
own line is removed from it.
file that gets read and edited, and only WrongGPU's line is removed (the stated policy).
ReplaceFileW. Changes made in that moment are detectedafterwards, when the live file is held and its identity and bytes are checked. That covers the original, the copy, or
Engine.inichanged or replaced right after the replace. Nothing is then written into the live file. The otherversion is kept beside it, and the result says so. A stop between the replace and those checks leaves the old bytes
next to it as
Engine.ini.wronggpu-old. When another program's version is kept beside the corrected file, the playerchooses between the two files; WrongGPU does not merge them.
power cut mid-write can leave a torn payload file, with the record still naming the newer hashes. The next roll back then
refuses, and Repair puts WrongGPU's file back.
is being written, and another program can read it partly written then.
SavePreviousstill replacesprevious\as a whole (RemoveTree). Also notchanged: adding the Engine.ini line (
ApplyRrConfig, path-based like the install's writes; Launcher: install, repair and update can delete or overwrite a file replaced after the backup #185 area), and the install,repair and update writes (Launcher: install, repair and update can delete or overwrite a file replaced after the backup #185).
before the held open, as in Launcher: coexist with other OptiScaler setups #47's
PinnedFile::Open. It is put back if the file is then not written.Tested
Windows, CPU only, 1 compile job, on the pushed head (main merged in). The end-to-end runs for the re-check fixes ran with
APPDATA, LOCALAPPDATA and ProgramData pointed at scratch folders.
-DWRONGGPU_TESTING=OFF -DWRONGGPU_PRESET_K=OFF -DWRONGGPU_DIRECT_ROUTE=OFF) ctest:wg-core, launcher-core, coexist-core, convert-ignore, model-choice, source-size and wording all pass (7/7).
launcher-core has 386 checks: 348 before this PR, 13 from its first commit, 17 from the review fixes, 5 from the
re-check fixes, 3 from the re-check 2 fixes. The new ones are listed in the fix sections above. The 13 earlier ones are unchanged: player-changed, hard-linked, held, missing and
appeared payload files at roll back; Engine.ini held against replace, delete and write; replaced before the open;
created before the absent-file restore (on disk and in memory); restored when gone; hard-linked.
RemoveTree(prev)back: fails at "previous\ goes only by its list...";part way leaves Engine.ini byte for byte as it was...";
WRONGGPU_TESTINGlauncher (mock payload and map fromrun_installer_tests.py --prepare-only,-DWRONGGPU_PRESET_K=OFF, direct route on):run_launcher_tests.py --only install_settings_uninstall rr_config_fix launcher_uninstall: 186 passed, 1 failed.Roll back and roll back again pass, and so do the Engine.ini
=offand uninstall cases byte for byte (read-only, BOM,the key's earlier value). The failure is "uninstall.exe is the small restorer, not the launcher": it depends on the size
of a local build, and Launcher: coexist with other OptiScaler setups #47 lists it as a baseline failure on local builds.
run_coexist_tests.py: 227 passed, 0 failed.Not tested
run_launcher_tests.py(rr,re9,direct_rr, adopt / self-install,ui_dump),run_installer_tests.py,and the Preset K and direct-route-only builds. None of them reaches the changed code beyond what is listed above.
previous.txt(absent:) or therrconfig-backuprecord line. This is reasoned fromits parser (unknown hash, so "damaged"; unknown line, so kept), not run.
=off/ uninstall path was not exercised; itcalls the same
RevertRrConfig.fault seams), a real full disk, a real power cut.
ReplaceFileWon file systems other than NTFS, and under Wine.