95d031fef9
Marks keeps one verdict per exe: on ("This is a game") or off ("This is
not a game"). detect: Launched > marked off (None) > marked on (Marked,
with the library game if any) > InstallDir. Serde writes
{"on": [...], "off": [...]} and still reads the plain array as on;
an exe in both lists is refused, MAX_MARKS counts both.
Also: collapsible-if for clippy, rustfmt, README and FORMATS updated.
Checked: cargo test -p arena-core (183 passed), clippy -D warnings,
fmt --check, check for wasm32-unknown-unknown and aarch64-linux-android.
235 lines
15 KiB
Markdown
235 lines
15 KiB
Markdown
# Formats: what `arena-core` accepts and refuses
|
||
|
||
Every launcher file and value is hostile input. Each parser below either returns a fully validated `Game` (or list
|
||
of paths) or a typed `ParseError`; it never truncates, guesses or panics. Nothing is read from disk here: the app
|
||
reads capped bytes and passes them in.
|
||
|
||
## Caps (`arena_core::limits`)
|
||
|
||
| Constant | Value | Applies to | Error when exceeded |
|
||
| :-- | :-- | :-- | :-- |
|
||
| `MAX_FILE` | 1 MiB (1 048 576 bytes) | whole VDF, ACF or `.item` input | `TooLarge` |
|
||
| `MAX_DEPTH` | 32 | nesting of VDF objects; JSON objects and arrays together | `TooDeep` |
|
||
| `MAX_KEY` | 256 bytes | a VDF key, after unescaping | `TooLong("key")` |
|
||
| `MAX_VALUE` | 4096 bytes | any VDF string, after unescaping | `TooLong("value")` |
|
||
| `MAX_ESCAPES` | 256 | escape sequences in one VDF string | `TooMany("escapes")` |
|
||
| `MAX_ENTRIES` | 65 536 | key/value pairs in one VDF document, all levels | `TooMany("entries")` |
|
||
| `MAX_LIBRARIES` | 64 | Steam library folders | `TooMany("libraries")` |
|
||
| `MAX_PATH` | 260 UTF-16 units | every `WinPath` | `BadPath(field)` |
|
||
| `MAX_TITLE` | 256 characters | every title, after trimming | `TooLong(field)` |
|
||
| `MAX_GAME_ID` | 96 bytes | `GameId` | `BadId` |
|
||
| `MAX_EPIC_APP` | 64 bytes | Epic `AppName` | `BadId` |
|
||
| `MAX_DOMI_ID` | 32 bytes | Domi / Atrium id | `BadId` |
|
||
| `MAX_GOG_ID` | 20 digits | GOG `gameID` | `BadId` |
|
||
| `MAX_ARGS_LINE` | 4096 bytes | GOG `launchParam` | `TooLong("launch_params")` |
|
||
| `MAX_ARGS` | 32 | arguments of an exe launch | `TooMany("args")` |
|
||
| `MAX_ARG` | 1024 bytes | one argument | `TooLong("arg")` |
|
||
| `MAX_URL` | 2048 bytes | a web-game URL | `TooLong("url")` |
|
||
| `MAX_HOST` | 253 bytes | the URL's host | `BadValue("url")` |
|
||
| `MAX_GAMES` | 100 000 | games one `merge` call considers | the rest are dropped |
|
||
| `MAX_FRAMES` | 1 048 576 | frametimes one `frames::stats` call takes | `None` |
|
||
| `MAX_MARKS` | 4096 | exes marked on or off, together (`detect::Marks`) | `TooMany("marks")` |
|
||
| `MAX_HOTKEY` | 64 bytes | shortcut text for `hotkey::parse` | `HotkeyError::TooLong` |
|
||
|
||
## Errors
|
||
|
||
`ParseError` is `#[non_exhaustive]` and implements `Display` and `std::error::Error`. The `&'static str` names
|
||
the field; an error never carries input text, so it is always safe to log.
|
||
|
||
| Variant | Meaning |
|
||
| :-- | :-- |
|
||
| `TooLarge` | input over `MAX_FILE` |
|
||
| `TooDeep` | nesting over `MAX_DEPTH` |
|
||
| `NotUtf8` | the input (VDF: as a whole; JSON: as a whole) is not valid UTF-8 |
|
||
| `Syntax { at }` | malformed at byte offset `at` of the input (BOM included) |
|
||
| `Missing(field)` | a required field is absent (or a title is blank) |
|
||
| `WrongType(field)` | an object where a string belongs, a number for a string, a non-object `.item`, ... |
|
||
| `BadPath(field)` | not a valid `WinPath`, or a path that leaves where it must stay |
|
||
| `BadId` | Steam app id, Epic app name, GOG id, Domi id or `GameId` malformed or out of range |
|
||
| `Duplicate(field)` | a key or entry appears twice (`"key"` for VDF keys, the field name for JSON) |
|
||
| `TooLong(field)` / `TooMany(field)` | over a cap above |
|
||
| `BadValue(field)` | control or bidi-override characters in a title, a bad URL, a bad argument |
|
||
| `NotAGame(why)` | a valid file for something that is not a game: callers skip it quietly |
|
||
|
||
## Shared rules
|
||
|
||
**Titles** (Steam `name`, Epic `DisplayName`, GOG `gameName`, manual title, Domi name): trimmed; blank is
|
||
`Missing`; over 256 characters is `TooLong`; any control character (C0, DEL, C1) or bidi override (U+202A–202E,
|
||
U+2066–2069, U+200E, U+200F, U+061C) is `BadValue`.
|
||
|
||
**`WinPath`**: must start `X:\` or `X:/` with an ASCII drive letter. Refused: UNC (`\\server\share`), `\\?\`,
|
||
`\\.\`, `\??\`, drive-relative `C:x`, rooted `\x`, components `.` and `..`, components ending in `.` or space,
|
||
control characters, `< > : " | ? *` (a `:` only after the drive letter, so no alternate data streams), device names
|
||
as the stem of any component (`CON PRN AUX NUL CONIN$ CONOUT$ COM0-9 COM¹²³ LPT0-9 LPT¹²³`, any case, any
|
||
extension, trailing spaces ignored), more than 260 UTF-16 units. Normalised: `/` to `\`, repeated separators
|
||
collapsed, drive letter uppercase, trailing separator dropped (`C:\` stays). `join` takes a relative path under the
|
||
same rules (so it cannot climb out); `starts_with` compares component-wise ignoring case.
|
||
|
||
**`GameId`**: `<source>:<native>` with the source one of `steam epic gog manual domi`, at most 96 bytes. Native
|
||
part: Steam a canonical non-zero `u32` (no sign, no leading zero); Epic `[a-z0-9_-]{1,64}` (the app name lowercased,
|
||
so two Epic apps differing only in case share an id and dedupe); GOG 1–20 digits; Manual exactly 16 lowercase hex
|
||
digits (FNV-1a 64 of the exe path, case-folded); Domi the Atrium id rule.
|
||
|
||
**Atrium id** (Domi ids and `domi-<app>://` links): `[a-z0-9-]{1,32}`, not starting or ending with `-`.
|
||
|
||
## VDF / KeyValues text (`arena_core::vdf`)
|
||
|
||
Accepted:
|
||
- one optional UTF-8 BOM at the very start;
|
||
- whitespace: space, tab, CR, LF;
|
||
- `//` comments to the end of the line;
|
||
- `{`, `}` and quoted strings `"..."`;
|
||
- escapes `\\`, `\"`, `\n`, `\t`, `\r`;
|
||
- a raw tab inside a string.
|
||
|
||
Refused (`Syntax { at }` unless noted):
|
||
- input that is not UTF-8 anywhere, comments included (`NotUtf8`);
|
||
- NUL anywhere, raw control characters other than tab inside a string, raw CR or LF inside a string;
|
||
- any other escape (`\x`, `\0`, `\'`, ...), a backslash at end of input;
|
||
- unterminated strings (reported at the opening quote) and unclosed objects (reported at end of input);
|
||
- unquoted tokens, `#include`, `#base`, `[$CONDITION]` tags, a single `/`;
|
||
- a `{` or `}` where a key belongs, a `}` where a value belongs, a key with no value;
|
||
- an empty key (`Missing("key")`), a key repeated in the same object, ignoring ASCII case (`Duplicate("key")`);
|
||
- anything over `MAX_FILE`, `MAX_DEPTH`, `MAX_KEY`, `MAX_VALUE`, `MAX_ESCAPES`, `MAX_ENTRIES`.
|
||
|
||
`vdf::write` emits Valve's layout (tabs, `"key"\t\t"value"`, `{` / `}` on their own lines) and escapes `\`, `"`,
|
||
LF and CR. `Obj::insert` applies the same caps and character rules as the parser, so any `Obj` built in code writes
|
||
and parses back to itself (property-tested), provided the written text stays under `MAX_FILE`.
|
||
|
||
## Steam `libraryfolders.vdf` (`steam::library_folders`)
|
||
|
||
Accepted: a root key `libraryfolders` (any case) holding an object. Under it, every key made only of digits is a
|
||
library: either the current layout `"0" { "path" "C:\\..." ... }` or the old one `"1" "D:\\SteamLibrary"`. Other
|
||
keys (`contentstatsid`, `TimeNextStatsReport`, ...) and every other field of a library (`label`, `apps`, ...) are
|
||
ignored, though they must still parse within the caps.
|
||
|
||
Refused: no root (`Missing("libraryfolders")`), a string root (`WrongType("libraryfolders")`), a library object
|
||
without `path` (`Missing("path")`) or with an object `path` (`WrongType("path")`), a path that is not a `WinPath`
|
||
(`BadPath("path")`), the same folder twice ignoring case and trailing separators (`Duplicate("path")`), more than
|
||
64 libraries (`TooMany("libraries")`).
|
||
|
||
## Steam `appmanifest_<id>.acf` (`steam::app_manifest`)
|
||
|
||
Reads `AppState` → `appid`, `name`, `installdir` (all required strings). Everything else is ignored.
|
||
|
||
- `appid`: canonical non-zero `u32`; else `BadId` (so `0`, `01`, `+5`, `-1`, ` 5`, `1e3`, `4294967296` and longer
|
||
are refused).
|
||
- `name`: the title rules.
|
||
- `installdir`: one plain folder name (no `\` or `/`, not `.` or `..`, no device name, ...); the install folder is
|
||
`<library>\steamapps\common\<installdir>` and must still be a valid `WinPath`; else `BadPath("installdir")`.
|
||
- Steam's redistributables and runtimes (`steam::is_tool`: 228980, 1070560, 1391110, 1628350, 1493710, 1826330,
|
||
1161040) give `NotAGame`.
|
||
|
||
Result: `steam:<id>`, launch `steam://rungameid/<id>`, cover `SteamLibraryCache { app_id }`.
|
||
|
||
`steam::app_id_from_manifest_name` accepts exactly `appmanifest_<canonical id>.acf` (lowercase), for filtering a
|
||
folder listing before reading anything.
|
||
|
||
## Epic `.item` (`epic::item`)
|
||
|
||
The input must be UTF-8 (one BOM allowed), at most 1 MiB and at most 32 levels of objects and arrays (checked
|
||
before parsing; brackets inside strings do not count), a single JSON object with nothing after it.
|
||
|
||
Reads `AppName`, `DisplayName`, `InstallLocation` (required strings) and `MainGameAppName` (optional string).
|
||
Unknown fields are ignored but must be valid JSON. Refused: `null` or any non-string for those fields
|
||
(`WrongType(field)`), a missing one (`Missing(field)`), any of them twice (`Duplicate(field)`), a document that is
|
||
not an object (`WrongType("item")`), syntax errors including trailing data and out-of-range numbers in read fields
|
||
(`Syntax { at }`).
|
||
|
||
- `AppName`: `[A-Za-z0-9_-]{1,64}`; else `BadId`. It is the only field that reaches the launch URI.
|
||
- `DisplayName`: the title rules (error field `DisplayName`).
|
||
- `InstallLocation`: a `WinPath`; else `BadPath("InstallLocation")`.
|
||
- `MainGameAppName` present and different from `AppName`: an add-on, `NotAGame`.
|
||
|
||
Result: `epic:<appname lowercased>`, launch `com.epicgames.launcher://apps/<AppName>?action=launch&silent=true`,
|
||
a lettered cover. `bIsIncompleteInstall` is not read: the Epic launcher handles a half-installed game itself.
|
||
|
||
## GOG (`gog::game`)
|
||
|
||
Values the app reads from the registry (assumption, verify on the PC: `HKLM\SOFTWARE\WOW6432Node\GOG.com\Games\
|
||
<gameID>` and the HKCU twin), passed in as `GogEntry`.
|
||
|
||
- `game_id`: 1–20 ASCII digits; else `BadId`.
|
||
- `name`: the title rules (error field `name`).
|
||
- `path`: a `WinPath`; else `BadPath("path")`. It becomes the install folder.
|
||
- `exe`: absolute, or relative to `path`; must lie strictly inside `path` (component-wise, ignoring case) and end in
|
||
`.exe` (ignoring case), so never a `.bat`, `.cmd` or `.lnk`; else `BadPath("exe")`.
|
||
- `working_dir`: absent or blank means the exe's folder; otherwise absolute or relative to `path`; else
|
||
`BadPath("working_dir")`.
|
||
- `launch_params`: at most 4096 bytes (`TooLong("launch_params")`), no control characters (tabs included) and no
|
||
unclosed `"` (`BadValue("launch_params")`). Split on spaces; `"` groups and is removed; nothing else (no
|
||
backslash escapes, no variables) is special. Then at most 32 arguments of at most 1024 bytes each.
|
||
|
||
Result: `gog:<gameID>`, `Launch::Exe` (started directly, never through a shell), a lettered cover.
|
||
|
||
## Manual (`manual::game`)
|
||
|
||
`exe` must be a `WinPath` ending in `.exe` (ignoring case) with a name before the extension; else `BadPath("exe")`.
|
||
The title is the given one, or the file name without `.exe`; title rules with error field `title`. Install and
|
||
working folder: the exe's folder; no arguments. Id: `manual:<FNV-1a 64 of the case-folded path, 16 hex>`, so the
|
||
same file added twice (any case, `/` or `\`) is the same game.
|
||
|
||
## Domi (`domi::game`)
|
||
|
||
`id` and a `DomiLaunch::Link { app }` follow the Atrium id rule; else `BadId`. `name` follows the title rules
|
||
(error field `name`). No install folder.
|
||
|
||
`DomiLaunch::Web { url, allowed_hosts }`: `https://` (scheme any case) + host + optional path, query and fragment.
|
||
The host is lowercased and must be a DNS name (labels `[a-z0-9-]{1,63}`, no `-` at either end, no empty label, at
|
||
most 253 bytes) equal, ignoring case, to one of `allowed_hosts`; subdomains are not implied. Refused: other schemes,
|
||
user info (`@`), ports, IP-literal brackets, spaces, `"`, `\`, `<`, `>`, `^`, `` ` ``, `{`, `|`, `}`, any non-ASCII
|
||
byte (percent-encode it), `%` not followed by two hex digits, more than 2048 bytes. Errors: `BadValue("url")` or
|
||
`TooLong("url")`.
|
||
|
||
## Launch strings
|
||
|
||
`Launch::uri` rebuilds the URI from the variant's fields and re-validates them every time, so a hand-built or
|
||
tampered value yields `None`:
|
||
|
||
| Variant | URI | Field rule |
|
||
| :-- | :-- | :-- |
|
||
| `SteamRunGameId(id)` | `steam://rungameid/<id>` | `id != 0` |
|
||
| `Epic { app_name }` | `com.epicgames.launcher://apps/<app_name>?action=launch&silent=true` | `[A-Za-z0-9_-]{1,64}` |
|
||
| `DomiLink { app }` | `domi-<app>://open` | Atrium id |
|
||
| `Url(url)` | the URL itself | the URL rules, already normalised; `uri_checked(hosts)` also checks the host |
|
||
| `Exe { .. }` | none | `.exe` only; arguments checked as above |
|
||
|
||
Deserialising a `Launch`, `Game` or `Library` runs the same checks; a stored URL's host cannot be checked without
|
||
the allow-list, so launching a stored web game goes through `uri_checked`.
|
||
|
||
## Dedupe (`merge`)
|
||
|
||
1. Scans are concatenated in order (at most `MAX_GAMES`); a `GameId` seen before is dropped (first wins).
|
||
2. For each install folder (compared ignoring case), only the games of the highest-priority source stay:
|
||
Steam > Epic > GOG > Domi > Manual. Games of the same source are never dropped for sharing a folder; games
|
||
without an install folder are never dropped here.
|
||
3. The result is sorted by title (lowercased, by code point), then by id, so it does not depend on scan order.
|
||
|
||
## Overlay: frametimes, detection, shortcut
|
||
|
||
**`frames::stats(&[f32])`** (milliseconds, presentation order) → `FrameStats { avg_fps, low_1, low_0_1, stutters,
|
||
frames, seconds }`. `avg_fps = frames / seconds`; the lows are `1000 / frametime` at the nearest-rank 99th and
|
||
99.9th percentile (rank `ceil(p × n)`), each capped so `low_0_1 <= low_1 <= avg_fps`; a stutter is a frame
|
||
`>= 2.5 ×` the median of the 60 frames before it (mean of the 30th and 31st smallest) **and** `>= 25 ms`; the first
|
||
60 frames are never stutters. `None` for an empty series, over `MAX_FRAMES`, any NaN, infinite or negative value,
|
||
or no time at all (zeros alone).
|
||
|
||
**`detect::detect(exe, launched_by_arena, library, marks)`**, first match wins: `Launched` (Arena started it,
|
||
whatever the marks; the game if the library owns the exe); `None` when the exe is marked **off** ("This is not a
|
||
game"); `Marked` when it is marked **on** ("This is a game"; the game if the library owns the exe); `InstallDir`
|
||
(the game's own launch exe, else the deepest `install_dir` strictly containing the exe; drive roots never count as
|
||
a containing folder). Otherwise `None`: an exe outside every install folder is never auto-detected. Comparison is
|
||
component-wise and ignores case; `WinPath` already refuses `..`, `.`, UNC and `\\?\`. Marks are per exe, never
|
||
per folder, and an exe is in at most one set.
|
||
|
||
`Marks` serialises as `{"on": [paths], "off": [paths]}`, each sorted by the case-folded path. Loading also takes a
|
||
plain array of paths as `on` (the first 0.2.0 form), treats a missing list as empty, refuses unknown keys, re-checks
|
||
each path, folds spellings of one exe, and refuses an exe in both lists (`Duplicate("marks")`) or more than
|
||
`MAX_MARKS` in all (`TooMany("marks")`).
|
||
|
||
**`hotkey::parse(&str)`**: `Mod+...+Key`, spaces around parts ignored, names ignore case. Modifiers `Ctrl Alt Shift
|
||
Win` (each once); key `A`–`Z`, `0`–`9`, `F1`–`F24`, last. Errors: `Empty`, `TooLong`, `Malformed` (empty part),
|
||
`UnknownModifier`, `DuplicateModifier`, `MissingKey`, `UnknownKey`, `NoModifier` (a letter or digit without Ctrl,
|
||
Alt or Win), `Reserved` (`Ctrl+Alt+Del`, `Ctrl+Shift+Esc`, `Win+L`, `Alt+F4`, any `F12`). `Display` is canonical
|
||
(`Ctrl+Alt+Shift+Win+<KEY>`); serde uses that text.
|