Skip to content

Commit

Permalink
#278: Unify some Legendary handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Dec 23, 2023
1 parent 91f72a8 commit 8777f2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 50 deletions.
51 changes: 8 additions & 43 deletions src/scan/launchers/heroic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -33,19 +36,6 @@ struct GogLibrary {
games: Vec<GogLibraryGame>,
}

/// 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<String, LegendaryInstalledGame>);

/// Deserialization of Heroic GamesConfig/*.json
#[derive(serde::Deserialize, Debug)]
struct GamesConfigWrapper(HashMap<String, GamesConfig>);
Expand Down Expand Up @@ -80,12 +70,9 @@ pub fn scan(
games
}

pub fn get_legendary_installed_games(
root: &RootsConfig,
legendary: Option<&StrictPath>,
) -> Vec<LegendaryInstalledGame> {
pub fn get_legendary_installed_games(root: &RootsConfig, legendary: Option<&StrictPath>) -> Vec<legendary::Game> {
log::trace!("detect_legendary_games searching for legendary config...");
let mut result: Vec<LegendaryInstalledGame> = Vec::new();
let mut out = vec![];

let legendary_paths = match legendary {
None => vec![
Expand All @@ -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::<LegendaryInstalled>(&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(
Expand Down
14 changes: 7 additions & 7 deletions src/scan/launchers/legendary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,8 +47,8 @@ pub fn scan(root: &RootsConfig, title_finder: &TitleFinder) -> HashMap<String, L
out
}

fn get_games(source: &StrictPath) -> Vec<Game> {
let mut out: Vec<Game> = Vec::new();
pub fn get_games(source: &StrictPath) -> Vec<Game> {
let mut out = vec![];

let library = source.joined("installed.json");

Expand Down

0 comments on commit 8777f2f

Please sign in to comment.