Skip to main content

game_scanner/
prelude.rs

1use serde::{Deserialize, Serialize};
2use std::path::PathBuf;
3
4#[derive(Clone, Debug, Default, Deserialize, Serialize)]
5pub struct Game {
6    pub _type: String,
7    pub id: String,
8    pub name: String,
9    pub path: Option<PathBuf>,
10    pub commands: GameCommands,
11    pub state: GameState,
12}
13
14#[derive(Clone, Debug, Default, Deserialize, Serialize)]
15pub struct GameCommands {
16    pub install: Option<Vec<String>>,
17    pub launch: Option<Vec<String>>,
18    pub uninstall: Option<Vec<String>>,
19}
20
21#[derive(Clone, Debug, Default, Deserialize, Serialize)]
22pub struct GameState {
23    pub installed: bool,
24    pub needs_update: bool,
25    pub downloading: bool,
26    pub total_bytes: Option<u64>,
27    pub received_bytes: Option<u64>,
28}
29
30#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
31pub enum GameType {
32    AmazonGames,
33    Blizzard,
34    EpicGames,
35    GOG,
36    Origin,
37    RiotGames,
38    Steam,
39    Ubisoft,
40}
41
42impl GameType {
43    pub fn to_string(&self) -> String {
44        match self {
45            Self::AmazonGames => "amazongames",
46            Self::Blizzard => "blizzard",
47            Self::EpicGames => "epicgames",
48            Self::GOG => "gog",
49            Self::Origin => "origin",
50            Self::RiotGames => "riotgames",
51            Self::Steam => "steam",
52            Self::Ubisoft => "ubisoft",
53        }
54        .to_string()
55    }
56}
57
58impl From<String> for GameType {
59    fn from(value: String) -> Self {
60        match value.as_str() {
61            "amazongames" => Self::AmazonGames,
62            "blizzard" => Self::Blizzard,
63            "epicgames" => Self::EpicGames,
64            "gog" => Self::GOG,
65            "origin" => Self::Origin,
66            "riotgames" => Self::RiotGames,
67            "steam" => Self::Steam,
68            "ubisoft" => Self::Ubisoft,
69            _ => panic!("invalid game type"),
70        }
71    }
72}