Skip to content

Commit

Permalink
Support '--infer steam' for wrap command
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Dec 29, 2023
1 parent 2b3c23d commit 412ce72
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

* Added:
* CLI: The `wrap` command now supports `--infer steam`,
which will check for the `STEAMAPPID` environment variable.

## v0.22.0 (2023-12-26)

* Added:
Expand Down
10 changes: 6 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
layout::BackupLayout, prepare_backup_target, scan_game_for_backup, BackupId, DuplicateDetector, Launchers,
OperationStepDecision, SteamShortcuts, TitleFinder,
},
wrap::{heroic::infer_game_from_heroic, WrapGameInfo},
wrap::{heroic::infer_game_from_heroic, infer_game_from_steam, WrapGameInfo},
};

#[derive(Clone, Debug, Default)]
Expand Down Expand Up @@ -792,6 +792,10 @@ pub fn run(sub: Subcommand, no_manifest_update: bool, try_manifest_update: bool)
gui,
commands,
} => {
let manifest = load_manifest(&config, &mut cache, no_manifest_update, try_manifest_update)?;
let layout = BackupLayout::new(config.restore.path.clone(), config.backup.retention.clone());
let title_finder = TitleFinder::new(&manifest, &layout);

// Determine raw game identifiers
let wrap_game_info = if let Some(name) = name_source.name.as_ref() {
Some(WrapGameInfo {
Expand All @@ -802,6 +806,7 @@ pub fn run(sub: Subcommand, no_manifest_update: bool, try_manifest_update: bool)
let roots = config.expanded_roots();
match infer {
parse::LauncherTypes::Heroic => infer_game_from_heroic(&roots, &commands),
parse::LauncherTypes::Steam => infer_game_from_steam(&title_finder),
}
} else {
unreachable!();
Expand All @@ -812,9 +817,6 @@ pub fn run(sub: Subcommand, no_manifest_update: bool, try_manifest_update: bool)
//
// e.g. "Slain: Back From Hell" from legendary to "Slain: Back from
// Hell" as known to ludusavi
let manifest = load_manifest(&config, &mut cache, no_manifest_update, try_manifest_update)?;
let layout = BackupLayout::new(config.restore.path.clone(), config.backup.retention.clone());
let title_finder = TitleFinder::new(&manifest, &layout);
let game_name = wrap_game_info.as_ref().and_then(|wrap_game_info| {
title_finder.maybe_find_one(wrap_game_info.name.as_ref(), None, wrap_game_info.gog_id, true)
});
Expand Down
1 change: 1 addition & 0 deletions src/cli/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl From<CliSort> for Sort {
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum LauncherTypes {
Heroic,
Steam,
}

#[derive(clap::Subcommand, Clone, Debug, PartialEq, Eq)]
Expand Down
19 changes: 19 additions & 0 deletions src/wrap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::scan::TitleFinder;

pub mod heroic;

/// Returned game information with whatever we could find
Expand All @@ -12,3 +14,20 @@ impl WrapGameInfo {
self.name.is_none() && self.gog_id.is_none()
}
}

pub fn infer_game_from_steam(title_finder: &TitleFinder) -> Option<WrapGameInfo> {
let app_id = std::env::var("STEAMAPPID").ok()?.parse::<u32>().ok()?;

log::debug!("Found Steam environment variable: STEAMAPPID={}", app_id,);

let result = WrapGameInfo {
name: title_finder.find_one(&[], &Some(app_id), &None, false),
gog_id: None,
};

if result.is_empty() {
None
} else {
Some(result)
}
}

0 comments on commit 412ce72

Please sign in to comment.