Skip to main content

pacenotes_installer\tree/
cached_package.rs

1/// What the cache holds for one package, as the tree needs to see it.
2#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
3pub struct CachedPackage {
4    pub game: String,
5    pub directory: String,
6    pub name: String,
7    pub sha256: String,
8    pub version: String,
9    pub display_name: Option<String>,
10    /// The rest of the manifest entry, the only record an offline run has; each
11    /// defaults so an index from before they existed still loads.
12    #[serde(default)]
13    pub exclusive_group: Option<String>,
14    #[serde(default)]
15    pub requires: Vec<String>,
16    #[serde(default)]
17    pub size: u64,
18    #[serde(default)]
19    pub updated_at: i64,
20}
21
22impl CachedPackage {
23    /// The snapshot taken when a package enters the cache.
24    pub fn of(package: &pacenotes_shared::PackageInfo) -> CachedPackage {
25        CachedPackage {
26            game: package.game.clone(),
27            directory: package.directory.clone(),
28            name: package.name.clone(),
29            sha256: package.sha256.clone(),
30            version: package.version.clone(),
31            display_name: package.display_name.clone(),
32            exclusive_group: package.exclusive_group.clone(),
33            requires: package.requires.clone(),
34            size: package.size,
35            updated_at: package.updated_at,
36        }
37    }
38
39    /// `game/directory/name`, the same string as `PackageInfo::download_path()`;
40    /// without the game, two games' `public/style/Numeric Standard` would collide.
41    pub fn key(&self) -> String {
42        format!("{}/{}/{}", self.game, self.directory, self.name)
43    }
44}