Skip to content

Commit

Permalink
#356: Allow lookup by secondary Steam/GOG IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Jun 26, 2024
1 parent be4410e commit dd214a4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
(e.g., `~/.config/lutris/games` and `~/.local/share/lutris/pga.db`).
To fix this, you can now specify a different `pga.db` path explicitly.
In some cases, Ludusavi can prompt you to update the root automatically.
* CLI: The `find` command's `--steam-id` and `--gog-id` options
only considered primary IDs from the manifest.
They will now also consider secondary IDs (e.g., for DLC or different editions).

## v0.24.1 (2024-06-15)

Expand Down
32 changes: 24 additions & 8 deletions src/resource/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,17 +490,33 @@ impl Manifest {
}

pub fn map_steam_ids_to_names(&self) -> HashMap<u32, String> {
self.0
.iter()
.filter_map(|(k, v)| v.steam.id.as_ref().map(|id| (*id, k.to_owned())))
.collect()
let mut out = HashMap::new();

for (k, v) in &self.0 {
if let Some(id) = v.steam.id {
out.insert(id, k.to_string());
}
for id in &v.id.steam_extra {
out.insert(*id, k.to_string());
}
}

out
}

pub fn map_gog_ids_to_names(&self) -> HashMap<u64, String> {
self.0
.iter()
.filter_map(|(k, v)| v.gog.id.as_ref().map(|id| (*id, k.to_owned())))
.collect()
let mut out = HashMap::new();

for (k, v) in &self.0 {
if let Some(id) = v.gog.id {
out.insert(id, k.to_string());
}
for id in &v.id.gog_extra {
out.insert(*id, k.to_string());
}
}

out
}

pub fn map_lutris_ids_to_names(&self) -> HashMap<String, String> {
Expand Down
20 changes: 20 additions & 0 deletions src/scan/title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ mod tests {
by-gog:
gog:
id: 2
by-steam-extra:
id:
steamExtra: [3]
by-gog-extra:
id:
gogExtra: [4]
by-lutris:
id:
lutris: slug
Expand Down Expand Up @@ -360,6 +366,20 @@ mod tests {
..Default::default()
}),
);
assert_eq!(
btree_set!["by-steam-extra".to_string()],
finder.find(TitleQuery {
steam_id: Some(3),
..Default::default()
}),
);
assert_eq!(
btree_set!["by-gog-extra".to_string()],
finder.find(TitleQuery {
gog_id: Some(4),
..Default::default()
}),
);
assert_eq!(
btree_set!["by-lutris".to_string()],
finder.find(TitleQuery {
Expand Down

0 comments on commit dd214a4

Please sign in to comment.