mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Refactor to make more readable
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
|
auth_key.txt
|
||||||
+92
-44
@@ -1,68 +1,116 @@
|
|||||||
use std::{env::{self}, fmt, fs::File, io::Write, path::Path};
|
use std::{
|
||||||
|
env::{self},
|
||||||
|
fmt,
|
||||||
|
fs::File,
|
||||||
|
io::Write,
|
||||||
|
path::Path,
|
||||||
|
};
|
||||||
mod egs;
|
mod egs;
|
||||||
use egs::{get_egs_manifests, ManifestItem};
|
use egs::{get_egs_manifests, ManifestItem};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use steam_shortcuts_util::{Shortcut, parse_shortcuts, shortcuts_to_bytes};
|
use steam_shortcuts_util::{
|
||||||
|
parse_shortcuts, shortcut::ShortcutOwned, shortcuts_to_bytes, Shortcut,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct ShortcutInfo {
|
||||||
|
pub path: String,
|
||||||
|
pub shortcuts: Vec<ShortcutOwned>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_shortcuts_for_user(user: &SteamUsersInfo) -> ShortcutInfo {
|
||||||
|
let mut shortcuts = vec![];
|
||||||
|
let mut new_path = user.shortcut_path.clone();
|
||||||
|
if let Some(shortcut_path) = &user.shortcut_path {
|
||||||
|
// std::fs::remove_file(path)
|
||||||
|
//TODO remove unwrap
|
||||||
|
let content = std::fs::read(shortcut_path).unwrap();
|
||||||
|
shortcuts = parse_shortcuts(content.as_slice())
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.map(|s| s.to_owned())
|
||||||
|
.collect();
|
||||||
|
println!(
|
||||||
|
"Found {} shortcuts , for user: {}",
|
||||||
|
shortcuts.len(),
|
||||||
|
user.steam_user_data_folder
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"Did not find a shortcut file for user {}, createing a new",
|
||||||
|
user.steam_user_data_folder
|
||||||
|
);
|
||||||
|
std::fs::create_dir_all(format!("{}/{}", user.steam_user_data_folder, "config")).unwrap();
|
||||||
|
new_path = Some(format!(
|
||||||
|
"{}/{}",
|
||||||
|
user.steam_user_data_folder, "config/shortcuts.vdf"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
ShortcutInfo {
|
||||||
|
shortcuts,
|
||||||
|
path: new_path.unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
let auth_key = std::fs::read_to_string("auth_key.txt")?;
|
||||||
|
let client = steamgriddb_api::Client::new(auth_key);
|
||||||
|
|
||||||
let egs_manifests = get_egs_manifests()?;
|
let egs_manifests = get_egs_manifests()?;
|
||||||
|
let egs_shortcuts: Vec<ShortcutOwned> =
|
||||||
|
egs_manifests.iter().map(manifest_to_shortcut).collect();
|
||||||
println!("Found {} installed EGS Games", egs_manifests.len());
|
println!("Found {} installed EGS Games", egs_manifests.len());
|
||||||
|
|
||||||
let userinfo_shortcuts = get_shortcuts_paths()?;
|
let userinfo_shortcuts = get_shortcuts_paths()?;
|
||||||
println!("Found {} user(s)", userinfo_shortcuts.len());
|
println!("Found {} user(s)", userinfo_shortcuts.len());
|
||||||
|
|
||||||
userinfo_shortcuts.iter().for_each(|user| {
|
userinfo_shortcuts.iter().for_each(|user| {
|
||||||
let mut shortcuts = vec![];
|
let shortcut_info = get_shortcuts_for_user(user);
|
||||||
let mut new_path = user.shortcut_path.clone();
|
let user_shortcuts = shortcut_info.shortcuts;
|
||||||
if let Some(shortcut_path) = &user.shortcut_path {
|
let new_path = shortcut_info.path;
|
||||||
//TODO remove unwrap
|
let new_user_shortcuts: Vec<&ShortcutOwned> = user_shortcuts
|
||||||
let content = std::fs::read(shortcut_path).unwrap();
|
.iter()
|
||||||
shortcuts = parse_shortcuts(content.as_slice())
|
.filter(|user_shortcut| !user_shortcut.tags.contains(&"EGS".to_owned()))
|
||||||
.unwrap()
|
.chain(egs_shortcuts.iter())
|
||||||
.iter()
|
.collect();
|
||||||
.map(|s| s.to_owned())
|
|
||||||
.collect();
|
|
||||||
println!(
|
|
||||||
"Found {} shortcuts , for user: {}",
|
|
||||||
shortcuts.len(),
|
|
||||||
user.steam_user_data_folder
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
println!(
|
|
||||||
"Did not find a shortcut file for user {}, createing a new",
|
|
||||||
user.steam_user_data_folder
|
|
||||||
);
|
|
||||||
std::fs::create_dir_all(format!("{}/{}", user.steam_user_data_folder, "config")).unwrap();
|
|
||||||
new_path = Some(format!("{}/{}", user.steam_user_data_folder, "config/shortcuts.vdf"));
|
|
||||||
}
|
|
||||||
let cur_number_of_shortcuts = shortcuts.len();
|
|
||||||
egs_manifests.iter().enumerate().for_each(|(i, manifest)| {
|
|
||||||
let exe = format!(
|
|
||||||
"{}/{}",
|
|
||||||
manifest.install_location, manifest.launch_executable
|
|
||||||
);
|
|
||||||
let shortcut = Shortcut::new(
|
|
||||||
cur_number_of_shortcuts + i,
|
|
||||||
manifest.display_name.as_str(),
|
|
||||||
exe.as_str(),
|
|
||||||
manifest.install_location.as_str(),
|
|
||||||
exe.as_str(),
|
|
||||||
exe.as_str(),
|
|
||||||
"",
|
|
||||||
);
|
|
||||||
shortcuts.push(shortcut.to_owned());
|
|
||||||
});
|
|
||||||
|
|
||||||
let shortcut_refs = shortcuts.iter().map(|f| f.borrow()).collect();
|
let shortcut_refs = new_user_shortcuts.iter().map(|f| f.borrow()).collect();
|
||||||
let new_content = shortcuts_to_bytes(&shortcut_refs);
|
let new_content = shortcuts_to_bytes(&shortcut_refs);
|
||||||
|
|
||||||
let mut file = File::create(new_path.unwrap()).unwrap();
|
let mut file = File::create(new_path).unwrap();
|
||||||
file.write(new_content.as_slice()).unwrap();
|
file.write(new_content.as_slice()).unwrap();
|
||||||
|
|
||||||
|
// shortcut_refs.iter().map(|shortcut| {
|
||||||
|
// client.search(shortcut.app_name).await?.iter().next();
|
||||||
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn manifest_to_shortcut(manifest: &ManifestItem) -> ShortcutOwned {
|
||||||
|
let exe = format!(
|
||||||
|
"\"{}\\{}\"",
|
||||||
|
manifest.install_location, manifest.launch_executable
|
||||||
|
);
|
||||||
|
let mut start_dir = manifest.install_location.clone();
|
||||||
|
if !manifest.install_location.starts_with("\"") {
|
||||||
|
start_dir = format!("\"{}\"", manifest.install_location);
|
||||||
|
}
|
||||||
|
let shortcut = Shortcut::new(
|
||||||
|
0,
|
||||||
|
manifest.display_name.as_str(),
|
||||||
|
exe.as_str(),
|
||||||
|
start_dir.as_str(),
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
let mut owned_shortcut = shortcut.to_owned();
|
||||||
|
owned_shortcut.tags.push("EGS".to_owned());
|
||||||
|
|
||||||
|
owned_shortcut
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct SteamFolderNotFound {
|
struct SteamFolderNotFound {
|
||||||
location_tried: String,
|
location_tried: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user