1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Game {
    pub _type: String,
    pub id: String,
    pub name: String,
    pub path: String,
    pub commands: GameCommands,
    pub state: GameState,
}

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct GameCommands {
    pub install: Option<Vec<String>>,
    pub launch: Vec<String>,
    pub uninstall: Option<Vec<String>>,
}

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct GameState {
    pub installed: bool,
    pub needs_update: bool,
    pub downloading: bool,
    pub total_bytes: Option<i32>,
    pub received_bytes: Option<i32>,
}

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum GameType {
    AmazonGames,
    Blizzard,
    EpicGames,
    GOG,
    Origin,
    RiotGames,
    Steam,
    Ubisoft,
}

impl GameType {
    pub fn to_string(&self) -> String {
        match self {
            Self::AmazonGames => "amazongames",
            Self::Blizzard => "blizzard",
            Self::EpicGames => "epicgames",
            Self::GOG => "gog",
            Self::Origin => "origin",
            Self::RiotGames => "riotgames",
            Self::Steam => "steam",
            Self::Ubisoft => "ubisoft",
        }
        .to_string()
    }
}

impl From<String> for GameType {
    fn from(value: String) -> Self {
        match value.as_str() {
            "amazongames" => Self::AmazonGames,
            "blizzard" => Self::Blizzard,
            "epicgames" => Self::EpicGames,
            "gog" => Self::GOG,
            "origin" => Self::Origin,
            "riotgames" => Self::RiotGames,
            "steam" => Self::Steam,
            "ubisoft" => Self::Ubisoft,
            _ => panic!("invalid game type"),
        }
    }
}