diff --git a/src/amazon/amazon_game.rs b/src/amazon/amazon_game.rs index 67d90b6..1014886 100644 --- a/src/amazon/amazon_game.rs +++ b/src/amazon/amazon_game.rs @@ -13,7 +13,7 @@ impl From for ShortcutOwned { fn from(game: AmazonGame) -> Self { let launch = format!("amazon-games://play/{}", game.id); let exe = game.launcher_path.to_string_lossy().to_string(); - let start_dir= game.launcher_path.parent().unwrap_or(Path::new("")).to_string_lossy().to_string(); + let start_dir= game.launcher_path.parent().unwrap_or_else(||Path::new("")).to_string_lossy().to_string(); Shortcut::new("0", game.title.as_str(), exe.as_str(), start_dir.as_str(), "", "", launch.as_str()).to_owned() } } diff --git a/src/config.rs b/src/config.rs index 5991f64..21ed4ba 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,7 +18,7 @@ pub fn get_config_folder() -> PathBuf { pub fn get_config_folder() -> PathBuf { let config_home = std::env::var("APPDATA"); match config_home { - Ok(p) => Path::new(&p).join("boilr").to_path_buf(), + Ok(p) => Path::new(&p).join("boilr"), Err(_) => Path::new("").to_path_buf(), } } @@ -26,21 +26,21 @@ pub fn get_config_folder() -> PathBuf { pub fn get_thumbnails_folder() -> PathBuf { let thumbnails_path = get_config_folder().join("thumbnails"); let _ = create_dir_all(&thumbnails_path); - thumbnails_path.to_path_buf() + thumbnails_path } pub fn get_config_file() -> PathBuf { - get_config_folder().join("config.toml").to_path_buf() + get_config_folder().join("config.toml") } pub fn get_cache_file() -> PathBuf { - get_config_folder().join("cache.json").to_path_buf() + get_config_folder().join("cache.json") } pub fn get_backups_flder() -> PathBuf { let backups_path = get_config_folder().join("backup"); let _ = create_dir_all(&backups_path); - backups_path.to_path_buf() + backups_path } #[cfg(target_family = "unix")] diff --git a/src/egs/get_manifests.rs b/src/egs/get_manifests.rs index 437b728..0b37ca6 100644 --- a/src/egs/get_manifests.rs +++ b/src/egs/get_manifests.rs @@ -1,6 +1,4 @@ use super::{EpicGamesLauncherSettings, ManifestItem}; -#[cfg(target_os = "windows")] -use std::env::{self}; use std::fs::{DirEntry, File}; use std::io::BufReader; diff --git a/src/egs/manifest_item.rs b/src/egs/manifest_item.rs index a174d2f..c479491 100644 --- a/src/egs/manifest_item.rs +++ b/src/egs/manifest_item.rs @@ -94,7 +94,7 @@ fn launcher_shortcut(manifest: ManifestItem) -> ShortcutOwned { .as_ref() .map(|p| { p.parent() - .unwrap_or(Path::new("")) + .unwrap_or_else(||Path::new("")) .to_string_lossy() .to_string() }) diff --git a/src/origin/origin_game.rs b/src/origin/origin_game.rs index 8c69f9d..0fdc21e 100644 --- a/src/origin/origin_game.rs +++ b/src/origin/origin_game.rs @@ -14,7 +14,7 @@ impl From for ShortcutOwned { fn from(game: OriginGame) -> Self { let launch = match game.origin_compat_folder{ Some(compat_folder) => - format!("STEAM_COMPAT_DATA_PATH=\"{}\" %command% \"origin2://game/launch?offerIds={}&autoDownload=1&authCode=&cmdParams=\"", compat_folder.to_string_lossy().to_string(), game.id) + format!("STEAM_COMPAT_DATA_PATH=\"{}\" %command% \"origin2://game/launch?offerIds={}&autoDownload=1&authCode=&cmdParams=\"", compat_folder.to_string_lossy(), game.id) , None => format!( "\"origin2://game/launch?offerIds={}&autoDownload=1&authCode=&cmdParams=\"", diff --git a/src/origin/origin_platform.rs b/src/origin/origin_platform.rs index e65308d..3e96da4 100644 --- a/src/origin/origin_platform.rs +++ b/src/origin/origin_platform.rs @@ -174,10 +174,11 @@ fn get_default_locations() -> Option { return None; } let exe_path = get_exe_path(); - if exe_path.is_none() { - return None; - } else { - res.exe_path = exe_path.unwrap(); + match exe_path { + Some(exe_path) => { + res.exe_path = exe_path; + } + None => return None, } } Some(res) @@ -194,7 +195,7 @@ fn get_exe_path() -> Option { let launcher_string: Result = launcher_key.get_value(""); if let Ok(launcher_string) = launcher_string { let path = Path::new(&launcher_string[1..launcher_string.len() - 6]); - println!("{:?}",path); + println!("{:?}", path); if path.exists() { return Some(path.to_path_buf()); } diff --git a/src/steam/installed_games.rs b/src/steam/installed_games.rs index 4477aa8..c671ed7 100644 --- a/src/steam/installed_games.rs +++ b/src/steam/installed_games.rs @@ -1,4 +1,7 @@ -use std::{ffi::OsStr, path::{Path, PathBuf}}; +use std::{ + ffi::OsStr, + path::{Path, PathBuf}, +}; use super::{get_steam_path, SteamSettings}; @@ -9,21 +12,19 @@ pub struct SteamGameInfo { } pub fn get_installed_games(settings: &SteamSettings) -> Vec { - let install_folders = get_install_folders(settings); + let install_folders = get_install_folders(settings); let mut games = vec![]; for apps_path in install_folders { - if let Ok(files) = std::fs::read_dir(apps_path) { - for file in files { - if let Ok(file) = file { - if let Some(game_info) = parse_manifest_file(&file.path()) { - games.push(game_info); - } + if let Ok(files) = std::fs::read_dir(apps_path) { + for file in files.flatten() { + if let Some(game_info) = parse_manifest_file(&file.path()) { + games.push(game_info); } } } } games.sort_by_key(|g| g.name.clone()); - return games; + games } fn get_install_folders(settings: &SteamSettings) -> Vec { @@ -33,7 +34,7 @@ fn get_install_folders(settings: &SteamSettings) -> Vec { let vdf_path = path.join("steamapps").join("libraryfolders.vdf"); if !vdf_path.exists() { - result.push(path.join("steamapps").to_path_buf()); + result.push(path.join("steamapps")); return result; } if let Ok(vdf_file) = std::fs::read_to_string(vdf_path) { @@ -45,8 +46,8 @@ fn get_install_folders(settings: &SteamSettings) -> Vec { } } } - - return result; + + result } fn parse_manifest_file(path: &Path) -> Option { diff --git a/src/ui/ui_backup.rs b/src/ui/ui_backup.rs index d122180..9b3a904 100644 --- a/src/ui/ui_backup.rs +++ b/src/ui/ui_backup.rs @@ -35,7 +35,7 @@ impl MyEguiApp { let available_backups = self .backup_state .available_backups - .get_or_insert_with(|| load_backups()); + .get_or_insert_with(load_backups); if available_backups.is_empty() { ui.label("No backups found, they will be created every time you run import"); @@ -58,8 +58,6 @@ impl MyEguiApp { } }); } - - } } @@ -77,7 +75,7 @@ pub fn restore_backup(steam_settings: &SteamSettings, shortcut_path: &Path) -> b } } } - return false; + false } pub fn load_backups() -> Vec { @@ -85,28 +83,26 @@ pub fn load_backups() -> Vec { let files = std::fs::read_dir(&backup_folder); let mut result = vec![]; if let Ok(files) = files { - for file in files { - if let Ok(file) = file { - if file - .path() - .extension() - .unwrap_or_default() - .to_string_lossy() - == "vdf" - { - result.push(file.path().to_path_buf()); - } + for file in files.flatten() { + if file + .path() + .extension() + .unwrap_or_default() + .to_string_lossy() + == "vdf" + { + result.push(file.path().to_path_buf()); } } } result.sort(); result.reverse(); - return result; + result } pub fn backup_shortcuts(steam_settings: &SteamSettings) { let backup_folder = get_backups_flder(); - let paths = get_shortcuts_paths(&steam_settings); + let paths = get_shortcuts_paths(steam_settings); let date = Local::now(); let date_string = date.format("%Y-%m-%d-%H-%M-%S"); if let Ok(user_infos) = paths { diff --git a/src/ui/ui_image_download.rs b/src/ui/ui_image_download.rs index 1105aba..5653a58 100644 --- a/src/ui/ui_image_download.rs +++ b/src/ui/ui_image_download.rs @@ -148,17 +148,14 @@ impl MyEguiApp { if let Some(value) = render_possible_names(possible_names, ui) { return value; } - } else { - if let Some(image_type) = state.image_type_selected.as_ref() { + } else if let Some(image_type) = state.image_type_selected.as_ref() { if let Some(action) = self.render_possible_images(ui, image_type, state) { return action; } - } else { - if let Some(action) = render_shortcut_images(ui, state) { - return action; - } - } + } else if let Some(action) = render_shortcut_images(ui, state) { + return action; } + } else { let is_shortcut = state.game_mode.is_shortcuts(); if ui @@ -178,11 +175,10 @@ impl MyEguiApp { if let Some(action) = self.render_shortcut_select(ui) { return action; } - } else { - if let Some(action) = render_steam_game_select(ui, state) { + } else if let Some(action) = render_steam_game_select(ui, state) { return action; - } } + } UserAction::NoAction } @@ -201,14 +197,11 @@ impl MyEguiApp { let texture = self.image_selected_state.image_handles.get(&key); let mut clicked = false; if let Some(texture) = texture { - match &texture.value() { - TextureState::Loaded(texture) => { - let mut size = texture.size_vec2(); - clamp_to_width(&mut size, 100.); - let image_button = ImageButton::new(texture, size); - clicked = clicked || ui.add(image_button).clicked(); - } - _ => {} + if let TextureState::Loaded(texture) = &texture.value() { + let mut size = texture.size_vec2(); + clamp_to_width(&mut size, 100.); + let image_button = ImageButton::new(texture, size); + clicked = clicked || ui.add(image_button).clicked(); } } @@ -241,7 +234,7 @@ impl MyEguiApp { .on_hover_text("Click here to clear the image") .clicked() { - return Some(UserAction::ImageTypeCleared(image_type.clone(), false)); + return Some(UserAction::ImageTypeCleared(*image_type, false)); } if ui @@ -249,7 +242,7 @@ impl MyEguiApp { .on_hover_text("Stop downloading this type of image for this shortcut at all") .clicked() { - return Some(UserAction::ImageTypeCleared(image_type.clone(), true)); + return Some(UserAction::ImageTypeCleared(*image_type, true)); } match &*state.image_options.borrow() { FetcStatus::Fetched(images) => { @@ -428,7 +421,7 @@ impl MyEguiApp { .image_selected_state .selected_shortcut .as_ref() - .map(|s| s.name().clone()) + .map(|s| s.name()) .unwrap_or_default(); let auth_key = self .settings @@ -437,7 +430,7 @@ impl MyEguiApp { .clone() .unwrap_or_default(); let client = steamgriddb_api::Client::new(&auth_key); - let search_results = self.rt.block_on(client.search(&app_name)); + let search_results = self.rt.block_on(client.search(app_name)); self.image_selected_state.possible_names = search_results.ok(); } @@ -452,7 +445,7 @@ impl MyEguiApp { let client = steamgriddb_api::Client::new(auth_key); let mut cache = CachedSearch::new(&client); if let Some(shortcut) = &self.image_selected_state.selected_shortcut { - cache.set_cache(shortcut.app_id(), shortcut.name().clone(), grid_id); + cache.set_cache(shortcut.app_id(), shortcut.name(), grid_id); cache.save(); } } @@ -571,14 +564,11 @@ impl MyEguiApp { } fn clear_loaded_images(&mut self) { - match &*self.image_selected_state.image_options.borrow() { - FetcStatus::Fetched(options) => { - for option in options { - let key = option.thumbnail_path.to_string_lossy().to_string(); - self.image_selected_state.image_handles.remove(&key); - } + if let FetcStatus::Fetched(options) = &*self.image_selected_state.image_options.borrow() { + for option in options { + let key = option.thumbnail_path.to_string_lossy().to_string(); + self.image_selected_state.image_handles.remove(&key); } - _ => {} } } @@ -598,7 +588,7 @@ impl MyEguiApp { state.selected_shortcut = Some(shortcut.clone()); for image_type in ImageType::all() { - let (path, key) = shortcut.key(image_type, &Path::new(&user.steam_user_data_folder)); + let (path, key) = shortcut.key(image_type, Path::new(&user.steam_user_data_folder)); let image = load_image_from_path(&path); if let Some(image) = image { let texture = ui.ctx().load_texture(&key, image); @@ -669,15 +659,14 @@ fn render_shortcut_images(ui: &mut egui::Ui, state: &ImageSelectState) -> Option let user_path = &state.steam_user.as_ref().unwrap().steam_user_data_folder; for image_type in ImageType::all() { ui.label(image_type.name()); - let (_path, key) = shortcut.key(&image_type, Path::new(&user_path)); + let (_path, key) = shortcut.key(image_type, Path::new(&user_path)); let texture = state .image_handles .get(&key) - .map(|k| match k.value() { + .and_then(|k| match k.value() { TextureState::Loaded(texture) => Some(texture.clone()), _ => None, - }) - .flatten(); + }); let clicked = render_thumbnail(ui, texture); if clicked { return Some(UserAction::ImageTypeSelected(*image_type)); @@ -728,7 +717,7 @@ fn clamp_to_width(size: &mut egui::Vec2, max_width: f32) { trait HasImageKey { fn key(&self, image_type: &ImageType, user_path: &Path) -> (PathBuf, String); } -const POSSIBLE_EXTENSIONS: [&'static str; 4] = ["png", "jpg", "ico", "webp"]; +const POSSIBLE_EXTENSIONS: [&str; 4] = ["png", "jpg", "ico", "webp"]; impl HasImageKey for GameType { fn key(&self, image_type: &ImageType, user_path: &Path) -> (PathBuf, String) { @@ -744,7 +733,7 @@ impl HasImageKey for SteamGameInfo { .iter() .map(|ext| key_from_extension(self.appid, image_type, user_path, ext)); let first = keys.next().unwrap(); - let other = keys.filter(|(exsists, _, _)| *exsists).next(); + let other = keys.find(|(exsists, _, _)| *exsists); let (_, path, key) = other.unwrap_or(first); (path, key) } @@ -756,7 +745,7 @@ impl HasImageKey for ShortcutOwned { .iter() .map(|ext| key_from_extension(self.app_id, image_type, user_path, ext)); let first = keys.next().unwrap(); - let other = keys.filter(|(exsists, _, _)| *exsists).next(); + let other = keys.find(|(exsists, _, _)| *exsists); let (_, path, key) = other.unwrap_or(first); (path, key) } diff --git a/src/ui/ui_settings.rs b/src/ui/ui_settings.rs index 9b97d20..c27ecf2 100644 --- a/src/ui/ui_settings.rs +++ b/src/ui/ui_settings.rs @@ -86,8 +86,7 @@ self.settings.heroic.default_launch_through_heroic{ let heroic_platform =HeroicPlatform{ settings:heroic_setting }; - let heroic_games = heroic_platform.get_heroic_games(&install_modes); - heroic_games + heroic_platform.get_heroic_games(&install_modes) }); let safe_open_games = &mut self.settings.heroic.launch_games_through_heroic; @@ -243,12 +242,10 @@ self.settings.heroic.default_launch_through_heroic{ self.settings.steamgrid_db.auth_key = Some(auth_key.to_string()); } } - if auth_key.is_empty() { - if ui.button("Paste from clipboard").clicked() { - if let Ok(mut clipboard_ctx) = copypasta::ClipboardContext::new() { - if let Ok(content) = clipboard_ctx.get_contents() { - self.settings.steamgrid_db.auth_key = Some(content.clone()); - } + if auth_key.is_empty() && ui.button("Paste from clipboard").clicked(){ + if let Ok(mut clipboard_ctx) = copypasta::ClipboardContext::new() { + if let Ok(content) = clipboard_ctx.get_contents() { + self.settings.steamgrid_db.auth_key = Some(content); } } } diff --git a/src/uplay/game.rs b/src/uplay/game.rs index 071659f..efd2ad0 100644 --- a/src/uplay/game.rs +++ b/src/uplay/game.rs @@ -13,7 +13,7 @@ pub(crate) struct Game { impl From for ShortcutOwned { fn from(game: Game) -> Self { let launch = format!("\"uplay://launch/{}/0\"", game.id); - let start_dir = game.launcher.parent().unwrap_or(Path::new("")).to_string_lossy(); + let start_dir = game.launcher.parent().unwrap_or_else(|| {Path::new("")}).to_string_lossy(); let exe = format!("\"{}\"",game.launcher.to_string_lossy()); Shortcut::new("0", &game.name, &exe, &start_dir, &game.icon, "", &launch).to_owned() } diff --git a/src/uplay/platform.rs b/src/uplay/platform.rs index 1271252..b29a3b8 100644 --- a/src/uplay/platform.rs +++ b/src/uplay/platform.rs @@ -29,18 +29,18 @@ impl Platform> for Uplay { #[cfg(target_family = "unix")] { //Linux not supported yet - return crate::platform::SettingsValidity::Invalid { + crate::platform::SettingsValidity::Invalid { reason: "Linux not supported yet".to_string(), - }; + } } #[cfg(target_os = "windows")] { if get_launcher_path().is_some() { - return crate::platform::SettingsValidity::Valid; + crate::platform::SettingsValidity::Valid } else { - return crate::platform::SettingsValidity::Invalid { + crate::platform::SettingsValidity::Invalid { reason: "Could not find UPlay instalation".to_string(), - }; + } } } } @@ -82,7 +82,7 @@ fn get_launcher_path() -> Option { if let Ok(launcher_dir) = launcher_dir { let path = Path::new(&launcher_dir).join("upc.exe"); if path.exists() { - return Some(path.to_path_buf()); + return Some(path); } } }