Backups and recovery
This page is for contributors. Players should use Restoring the game.
The baseline records original game files. The journal records changes so they can be undone after a crash.
Stored files
| Path | Contents |
|---|---|
$DATA/baseline/objects/<sha256> | Original file contents |
$DATA/baseline/<build_id>/baseline. | File sizes and hashes for a game build |
$DATA/state/journal/<id>. | Changes to undo; "session": true for a swofty run session |
$DATA/state/placed. | Every file the launcher wrote into the game folder, with its SHA-256 |
$DATA/state/session. | Held by a running session until its game files are rolled back |
$DATA/state/build. | The build a session is running: its process, profile, addons, step (building or copying), files done and total |
$DATA/state/cancel-build | Asks the running build to stop |
$DATA/state/blocked. | Files of unknown origin that stopped the last launch |
$DATA/state/not-stock. | Game files that don't match Steam's copy, which stopped the last launch, with each file's measured path, found size, Steam's size and modified time |
$DATA/state/recovered. | The last recovery, for the launcher to announce |
$DATA/state/setup. | The one-time setup: its version, the player's answer about other mods, when the game folder was put back, when the setup finished, and whether the first-launch notice was shown |
$DATA/baseline-retired/ | The baselines the setup moved aside, until the setup finishes |
$DATA/addon-storage/<id>/ | The files an addon wrote through the storage API under swofty/addons/<id>/, between sessions |
Checking against Steam
Steam keeps a manifest for each installed depot in <steam>/depotcache/<depot>_<manifest>.manifest, listing every file's size and SHA-1. The installed depots and their manifest ids are in the library's appmanifest_3059520.acf. Before a session builds anything, swofty run and swofty apply check the game against them:
- Each original the baseline recorded at first sight (
"source": "first-sight") is compared with Steam's copy. A match becomes"source": "depot"and isn't compared again. A mismatch whose game folder file now matches Steam's, as after a Verify in Steam, is backed up again from the game folder. - Until a check passes for a game build, every file Steam installed is checked by size (
"stock_checked": trueinbaseline.jsononce it has). Filesplaced.jsonrecords as written by the launcher are left to the install. - EA AntiCheat's launcher files (
EAAntiCheat.*in the game root) are logged when they differ from Steam's and never stop a launch. EA rewrites them on a normal start. Modded sessions do not use them. Offline play parks and restoresEAAntiCheat.GameServiceLauncher.exethrough its own journal. - A DLL in Steam's list that is in the game folder but differs from Steam's copy is a third-party file, such as an FSR 4 build of
amd_fidelityfx_dx12.dll(HelixSR), OpenComposite'sopenvr_api.dllor a DLSS swap. It never stops a launch, and the launch log names every such DLL with its size and Steam's in one[stock]line. A DLL in Steam's list that is missing from the game folder stops the launch like any other missing file. Verify integrity of game files in Steam puts Steam's copies back.F1_25.exeandsteam_api64.dllmust still be Steam's; see Copies Swofty plays. - The launcher does not write or restore
amd_fidelityfx_dx12.dll, and no addon or profile can replace it. - A DLL Steam doesn't list, such as a
dxgi.dlldrop-in, is not checked. A drop-in namedversion.dllcannot be used with Swofty: the launcher places its ownversion.dll, and aversion.dllit didn't put there stops the install as described in Leftovers. - When a game repair or update put
EAAntiCheat.GameServiceLauncher.exeback while offline play was staged, rolling back offline play counts it as restored: with no.bakleft (an EA app repair), or with a.bakidentical to the repaired exe, which is removed (a Steam verify). A repaired exe whose certificate names Electronic Arts as the signer is kept, and a.bakthat differs from it is set aside underswofty/offline-recovery/. Any other.bakthat differs from the repaired exe still stops the roll-back. - On an EA app copy, the session checks the exe when F1 25 starts. When an EA app repair replaced offline play's file with EA's, EA's file becomes the
.bakand the journal records its digest, the older.bakis set aside underswofty/offline-recovery/, and offline play's file goes back in place. - A
.bakthat is offline play's file is never put back as the original: the pinned stub, the stub the journal recorded, or a program Electronic Arts didn't sign. The roll-back and the stale-backup clean-up set it aside underswofty/offline-recovery/. When there's no.bakand the exe is offline play's file, the clean-up sets the exe aside too and the log says to repair F1 25 in the EA app or verify it in Steam. - Before the check, a stale
EAAntiCheat.GameServiceLauncher.exe.bakan interrupted session left is cleared: a backup that is Steam's copy is put back over the live exe, and a backup that is not is set aside underswofty/offline-recovery/while a Steam-verified live exe is kept. This step is skipped while a session is pending. - Each original the install backs up for the first time is compared with Steam's copy before it is copied.
Some Steam installs keep their manifests with the file names encrypted (filenames_encrypted in the manifest's metadata). Each file is still listed under the SHA-1 of its lowercased path with \ separators, with its size and content SHA-1, and the checks above find a file by that path hash. A file whose path hash isn't listed counts as Steam's when its size and SHA-1 are those of a file in the manifest. With encrypted names, the size check of every file is skipped, stock_checked stays false, and the launch log says [stock] Steam's manifests have encrypted file names. setup::store_checks counts such a copy as one it can't check.
A file that doesn't match, other than an EA AntiCheat launcher file or a third-party DLL, stops the session before anything is built or changed and writes state/not-stock.json. The launcher opens a Your game files have been edited modal that says how many files changed, names the first six, and lists the fix: Verify game files in Steam (steam://validate/3059520), or add mods through the Simplified Importer. swofty run and swofty apply print the same link. Files Steam doesn't list are not checked. A game folder outside Steam is not checked. Without a readable manifest for every installed depot, the check is skipped and the launch log says why.
The one-time setup
Modded play waits for the setup in swofty_core::setup. The launcher opens it on Play, and swofty setup runs it from the command line.
- The player says whether the game folder holds mods Swofty didn't add.
setup::resettakes the session lock and restores the game folder asswofty restoredoes. It then moves$DATA/baselineto$DATA/baseline-retiredand deletes$DATA/cache/overlay.- When the restore fails on a Steam or EA app copy, the reset continues:
$DATA/state/journalmoves to$DATA/baseline-retired/journal, and a second restore against the empty record removes Swofty's own files. The wizard names the error and says verifying puts the rest back. - When the restore fails on a copy from neither store, the reset stops before anything moves.
- When the restore fails on a Steam or EA app copy, the reset continues:
- The player verifies the game files in Steam or repairs them in the EA app. A player who says no other mods are in the folder skips this on a Steam copy whose depot manifests
setup::store_checkscan read, when the restore put every file back: the install checks each original against those manifests. On a Steam copy, I've verified, continue stays off until the player opens the verify, and while Steam is verifying or updating the game. A running Steam's state comes from itslogs/content_log.txt, since Steam doesn't update theStateFlagsof the app manifest during a verify; the manifest covers the rest. setup::finishrecords the setup as done and deletes$DATA/baseline-retired.
The next install records each original again as it first sees it, checked against Steam's manifests when they can be read. Raising setup::VERSION sends every player through the setup again. A build whose record names an original missing from $DATA/baseline/objects stops with the names of the missing files, deletes $DATA/state/setup.json, and the next Play opens the setup again. swofty run --apply and every install refuse to start until the setup is done. swofty run also refuses to start while Steam is verifying or updating the game.
Recovery rules
Record every change of an install in the journal, in one write, before applying the first. Undo changes in reverse order, including steps that may have been interrupted or never started.
Restore replaced files from backups. Remove files and empty folders created by the launcher. Remove the Wine override added for the session.
A swofty/ folder that holds no files, only empty folders, does not count as left over: a restore that leaves one in place still reports the game folder as restored, and swofty verify passes. A file left under swofty/ is reported by its path, as swofty/<path> is not part of the game.
If a file has unexpected contents, leave it alone and report it. Never restore files from an old game build over a newer one.
Before a rollback undoes a journal, the files in each swofty/addons/<id>/ folder the journal placed files in, other than files placed.json or the journal records, move to $DATA/addon-storage/<id>/. The next install with that addon moves them back, except at a path it places and where the game folder already holds a file. A restore moves those files out of every addon folder before it removes swofty/.
Free space
Before an install backs up or copies anything, it adds up the free space it needs on each volume. On the data folder's, that is the originals it backs up for the first time and 2 KB per file for the journal and the other state files. On the game folder's:
- A file linked straight from the build output needs none.
- The files linked from the link cache (
swofty-cache/overlay, see The game drive copy) need the ones the cache doesn't hold yet, matched by size, modified time and SHA-256 as the cache matches them, plus 2 GB to spare; or, when it is less, what copying them straight into the game folder needs, less the files they replace. Play copies them that way when the cache has too little room. Cached files the profile no longer places are deleted first and count as freed. With an empty cache, every file counts. - With
SWOFTY_INSTALL_COPY=1, or when the launcher can't tell the drives apart, every file counts as copied, less the files they replace.
Both folders on one volume count together. When a volume has less free space than that, the install stops with not enough free space on <drive>: this profile needs about <X> GB, <Y> GB free, in GB of 1024³ bytes, with what that volume needs and has free. A write that fails on a full volume during the install stops it with the same message and what copying every file needs there, and the session rolls back.
Sessions
The swofty run wrapper holds session.lock from before it installs the profile until the offline play staging and the profile are rolled back. It rolls back when the game exits for any reason, on an error, and on a stop signal. A direct swofty run waits for the wrapper to exit and rolls back anything the wrapper left.
While the wrapper builds and installs the profile, it rewrites build.json every 2 seconds and deletes it when the install ends. The build checks for cancel-build before each archive edit, before each archive it writes and between the steps of the build; the install checks before each file it copies. A cancelled build stops with the build was cancelled; the game folder is back as it was, writes no saved build for the profile, and the wrapper rolls back the files it copied. Installing over, updating or removing an addon listed in a live build.json fails with <name> is in the build that is running.
A session journal still open while the lock is free belongs to a session that ended without rolling back. swofty run, swofty apply and the wrapper roll back every open journal before they start. The launcher rolls back session journals when it starts, and keeps a swofty apply install. A build.json left while the lock is free belongs to a build whose process ended; the same rollback deletes it and cancel-build, and logs the last Play stopped while <step>; Play starts the build again. The launcher runs that rollback as soon as it finds one.
Each session journal records the game folder it was written for ("game"). When that folder no longer has F1_25.exe and the rollback runs for another folder, as after Steam moved the library or the game was reinstalled elsewhere, the journal rolls back there only the files that hold exactly what it wrote: a replaced file goes back to its original and an added file is removed. Every other file of the journal is left in place and reported as <file> is not what the earlier session wrote in the old game folder nor its original; left in place; the stock check then names it. The journal closes either way and never stops a launch.
When a file of offline play's journal stays locked, as while F1 25 or the EA app is still open, the roll back names each locked file and the journal stays. The direct swofty run, the next launcher start and the next Play replay it before anything else, and until one finishes the log never says the game files are rolled back: the wrapper says rolled the profile's game files back, but not the offline play files above, and the direct swofty run ends on not every game file is back yet.
Offline play's journal names its game folder on its meta line. When that folder no longer has F1_25.exe, recovery and swofty restore move the journal's paths to the game folder they run for, when that folder holds at least one file the journal staged with the recorded digest and none that differs. Otherwise they stop with offline play's record is for F1 25 in <folder>, which is gone, ... and the journal stays.
Leftovers
A file in the way of an install counts as the launcher's own when placed.json records those exact bytes at that path, or when it is byte-identical to the file about to be placed and not a backed-up original. The install clears those files, logs the recovery and the swofty doctor report, and tries once more. Any other file stops the install untouched and is recorded in blocked.json; swofty restore moves it to $DATA/set-aside/<time>/. A recorded file that replaced a game file and is now Steam's copy, as after a Verify, stays in place instead, and the baseline takes it as the original ("source": "depot"). The launcher opens the Your game files have been edited modal, whose Restore game folder button runs the same restore.
swofty restore stops at once while another process holds session.lock. Restore game folder waits for it:
| What holds the lock | The button |
|---|---|
A Play still building or checking the game files (a live build.) | Waits up to 15 minutes, then says Play is still <step> for profile <name>, started <when>; restore the game folder again when it finishes, or cancel the build in the launcher |
| F1 25, running from that game folder | Stops at once with F1 25 is still running; close F1 25, then restore the game folder again |
| A session starting F1 25 or putting its files back, with F1 25 closed | Waits up to 2 minutes, then says to close any Steam or EA app window that is starting F1 25 and try again |
At start, files that placed.json records and no open journal covers are cleared the same way.
The launcher's menus in a game original
Before the menu build patches the game's menu archives, it reads the original of each of these (the original backed up for the game build, else the game folder's file) for the entries only the launcher's menus add:
| Archive | Entries |
|---|---|
databases. | the tooltips mod_menu, mod_menu_offline and swofty_adjust, ui_menu_data., settings. |
persistent. | the resources swofty_o_row. and swofty_o_career_row. |
flow_persistent. | messages with a swofty_ id |
An original that holds one of them is a menu build's output that an earlier session left in place of the game's file. The build stops with menus: the game's <archive> already holds <entries>, and Play puts a clean original back the way it does for an addon's entry:
- When the recorded original holds the entries and the game folder's file differs, the game folder's file becomes the recorded original.
- Otherwise the newest original of the file backed up for another game build goes back into the game folder.
The build then runs again, and the log starts with stale: <file> in the game folder still held the launcher's changes from an earlier session; .... With no clean original on record, Play stops with the same message, the launcher has no clean copy of it on record, and the repair steps for Steam and the EA app. A check before Play, such as Check conflicts, says that Play puts the backed-up original back.
The menu build writes its tooltips, ui_menu_data.swofty, settings.swofty_addons and the F1 World flow entries swofty_enter_time_trial, swofty_enter_grand_prix and swofty_enter_return in place of the ones the archive it reads already holds. A menu build of databases.erp from its own output writes the same archive.
Damaged state files
State files are written to a temporary file, flushed to disk and renamed over the old one. Backups in baseline/objects and restored originals are flushed before they take their name.
A state file that is not JSON at all (empty, zero-filled or truncated) is moved to <name>.corrupt-<unix time> and never deleted. Valid JSON in a shape the launcher cannot read is left in place and reported as an error.
| File | When damaged |
|---|---|
baseline. | Started over in rebuild mode ("rebuild" in the file) |
| A journal | Skipped; placed. and the baseline clear its leftovers |
placed. | Started over empty; leftovers are reported as files of unknown origin |
A profile or config. | Started over as if missing |
In rebuild mode a game file is recorded as an original only when its bytes are already a backed-up original in baseline/objects. Any other file stops the install untouched with "the launcher's record of your original game files is damaged; verify the game files in Steam, then press Play again". The next install records such files at first sight. A file that placed.json records as written by the launcher is never recorded as an original, and swofty verify reports it until the game files are verified.
swofty doctor lists the set-aside copies.
Commands
swofty restore: restore originals and remove launcher additions.swofty verify: report remaining changes.swofty doctor: report changes and check the rest of the setup.
Tests
packages/core/tests/restore.rs covers profile changes, interrupted changes and game updates using a test folder. packages/core/tests/session_recovery.rs covers crashed and killed sessions, leftovers of lost journals and files copied in by hand. packages/core/tests/damaged_state.rs covers damaged state files.
cargo test -p swofty-core --test restore --test session_recovery --test damaged_state