Skip to content

Commit

Permalink
Add support for storeGameId placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Oct 14, 2024
1 parent 02bba43 commit 14e68b0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
The Linux and Mac downloads are now provided in `.tar.gz` format
to better preserve the files' executable permissions.

* Added:
* Paths may now use the `<storeGameId>` placeholder.
This is supported in Steam, GOG, and Lutris roots.
For Steam roots, this also supports shortcuts to non-Steam games,
where the placeholder will map to the shortcut's dynamic app ID.
* Fixed:
* Files on Windows network shares were not backed up correctly.
For example, a file identified as `\\localhost\share\test.txt`
Expand Down
7 changes: 7 additions & 0 deletions src/resource/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod placeholder {
pub const GAME: &str = "<game>";
pub const BASE: &str = "<base>";
pub const HOME: &str = "<home>";
pub const STORE_GAME_ID: &str = "<storeGameId>";
pub const STORE_USER_ID: &str = "<storeUserId>";
pub const OS_USER_NAME: &str = "<osUserName>";
pub const WIN_APP_DATA: &str = "<winAppData>";
Expand Down Expand Up @@ -349,6 +350,12 @@ impl<'a> IdSet<'a> {
.chain(std::iter::once(shortcut))
.flatten()
}

pub fn gog(&'a self) -> impl Iterator<Item = u64> + 'a {
std::iter::once(self.gog)
.chain(self.gog_extra.iter().map(|x| Some(*x)))
.flatten()
}
}

#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
Expand Down
29 changes: 29 additions & 0 deletions src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,35 @@ pub fn parse_paths(
}
}

let paths = if path.contains(STORE_GAME_ID) {
let mut expanded = HashSet::new();

for (p, c) in paths {
match root.store() {
Store::Gog => {
for id in ids.gog() {
expanded.insert((p.replace(STORE_GAME_ID, &id.to_string()), c));
}
}
Store::Lutris => {
if let Some(id) = ids.lutris.as_ref() {
expanded.insert((p.replace(STORE_GAME_ID, id), c));
}
}
Store::Steam => {
for id in ids.steam(steam_shortcut.map(|x| x.id)) {
expanded.insert((p.replace(STORE_GAME_ID, &id.to_string()), c));
}
}
_ => continue,
}
}

expanded
} else {
paths
};

paths
.into_iter()
// This excludes `SKIP` and any other unmatched placeholders.
Expand Down

0 comments on commit 14e68b0

Please sign in to comment.