diff --git a/src/egs/manifest_item.rs b/src/egs/manifest_item.rs index 4d5cb7a..c8ecd72 100644 --- a/src/egs/manifest_item.rs +++ b/src/egs/manifest_item.rs @@ -26,7 +26,7 @@ impl From for ShortcutOwned { manifest.install_location, manifest.launch_executable ); let mut start_dir = manifest.install_location.clone(); - if !manifest.install_location.starts_with("\"") { + if !manifest.install_location.starts_with('"') { start_dir = format!("\"{}\"", manifest.install_location); } let shortcut = Shortcut::new( diff --git a/src/gog/gog_platform.rs b/src/gog/gog_platform.rs index 86a030d..43d41bc 100644 --- a/src/gog/gog_platform.rs +++ b/src/gog/gog_platform.rs @@ -54,12 +54,10 @@ impl Platform for GogPlatform { if path.exists() { let dirs = path.read_dir(); if let Ok(dirs) = dirs { - for dir in dirs { - if let Ok(dir) = dir { - if let Ok(file_type) = dir.file_type() { - if file_type.is_dir() { - game_folders.push(dir.path()); - } + for dir in dirs.flatten() { + if let Ok(file_type) = dir.file_type() { + if file_type.is_dir() { + game_folders.push(dir.path()); } } } @@ -69,22 +67,18 @@ impl Platform for GogPlatform { let mut games = vec![]; for game_folder in &game_folders { if let Ok(files) = game_folder.read_dir() { - for file in files { - if let Ok(file) = file { - if let Some(file_name) = file.file_name().to_str() { - if file_name.starts_with("goggame-") { - if let Some(extension) = file.path().extension() { - if let Some(extension) = extension.to_str() { - if extension == "info" { - // Finally we know we can parse this as a game - if let Ok(content) = - std::fs::read_to_string(file.path()) + for file in files.flatten() { + if let Some(file_name) = file.file_name().to_str() { + if file_name.starts_with("goggame-") { + if let Some(extension) = file.path().extension() { + if let Some(extension) = extension.to_str() { + if extension == "info" { + // Finally we know we can parse this as a game + if let Ok(content) = std::fs::read_to_string(file.path()) { + if let Ok(gog_game) = + serde_json::from_str::(&content) { - if let Ok(gog_game) = - serde_json::from_str::(&content) - { - games.push((gog_game, game_folder)); - } + games.push((gog_game, game_folder)); } } } @@ -114,7 +108,7 @@ impl Platform for GogPlatform { Some(working_dir) => game_folder .join(working_dir) .to_str() - .unwrap_or(folder_path.as_str()) + .unwrap_or_else(|| folder_path.as_str()) .to_string(), None => folder_path.to_string(), }; diff --git a/src/itch/itch_platform.rs b/src/itch/itch_platform.rs index 60d3589..bf0207d 100644 --- a/src/itch/itch_platform.rs +++ b/src/itch/itch_platform.rs @@ -2,7 +2,6 @@ use super::butler_db_parser::*; use super::receipt::Receipt; use super::{ItchGame, ItchSettings}; use crate::platform::Platform; -use _core::iter::FromIterator; use failure::*; use flate2::read::GzDecoder; use std::collections::HashSet; @@ -50,7 +49,7 @@ impl Platform for ItchPlatform { }?; //This is done to remove douplicates - let paths: HashSet<&DbPaths> = HashSet::from_iter(paths.iter()); + let paths: HashSet<&DbPaths> = paths.iter().collect(); let res = paths.iter().filter_map(|e| dbpath_to_game(*e)).collect(); Ok(res) diff --git a/src/legendary/legendary_game.rs b/src/legendary/legendary_game.rs index a06e5f7..87b47dd 100644 --- a/src/legendary/legendary_game.rs +++ b/src/legendary/legendary_game.rs @@ -16,7 +16,7 @@ impl From for ShortcutOwned { let exe = format!("\"{}\\{}\"", game.install_path, game.executable); let launch = format!("legendary launch {}", game.app_name); let mut start_dir = game.install_path.clone(); - if !game.install_path.starts_with("\"") { + if !game.install_path.starts_with('"') { start_dir = format!("\"{}\"", game.install_path); } let shortcut = Shortcut::new( diff --git a/src/origin/origin_platform.rs b/src/origin/origin_platform.rs index 25039c9..2922da9 100644 --- a/src/origin/origin_platform.rs +++ b/src/origin/origin_platform.rs @@ -32,7 +32,7 @@ impl Platform for OriginPlatform { .settings .path .clone() - .unwrap_or_else(|| get_default_location()), + .unwrap_or_else(get_default_location), ) .join("LocalContent"); if !origin_folder.exists() { @@ -59,7 +59,7 @@ impl Platform for OriginPlatform { None => None, }; id.map(|id| OriginGame { - id: id.to_string(), + id, title: game_title, }) }); @@ -72,8 +72,7 @@ fn get_folder_mfst_file_content(game_folder_path: &Path) -> Option { if let Ok(game_folder_files) = game_folder_files { let mfst_file = game_folder_files .filter_map(|file| file.ok()) - .filter(is_mfst_file) - .next() + .find(is_mfst_file) .map(|file| std::fs::read_to_string(&file.path())); return match mfst_file { Some(mfst_file) => mfst_file.ok(), @@ -99,7 +98,6 @@ fn parse_id_from_file(i: &str) -> nom::IResult<&str, &str> { #[cfg(target_os = "linux")] pub fn get_default_location() -> String { - //TODO implement this for linux: // https://www.toptensoftware.com/blog/running-ea-origin-games-under-linux-via-steam-and-proton/ diff --git a/src/steamgriddb/downloader.rs b/src/steamgriddb/downloader.rs index 506ca09..9ac4b80 100644 --- a/src/steamgriddb/downloader.rs +++ b/src/steamgriddb/downloader.rs @@ -17,7 +17,7 @@ use super::CachedSearch; const CONCURRENT_REQUESTS: usize = 10; -pub async fn download_images_for_users<'b>(settings: &Settings, users: &Vec) { +pub async fn download_images_for_users<'b>(settings: &Settings, users: &[SteamUsersInfo]) { let auth_key = &settings.steamgrid_db.auth_key; if let Some(auth_key) = auth_key { println!("Checking for game images"); @@ -51,7 +51,7 @@ pub async fn download_images_for_users<'b>(settings: &Settings, users: &Vec(settings: &Settings, users: &Vec( +async fn search_fo_to_download( known_images: Vec, user_data_folder: &str, - shortcuts: &Vec, - search: &CachedSearch<'b>, + shortcuts: &[ShortcutOwned], + search: &CachedSearch<'_>, client: &Client, ) -> Result, Box> { let shortcuts_to_search_for = shortcuts.iter().filter(|s| { @@ -82,7 +82,7 @@ async fn search_fo_to_download<'b>( format!("{}_logo.png", s.app_id), ]; // if we are missing any of the images we need to search for them - images.iter().any(|image| !known_images.contains(&image)) && "" != s.app_name + images.iter().any(|image| !known_images.contains(image)) && !s.app_name.is_empty() }); let shortcuts_to_search_for: Vec<&ShortcutOwned> = shortcuts_to_search_for.collect(); if shortcuts_to_search_for.is_empty() { @@ -96,19 +96,15 @@ async fn search_fo_to_download<'b>( return None; } let search_result = search_result.unwrap(); - if search_result.is_none() { - return None; - } + search_result?; let search_result = search_result.unwrap(); Some((s.app_id, search_result)) }) .buffer_unordered(CONCURRENT_REQUESTS) .collect::>>() .await; - for r in search_results_a { - if let Some((app_id, search)) = r { - search_results.insert(app_id, search); - } + for (app_id, search) in search_results_a.into_iter().flatten() { + search_results.insert(app_id, search); } let types = vec![ImageType::Logo, ImageType::Hero, ImageType::Grid]; let mut to_download = vec![]; @@ -120,7 +116,7 @@ async fn search_fo_to_download<'b>( let image_ids: Vec = images_needed .clone() .filter_map(|s| search_results.get(&s.app_id)) - .map(|search| *search) + .copied() .collect(); use steamgriddb_api::query_parameters::QueryType::*; let query_type = match image_type { diff --git a/src/sync/mod.rs b/src/sync/mod.rs index 1b92daf..f7dfc0f 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -1,5 +1,5 @@ #[cfg(target_os = "linux")] mod symlinks; -mod sync; +mod synchronization; -pub use sync::run_sync; +pub use synchronization::run_sync; diff --git a/src/sync/sync.rs b/src/sync/synchronization.rs similarity index 93% rename from src/sync/sync.rs rename to src/sync/synchronization.rs index b3432a7..a1895eb 100644 --- a/src/sync/sync.rs +++ b/src/sync/synchronization.rs @@ -14,9 +14,9 @@ use crate::{gog::GogPlatform, itch::ItchPlatform, origin::OriginPlatform}; use std::{fs::File, io::Write, path::Path}; pub async fn run_sync(settings: &Settings) -> Result<(), Box> { - let userinfo_shortcuts = get_shortcuts_paths(&settings.steam)?; + let mut userinfo_shortcuts = get_shortcuts_paths(&settings.steam)?; println!("Found {} user(s)", userinfo_shortcuts.len()); - for user in userinfo_shortcuts.iter() { + for user in userinfo_shortcuts.iter_mut() { let start_time = std::time::Instant::now(); let mut shortcut_info = get_shortcuts_for_user(user); @@ -29,6 +29,7 @@ pub async fn run_sync(settings: &Settings) -> Result<(), Box> { update_platforms(settings, &mut shortcut_info.shortcuts); fix_shortcut_icons(user, &mut shortcut_info.shortcuts); save_shortcuts(&shortcut_info.shortcuts, Path::new(&shortcut_info.path)); + user.shortcut_path = Some(shortcut_info.path.to_string_lossy().to_string()); let duration = start_time.elapsed(); println!("Finished synchronizing games in: {:?}", duration); @@ -91,7 +92,7 @@ fn update_platforms(settings: &Settings, new_user_shortcuts: &mut Vec, path: &Path) { +fn save_shortcuts(shortcuts: &[ShortcutOwned], path: &Path) { let mut shortcuts_refs = vec![]; for shortcut in shortcuts { shortcuts_refs.push(shortcut.borrow()); @@ -99,7 +100,9 @@ fn save_shortcuts(shortcuts: &Vec, path: &Path) { let new_content = shortcuts_to_bytes(&shortcuts_refs); match File::create(path) { Ok(mut file) => match file.write_all(new_content.as_slice()) { - Ok(_) => println!("Saved {} shortcuts", shortcuts.len()), + Ok(_) => { + println!("Saved {} shortcuts", shortcuts.len()) + } Err(e) => println!( "Failed to save shortcuts to {} error: {}", path.to_string_lossy(), diff --git a/src/ui/ui.rs b/src/ui/ui.rs index 80ac0e3..7a04074 100644 --- a/src/ui/ui.rs +++ b/src/ui/ui.rs @@ -39,7 +39,6 @@ pub async fn run_ui() -> Result<(), Box> { Ok(()) } -#[cfg(feature = "ui")] fn empty_or_whitespace(input: String) -> Option { if input.trim().is_empty() { None @@ -47,7 +46,6 @@ fn empty_or_whitespace(input: String) -> Option { Some(input) } } -#[cfg(feature = "ui")] fn update_settings_with_ui_values(settings: &mut Settings, ui: &UserInterface) { // Steam location settings.steam.location = empty_or_whitespace(ui.steam_location_input.value()); @@ -78,14 +76,12 @@ fn update_settings_with_ui_values(settings: &mut Settings, ui: &UserInterface) { settings.gog.wine_c_drive = empty_or_whitespace(ui.gog_winedrive_input.value()); } -#[cfg(feature = "ui")] fn save_settings_to_file(settings: &Settings) { let toml = toml::to_string(&settings).unwrap(); std::fs::write("config.toml", toml).unwrap(); } -#[cfg(feature = "ui")] fn update_ui_with_settings(ui: &mut UserInterface, settings: &Settings) { use std::path::Path;