mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Add setting optional location for steam
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
debug= false
|
debug= false
|
||||||
|
|
||||||
|
[steam]
|
||||||
|
|
||||||
[steamgrid_db]
|
[steamgrid_db]
|
||||||
enabled = true
|
enabled = true
|
||||||
+1
-1
@@ -32,7 +32,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let client = steamgriddb_api::Client::new(auth_key);
|
let client = steamgriddb_api::Client::new(auth_key);
|
||||||
let mut search = CachedSearch::new(&client);
|
let mut search = CachedSearch::new(&client);
|
||||||
|
|
||||||
let userinfo_shortcuts = get_shortcuts_paths()?;
|
let userinfo_shortcuts = get_shortcuts_paths(&settings.steam)?;
|
||||||
println!("Found {} user(s)", userinfo_shortcuts.len());
|
println!("Found {} user(s)", userinfo_shortcuts.len());
|
||||||
|
|
||||||
for user in userinfo_shortcuts.iter() {
|
for user in userinfo_shortcuts.iter() {
|
||||||
|
|||||||
+2
-3
@@ -1,6 +1,4 @@
|
|||||||
use crate::{
|
use crate::{egs::EpicGamesLauncherSettings, legendary::LegendarySettings, steam::SteamSettings, steamgriddb::SteamGridDbSettings};
|
||||||
egs::EpicGamesLauncherSettings, legendary::LegendarySettings, steamgriddb::SteamGridDbSettings,
|
|
||||||
};
|
|
||||||
|
|
||||||
use config::{Config, ConfigError, Environment, File};
|
use config::{Config, ConfigError, Environment, File};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@@ -12,6 +10,7 @@ pub struct Settings {
|
|||||||
pub epic_games: EpicGamesLauncherSettings,
|
pub epic_games: EpicGamesLauncherSettings,
|
||||||
pub legendary: LegendarySettings,
|
pub legendary: LegendarySettings,
|
||||||
pub steamgrid_db: SteamGridDbSettings,
|
pub steamgrid_db: SteamGridDbSettings,
|
||||||
|
pub steam: SteamSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
//https://github.com/JosefNemec/Playnite/tree/master/source/Plugins/OriginLibrary
|
//https://github.com/JosefNemec/Playnite/tree/master/source/Plugins/OriginLibrary
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
mod utils;
|
mod utils;
|
||||||
|
mod settings;
|
||||||
|
|
||||||
pub use utils::*;
|
pub use utils::*;
|
||||||
|
pub use settings::SteamSettings;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
|
pub struct SteamSettings{
|
||||||
|
pub location: Option<String>,
|
||||||
|
}
|
||||||
+43
-26
@@ -1,17 +1,18 @@
|
|||||||
use std::error::Error;
|
|
||||||
use std::{
|
|
||||||
fmt,
|
|
||||||
path::Path,
|
|
||||||
};
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
use std::env::{self};
|
use std::env::{self};
|
||||||
|
use std::error::Error;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::{fmt, path::Path};
|
||||||
|
|
||||||
use steam_shortcuts_util::{parse_shortcuts, shortcut::ShortcutOwned};
|
use steam_shortcuts_util::{parse_shortcuts, shortcut::ShortcutOwned};
|
||||||
|
|
||||||
|
use super::SteamSettings;
|
||||||
|
|
||||||
pub fn get_shortcuts_for_user(user: &SteamUsersInfo) -> ShortcutInfo {
|
pub fn get_shortcuts_for_user(user: &SteamUsersInfo) -> ShortcutInfo {
|
||||||
let mut shortcuts = vec![];
|
let mut shortcuts = vec![];
|
||||||
let mut new_path = user.shortcut_path.clone();
|
|
||||||
if let Some(shortcut_path) = &user.shortcut_path {
|
let new_path = match &user.shortcut_path {
|
||||||
|
Some(shortcut_path) => {
|
||||||
let content = std::fs::read(shortcut_path).unwrap();
|
let content = std::fs::read(shortcut_path).unwrap();
|
||||||
shortcuts = parse_shortcuts(content.as_slice())
|
shortcuts = parse_shortcuts(content.as_slice())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -23,25 +24,27 @@ pub fn get_shortcuts_for_user(user: &SteamUsersInfo) -> ShortcutInfo {
|
|||||||
shortcuts.len(),
|
shortcuts.len(),
|
||||||
user.steam_user_data_folder
|
user.steam_user_data_folder
|
||||||
);
|
);
|
||||||
} else {
|
Path::new(&shortcut_path).to_path_buf()
|
||||||
|
}
|
||||||
|
None => {
|
||||||
println!(
|
println!(
|
||||||
"Did not find a shortcut file for user {}, createing a new",
|
"Did not find a shortcut file for user {}, creating a new",
|
||||||
user.steam_user_data_folder
|
user.steam_user_data_folder
|
||||||
);
|
);
|
||||||
std::fs::create_dir_all(format!("{}/{}", user.steam_user_data_folder, "config")).unwrap();
|
let path = Path::new(&user.steam_user_data_folder).join("config");
|
||||||
new_path = Some(format!(
|
std::fs::create_dir_all(path.clone()).unwrap();
|
||||||
"{}/{}",
|
path.join("shortcuts.vdf")
|
||||||
user.steam_user_data_folder, "config/shortcuts.vdf"
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ShortcutInfo {
|
ShortcutInfo {
|
||||||
shortcuts,
|
shortcuts,
|
||||||
path: new_path.unwrap(),
|
path: new_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ShortcutInfo {
|
pub struct ShortcutInfo {
|
||||||
pub path: String,
|
pub path: PathBuf,
|
||||||
pub shortcuts: Vec<ShortcutOwned>,
|
pub shortcuts: Vec<ShortcutOwned>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,28 +54,42 @@ pub struct SteamUsersInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the paths to the steam users shortcuts (one for each user)
|
/// Get the paths to the steam users shortcuts (one for each user)
|
||||||
pub fn get_shortcuts_paths() -> Result<Vec<SteamUsersInfo>, Box<dyn Error>> {
|
pub fn get_shortcuts_paths(
|
||||||
|
settings: &SteamSettings,
|
||||||
|
) -> Result<Vec<SteamUsersInfo>, Box<dyn Error>> {
|
||||||
|
let user_location = settings.location.clone();
|
||||||
|
let steam_path_str = match user_location {
|
||||||
|
Some(location) => location,
|
||||||
|
None => {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let path_string = {
|
let path_string = {
|
||||||
let key = "PROGRAMFILES(X86)";
|
let key = "PROGRAMFILES(X86)";
|
||||||
let program_files = env::var(key)?;
|
let program_files = env::var(key)?;
|
||||||
format!(
|
format!("{program_files}//Steam//", program_files = program_files)
|
||||||
"{program_files}//Steam//userdata//",
|
|
||||||
program_files = program_files
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
let path_string = {
|
let path_string = {
|
||||||
let home = std::env::var("HOME")?;
|
let home = std::env::var("HOME")?;
|
||||||
format!("{}/.steam/steam/userdata/", home)
|
format!("{}/.steam/steam/", home)
|
||||||
};
|
};
|
||||||
|
path_string
|
||||||
let user_data_path = Path::new(path_string.as_str());
|
}
|
||||||
if !user_data_path.exists() {
|
};
|
||||||
|
let steam_path = Path::new(&steam_path_str);
|
||||||
|
if !steam_path.exists() {
|
||||||
return Result::Err(Box::new(SteamFolderNotFound {
|
return Result::Err(Box::new(SteamFolderNotFound {
|
||||||
location_tried: path_string,
|
location_tried: format!("{:?}", steam_path),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let user_data_path = steam_path.join("userdata");
|
||||||
|
if !user_data_path.exists() {
|
||||||
|
return Result::Err(Box::new(SteamFolderNotFound {
|
||||||
|
location_tried: format!("{:?}", user_data_path),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if !user_data_path.exists() {}
|
||||||
let user_folders = std::fs::read_dir(&user_data_path)?;
|
let user_folders = std::fs::read_dir(&user_data_path)?;
|
||||||
let users_info = user_folders
|
let users_info = user_folders
|
||||||
.filter_map(|f| f.ok())
|
.filter_map(|f| f.ok())
|
||||||
|
|||||||
Reference in New Issue
Block a user