From 8777f2f29915915a6fa39ae0fb8013b6cd48685d Mon Sep 17 00:00:00 2001 From: mtkennerly Date: Sat, 23 Dec 2023 10:07:50 +0800 Subject: [PATCH] #278: Unify some Legendary handling --- src/scan/launchers/heroic.rs | 51 ++++++--------------------------- src/scan/launchers/legendary.rs | 14 ++++----- 2 files changed, 15 insertions(+), 50 deletions(-) diff --git a/src/scan/launchers/heroic.rs b/src/scan/launchers/heroic.rs index 3d62fe4d..fb063aa1 100644 --- a/src/scan/launchers/heroic.rs +++ b/src/scan/launchers/heroic.rs @@ -4,7 +4,10 @@ use crate::prelude::{StrictPath, ENV_DEBUG}; use crate::{ resource::{config::RootsConfig, manifest::Os}, - scan::{launchers::LauncherGame, TitleFinder}, + scan::{ + launchers::{legendary, LauncherGame}, + TitleFinder, + }, }; /// Deserialization of Heroic gog_store/installed.json @@ -33,19 +36,6 @@ struct GogLibrary { games: Vec, } -/// Deserialization of Legendary legendary/installed.json -#[derive(Clone, serde::Deserialize)] -pub struct LegendaryInstalledGame { - /// This is an opaque ID, not the human-readable title. - #[serde(rename = "app_name")] - pub app_name: String, - pub title: String, - platform: String, - install_path: String, -} -#[derive(serde::Deserialize)] -struct LegendaryInstalled(HashMap); - /// Deserialization of Heroic GamesConfig/*.json #[derive(serde::Deserialize, Debug)] struct GamesConfigWrapper(HashMap); @@ -80,12 +70,9 @@ pub fn scan( games } -pub fn get_legendary_installed_games( - root: &RootsConfig, - legendary: Option<&StrictPath>, -) -> Vec { +pub fn get_legendary_installed_games(root: &RootsConfig, legendary: Option<&StrictPath>) -> Vec { log::trace!("detect_legendary_games searching for legendary config..."); - let mut result: Vec = Vec::new(); + let mut out = vec![]; let legendary_paths = match legendary { None => vec![ @@ -97,32 +84,10 @@ pub fn get_legendary_installed_games( }; for legendary_path in legendary_paths { - if legendary_path.is_dir() { - log::trace!( - "detect_legendary_games checking for legendary configuration in {}", - legendary_path.interpret() - ); - - let legendary_installed = legendary_path.joined("installed.json"); - if legendary_installed.is_file() { - // read list of installed games and call find_prefix for result - if let Ok(installed_games) = - serde_json::from_str::(&legendary_installed.read().unwrap_or_default()) - { - for game in installed_games.0.values() { - result.push(game.clone()); - } - } - } else { - log::trace!( - "detect_legendary_games no such file '{:?}', legendary probably not used yet... skipping", - legendary_installed - ); - } - } + out.extend(legendary::get_games(&legendary_path)); } - result + out } fn detect_legendary_games( diff --git a/src/scan/launchers/legendary.rs b/src/scan/launchers/legendary.rs index a9e33a2a..72fe4620 100644 --- a/src/scan/launchers/legendary.rs +++ b/src/scan/launchers/legendary.rs @@ -7,12 +7,12 @@ use crate::{ }; #[derive(Clone, serde::Deserialize)] -struct Game { +pub struct Game { /// This is an opaque ID, not the human-readable title. - app_name: String, - title: String, - platform: String, - install_path: String, + pub app_name: String, + pub title: String, + pub platform: String, + pub install_path: String, } /// installed.json @@ -47,8 +47,8 @@ pub fn scan(root: &RootsConfig, title_finder: &TitleFinder) -> HashMap Vec { - let mut out: Vec = Vec::new(); +pub fn get_games(source: &StrictPath) -> Vec { + let mut out = vec![]; let library = source.joined("installed.json");