mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
UI image selection (#97)
This commit is contained in:
+22
-20
@@ -42,7 +42,7 @@ struct ActualSteamCollection {
|
||||
}
|
||||
|
||||
impl ActualSteamCollection {
|
||||
fn new<B: AsRef<str>>(name: B, ids: &Vec<usize>) -> Self {
|
||||
fn new<B: AsRef<str>>(name: B, ids: &[usize]) -> Self {
|
||||
let name = name.as_ref();
|
||||
let key = format!("user-collections.{}", name_to_key(name));
|
||||
let value = serialize_collection_value(name, ids);
|
||||
@@ -80,13 +80,13 @@ impl ValueCollection {
|
||||
fn new<S: AsRef<str>>(name: S, game_ids: &[usize]) -> Self {
|
||||
let name = name.as_ref();
|
||||
let id = name_to_key(name);
|
||||
let value = ValueCollection {
|
||||
|
||||
ValueCollection {
|
||||
id,
|
||||
name: name.to_string(),
|
||||
added: game_ids.to_vec(),
|
||||
removed: vec![],
|
||||
};
|
||||
value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ pub struct Collection {
|
||||
|
||||
pub fn write_collections<S: AsRef<str>>(
|
||||
steam_user_id: S,
|
||||
collections_to_add: &Vec<Collection>,
|
||||
collections_to_add: &[Collection],
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let steam_user_id = steam_user_id.as_ref();
|
||||
let new_collections: Vec<(String, SteamCollection)> = collections_to_add
|
||||
@@ -134,7 +134,7 @@ pub fn write_collections<S: AsRef<str>>(
|
||||
let boilr_keys: Vec<String> = vdf_collections
|
||||
.keys()
|
||||
.filter(|k| k.contains(BOILR_TAG))
|
||||
.map(|k| k.clone())
|
||||
.cloned()
|
||||
.collect();
|
||||
for key in boilr_keys {
|
||||
vdf_collections.remove(&key);
|
||||
@@ -142,12 +142,12 @@ pub fn write_collections<S: AsRef<str>>(
|
||||
|
||||
let new_vdfs = collections_to_add.iter().map(|collection| {
|
||||
let key = name_to_key(&collection.name);
|
||||
let vd_collection = VdfCollection {
|
||||
|
||||
VdfCollection {
|
||||
id: key,
|
||||
added: collection.game_ids.clone(),
|
||||
removed: vec![],
|
||||
};
|
||||
vd_collection
|
||||
}
|
||||
});
|
||||
for new_vdf in new_vdfs {
|
||||
vdf_collections.insert(new_vdf.id.clone(), new_vdf.clone());
|
||||
@@ -181,11 +181,11 @@ fn get_vdf_path<S: AsRef<str>>(steamid: S) -> Option<PathBuf> {
|
||||
.join("config")
|
||||
.join("localconfig.vdf");
|
||||
if path.exists() {
|
||||
return Some(path.to_path_buf());
|
||||
return Some(path);
|
||||
}
|
||||
return None;
|
||||
None
|
||||
}
|
||||
Err(_e) => return None,
|
||||
Err(_e) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ fn get_vdf_path<S: AsRef<str>>(steamid: S) -> Option<PathBuf> {
|
||||
.join("config")
|
||||
.join("localconfig.vdf");
|
||||
if path.exists() {
|
||||
Some(path.to_path_buf())
|
||||
Some(path)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -220,10 +220,12 @@ fn save_category<S: AsRef<str>>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
type CollectionCategories = HashMap<String, Vec<(String, SteamCollection)>>;
|
||||
|
||||
fn get_categories<S: AsRef<str>>(
|
||||
steamid: S,
|
||||
db: &mut DB,
|
||||
) -> Result<HashMap<String, Vec<(String, SteamCollection)>>, Box<dyn Error>> {
|
||||
) -> Result<CollectionCategories, Box<dyn Error>> {
|
||||
let namespace_keys = get_namespace_keys(steamid, db);
|
||||
let mut db_iter = db.new_iter()?;
|
||||
let mut res = HashMap::new();
|
||||
@@ -295,11 +297,11 @@ fn get_level_db_location() -> Option<PathBuf> {
|
||||
.join("Local Storage")
|
||||
.join("leveldb");
|
||||
if path.exists() {
|
||||
return Some(path.to_path_buf());
|
||||
return Some(path);
|
||||
}
|
||||
return None;
|
||||
None
|
||||
}
|
||||
Err(_e) => return None,
|
||||
Err(_e) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +316,7 @@ fn get_level_db_location() -> Option<PathBuf> {
|
||||
.join("leveldb");
|
||||
if path.exists() {
|
||||
Some(path)
|
||||
}else{
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -324,7 +326,7 @@ fn get_level_db_location() -> Option<PathBuf> {
|
||||
|
||||
fn serialize_collection_value<S: AsRef<str>>(name: S, game_ids: &[usize]) -> String {
|
||||
let value = ValueCollection::new(name, game_ids);
|
||||
serde_json::to_string(&value).expect("Should be able to serialize known type")
|
||||
serde_json::to_string(&value).expect("Should be able to serialize known type")
|
||||
}
|
||||
|
||||
fn name_to_key<S: AsRef<str>>(name: S) -> String {
|
||||
@@ -339,7 +341,7 @@ fn parse_steam_collections<S: AsRef<str>>(
|
||||
) -> Result<Vec<(String, SteamCollection)>, Box<dyn Error>> {
|
||||
let input = input.as_ref();
|
||||
let input = input.strip_prefix('\u{1}').unwrap_or(input);
|
||||
let res = serde_json::from_str::<Vec<(String, SteamCollection)>>(&input)?;
|
||||
let res = serde_json::from_str::<Vec<(String, SteamCollection)>>(input)?;
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
|
||||
+5
-6
@@ -1,12 +1,11 @@
|
||||
mod settings;
|
||||
mod utils;
|
||||
mod collections;
|
||||
mod proton_vdf_util;
|
||||
mod restarter;
|
||||
mod settings;
|
||||
mod utils;
|
||||
|
||||
|
||||
pub use settings::SteamSettings;
|
||||
pub use utils::*;
|
||||
pub use collections::*;
|
||||
pub use proton_vdf_util::*;
|
||||
pub use restarter::*;
|
||||
pub use restarter::*;
|
||||
pub use settings::SteamSettings;
|
||||
pub use utils::*;
|
||||
|
||||
@@ -2,19 +2,16 @@ use std::path::Path;
|
||||
|
||||
use nom::FindSubstring;
|
||||
|
||||
|
||||
pub fn setup_proton_games<B: AsRef<str>>(games: &[B]){
|
||||
if let Ok(home) = std::env::var("HOME"){
|
||||
pub fn setup_proton_games<B: AsRef<str>>(games: &[B]) {
|
||||
if let Ok(home) = std::env::var("HOME") {
|
||||
let config_file = Path::new(&home).join(".local/share/Steam/config/config.vdf");
|
||||
if config_file.exists(){
|
||||
if let Ok(config_content) = std::fs::read_to_string(&config_file){
|
||||
if config_file.exists() {
|
||||
if let Ok(config_content) = std::fs::read_to_string(&config_file) {
|
||||
let new_string = enable_proton_games(config_content, games);
|
||||
std::fs::write(config_file, new_string).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn enable_proton_games<S: AsRef<str>, B: AsRef<str>>(vdf_content: S, games: &[B]) -> String {
|
||||
@@ -44,7 +41,6 @@ fn enable_proton_games<S: AsRef<str>, B: AsRef<str>>(vdf_content: S, games: &[B]
|
||||
let res = res.replace("\"X\"", &format!("\"{}\"", game_id.as_ref()));
|
||||
let res = res.replace('=', &base_indent_string);
|
||||
res.replace('+', &field_indent_string)
|
||||
|
||||
});
|
||||
let mut new_section = section_str.to_string();
|
||||
for game_string in games_strings_to_add {
|
||||
@@ -116,22 +112,21 @@ mod tests {
|
||||
let expected = include_str!("../testdata/vdf/compatmappingsection.vdf");
|
||||
assert_eq!(expected, actual);
|
||||
assert_eq!(4, base_indentation);
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn enable_proton_test() {
|
||||
let input = include_str!("../testdata/vdf/testconfig.vdf");
|
||||
let output = enable_proton_games(input, &vec!["42", "43", "44"]);
|
||||
let output = enable_proton_games(input, &["42", "43", "44"]);
|
||||
let expected = include_str!("../testdata/vdf/testconfig_expected.vdf");
|
||||
assert_eq!(expected,output );
|
||||
assert_eq!(expected, output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn enable_proton_test_empty() {
|
||||
let input = include_str!("../testdata/vdf/testconfig.vdf");
|
||||
let output = enable_proton_games(input, &vec!["2719403116"]);
|
||||
let output = enable_proton_games(input, &["2719403116"]);
|
||||
let expected = include_str!("../testdata/vdf/testconfig.vdf");
|
||||
assert_eq!(expected,output );
|
||||
assert_eq!(expected, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{path::Path, process::Command, thread::sleep, time::Duration};
|
||||
use std::{process::Command, thread::sleep, time::Duration};
|
||||
|
||||
use sysinfo::{ProcessExt, System, SystemExt};
|
||||
|
||||
@@ -7,9 +7,9 @@ pub fn ensure_steam_stopped() {
|
||||
let steam_name = "steam.exe";
|
||||
#[cfg(target_family = "unix")]
|
||||
let steam_name = "steam";
|
||||
|
||||
|
||||
let s = System::new_all();
|
||||
let processes = s.processes_by_name(&steam_name);
|
||||
let processes = s.processes_by_name(steam_name);
|
||||
for process in processes {
|
||||
let mut s = System::new();
|
||||
process.kill_with(sysinfo::Signal::Quit);
|
||||
@@ -26,13 +26,13 @@ pub fn ensure_steam_stopped() {
|
||||
pub fn ensure_steam_started(settings: &super::SteamSettings) {
|
||||
let steam_name = "steam.exe";
|
||||
let s = System::new_all();
|
||||
let mut processes = s.processes_by_name(&steam_name);
|
||||
let mut processes = s.processes_by_name(steam_name);
|
||||
if processes.next().is_none() {
|
||||
//no steam, we need to start it
|
||||
println!("Starting steam");
|
||||
let folder = super::get_steam_path(settings);
|
||||
if let Ok(folder) = folder {
|
||||
let path = Path::new(&folder).join(steam_name);
|
||||
let path = std::path::Path::new(&folder).join(steam_name);
|
||||
let mut command = Command::new(&path);
|
||||
if let Err(e) = command.spawn() {
|
||||
println!("Failed to start steam: {:?}", e);
|
||||
@@ -45,7 +45,7 @@ pub fn ensure_steam_started(settings: &super::SteamSettings) {
|
||||
pub fn ensure_steam_started(_settings: &super::SteamSettings) {
|
||||
let steam_name = "steam";
|
||||
let s = System::new_all();
|
||||
let mut processes = s.processes_by_name(&steam_name);
|
||||
let mut processes = s.processes_by_name(steam_name);
|
||||
if processes.next().is_none() {
|
||||
//no steam, we need to start it
|
||||
println!("Starting steam");
|
||||
@@ -54,4 +54,4 @@ pub fn ensure_steam_started(_settings: &super::SteamSettings) {
|
||||
println!("Failed to start steam: {:?}", e);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-8
@@ -43,10 +43,11 @@ pub struct ShortcutInfo {
|
||||
pub shortcuts: Vec<ShortcutOwned>,
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq, Clone)]
|
||||
pub struct SteamUsersInfo {
|
||||
pub steam_user_data_folder: String,
|
||||
pub shortcut_path: Option<String>,
|
||||
pub user_id : String,
|
||||
pub user_id: String,
|
||||
}
|
||||
|
||||
/// Get the paths to the steam users shortcuts (one for each user)
|
||||
@@ -89,14 +90,14 @@ pub fn get_shortcuts_paths(
|
||||
return SteamUsersInfo {
|
||||
steam_user_data_folder: folder_string,
|
||||
shortcut_path: Some(shortcuts_path.to_str().unwrap().to_string()),
|
||||
user_id
|
||||
user_id,
|
||||
};
|
||||
} else {
|
||||
return SteamUsersInfo {
|
||||
SteamUsersInfo {
|
||||
steam_user_data_folder: folder_string,
|
||||
shortcut_path: None,
|
||||
user_id
|
||||
};
|
||||
user_id,
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
@@ -203,6 +204,3 @@ pub fn get_users_images(user: &SteamUsersInfo) -> Result<Vec<String>, Box<dyn Er
|
||||
.collect();
|
||||
Ok(file_names)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user