Skip to main content

pacenotes_shared/
game_schema.rs

1/// A game's schema file on the server, `<data>/<game>/schema.toml`; the
2/// canonical copy is the repository's `schemas/<game>.toml`.
3pub const SCHEMA_FILE: &str = "schema.toml";
4
5/// `SchemaCategory::select`: the user must pick exactly one.
6pub const SELECT_ONE: &str = "one";
7/// `SchemaCategory::select`: optional, installed as ticked.
8pub const SELECT_ANY: &str = "any";
9
10/// `SchemaCategory::install_root`: the folder holding the game's marker executable.
11pub const INSTALL_ROOT_GAME: &str = "game";
12
13/// A game's install schema as the manifest publishes it: which categories its
14/// catalogue has, which ask for one pick, and where each installs.
15///
16/// The installer only compares `sha256` with the schema it was built with and
17/// stops downloading on a mismatch; its behaviour never comes from these
18/// fields, so a server cannot steer where files go. Every field is a plain
19/// `String` so a newer server's values fail an old installer's comparison, never its parse.
20#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)]
21pub struct GameSchema {
22    /// Of the schema file's exact bytes, lowercase hex.
23    pub sha256: String,
24    pub categories: Vec<SchemaCategory>,
25}
26
27/// One `[[category]]` of a game's schema.
28#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)]
29pub struct SchemaCategory {
30    /// The folder under an access directory, as `PackageInfo::category()` reports it.
31    pub id: String,
32    /// `SELECT_ONE` or `SELECT_ANY`.
33    pub select: String,
34    /// A token such as `INSTALL_ROOT_GAME`, never a path.
35    pub install_root: String,
36}
37
38#[cfg(test)]
39mod tests {
40    #[test]
41    fn unknown_schema_values_never_break_parsing() {
42        let future = r#"{"sha256":"cc","categories":[
43            {"id":"x","select":"some-of","install_root":"user-docs"}]}"#;
44        let schema: super::GameSchema = serde_json::from_str(future).unwrap();
45        assert_eq!(schema.categories[0].select, "some-of");
46    }
47}