Skip to content

Commit 4283198

Browse files
authored
Merge pull request #57 from Tormak9970/dev
fixed user id not being found
2 parents 00aef89 + 6581239 commit 4283198

File tree

3 files changed

+26
-118
lines changed

3 files changed

+26
-118
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ To get the most recent release, head to [releases](https://github.com/Tormak9970
1616

1717
## How to use the app
1818
When using Steam Art Manager, your workflow will typically be:
19-
- Make sure Steam is already running (windows only)
2019
- Open Steam Art Manager
2120
- Set your SteamGridDB api key (if you wish to browse images from SteamGridDB)
2221
- Wait for it to load your games

src-tauri/src/steam.rs

Lines changed: 26 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ use tauri::AppHandle;
1212

1313
#[cfg(target_os = "linux")]
1414
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-
2015

2116
#[cfg(target_os = "windows")]
2217
pub fn get_steam_root_dir() -> PathBuf {
@@ -69,38 +64,42 @@ pub fn get_appinfo_path(app_handle: AppHandle) -> String {
6964
logger::log_to_file(app_handle.to_owned(), "Getting steam appinfo.vdf...", 0);
7065

7166
let steam_root = get_steam_root_dir();
72-
println!("Steam Base Directory: {}", steam_root.display());
7367
return steam_root.join("appcache/appinfo.vdf").to_str().expect("Should have been able to convert to a string.").to_owned().replace("\\", "/");
7468
}
7569

7670
#[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")]
9271
pub fn get_active_user(app_handle: AppHandle) -> u32 {
9372
logger::log_to_file(app_handle.to_owned(), "Checking config/loginusers.vdf for current user info.", 0);
9473

9574
let steam_root = get_steam_root_dir();
9675
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();
9880

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;
10084

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;
104103
let id = u32::try_from(big_id).expect("Should have been able to convert subtracted big_id to u32.");
105104

106105
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 {
111110
logger::log_to_file(app_handle, "Did not find a most recent user", 2);
112111

113112
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+
}

src-tauri/src/vdf_structs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub struct User {
1515
}
1616

1717

18-
1918
#[derive(Serialize, Deserialize, Debug, PartialEq)]
2019
#[allow(non_snake_case)]
2120
pub struct HKLMSteam {

0 commit comments

Comments
 (0)