1use log::error;
2
3#[cfg(feature = "epic_games")]
4pub mod epic_games;
5#[cfg(feature = "ms_store")]
6pub mod ms_store;
7#[cfg(feature = "steam")]
8pub mod steam;
9
10#[non_exhaustive]
11#[derive(Debug)]
12pub enum InstalledGame {
13 #[cfg(feature = "steam")]
14 Steam(Box<steam::AppState>),
15 #[cfg(feature = "epic_games")]
16 EpicGames(Box<epic_games::Manifest>),
17 #[cfg(feature = "ms_store")]
18 MicrosoftStore(Box<ms_store::GamePackage>),
19}
20
21impl InstalledGame {
22 pub fn store_name(&self) -> &str {
23 match self {
24 #[cfg(feature = "steam")]
25 InstalledGame::Steam(_) => "Steam",
26 #[cfg(feature = "epic_games")]
27 InstalledGame::EpicGames(_) => "Epic Games",
28 #[cfg(feature = "ms_store")]
29 InstalledGame::MicrosoftStore(_) => "Microsoft Store",
30 }
31 }
32}
33
34pub fn find_all_games() -> Vec<InstalledGame> {
35 let mut games = vec![];
36 #[cfg(feature = "ms_store")]
37 {
38 match ms_store::get_game_packages() {
39 Ok(packages) => {
40 games.extend(
41 packages
42 .into_iter()
43 .map(|p| InstalledGame::MicrosoftStore(Box::new(p))),
44 );
45 }
46 Err(e) => {
47 error!("Failed to read Microsoft Store packages: {e}");
48 }
49 }
50 }
51
52 #[cfg(feature = "steam")]
53 {
54 match steam::get_all_apps() {
55 Ok(apps) => {
56 games.extend(apps.into_iter().map(|a| InstalledGame::Steam(Box::new(a))));
57 }
58 Err(e) => {
59 error!("Failed to read Steam apps: {e}");
60 }
61 }
62 }
63
64 #[cfg(feature = "epic_games")]
65 {
66 match epic_games::get_all_manifests() {
67 Ok(manifests) => {
68 games.extend(
69 manifests
70 .into_iter()
71 .map(|m| InstalledGame::EpicGames(Box::new(m))),
72 );
73 }
74 Err(e) => {
75 error!("Failed to read Epic Games manifests: {e}");
76 }
77 }
78 }
79
80 games
81}