diff --git a/src/scan/launchers/heroic/gog.rs b/src/scan/launchers/heroic/gog.rs index be3c58e..06e0a3f 100644 --- a/src/scan/launchers/heroic/gog.rs +++ b/src/scan/launchers/heroic/gog.rs @@ -11,32 +11,39 @@ use crate::{ }, }; -/// `gog_store/installed.json` -#[derive(serde::Deserialize)] -struct Installed { - installed: Vec, -} +pub mod installed { + pub const PATH: &str = "gog_store/installed.json"; -#[derive(serde::Deserialize)] -struct InstalledGame { - /// This is an opaque ID, not the human-readable title. - #[serde(rename = "appName")] - app_name: String, - platform: String, - install_path: String, -} + #[derive(serde::Deserialize)] + pub struct Data { + pub installed: Vec, + } -/// `gog_store/library.json` or `store_cache/gog_library.json` -#[derive(serde::Deserialize)] -struct Library { - games: Vec, + #[derive(serde::Deserialize)] + pub struct Game { + /// This is an opaque ID, not the human-readable title. + #[serde(rename = "appName")] + pub app_name: String, + pub platform: String, + pub install_path: String, + } } -#[derive(serde::Deserialize)] -pub struct LibraryGame { - /// This is an opaque ID, not the human-readable title. - pub app_name: String, - pub title: String, +pub mod library { + pub const PATH: &str = "store_cache/gog_library.json"; + pub const PATH_LEGACY: &str = "gog_store/library.json"; + + #[derive(serde::Deserialize)] + pub struct Data { + pub games: Vec, + } + + #[derive(serde::Deserialize)] + pub struct Game { + /// This is an opaque ID, not the human-readable title. + pub app_name: String, + pub title: String, + } } pub fn scan(root: &RootsConfig, title_finder: &TitleFinder) -> HashMap { @@ -52,10 +59,10 @@ pub fn scan(root: &RootsConfig, title_finder: &TitleFinder) -> HashMap(&content.unwrap_or_default()) { + match serde_json::from_str::(&content.unwrap_or_default()) { Ok(installed_games) => { for game in installed_games.installed { let Some(game_title) = game_titles.get(&game.app_name) else { @@ -106,11 +113,8 @@ pub fn scan(root: &RootsConfig, title_finder: &TitleFinder) -> HashMap Vec { - let libraries = [ - root.path.joined("store_cache").joined("gog_library.json"), - root.path.joined("gog_store").joined("library.json"), - ]; +pub fn get_library(root: &RootsConfig) -> Vec { + let libraries = [root.path.joined(library::PATH), root.path.joined(library::PATH_LEGACY)]; let library_path = 'outer: { for library in libraries { @@ -122,7 +126,7 @@ pub fn get_library(root: &RootsConfig) -> Vec { return vec![]; }; - match serde_json::from_str::(&library_path.read().unwrap_or_default()) { + match serde_json::from_str::(&library_path.read().unwrap_or_default()) { Ok(gog_library) => { log::trace!("Found {} games in {:?}", gog_library.games.len(), &library_path); diff --git a/src/scan/launchers/heroic/legendary.rs b/src/scan/launchers/heroic/legendary.rs index 4c560fc..05c2649 100644 --- a/src/scan/launchers/heroic/legendary.rs +++ b/src/scan/launchers/heroic/legendary.rs @@ -50,7 +50,7 @@ pub fn scan( games } -pub fn get_installed(root: &RootsConfig, legendary: Option<&StrictPath>) -> Vec { +pub fn get_installed(root: &RootsConfig, legendary: Option<&StrictPath>) -> Vec { let mut out = vec![]; let legendary_paths = match legendary { diff --git a/src/scan/launchers/legendary.rs b/src/scan/launchers/legendary.rs index 75a05ae..7a90cb0 100644 --- a/src/scan/launchers/legendary.rs +++ b/src/scan/launchers/legendary.rs @@ -6,18 +6,23 @@ use crate::{ scan::{launchers::LauncherGame, TitleFinder}, }; -#[derive(Clone, serde::Deserialize)] -pub struct Game { - /// This is an opaque ID, not the human-readable title. - pub app_name: String, - pub title: String, - pub platform: String, - pub install_path: String, -} +pub mod installed { + use std::collections::HashMap; + + pub const PATH: &str = "installed.json"; + + #[derive(serde::Deserialize)] + pub struct Data(pub HashMap); -/// `installed.json` -#[derive(serde::Deserialize)] -struct Library(HashMap); + #[derive(Clone, serde::Deserialize)] + pub struct Game { + /// This is an opaque ID, not the human-readable title. + pub app_name: String, + pub title: String, + pub platform: String, + pub install_path: String, + } +} pub fn scan(root: &RootsConfig, title_finder: &TitleFinder) -> HashMap { let mut out = HashMap::new(); @@ -53,10 +58,10 @@ pub fn scan(root: &RootsConfig, title_finder: &TitleFinder) -> HashMap Vec { +pub fn get_games(source: &StrictPath) -> Vec { let mut out = vec![]; - let library = source.joined("installed.json"); + let library = source.joined(installed::PATH); let content = match library.try_read() { Ok(content) => content, @@ -70,7 +75,7 @@ pub fn get_games(source: &StrictPath) -> Vec { } }; - if let Ok(installed_games) = serde_json::from_str::(&content) { + if let Ok(installed_games) = serde_json::from_str::(&content) { out.extend(installed_games.0.into_values()); }