copy_blob() backs up a blob before a commit overwrites it and copies it
back when an update is rolled back. It used std::filesystem::copy_file,
which in MSVC calls CopyFile2. Wine 9 and the Protons built on it do not
implement CopyFile2, and the call aborts the process (kevincommits'
finding in #1608, batch 18 item 1). file_system.cpp already avoids it
for the same reason.
copy_blob() now calls CopyFileW(from, to, FALSE). On Windows it copies
the same way: contents, attributes and last-write time, replacing an
existing file.
xgameruntime_gamesave_test gains a case that patches this process's
CopyFile2 to fail and count calls, as Wine's stub would, then runs an
update that overwrites a blob and one that is rolled back. Its 3 checks
fail with main's copy_blob and pass with the fix.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With LEONIDA_TRACE_XGAMESAVE=1 the offline XGameSaveImpl logs one
"[rt] xgamesave:" line per XGameSave* and XGameSaveFiles* call: the call,
its handles, container and blob names, sizes and HRESULT, with the
milliseconds since the process started and the thread id. An async call
also logs when begin() schedules its job, when the work runs (and how
long it waited on the queue), when it completes and when the title
collects the result, all naming the title's XAsyncBlock. Blob contents
are never logged. Off by default: a call then pays one relaxed load.
xgameruntime_gamesave_test turns it on through a test hook, writes and
reads a blob (sync and async) and checks the lines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A title sizes the read buffer as the sum of sizeof(XGameSaveBlob), the data and
the name with its NUL for each blob. The shim required the 8-byte aligned layout
and refused such a buffer with E_GS_PROVIDED_BUFFER_TOO_SMALL. The minimum (and
the async result size) is now the unpadded sum; the blobs are packed aligned
when the buffer has room for that and back to back otherwise.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
commit() replaced blobs one rename at a time. When a later rename failed (the blob held open by another
process without FILE_SHARE_DELETE), the earlier renames stayed, the update returned
E_GS_OUT_OF_LOCAL_STORAGE and the container was left half new, with "<blob>~" temporaries behind.
Each op now copies its blob to "<blob>~b~" before it changes the blob. A failed op undoes the applied ones,
newest first. Deletes are applied in the same ordered pass, so a failed write also undoes a delete. The
scratch names end in '~', which encode_name never produces and decode_name rejects, so enumeration and the
quota never see them. A backup whose restore failed is kept, and later commits only remove backups they
wrote themselves. A commit drops the temporaries of one that died midway. A blob never leaves its name, so a
process that dies midway leaves each blob old or new, as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A GDK title opens its save provider at boot; QueryApiImpl now serves
XGameSaveImpl (IXGameSaveImpl..3, 33 slots from xgameruntime-docs' layout,
signatures and error codes from the public GDK reference). Saves are files
in LEONIDA_SAVE_DIR\local-user\<container>\<blob> (default
%LOCALAPPDATA%\Leonida\saves), %-encoded: the layout tools/saves.py import
already writes. Updates are buffered and committed by write-then-rename;
container names follow the documented rule; the 16 MB update limit, the
documented E_GS_* codes, async variants through XAsync, and the
XGameSaveFiles folder/quota slots. Assumptions (quota, blob-name length,
nullptr blob list) are marked in the source and docs.
xgameruntime_gamesave_test drives every slot (50 checks). The two tests that
used XGameSaveImpl's id as "a class not served" now use a made-up id.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>