Skip to main content

pacenotes_installer\tree/
node.rs

1/// Where a leaf stands between the server and this computer.
2#[derive(Clone, Copy, PartialEq, Eq, Debug)]
3pub enum LeafState {
4    NotCached,
5    /// Cached at exactly the sha the server lists.
6    Downloaded,
7    /// Cached, but the server lists a different sha.
8    UpdateAvailable,
9    /// Cached and no longer listed: withdrawn, or no longer granted. Still installable.
10    LocalOnly,
11    /// Installed, and in neither the catalogue nor the cache, so nothing can
12    /// reinstall it; shown so the user can keep it, since Apply removes what is unselected.
13    Unavailable,
14}
15
16impl LeafState {
17    /// Whether some payload is on this computer, an outdated one included, so the leaf installs offline.
18    pub fn has_payload(self) -> bool {
19        matches!(
20            self,
21            LeafState::Downloaded | LeafState::UpdateAvailable | LeafState::LocalOnly
22        )
23    }
24
25    /// Not the negation of `has_payload`: an update has old bytes yet still needs the new ones.
26    pub fn needs_download(self) -> bool {
27        matches!(self, LeafState::NotCached | LeafState::UpdateAvailable)
28    }
29}
30
31/// A row's checkbox; a grouping row's is derived from the leaves under it.
32#[derive(Clone, Copy, PartialEq, Eq, Debug)]
33pub enum Check {
34    Unchecked,
35    Checked,
36    Partial,
37}
38
39/// One row. Grouping rows carry no package.
40#[derive(Clone, Debug)]
41pub struct Node {
42    /// Without the state suffix, which the UI adds localized.
43    pub label: String,
44    pub parent: Option<usize>,
45    pub children: Vec<usize>,
46    /// Leaves only: the package's `game/directory/name`.
47    pub key: Option<String>,
48    /// Leaves only: where the package stands against the cache.
49    pub state: Option<LeafState>,
50    /// In this game folder's ledger, which is independent of the per-user cache.
51    pub installed: bool,
52    /// Leaves only; see `Tree::check_of` for grouping rows.
53    pub(super) checked: bool,
54}
55
56impl Node {
57    pub fn is_leaf(&self) -> bool {
58        self.key.is_some()
59    }
60}