@@ -12,11 +12,6 @@ use tauri::AppHandle;
12
12
13
13
#[ cfg( target_os = "linux" ) ]
14
14
use home:: home_dir;
15
- #[ cfg( target_os = "linux" ) ]
16
- use crate :: vdf_structs;
17
- #[ cfg( target_os = "linux" ) ]
18
- use std:: collections:: HashMap ;
19
-
20
15
21
16
#[ cfg( target_os = "windows" ) ]
22
17
pub fn get_steam_root_dir ( ) -> PathBuf {
@@ -69,38 +64,42 @@ pub fn get_appinfo_path(app_handle: AppHandle) -> String {
69
64
logger:: log_to_file ( app_handle. to_owned ( ) , "Getting steam appinfo.vdf..." , 0 ) ;
70
65
71
66
let steam_root = get_steam_root_dir ( ) ;
72
- println ! ( "Steam Base Directory: {}" , steam_root. display( ) ) ;
73
67
return steam_root. join ( "appcache/appinfo.vdf" ) . to_str ( ) . expect ( "Should have been able to convert to a string." ) . to_owned ( ) . replace ( "\\ " , "/" ) ;
74
68
}
75
69
76
70
#[ tauri:: command]
77
- #[ cfg( target_os = "windows" ) ]
78
- pub fn get_active_user ( app_handle : AppHandle ) -> u32 {
79
- logger:: log_to_file ( app_handle. to_owned ( ) , "Checking registry for current user." , 0 ) ;
80
- let hkcu: RegKey = RegKey :: predef ( HKEY_CURRENT_USER ) ;
81
-
82
- let steam_active_process: RegKey = hkcu. open_subkey ( "SOFTWARE\\ Valve\\ Steam\\ ActiveProcess" ) . expect ( "Couldn't getActiveProcess from the registry" ) ;
83
- let active_user_dword: u32 = steam_active_process. get_value ( "ActiveUser" ) . expect ( "Couldn't get ActiveUser from the registry" ) ;
84
-
85
- logger:: log_to_file ( app_handle, format ! ( "Got current_user_id: {}" , active_user_dword) . as_str ( ) , 0 ) ;
86
-
87
- return active_user_dword;
88
- }
89
-
90
- #[ tauri:: command]
91
- #[ cfg( target_os = "linux" ) ]
92
71
pub fn get_active_user ( app_handle : AppHandle ) -> u32 {
93
72
logger:: log_to_file ( app_handle. to_owned ( ) , "Checking config/loginusers.vdf for current user info." , 0 ) ;
94
73
95
74
let steam_root = get_steam_root_dir ( ) ;
96
75
let loginusers_vdf = steam_root. join ( "config/loginusers.vdf" ) ;
97
- let contents = fs:: read_to_string ( loginusers_vdf) . unwrap ( ) ;
76
+ let contents: String = fs:: read_to_string ( loginusers_vdf) . unwrap ( ) ;
77
+
78
+ let close_braces_matches: Vec < _ > = contents. match_indices ( "}" ) . collect ( ) ;
79
+ let most_recent_matches: Vec < _ > = contents. match_indices ( "\" MostRecent\" " ) . collect ( ) ;
98
80
99
- let users = vdf_serde:: from_str :: < HashMap < String , vdf_structs:: User > > ( & contents) . unwrap ( ) ;
81
+ const MOST_RECENT_LEN : usize = 12 ;
82
+ const VAL_TABS_LEN : usize = 2 ;
83
+ const START_OFFSET : usize = 11 ;
100
84
101
- for ( key, value) in users. into_iter ( ) {
102
- if value. MostRecent == "1" {
103
- let big_id = key. parse :: < u64 > ( ) . unwrap ( ) - 76561197960265728 ;
85
+ for ( vec_index, ( index, _) ) in most_recent_matches. iter ( ) . enumerate ( ) {
86
+ let most_recent_str: String = contents. chars ( ) . skip ( index + MOST_RECENT_LEN + VAL_TABS_LEN + 1 ) . take ( 1 ) . collect ( ) ;
87
+ let most_recent = most_recent_str. parse :: < u32 > ( ) . unwrap ( ) == 1 ;
88
+
89
+ if most_recent {
90
+ let chars: String ;
91
+
92
+ if vec_index == 0 {
93
+ chars = contents. chars ( ) . skip ( START_OFFSET + 1 ) . take ( contents. len ( ) - START_OFFSET - 2 ) . collect ( ) ;
94
+ } else {
95
+ let ( brace_index, _) = close_braces_matches[ vec_index] ;
96
+ chars = contents. chars ( ) . skip ( brace_index + 4 ) . take ( contents. len ( ) - brace_index - 2 ) . collect ( ) ;
97
+ }
98
+
99
+ let next_quote = chars. find ( "\" " ) . unwrap ( ) ;
100
+ let user_id_64_str: String = chars. chars ( ) . take ( next_quote) . collect ( ) ;
101
+
102
+ let big_id = user_id_64_str. parse :: < u64 > ( ) . unwrap ( ) - 76561197960265728 ;
104
103
let id = u32:: try_from ( big_id) . expect ( "Should have been able to convert subtracted big_id to u32." ) ;
105
104
106
105
logger:: log_to_file ( app_handle. to_owned ( ) , format ! ( "Got current_user_id: {}" , id) . as_str ( ) , 0 ) ;
@@ -111,93 +110,4 @@ pub fn get_active_user(app_handle: AppHandle) -> u32 {
111
110
logger:: log_to_file ( app_handle, "Did not find a most recent user" , 2 ) ;
112
111
113
112
return 0 ;
114
- }
115
-
116
- // ! This isn't needed anymore but leaving it because in the event something changes its still quite useful.
117
- // #[tauri::command]
118
- // #[cfg(target_os = "windows")]
119
- // pub fn get_steam_apps(app_handle: AppHandle) -> String {
120
- // let mut steam_apps: String = "".to_owned();
121
-
122
- // logger::log_to_file(app_handle.to_owned(), "Checking registry for steam games.", 0);
123
-
124
- // let hkcu = RegKey::predef(HKEY_CURRENT_USER);
125
- // let steam_apps_reg = hkcu.open_subkey("SOFTWARE\\Valve\\Steam\\Apps").expect("Couldn't Apps from the registry");
126
-
127
- // for field in steam_apps_reg.enum_keys().map(|x| x.unwrap()) {
128
- // let mut app: String = "".to_owned();
129
- // app.push_str("\"appId\":");
130
- // app.push_str(&field);
131
- // app.push_str(",");
132
-
133
- // let app_reg: RegKey = steam_apps_reg.open_subkey(field).expect("Couldn't get app from registry");
134
- // let mut app_name = "";
135
-
136
- // let app_name_reg: Result<String> = app_reg.get_value("Name");
137
-
138
- // if app_name_reg.is_ok() {
139
- // app_name = app_name_reg.as_ref().unwrap();
140
- // }
141
-
142
- // app.push_str("\"name\":\"");
143
- // app.push_str(app_name);
144
- // app.push_str("\",");
145
- // let mut updated_app = "".to_owned();
146
- // updated_app.push_str("{");
147
- // updated_app.push_str(&app[..(app.len() - 1)]);
148
- // updated_app.push_str("},");
149
-
150
- // steam_apps.push_str(&updated_app);
151
- // }
152
-
153
- // let mut updated_apps = "".to_owned();
154
- // updated_apps.push_str(&"[");
155
- // updated_apps.push_str(&steam_apps[..(steam_apps.len() - 1)]);
156
- // updated_apps.push_str(&"]");
157
-
158
- // return updated_apps;
159
- // }
160
-
161
- // #[tauri::command]
162
- // #[cfg(target_os = "linux")]
163
- // pub fn get_steam_apps(app_handle: AppHandle) -> String {
164
- // let mut steam_apps: String = "".to_owned();
165
-
166
- // logger::log_to_file(app_handle.to_owned(), "Checking registry.vdf for steam games.", 0);
167
-
168
- // let steam_root = get_steam_root_dir();
169
- // let registry_vdf = steam_root.parent().expect("Parent should have existed").join("registry.vdf");
170
- // let contents = fs::read_to_string(registry_vdf).unwrap();
171
-
172
- // let steam_apps_res = vdf_serde::from_str::<vdf_structs::Registry>(&contents).unwrap().HKCU.Software.Valve.Steam.apps;
173
-
174
- // for (key, value) in steam_apps_res.into_iter() {
175
- // let mut app: String = "".to_owned();
176
- // app.push_str("\"appId\":");
177
- // app.push_str(&key);
178
- // app.push_str(",");
179
-
180
- // let mut app_name = "";
181
-
182
- // if value.contains_key("name") {
183
- // app_name = value.get("name").unwrap().as_ref();
184
- // }
185
-
186
- // app.push_str("\"name\":\"");
187
- // app.push_str(app_name);
188
- // app.push_str("\",");
189
- // let mut updated_app = "".to_owned();
190
- // updated_app.push_str("{");
191
- // updated_app.push_str(&app[..(app.len() - 1)]);
192
- // updated_app.push_str("},");
193
-
194
- // steam_apps.push_str(&updated_app);
195
- // }
196
-
197
- // let mut updated_apps = "".to_owned();
198
- // updated_apps.push_str(&"[");
199
- // updated_apps.push_str(&steam_apps[..(steam_apps.len() - 1)]);
200
- // updated_apps.push_str(&"]");
201
-
202
- // return updated_apps;
203
- // }
113
+ }
0 commit comments