From 4ed9490c572b4cc16b3cb98bdfbc21468d24a7ea Mon Sep 17 00:00:00 2001 From: Philip Kristoffersen Date: Wed, 4 Jan 2023 20:28:43 +0100 Subject: [PATCH] Clippy fixes (#309) * Automatic clippy fixes * Manual clippy corrections --- src/main.rs | 2 +- src/platforms/egs/get_manifests.rs | 12 ++++++------ src/platforms/egs/paths.rs | 2 +- src/platforms/gog/gog_game.rs | 2 +- src/platforms/gog/gog_platform.rs | 4 ++-- src/platforms/itch/itch_platform.rs | 4 ++-- src/platforms/minigalaxy/platform.rs | 6 ++---- src/platforms/origin/origin_platform.rs | 4 ++-- src/steam/collections.rs | 2 +- src/steam/restarter.rs | 2 +- src/steamgriddb/cached_search.rs | 2 +- src/sync/symlinks.rs | 4 ++-- src/ui/components/game_image_button.rs | 2 +- src/ui/components/steam_user_select.rs | 14 ++++++-------- src/ui/defines.rs | 6 +++--- src/ui/images/hasimagekey.rs | 2 +- src/ui/images/pages/change_grid_db_id.rs | 2 +- src/ui/images/pages/pick_new_image.rs | 2 +- src/ui/images/ui_image_download.rs | 8 ++++---- src/ui/ui_backup.rs | 4 ++-- src/ui/uiapp.rs | 2 +- 21 files changed, 42 insertions(+), 46 deletions(-) diff --git a/src/main.rs b/src/main.rs index d59d763..3937b64 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,5 +25,5 @@ fn main() -> Result<()> { fn ensure_config_folder() { let path = config::get_config_folder(); - let _ = std::fs::create_dir_all(&path); + let _ = std::fs::create_dir_all(path); } diff --git a/src/platforms/egs/get_manifests.rs b/src/platforms/egs/get_manifests.rs index 94247be..3e1add6 100644 --- a/src/platforms/egs/get_manifests.rs +++ b/src/platforms/egs/get_manifests.rs @@ -71,18 +71,18 @@ fn get_manifest_item(dir_entry: DirEntry, _path: Option) -> Option for ShortcutOwned { fn from(gogs: GogShortcut) -> Self { let exe = Path::new(&gogs.game_folder).join(gogs.path); let icon_file = format!("goggame-{}.ico", gogs.game_id); - let icon_path = Path::new(&gogs.game_folder).join(&icon_file); + let icon_path = Path::new(&gogs.game_folder).join(icon_file); let icon = if icon_path.exists() { icon_path.to_str().unwrap().to_string() } else { diff --git a/src/platforms/gog/gog_platform.rs b/src/platforms/gog/gog_platform.rs index 99a6abb..50194f3 100644 --- a/src/platforms/gog/gog_platform.rs +++ b/src/platforms/gog/gog_platform.rs @@ -86,7 +86,7 @@ fn get_shortcuts_from_games(games: Vec<(GogGame, PathBuf)>) -> Vec || t.category.as_ref().unwrap_or(&String::from("")) == "game") }) { if let Some(task_path) = &primary_task.path { - let full_path = game_folder.join(&task_path); + let full_path = game_folder.join(task_path); if let Some(full_path) = full_path.to_str() { let folder_path = folder_path.to_string(); @@ -201,7 +201,7 @@ fn fix_paths(wine_c_drive: &str, paths: Vec) -> Vec { } fn get_install_locations(path: PathBuf) -> eyre::Result> { - let data_res = std::fs::read_to_string(&path)?; + let data_res = std::fs::read_to_string(path)?; let config: GogConfig = serde_json::from_str(&data_res)?; let path_vec = match config.library_path { Some(path) => vec![path], diff --git a/src/platforms/itch/itch_platform.rs b/src/platforms/itch/itch_platform.rs index c51d6da..914dea9 100644 --- a/src/platforms/itch/itch_platform.rs +++ b/src/platforms/itch/itch_platform.rs @@ -42,7 +42,7 @@ impl ItchPlatform { //This is done to paths dedupe let paths: HashSet<&DbPaths> = paths.iter().collect(); - let res = paths.iter().filter_map(|e| dbpath_to_game(*e)).collect(); + let res = paths.iter().filter_map(|e| dbpath_to_game(e)).collect(); Ok(res) } } @@ -57,7 +57,7 @@ fn dbpath_to_game(paths: &DbPaths) -> Option { paths .paths .iter() - .filter(|p| Path::new(&paths.base_path).join(&p).is_executable()) + .filter(|p| Path::new(&paths.base_path).join(p).is_executable()) .find_map(|executable| { let gz_bytes = std::fs::read(&recipt).unwrap(); let mut d = GzDecoder::new(gz_bytes.as_slice()); diff --git a/src/platforms/minigalaxy/platform.rs b/src/platforms/minigalaxy/platform.rs index d933e20..faca934 100644 --- a/src/platforms/minigalaxy/platform.rs +++ b/src/platforms/minigalaxy/platform.rs @@ -80,10 +80,8 @@ impl GamesPlatform for MiniGalaxyPlatform{ }; let dirs = games_folder.read_dir()?; let mut game_folders = vec![]; - for game_folder in dirs{ - if let Ok(game_folder) = game_folder{ - game_folders.push(game_folder.path().to_owned()); - } + for game_folder in dirs.flatten(){ + game_folders.push(game_folder.path().to_owned()); } let gog_games = crate::platforms::get_gog_shortcuts_from_game_folders(game_folders); crate::platforms::to_shortcuts(self, Ok(gog_games)) diff --git a/src/platforms/origin/origin_platform.rs b/src/platforms/origin/origin_platform.rs index e70112c..7cce76c 100644 --- a/src/platforms/origin/origin_platform.rs +++ b/src/platforms/origin/origin_platform.rs @@ -68,7 +68,7 @@ fn get_folder_mfst_file_content(game_folder_path: &Path) -> Option { let mfst_file = game_folder_files .filter_map(|file| file.ok()) .find(is_mfst_file) - .map(|file| std::fs::read_to_string(&file.path())); + .map(|file| std::fs::read_to_string(file.path())); return match mfst_file { Some(mfst_file) => mfst_file.ok(), None => None, @@ -111,7 +111,7 @@ fn get_default_locations() -> Option { .join("steamapps") .join("compatdata"); - if let Ok(compat_folder) = std::fs::read_dir(&compat_folder_path) { + if let Ok(compat_folder) = std::fs::read_dir(compat_folder_path) { for dir in compat_folder.flatten() { let origin_exe_path = dir .path() diff --git a/src/steam/collections.rs b/src/steam/collections.rs index e3bde76..9c7bd20 100644 --- a/src/steam/collections.rs +++ b/src/steam/collections.rs @@ -154,7 +154,7 @@ pub fn write_collections>( } let new_string = write_vdf_collection_to_string( - &path.clone().to_string_lossy(), + path.clone().to_string_lossy(), &vdf_collections, ); if let Some(new_string) = new_string { diff --git a/src/steam/restarter.rs b/src/steam/restarter.rs index da3f137..1c7bbcb 100644 --- a/src/steam/restarter.rs +++ b/src/steam/restarter.rs @@ -49,7 +49,7 @@ pub fn ensure_steam_started(_settings: &super::SteamSettings) { if processes.next().is_none() { //no steam, we need to start it println!("Starting steam"); - let mut command = Command::new(&steam_name); + let mut command = Command::new(steam_name); if let Err(e) = command.spawn() { println!("Failed to start steam: {:?}", e); }; diff --git a/src/steamgriddb/cached_search.rs b/src/steamgriddb/cached_search.rs index 4e89f28..7f6c2fc 100644 --- a/src/steamgriddb/cached_search.rs +++ b/src/steamgriddb/cached_search.rs @@ -68,6 +68,6 @@ fn get_search_map() -> SearchMap { fn save_search_map(search_map: &SearchMap) { let string = serde_json::to_string(search_map).unwrap(); let path = get_cache_file(); - let mut file = File::create(&path).unwrap(); + let mut file = File::create(path).unwrap(); file.write_all(string.as_bytes()).unwrap(); } diff --git a/src/sync/symlinks.rs b/src/sync/symlinks.rs index 9e0d13c..fcac345 100644 --- a/src/sync/symlinks.rs +++ b/src/sync/symlinks.rs @@ -15,8 +15,8 @@ pub fn create_sym_links(shortcut: &ShortcutOwned) -> ShortcutOwned { use std::os::unix::fs::symlink; // If the links exsists, then they must point towards what is needed, otherwise they would have a different app id - let target_ok = target_link.exists() || symlink(&target_original, &target_link).is_ok(); - let workdir_ok = workdir_link.exists() || symlink(&workdir_original, &workdir_link).is_ok(); + let target_ok = target_link.exists() || symlink(target_original, &target_link).is_ok(); + let workdir_ok = workdir_link.exists() || symlink(workdir_original, &workdir_link).is_ok(); match (target_ok, workdir_ok) { (true, true) => { let exe = target_link.to_string_lossy().to_string(); diff --git a/src/ui/components/game_image_button.rs b/src/ui/components/game_image_button.rs index 98746a4..c93595c 100644 --- a/src/ui/components/game_image_button.rs +++ b/src/ui/components/game_image_button.rs @@ -75,7 +75,7 @@ fn render_possible_image( } TextureDownloadState::Downloaded => { //Need to load - let image_data = load_image_from_path(&path); + let image_data = load_image_from_path(path); match image_data { Ok(image_data) => { let handle = ui.ctx().load_texture( diff --git a/src/ui/components/steam_user_select.rs b/src/ui/components/steam_user_select.rs index 6d1c8d1..adafc81 100644 --- a/src/ui/components/steam_user_select.rs +++ b/src/ui/components/steam_user_select.rs @@ -5,19 +5,14 @@ pub fn render_user_select<'a>( steam_users: &'a [SteamUsersInfo], ui: &mut egui::Ui, ) -> Option<&'a SteamUsersInfo> { - if steam_user.is_none() { - if steam_users.len() > 0 { - return Some(&steam_users[0]); - } - } else { - let mut selected_user = steam_user.as_ref().unwrap().clone(); + if let Some(mut selected_user) = steam_user { let id_before = selected_user.user_id.clone(); - if steam_users.len() > 0 { + if !steam_users.is_empty() { let combo_box = egui::ComboBox::new("ImageUserSelect", "") .selected_text(format!("Steam user id: {}", &selected_user.user_id)); combo_box.show_ui(ui, |ui| { for user in steam_users { - ui.selectable_value(&mut selected_user, &user, &user.user_id); + ui.selectable_value(&mut selected_user, user, &user.user_id); } }); } @@ -25,6 +20,9 @@ pub fn render_user_select<'a>( if !id_before.eq(&id_now) { return Some(selected_user); } + } else if !steam_users.is_empty() { + return Some(&steam_users[0]); } + None } diff --git a/src/ui/defines.rs b/src/ui/defines.rs index 81a0866..92e4499 100644 --- a/src/ui/defines.rs +++ b/src/ui/defines.rs @@ -39,8 +39,8 @@ pub mod ui_images { let image_buffer = image.to_rgba8(); let pixels = image_buffer.as_flat_samples(); IconData { - height: image.height() as u32, - width: image.width() as u32, + height: image.height(), + width: image.width(), rgba: pixels.as_slice().to_vec(), } } @@ -48,7 +48,7 @@ pub mod ui_images { pub fn load_image_from_path(path: &std::path::Path) -> eyre::Result { let path_owned = path.to_owned(); let handle: JoinHandle> = std::thread::spawn(move || { - let image = image::io::Reader::open(&path_owned)? + let image = image::io::Reader::open(path_owned)? .with_guessed_format()? .decode()?; let size = [image.width() as _, image.height() as _]; diff --git a/src/ui/images/hasimagekey.rs b/src/ui/images/hasimagekey.rs index d3f607c..41012fa 100644 --- a/src/ui/images/hasimagekey.rs +++ b/src/ui/images/hasimagekey.rs @@ -56,7 +56,7 @@ fn key_from_extension( ext: &str, ) -> (bool, PathBuf, String) { let file_name = image_type.file_name(app_id, ext); - let path = user_path.join("config").join("grid").join(&file_name); + let path = user_path.join("config").join("grid").join(file_name); let key = path.to_string_lossy().to_string(); (path.exists(), path, key) } diff --git a/src/ui/images/pages/change_grid_db_id.rs b/src/ui/images/pages/change_grid_db_id.rs index 7cbed43..47d589b 100644 --- a/src/ui/images/pages/change_grid_db_id.rs +++ b/src/ui/images/pages/change_grid_db_id.rs @@ -64,7 +64,7 @@ pub fn handle_correct_grid_request(app:&mut MyEguiApp) { .auth_key .clone() .unwrap_or_default(); - let client = steamgriddb_api::Client::new(&auth_key); + let client = steamgriddb_api::Client::new(auth_key); let search_results = app.rt.block_on(client.search(app_name)); app.image_selected_state.possible_names = search_results.ok(); } diff --git a/src/ui/images/pages/pick_new_image.rs b/src/ui/images/pages/pick_new_image.rs index f324498..81b2dc3 100644 --- a/src/ui/images/pages/pick_new_image.rs +++ b/src/ui/images/pages/pick_new_image.rs @@ -64,7 +64,7 @@ pub fn render_page_pick_image( if render_image_from_path_or_url( ui, &state.image_handles, - &path, + path, column_width, &image.full_url, image_type, diff --git a/src/ui/images/ui_image_download.rs b/src/ui/images/ui_image_download.rs index fff4dc8..1edadd7 100644 --- a/src/ui/images/ui_image_download.rs +++ b/src/ui/images/ui_image_download.rs @@ -44,7 +44,7 @@ impl MyEguiApp { let users = state.steam_users.as_ref(); if let Some(users) = users { if let Some(value) = - render_user_select(state.steam_user.as_ref(), &users, ui) + render_user_select(state.steam_user.as_ref(), users, ui) { return Some(UserAction::UserSelected(value.clone())); } @@ -67,7 +67,7 @@ impl MyEguiApp { return value; } } else if let Some(image_type) = state.image_type_selected.as_ref() { - if let Some(action) = render_page_pick_image(&self, ui, image_type, state) { + if let Some(action) = render_page_pick_image(self, ui, image_type, state) { return action; } } else if let Some(action) = render_page_shortcut_select_image_type(ui, state) { @@ -76,7 +76,7 @@ impl MyEguiApp { } else { let is_shortcut = state.game_mode.is_shortcuts(); if is_shortcut { - if let Some(action) = render_page_shortcut_images_overview(&self, ui) { + if let Some(action) = render_page_shortcut_images_overview(self, ui) { return action; } } else if let Some(action) = render_page_steam_images_overview(ui, state) { @@ -246,7 +246,7 @@ impl MyEguiApp { let path = Path::new(data_folder) .join("config") .join("grid") - .join(&file_name); + .join(file_name); if path.exists() { let _ = std::fs::remove_file(&path); } diff --git a/src/ui/ui_backup.rs b/src/ui/ui_backup.rs index 6a89da8..3a93ae6 100644 --- a/src/ui/ui_backup.rs +++ b/src/ui/ui_backup.rs @@ -80,7 +80,7 @@ pub fn restore_backup(steam_settings: &SteamSettings, shortcut_path: &Path) -> b pub fn load_backups() -> Vec { let backup_folder = get_backups_flder(); - let files = std::fs::read_dir(&backup_folder); + let files = std::fs::read_dir(backup_folder); let mut result = vec![]; if let Ok(files) = files { for file in files.flatten() { @@ -118,7 +118,7 @@ pub fn backup_shortcuts(steam_settings: &SteamSettings) { user_info.user_id, date_string )); println!("Backed up shortcut at: {:?}", new_path); - std::fs::copy(&shortcut_path, &new_path).unwrap(); + std::fs::copy(shortcut_path, &new_path).unwrap(); } } } diff --git a/src/ui/uiapp.rs b/src/ui/uiapp.rs index 96b76a2..52e96e5 100644 --- a/src/ui/uiapp.rs +++ b/src/ui/uiapp.rs @@ -372,7 +372,7 @@ pub fn run_ui(args: Vec) { ); } -fn is_fullscreen(args: &Vec) -> bool { +fn is_fullscreen(args: &[String]) -> bool { let is_steam_mode = match std::env::var("SteamAppId") { Ok(value) => !value.is_empty(), Err(_) => false,