Skip to content

Commit b52a3f7

Browse files
authored
Fix finding more game pass games (#353)
1 parent 04fb458 commit b52a3f7

File tree

3 files changed

+80
-27
lines changed

3 files changed

+80
-27
lines changed

Cargo.lock

+17-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
edition = "2021"
33
name = "boilr"
4-
version = "1.9.0"
4+
version = "1.9.1"
55

66
[dependencies]
77
base64 = "^0.21.0"
@@ -64,6 +64,7 @@ winres = "^0.1.12"
6464
[target."cfg(windows)".dependencies]
6565
winreg = "^0.50.0"
6666
sqlite = "^0.30.3"
67+
roxmltree = "^0.18.0"
6768

6869
[features]
6970
# This feature is enabled when building for a flatpak environment

src/platforms/gamepass/platform.rs

+61-25
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ pub struct GamePassPlatForm {
1414
settings: GamePassSettings,
1515
}
1616

17-
#[derive(Serialize,Deserialize, Default, Clone)]
17+
#[derive(Serialize, Deserialize, Default, Clone)]
1818
pub struct GamePassSettings {
1919
enabled: bool,
2020
}
2121

22-
2322
impl GamesPlatform for GamePassPlatForm {
2423
fn name(&self) -> &str {
2524
"Game Pass"
@@ -37,39 +36,44 @@ impl GamesPlatform for GamePassPlatForm {
3736
let command = include_str!("./game_pass_games.ps1");
3837
let res = run_powershell_command(command)?;
3938
let apps: Vec<AppInfo> = serde_json::from_str(&res)?;
40-
let expanded_search = false;
41-
4239
let windows_dir = std::env::var("WinDir").unwrap_or("C:\\Windows".to_string());
4340
let explorer = Path::new(&windows_dir)
4441
.join("explorer.exe")
4542
.to_string_lossy()
4643
.to_string();
44+
45+
let name_getters: [fn(&AppInfo) -> eyre::Result<String>; 3] =
46+
[get_name_from_game, get_name_from_config, get_name_from_xml];
47+
4748
let games_iter = apps
4849
.iter()
4950
.filter(|app| {
50-
app.kind.is_game()
51-
|| (expanded_search
52-
&& (app.display_name.contains("DisplayName")
53-
|| app.display_name.contains("ms-resource")))
51+
!(app.display_name.contains("DisplayName")
52+
|| app.display_name.contains("ms-resource"))
5453
})
55-
.filter(|game| game.microsoft_game_path().exists() || game.appx_manifest().exists())
56-
.map(|game| {
54+
.filter_map(|game| {
5755
let launch_url = format!("shell:AppsFolder\\{}", game.aum_id());
58-
let shortcut = Shortcut::new(
59-
"0",
60-
&game.display_name,
61-
&explorer,
62-
&windows_dir,
63-
"",
64-
"",
65-
&launch_url,
66-
);
67-
ShortcutToImport {
68-
shortcut: shortcut.to_owned(),
69-
needs_proton: false,
70-
needs_symlinks: false,
71-
}
56+
name_getters
57+
.iter()
58+
.find_map(|&f| f(game).ok())
59+
.map(|game_name| {
60+
let shortcut = Shortcut::new(
61+
"0",
62+
&game_name,
63+
&explorer,
64+
&windows_dir,
65+
"",
66+
"",
67+
&launch_url,
68+
);
69+
ShortcutToImport {
70+
shortcut: shortcut.to_owned(),
71+
needs_proton: false,
72+
needs_symlinks: false,
73+
}
74+
})
7275
});
76+
7377
Ok(games_iter.collect())
7478
}
7579

@@ -83,6 +87,38 @@ impl GamesPlatform for GamePassPlatForm {
8387
}
8488
}
8589

90+
fn get_name_from_xml(app_info: &AppInfo) -> eyre::Result<String> {
91+
use roxmltree::Document;
92+
let path_to_config = app_info.appx_manifest();
93+
let xml = std::fs::read_to_string(path_to_config)?;
94+
let doc = Document::parse(&xml)?;
95+
doc.descendants()
96+
.find(|n| n.has_tag_name("uap::VisualElements"))
97+
.and_then(|n| n.attribute("DisplayName"))
98+
.map(|n| n.to_string())
99+
.ok_or(eyre::format_err!("Name not found"))
100+
}
101+
102+
fn get_name_from_game(app_info: &AppInfo) -> eyre::Result<String> {
103+
if !app_info.kind.is_game() {
104+
Err(eyre::format_err!("Not a game type"))
105+
} else {
106+
Ok(app_info.display_name.to_owned())
107+
}
108+
}
109+
110+
fn get_name_from_config(app_info: &AppInfo) -> eyre::Result<String> {
111+
use roxmltree::Document;
112+
let path_to_config = app_info.microsoft_game_path();
113+
let xml = std::fs::read_to_string(path_to_config)?;
114+
let doc = Document::parse(&xml)?;
115+
doc.descendants()
116+
.find(|n| n.has_tag_name("ShellVisuals"))
117+
.and_then(|n| n.attribute("DefaultDisplayName"))
118+
.map(|n| n.to_string())
119+
.ok_or(eyre::format_err!("Name not found"))
120+
}
121+
86122
#[derive(Deserialize, Debug)]
87123
struct AppInfo {
88124
kind: Kind,
@@ -105,7 +141,7 @@ impl AppInfo {
105141
}
106142

107143
fn microsoft_game_path(&self) -> PathBuf {
108-
Path::new(&self.install_location).join("MicrosoftGames.config")
144+
Path::new(&self.install_location).join("MicrosoftGame.config")
109145
}
110146

111147
fn appx_manifest(&self) -> PathBuf {

0 commit comments

Comments
 (0)