[core] Parsers: strict VDF, Steam, Epic, GOG, manual and Domi sources, WinPath, GameId, Launch URIs, merge
This commit is contained in:
@@ -6,3 +6,68 @@ frametime statistics and replay-ring logic. No I/O: inputs are bytes or values,
|
||||
Windows, Android and WebAssembly.
|
||||
|
||||
Licence: MPL-2.0 (see LICENSE).
|
||||
|
||||
## Crates
|
||||
|
||||
| Crate | Lib | What it holds |
|
||||
| :-- | :-- | :-- |
|
||||
| `crates/arena-core` | `arena_core` | launcher parsers, `WinPath`, `GameId`, `Launch`, the `Game` / `Library` model, `merge` |
|
||||
|
||||
## `arena-core` in one screen
|
||||
|
||||
Pure: no `std::fs`, `std::process`, network, environment, registry or clock. The window app reads the files and
|
||||
registry values (capped) and hands the bytes or values in. Every parser treats its input as hostile: caps on size,
|
||||
depth, lengths and counts, typed errors, no panics, `#![forbid(unsafe_code)]`.
|
||||
|
||||
```rust
|
||||
use arena_core::{merge, steam, epic, gog, manual, domi, DomiLaunch, WinPath, Launch};
|
||||
|
||||
// Steam: the library folders, then one manifest per installed app.
|
||||
let libraries: Vec<WinPath> = steam::library_folders(&vdf_bytes)?;
|
||||
let game = steam::app_manifest(&acf_bytes, &libraries[0])?; // Err(NotAGame) for redistributables
|
||||
let id = steam::app_id_from_manifest_name("appmanifest_10.acf"); // Some(10): filter a folder listing
|
||||
|
||||
// Epic: one `.item` JSON manifest per app.
|
||||
let game = epic::item(&item_bytes)?; // Err(NotAGame) for add-ons
|
||||
|
||||
// GOG: registry values the app read.
|
||||
let game = gog::game(&gog::GogEntry { game_id, name, path, exe, working_dir, launch_params })?;
|
||||
|
||||
// A game the user picked, and a Domi game from the Atrium registry.
|
||||
let game = manual::game(r"D:\Games\Old\old.exe", None)?;
|
||||
let game = domi::game("lapilli", "Lapilli", DomiLaunch::Link { app: "lapilli" })?;
|
||||
let game = domi::game("rosea", "Rosea", DomiLaunch::Web { url, allowed_hosts: &["rosea.example.org"] })?;
|
||||
|
||||
// One library: the same id once, the same install folder kept for the best source
|
||||
// (Steam > Epic > GOG > Domi > Manual), ordered by title.
|
||||
let library = merge(vec![steam_games, epic_games, gog_games, domi_games, manual_games]);
|
||||
|
||||
// Launching: a URI for the protocol variants, built only from validated fields.
|
||||
match &game.launch {
|
||||
Launch::Exe { exe, working_dir, args } => { /* Command::new(exe).current_dir(working_dir).args(args) */ }
|
||||
Launch::Url(_) => { let uri = game.launch.uri_checked(&allowed_hosts); }
|
||||
other => { let uri = other.uri(); } // steam://, com.epicgames.launcher://, domi-<app>://
|
||||
}
|
||||
```
|
||||
|
||||
| Type | Rule |
|
||||
| :-- | :-- |
|
||||
| `GameId` | `<source>:<native>`, `[a-z0-9:._-]`, at most 96 bytes, checked per source; `Display` + strict `FromStr` |
|
||||
| `WinPath` | absolute with a drive letter; no UNC, `\\?\`, `..`, NUL, device names; at most 260 UTF-16 units |
|
||||
| `Launch` | `SteamRunGameId(u32)`, `Epic { app_name }`, `Exe { exe, working_dir, args }`, `DomiLink { app }`, `Url` |
|
||||
| `Game` | `{ id, source, title, install_dir, launch, cover }`; serde round trip validates every field |
|
||||
| `ParseError` | typed, `Display`, never carries input text |
|
||||
|
||||
`Game`, `Library`, `GameId`, `WinPath` and `Launch` serialise with serde, and deserialising runs the same checks
|
||||
as the parsers, so a tampered `library.json` cannot smuggle in a bad path or launch string.
|
||||
|
||||
Docs: [`docs/FORMATS.md`](docs/FORMATS.md) (what each parser accepts and refuses, every cap) and
|
||||
[`docs/PORTABILITY.md`](docs/PORTABILITY.md) (the target checks).
|
||||
|
||||
## Commands
|
||||
|
||||
```
|
||||
cargo test # unit, hostile, property, launch and dedupe tests
|
||||
cargo clippy --all-targets -- -D warnings
|
||||
cargo fmt --check
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user