-
Notifications
You must be signed in to change notification settings - Fork 22
/
steam.rs
267 lines (229 loc) 路 7.82 KB
/
steam.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
use crate::launchers::GameObject;
use crate::modules::banners;
use crate::operations::custom_fs::{d_f_exists, read_dir, read_file};
use serde::{Deserialize, Deserializer};
use std::{collections::HashMap, fmt};
#[cfg(target_os = "windows")]
use std::{os::windows::process::CommandExt, process::Command};
#[cfg(any(target_os = "linux", target_os = "macos"))]
use tauri::api::path;
fn blacklist_appid() -> Vec<i32> {
return vec![
228980, 231350, 1493710, 1391110, 1070560, 1826330, 1113280, 1245040, 1420170, 1580130,
1887720, 1628350, 2348590, 2180100,
];
}
struct LibraryFolders {
folders: HashMap<String, Folder>,
}
#[derive(Deserialize)]
struct Folder {
path: String,
}
#[cfg(target_os = "macos")]
#[derive(Deserialize, Debug)]
struct AppState {
appid: String,
name: String,
#[serde(rename = "SizeOnDisk")]
size_on_disk: String,
installdir: String,
}
#[cfg(target_os = "windows")]
#[derive(Deserialize, Debug)]
struct AppState {
appid: String,
name: String,
#[serde(rename = "SizeOnDisk")]
size_on_disk: String,
#[serde(rename = "LauncherPath")]
launcherpath: String,
}
#[cfg(target_os = "linux")]
#[derive(Deserialize, Debug)]
struct AppState {
appid: String,
name: String,
#[serde(rename = "SizeOnDisk")]
size_on_disk: String,
}
impl<'de> Deserialize<'de> for LibraryFolders {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct LibraryFoldersVisitor;
impl<'de> serde::de::Visitor<'de> for LibraryFoldersVisitor {
type Value = LibraryFolders;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("struct LibraryFolders")
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: serde::de::MapAccess<'de>,
{
let mut folders = HashMap::new();
while let Some((key, value)) = map.next_entry::<String, Folder>()? {
folders.insert(key, value);
}
Ok(LibraryFolders { folders })
}
}
deserializer.deserialize_map(LibraryFoldersVisitor)
}
}
pub async fn get_installed_games() -> Vec<GameObject> {
let mut all_games: Vec<GameObject> = Vec::new();
let paths: Vec<String> = get_steam_location().await;
if paths.is_empty() {
return all_games;
}
for path in paths {
#[cfg(target_os = "windows")]
let acf_base_path = format!("{}\\steamapps", path);
#[cfg(target_os = "linux")]
let acf_base_path = format!("{}/steamapps", path);
#[cfg(target_os = "macos")]
let acf_base_path = format!("{}/steamapps", path);
if !d_f_exists(&acf_base_path).await.unwrap_or(false) {
continue;
}
let base_path_content = read_dir(&acf_base_path).await.unwrap();
let acf_files: Vec<String> = base_path_content
.into_iter()
.filter(|filename| filename.ends_with(".acf"))
.collect();
for acf_file in acf_files {
let game_file: String = read_file(format!("{}/{}", acf_base_path, acf_file)).unwrap();
let game_file_parsed: AppState = keyvalues_serde::from_str(&game_file).unwrap();
if blacklist_appid()
.iter()
.any(|&item: &i32| item == game_file_parsed.appid.parse::<i32>().unwrap())
{
continue;
}
let mut temp_all_games: Vec<GameObject> = Vec::new();
#[cfg(target_os = "macos")]
temp_all_games.push(GameObject::new(
banners::get_banner(&game_file_parsed.name, &game_file_parsed.appid, "Steam", "")
.await,
String::new(),
game_file_parsed.installdir.to_string(),
game_file_parsed.name,
game_file_parsed.appid.parse().unwrap(),
"0".to_string(),
game_file_parsed.size_on_disk.parse().unwrap(),
String::new(),
"Steam".to_string(),
vec![],
));
#[cfg(target_os = "windows")]
temp_all_games.push(GameObject::new(
banners::get_banner(&game_file_parsed.name, &game_file_parsed.appid, "Steam", "")
.await,
String::new(),
game_file_parsed.launcherpath.to_string(),
game_file_parsed.name,
game_file_parsed.appid.parse().unwrap(),
"0".to_string(),
game_file_parsed.size_on_disk.parse().unwrap(),
String::new(),
"Steam".to_string(),
vec![],
));
#[cfg(target_os = "linux")]
temp_all_games.push(GameObject::new(
banners::get_banner(&game_file_parsed.name, &game_file_parsed.appid, "Steam", "")
.await,
String::new(),
String::new(),
game_file_parsed.name,
game_file_parsed.appid.parse().unwrap(),
"0".to_string(),
game_file_parsed.size_on_disk.parse().unwrap(),
String::new(),
"Steam".to_string(),
vec![],
));
for game in temp_all_games {
if !all_games
.iter()
.any(|obj| obj.display_name == game.display_name)
{
all_games.push(game);
}
}
}
}
return all_games;
}
async fn get_steam_location() -> Vec<String> {
let mut launcher_location: Vec<String> = Vec::new();
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
let output = Command::new("cmd")
.args(&[
"/C",
"Reg",
"Query",
"HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Valve\\Steam",
"/v",
"InstallPath",
])
.creation_flags(0x08000000)
.output()
.expect("failed to execute process.");
#[cfg(all(target_os = "windows", target_arch = "x86"))]
let output = Command::new("cmd")
.args(&[
"/C",
"Reg",
"Query",
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Valve\\Steam",
"/v",
"InstallPath",
])
.creation_flags(0x08000000)
.output()
.expect("failed to execute process.");
#[cfg(target_os = "windows")]
if output.stdout.is_empty() {
return launcher_location;
}
#[cfg(target_os = "windows")]
let path = String::from_utf8_lossy(&output.stdout)
.to_string()
.split("REG_SZ")
.collect::<Vec<_>>()[1]
.split("\r\n\r\n")
.collect::<Vec<_>>()[0]
.trim()
.to_string()
+ "\\steamapps\\libraryfolders.vdf";
#[cfg(target_os = "linux")]
let path: String = path::home_dir()
.unwrap()
.into_os_string()
.into_string()
.unwrap()
+ "/.steam/steam/steamapps/libraryfolders.vdf";
#[cfg(target_os = "macos")]
let path: String = path::home_dir()
.unwrap()
.into_os_string()
.into_string()
.unwrap()
+ "/Library/Application Support/Steam/steamapps/libraryfolders.vdf";
if d_f_exists(&path).await.unwrap_or(false) {
let vdf_file = read_file(path.to_string()).unwrap();
if vdf_file.is_empty() {
return launcher_location;
};
let parsed: LibraryFolders = keyvalues_serde::from_str(&vdf_file).unwrap();
for (_, folder) in parsed.folders.iter() {
launcher_location.push(folder.path.clone());
}
} else {
return launcher_location;
}
launcher_location
}