@@ -14,12 +14,11 @@ pub struct GamePassPlatForm {
14
14
settings : GamePassSettings ,
15
15
}
16
16
17
- #[ derive( Serialize , Deserialize , Default , Clone ) ]
17
+ #[ derive( Serialize , Deserialize , Default , Clone ) ]
18
18
pub struct GamePassSettings {
19
19
enabled : bool ,
20
20
}
21
21
22
-
23
22
impl GamesPlatform for GamePassPlatForm {
24
23
fn name ( & self ) -> & str {
25
24
"Game Pass"
@@ -37,39 +36,44 @@ impl GamesPlatform for GamePassPlatForm {
37
36
let command = include_str ! ( "./game_pass_games.ps1" ) ;
38
37
let res = run_powershell_command ( command) ?;
39
38
let apps: Vec < AppInfo > = serde_json:: from_str ( & res) ?;
40
- let expanded_search = false ;
41
-
42
39
let windows_dir = std:: env:: var ( "WinDir" ) . unwrap_or ( "C:\\ Windows" . to_string ( ) ) ;
43
40
let explorer = Path :: new ( & windows_dir)
44
41
. join ( "explorer.exe" )
45
42
. to_string_lossy ( )
46
43
. 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
+
47
48
let games_iter = apps
48
49
. iter ( )
49
50
. 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" ) )
54
53
} )
55
- . filter ( |game| game. microsoft_game_path ( ) . exists ( ) || game. appx_manifest ( ) . exists ( ) )
56
- . map ( |game| {
54
+ . filter_map ( |game| {
57
55
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
+ } )
72
75
} ) ;
76
+
73
77
Ok ( games_iter. collect ( ) )
74
78
}
75
79
@@ -83,6 +87,38 @@ impl GamesPlatform for GamePassPlatForm {
83
87
}
84
88
}
85
89
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
+
86
122
#[ derive( Deserialize , Debug ) ]
87
123
struct AppInfo {
88
124
kind : Kind ,
@@ -105,7 +141,7 @@ impl AppInfo {
105
141
}
106
142
107
143
fn microsoft_game_path ( & self ) -> PathBuf {
108
- Path :: new ( & self . install_location ) . join ( "MicrosoftGames .config" )
144
+ Path :: new ( & self . install_location ) . join ( "MicrosoftGame .config" )
109
145
}
110
146
111
147
fn appx_manifest ( & self ) -> PathBuf {
0 commit comments