Skip to content

Commit

Permalink
Fix finding more game pass games (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipK committed Jun 11, 2023
1 parent 04fb458 commit b52a3f7
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 27 deletions.
18 changes: 17 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "boilr"
version = "1.9.0"
version = "1.9.1"

[dependencies]
base64 = "^0.21.0"
Expand Down Expand Up @@ -64,6 +64,7 @@ winres = "^0.1.12"
[target."cfg(windows)".dependencies]
winreg = "^0.50.0"
sqlite = "^0.30.3"
roxmltree = "^0.18.0"

[features]
# This feature is enabled when building for a flatpak environment
Expand Down
86 changes: 61 additions & 25 deletions src/platforms/gamepass/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ pub struct GamePassPlatForm {
settings: GamePassSettings,
}

#[derive(Serialize,Deserialize, Default, Clone)]
#[derive(Serialize, Deserialize, Default, Clone)]
pub struct GamePassSettings {
enabled: bool,
}


impl GamesPlatform for GamePassPlatForm {
fn name(&self) -> &str {
"Game Pass"
Expand All @@ -37,39 +36,44 @@ impl GamesPlatform for GamePassPlatForm {
let command = include_str!("./game_pass_games.ps1");
let res = run_powershell_command(command)?;
let apps: Vec<AppInfo> = serde_json::from_str(&res)?;
let expanded_search = false;

let windows_dir = std::env::var("WinDir").unwrap_or("C:\\Windows".to_string());
let explorer = Path::new(&windows_dir)
.join("explorer.exe")
.to_string_lossy()
.to_string();

let name_getters: [fn(&AppInfo) -> eyre::Result<String>; 3] =
[get_name_from_game, get_name_from_config, get_name_from_xml];

let games_iter = apps
.iter()
.filter(|app| {
app.kind.is_game()
|| (expanded_search
&& (app.display_name.contains("DisplayName")
|| app.display_name.contains("ms-resource")))
!(app.display_name.contains("DisplayName")
|| app.display_name.contains("ms-resource"))
})
.filter(|game| game.microsoft_game_path().exists() || game.appx_manifest().exists())
.map(|game| {
.filter_map(|game| {
let launch_url = format!("shell:AppsFolder\\{}", game.aum_id());
let shortcut = Shortcut::new(
"0",
&game.display_name,
&explorer,
&windows_dir,
"",
"",
&launch_url,
);
ShortcutToImport {
shortcut: shortcut.to_owned(),
needs_proton: false,
needs_symlinks: false,
}
name_getters
.iter()
.find_map(|&f| f(game).ok())
.map(|game_name| {
let shortcut = Shortcut::new(
"0",
&game_name,
&explorer,
&windows_dir,
"",
"",
&launch_url,
);
ShortcutToImport {
shortcut: shortcut.to_owned(),
needs_proton: false,
needs_symlinks: false,
}
})
});

Ok(games_iter.collect())
}

Expand All @@ -83,6 +87,38 @@ impl GamesPlatform for GamePassPlatForm {
}
}

fn get_name_from_xml(app_info: &AppInfo) -> eyre::Result<String> {
use roxmltree::Document;
let path_to_config = app_info.appx_manifest();
let xml = std::fs::read_to_string(path_to_config)?;
let doc = Document::parse(&xml)?;
doc.descendants()
.find(|n| n.has_tag_name("uap::VisualElements"))
.and_then(|n| n.attribute("DisplayName"))
.map(|n| n.to_string())
.ok_or(eyre::format_err!("Name not found"))
}

fn get_name_from_game(app_info: &AppInfo) -> eyre::Result<String> {
if !app_info.kind.is_game() {
Err(eyre::format_err!("Not a game type"))
} else {
Ok(app_info.display_name.to_owned())
}
}

fn get_name_from_config(app_info: &AppInfo) -> eyre::Result<String> {
use roxmltree::Document;
let path_to_config = app_info.microsoft_game_path();
let xml = std::fs::read_to_string(path_to_config)?;
let doc = Document::parse(&xml)?;
doc.descendants()
.find(|n| n.has_tag_name("ShellVisuals"))
.and_then(|n| n.attribute("DefaultDisplayName"))
.map(|n| n.to_string())
.ok_or(eyre::format_err!("Name not found"))
}

#[derive(Deserialize, Debug)]
struct AppInfo {
kind: Kind,
Expand All @@ -105,7 +141,7 @@ impl AppInfo {
}

fn microsoft_game_path(&self) -> PathBuf {
Path::new(&self.install_location).join("MicrosoftGames.config")
Path::new(&self.install_location).join("MicrosoftGame.config")
}

fn appx_manifest(&self) -> PathBuf {
Expand Down

0 comments on commit b52a3f7

Please sign in to comment.