From 27b429adcd31021ac9b2e38f4bc887dcf82967dc Mon Sep 17 00:00:00 2001 From: Philip Kristoffersen Date: Thu, 2 Feb 2023 21:33:42 +0100 Subject: [PATCH] Inline print variables (#328) * Inline format messages * Cargo auto fixes --- src/migration.rs | 4 ++-- src/platforms/egs/epic_ui.rs | 2 +- src/platforms/egs/manifest_item.rs | 10 ++++----- src/platforms/gog/gog_game.rs | 4 ++-- src/platforms/heroic/heroic_game.rs | 4 ++-- src/platforms/heroic/heroic_game_type.rs | 5 ++--- src/platforms/heroic/heroic_platform.rs | 4 ++-- src/platforms/itch/itch_platform.rs | 2 +- src/platforms/platforms_load.rs | 5 ++--- src/settings.rs | 2 +- src/steam/collections.rs | 10 ++++----- src/steam/proton_vdf_util.rs | 2 +- src/steam/restarter.rs | 2 +- src/steam/utils.rs | 2 +- src/steamgriddb/cached_search.rs | 2 +- src/steamgriddb/downloader.rs | 13 ++++++------ src/steamgriddb/image_type.rs | 27 ++++++++++-------------- src/sync/symlinks.rs | 3 +-- src/sync/synchronization.rs | 2 +- src/ui/images/ui_image_download.rs | 2 +- src/ui/ui_backup.rs | 12 +++++------ src/ui/ui_import_games.rs | 4 ++-- src/ui/ui_settings.rs | 2 +- src/ui/uiapp.rs | 8 +++---- 24 files changed, 61 insertions(+), 72 deletions(-) diff --git a/src/migration.rs b/src/migration.rs index c438e1f..68f225e 100644 --- a/src/migration.rs +++ b/src/migration.rs @@ -14,7 +14,7 @@ pub fn migrate_config() { if old_path.exists() { println!("Migrating from configuration version 0 to version 1"); let new_path = crate::config::get_config_file(); - println!("Your configuration file will be moved to {:?}", new_path); + println!("Your configuration file will be moved to {new_path:?}"); let _ = std::fs::copy(old_path, new_path); let _ = std::fs::remove_file(old_path); } @@ -39,7 +39,7 @@ pub fn migrate_config() { settings.config_version = Some(1); let platforms = get_platforms(); if let Err(err) = save_settings(&settings, &platforms){ - eprintln!("Failed to load settings {:?}", err); + eprintln!("Failed to load settings {err:?}"); } } } diff --git a/src/platforms/egs/epic_ui.rs b/src/platforms/egs/epic_ui.rs index dc54017..4cb6ff9 100644 --- a/src/platforms/egs/epic_ui.rs +++ b/src/platforms/egs/epic_ui.rs @@ -9,7 +9,7 @@ impl EpicPlatform { let safe_mode_header = match epic_settings.safe_launch.len() { 0 => "Force games to launch through Epic Launcher".to_string(), 1 => "One game forced to launch through Epic Launcher".to_string(), - x => format!("{} games forced to launch through Epic Launcher", x), + x => format!("{x} games forced to launch through Epic Launcher"), }; egui::CollapsingHeader::new(safe_mode_header) diff --git a/src/platforms/egs/manifest_item.rs b/src/platforms/egs/manifest_item.rs index ea5950d..11c48c2 100644 --- a/src/platforms/egs/manifest_item.rs +++ b/src/platforms/egs/manifest_item.rs @@ -53,12 +53,12 @@ fn exe_shortcut(manifest: ManifestItem) -> ShortcutOwned { let start_dir = start_dir.trim_matches('\"'); #[cfg(target_family = "unix")] - let start_dir_string = format!("\"{}\"", start_dir); + let start_dir_string = format!("\"{start_dir}\""); #[cfg(target_family = "unix")] let start_dir = start_dir_string.as_str(); #[cfg(target_family = "unix")] - let exe_string = format!("\"{}\"", exe); + let exe_string = format!("\"{exe}\""); #[cfg(target_family = "unix")] let exe = exe_string.as_str(); @@ -105,7 +105,7 @@ fn launcher_shortcut(manifest: ManifestItem) -> ShortcutOwned { .unwrap_or_default(); #[cfg(target_family = "unix")] - let parent_folder = format!("\"{}\"", parent_folder); + let parent_folder = format!("\"{parent_folder}\""); let launcher_path = manifest .launcher_path @@ -114,7 +114,7 @@ fn launcher_shortcut(manifest: ManifestItem) -> ShortcutOwned { .unwrap_or_default(); #[cfg(target_family = "unix")] - let launcher_path = format!("\"{}\"", launcher_path); + let launcher_path = format!("\"{launcher_path}\""); Shortcut::new( "0", @@ -149,7 +149,7 @@ impl ManifestItem { .join(&manifest.launch_executable) .to_string_lossy() .to_string(); - let exe = format!("\"{}\"", exe_path); + let exe = format!("\"{exe_path}\""); exe } diff --git a/src/platforms/gog/gog_game.rs b/src/platforms/gog/gog_game.rs index 5b09042..6108c0c 100644 --- a/src/platforms/gog/gog_game.rs +++ b/src/platforms/gog/gog_game.rs @@ -48,12 +48,12 @@ impl From for ShortcutOwned { }; let mut exe_string = exe.to_string_lossy().to_string(); if exe_string.contains(' ') && !exe_string.starts_with('\"') { - exe_string = format!("\"{}\"", exe_string); + exe_string = format!("\"{exe_string}\""); } let mut working_dir_string = gogs.working_dir; if working_dir_string.contains(' ') && !working_dir_string.starts_with('\"') { - working_dir_string = format!("\"{}\"", working_dir_string); + working_dir_string = format!("\"{working_dir_string}\""); } let shortcut = Shortcut::new( diff --git a/src/platforms/heroic/heroic_game.rs b/src/platforms/heroic/heroic_game.rs index 7f0bb19..0c019cb 100644 --- a/src/platforms/heroic/heroic_game.rs +++ b/src/platforms/heroic/heroic_game.rs @@ -29,7 +29,7 @@ impl From for ShortcutOwned { #[cfg(target_family = "unix")] { if !target.starts_with('\"') && !target.ends_with('\"') { - target = format!("\"{}\"", target); + target = format!("\"{target}\""); } } @@ -38,7 +38,7 @@ impl From for ShortcutOwned { #[cfg(target_family = "unix")] { if !install_path.starts_with('\"') && !install_path.ends_with('\"') { - install_path = format!("\"{}\"", install_path); + install_path = format!("\"{install_path}\""); } } #[cfg(target_os = "windows")] diff --git a/src/platforms/heroic/heroic_game_type.rs b/src/platforms/heroic/heroic_game_type.rs index 4c2d2db..ef5d38b 100644 --- a/src/platforms/heroic/heroic_game_type.rs +++ b/src/platforms/heroic/heroic_game_type.rs @@ -51,13 +51,12 @@ impl From for ShortcutOwned { app_name, install_mode, } => { - let launch_parameter = format!("heroic://launch/{}", app_name); + let launch_parameter = format!("heroic://launch/{app_name}"); let (exe, parameter) = match install_mode { InstallationMode::FlatPak => ( "flatpak", format!( - "run com.heroicgameslauncher.hgl {} --no-gui --no-sandbox", - launch_parameter + "run com.heroicgameslauncher.hgl {launch_parameter} --no-gui --no-sandbox" ), ), InstallationMode::UserBin => ("heroic", launch_parameter), diff --git a/src/platforms/heroic/heroic_platform.rs b/src/platforms/heroic/heroic_platform.rs index 8f41474..c923e52 100644 --- a/src/platforms/heroic/heroic_platform.rs +++ b/src/platforms/heroic/heroic_platform.rs @@ -237,11 +237,11 @@ impl GamesPlatform for HeroicPlatform { ) { (false, 0) => "Force games to launch through Heroic Launcher".to_string(), (false, 1) => "One game forced to launch through Heroic Launcher".to_string(), - (false, x) => format!("{} games forced to launch through Heroic Launcher", x), + (false, x) => format!("{x} games forced to launch through Heroic Launcher"), (true, 0) => "Force games to launch directly".to_string(), (true, 1) => "One game forced to launch directly".to_string(), - (true, x) => format!("{} games forced to launch directly", x), + (true, x) => format!("{x} games forced to launch directly"), }; egui::CollapsingHeader::new(safe_mode_header).id_source("Heroic_Launcher_safe_launch").show(ui, |ui| { diff --git a/src/platforms/itch/itch_platform.rs b/src/platforms/itch/itch_platform.rs index 162d62b..f466cde 100644 --- a/src/platforms/itch/itch_platform.rs +++ b/src/platforms/itch/itch_platform.rs @@ -79,7 +79,7 @@ fn dbpath_to_game(paths: &DbPaths) -> Option { pub fn get_default_location() -> String { //If we don't have a home drive we have to just die let home = std::env::var("HOME").unwrap_or_default(); - format!("{}/.config/itch/", home) + format!("{home}/.config/itch/") } #[cfg(target_os = "windows")] diff --git a/src/platforms/platforms_load.rs b/src/platforms/platforms_load.rs index 18bcf94..99acdd6 100644 --- a/src/platforms/platforms_load.rs +++ b/src/platforms/platforms_load.rs @@ -84,8 +84,7 @@ pub fn get_platforms() -> Platforms { Ok(s) => s, Err(err) => { eprintln!( - "Could not load platform settings, using defaults: Error: {:?}", - err + "Could not load platform settings, using defaults: Error: {err:?}" ); HashMap::new() } @@ -113,7 +112,7 @@ where Ok(k) => k, Err(err) => { if !str.is_empty() { - eprintln!("Error reading settings file {:?}", err); + eprintln!("Error reading settings file {err:?}"); } Setting::default() } diff --git a/src/settings.rs b/src/settings.rs index e5ceb74..e8bd522 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -30,7 +30,7 @@ impl Settings { // Add in the current environment file // Default to 'development' env // Note that this file is _optional_ - .add_source(File::with_name(&format!("config/{}", env)).required(false)) + .add_source(File::with_name(&format!("config/{env}")).required(false)) // Add in a local configuration file // This file shouldn't be checked in to git .add_source(File::with_name("local.toml").required(false)) diff --git a/src/steam/collections.rs b/src/steam/collections.rs index 4a53568..0ea3d70 100644 --- a/src/steam/collections.rs +++ b/src/steam/collections.rs @@ -62,7 +62,7 @@ impl ActualSteamCollection { pub fn is_boilr_collection(&self) -> bool { self.key - .contains(&format!("user-collections.{}", BOILR_TAG)) + .contains(&format!("user-collections.{BOILR_TAG}")) } } @@ -215,7 +215,7 @@ fn save_category>( batch: &mut WriteBatch, ) -> Result<(), Box> { let json = serde_json::to_string(&category)?; - let prefixed = format!("\u{1}{}", json); + let prefixed = format!("\u{1}{json}"); batch.put(category_key.as_ref().as_bytes(), prefixed.as_bytes()); Ok(()) } @@ -260,7 +260,7 @@ fn open_db() -> eyre::Result { fn get_namespace_keys>(steamid: S, db: &mut DB) -> HashSet { let keyprefix = get_steam_user_prefix(steamid); - let namespaces_key = format!("{}s", keyprefix); + let namespaces_key = format!("{keyprefix}s"); let key_bytes = namespaces_key.as_bytes(); let namespaces = get_namespaces(db, key_bytes).unwrap_or_default(); let namespace_keys = namespaces @@ -330,7 +330,7 @@ fn name_to_key>(name: S) -> String { } else { &base64 }; - format!("{}-{}", BOILR_TAG, base64_no_end) + format!("{BOILR_TAG}-{base64_no_end}") } fn parse_steam_collections>( @@ -371,7 +371,7 @@ pub fn write_vdf_collection_to_string>( input.get(..start_index_plus_key), input.get(end_index_in_full..), ) { - let result = format!("{}{}{}", before, encoded_json, after); + let result = format!("{before}{encoded_json}{after}"); return Some(result); } } diff --git a/src/steam/proton_vdf_util.rs b/src/steam/proton_vdf_util.rs index 01e175c..1f9e4b3 100644 --- a/src/steam/proton_vdf_util.rs +++ b/src/steam/proton_vdf_util.rs @@ -52,7 +52,7 @@ fn enable_proton_games, B: AsRef>(vdf_content: S, games: &[B] if let Some(before_section) = vdf_content.get(..section_info.start) { if let Some(after_section) = vdf_content.get(section_info.end..) { - return format!("{}{}{}", before_section, new_section, after_section); + return format!("{before_section}{new_section}{after_section}"); } } } diff --git a/src/steam/restarter.rs b/src/steam/restarter.rs index 4f7b292..0c86393 100644 --- a/src/steam/restarter.rs +++ b/src/steam/restarter.rs @@ -51,7 +51,7 @@ pub fn ensure_steam_started(_settings: &super::SteamSettings) { println!("Starting steam"); let mut command = Command::new(steam_name); if let Err(e) = command.spawn() { - println!("Failed to start steam: {:?}", e); + println!("Failed to start steam: {e:?}"); }; } } diff --git a/src/steam/utils.rs b/src/steam/utils.rs index c44da5a..ff07b0a 100644 --- a/src/steam/utils.rs +++ b/src/steam/utils.rs @@ -87,7 +87,7 @@ pub fn get_shortcuts_paths(settings: &SteamSettings) -> eyre::Result CachedSearch<'a> { pub fn save(&self) { if let Err(err) = save_search_map(&self.search_map) { - eprintln!("Failed saving searchmap : {:?}", err); + eprintln!("Failed saving searchmap : {err:?}"); } } diff --git a/src/steamgriddb/downloader.rs b/src/steamgriddb/downloader.rs index c58c0e8..b844b47 100644 --- a/src/steamgriddb/downloader.rs +++ b/src/steamgriddb/downloader.rs @@ -105,7 +105,7 @@ pub async fn download_images_for_users<'b>( .collect::>() .await; let duration = start_time.elapsed(); - println!("Finished getting images in: {:?}", duration); + println!("Finished getting images in: {duration:?}"); //Validate that the downloads where ok for to_download in to_downloads { @@ -277,7 +277,7 @@ async fn search_for_images_to_download( to_download.extend(download_for_this_type); } - Err(err) => eprintln!("Error getting images: {}", err), + Err(err) => eprintln!("Error getting images: {err}"), } } } @@ -308,7 +308,7 @@ async fn get_images_for_ids( let image_search_result = client.get_images_for_ids(image_ids, &query_type).await; - image_search_result.map_err(|e| format!("Image search failed {:?}", e)) + image_search_result.map_err(|e| format!("Image search failed {e:?}")) } const BIG_PICTURE_DIMS: [GridDimentions; 2] = [GridDimentions::D920x430, GridDimentions::D460x215]; @@ -374,7 +374,7 @@ async fn get_steam_image_url(game_id: usize, image_type: &ImageType) -> Option().await; @@ -398,7 +398,7 @@ async fn get_steam_image_url(game_id: usize, image_type: &ImageType) -> Option Option { - let steamgriddb_page_url = format!("https://www.steamgriddb.com/api/public/game/{}/", game_id); + let steamgriddb_page_url = format!("https://www.steamgriddb.com/api/public/game/{game_id}/"); let response = reqwest::get(steamgriddb_page_url).await; if let Ok(response) = response { let text_response = response.json::().await; @@ -423,8 +423,7 @@ async fn get_steam_icon_url(game_id: usize) -> Option { fn icon_url(steam_app_id: &str, icon_id: &str) -> String { format!( - "https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/{}/{}.ico", - steam_app_id, icon_id + "https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/{steam_app_id}/{icon_id}.ico" ) } diff --git a/src/steamgriddb/image_type.rs b/src/steamgriddb/image_type.rs index 2ba254c..f109e69 100644 --- a/src/steamgriddb/image_type.rs +++ b/src/steamgriddb/image_type.rs @@ -51,12 +51,12 @@ impl ImageType { pub fn file_name_no_extension(&self, app_id: u32) -> String { match self { - ImageType::Hero => format!("{}_hero", app_id), - ImageType::Grid => format!("{}p", app_id), - ImageType::WideGrid => format!("{}", app_id), - ImageType::Logo => format!("{}_logo", app_id), - ImageType::BigPicture => format!("{}_bigpicture", app_id), - ImageType::Icon => format!("{}-icon", app_id), + ImageType::Hero => format!("{app_id}_hero"), + ImageType::Grid => format!("{app_id}p"), + ImageType::WideGrid => format!("{app_id}"), + ImageType::Logo => format!("{app_id}_logo"), + ImageType::BigPicture => format!("{app_id}_bigpicture"), + ImageType::Icon => format!("{app_id}-icon"), } } @@ -64,24 +64,19 @@ impl ImageType { let steam_app_id = steam_app_id.as_ref(); match self { ImageType::Hero => format!( - "https://cdn.cloudflare.steamstatic.com/steam/apps/{}/library_hero.jpg?t={}", - steam_app_id, mtime + "https://cdn.cloudflare.steamstatic.com/steam/apps/{steam_app_id}/library_hero.jpg?t={mtime}" ), ImageType::Grid => format!( - "https://cdn.cloudflare.steamstatic.com/steam/apps/{}/library_600x900_2x.jpg?t={}", - steam_app_id, mtime + "https://cdn.cloudflare.steamstatic.com/steam/apps/{steam_app_id}/library_600x900_2x.jpg?t={mtime}" ), ImageType::WideGrid => format!( - "https://cdn.cloudflare.steamstatic.com/steam/apps/{}/header.jpg?t={}", - steam_app_id, mtime + "https://cdn.cloudflare.steamstatic.com/steam/apps/{steam_app_id}/header.jpg?t={mtime}" ), ImageType::Logo => format!( - "https://cdn.cloudflare.steamstatic.com/steam/apps/{}/logo.png?t={}", - steam_app_id, mtime + "https://cdn.cloudflare.steamstatic.com/steam/apps/{steam_app_id}/logo.png?t={mtime}" ), ImageType::BigPicture => format!( - "https://cdn.cloudflare.steamstatic.com/steam/apps/{}/header.jpg?t={}", - steam_app_id, mtime + "https://cdn.cloudflare.steamstatic.com/steam/apps/{steam_app_id}/header.jpg?t={mtime}" ), // This should not happen _ => "".to_string(), diff --git a/src/sync/symlinks.rs b/src/sync/symlinks.rs index fcac345..37d4f70 100644 --- a/src/sync/symlinks.rs +++ b/src/sync/symlinks.rs @@ -54,8 +54,7 @@ pub fn ensure_links_folder_created(name: &str) { if !boilr_links_path.exists() { if let Err(e) = std::fs::create_dir_all(&boilr_links_path) { println!( - "Could not create links folder for symlinks at path: {:?} , error: {:?} , you can try to disable creating symlinks for platform {}", - boilr_links_path, e, name + "Could not create links folder for symlinks at path: {boilr_links_path:?} , error: {e:?} , you can try to disable creating symlinks for platform {name}" ); } } diff --git a/src/sync/synchronization.rs b/src/sync/synchronization.rs index 08ea21a..47ff3d7 100644 --- a/src/sync/synchronization.rs +++ b/src/sync/synchronization.rs @@ -115,7 +115,7 @@ pub fn sync_shortcuts( } let duration = start_time.elapsed(); - println!("Finished synchronizing games in: {:?}", duration); + println!("Finished synchronizing games in: {duration:?}"); } Ok(userinfo_shortcuts) } diff --git a/src/ui/images/ui_image_download.rs b/src/ui/images/ui_image_download.rs index 4e2b84a..914d470 100644 --- a/src/ui/images/ui_image_download.rs +++ b/src/ui/images/ui_image_download.rs @@ -124,7 +124,7 @@ impl MyEguiApp { match paths { Ok(paths) => self.image_selected_state.steam_users = Some(paths), Err(err) => { - self.image_selected_state.settings_error = Some(format!("Could not find user steam location, error message: {} , try to clear the steam location field in settings to let BoilR find it itself",err)); + self.image_selected_state.settings_error = Some(format!("Could not find user steam location, error message: {err} , try to clear the steam location field in settings to let BoilR find it itself")); } } } diff --git a/src/ui/ui_backup.rs b/src/ui/ui_backup.rs index 2caa30d..45ec05a 100644 --- a/src/ui/ui_backup.rs +++ b/src/ui/ui_backup.rs @@ -24,7 +24,7 @@ impl MyEguiApp { ui.add_space(15.0); if let Some(last_restore) = self.backup_state.last_restore.as_ref() { - ui.heading(format!("Last restored {:?}", last_restore)); + ui.heading(format!("Last restored {last_restore:?}")); } if ui.button("Click here to create a new backup").clicked() { @@ -70,12 +70,11 @@ pub fn restore_backup(steam_settings: &SteamSettings, shortcut_path: &Path) -> b if file_name.to_string_lossy().starts_with(&user.user_id) { match std::fs::copy(shortcut_path, Path::new(&user_shortcut_path)) { Ok(_) => { - println!("Restored shortcut to path : {}", user_shortcut_path); + println!("Restored shortcut to path : {user_shortcut_path}"); } Err(err) => { eprintln!( - "Failed to restored shortcut to path : {} gave error: {:?}", - user_shortcut_path, err + "Failed to restored shortcut to path : {user_shortcut_path} gave error: {err:?}" ); } } @@ -129,12 +128,11 @@ pub fn backup_shortcuts(steam_settings: &SteamSettings) { )); match std::fs::copy(shortcut_path, &new_path) { Ok(_) => { - println!("Backed up shortcut at: {:?}", new_path); + println!("Backed up shortcut at: {new_path:?}"); } Err(err) => { eprintln!( - "Failed to backup shortcut at: {:?}, error: {:?}", - new_path, err + "Failed to backup shortcut at: {new_path:?}, error: {err:?}" ); } } diff --git a/src/ui/ui_import_games.rs b/src/ui/ui_import_games.rs index 914e8ff..2496a79 100644 --- a/src/ui/ui_import_games.rs +++ b/src/ui/ui_import_games.rs @@ -87,7 +87,7 @@ impl MyEguiApp { let contents = serde_json::to_string(&self.rename_map); if let Ok(contents) = contents{ let res = std::fs::write(&rename_file_path, contents); - println!("Write rename file at {:?} with result: {:?}",rename_file_path, res); + println!("Write rename file at {rename_file_path:?} with result: {res:?}"); } } } @@ -212,7 +212,7 @@ where } } if let Err(err) = setup_proton_games(&shortcuts_to_proton){ - eprintln!("failed to save proton settings: {:?}",err); + eprintln!("failed to save proton settings: {err:?}"); } } } diff --git a/src/ui/ui_settings.rs b/src/ui/ui_settings.rs index d5735d7..593b839 100644 --- a/src/ui/ui_settings.rs +++ b/src/ui/ui_settings.rs @@ -34,7 +34,7 @@ impl MyEguiApp { platform.render_ui(ui); ui.add_space(SECTION_SPACING); } - ui.label(format!("Version: {}", VERSION)); + ui.label(format!("Version: {VERSION}")); }); } diff --git a/src/ui/uiapp.rs b/src/ui/uiapp.rs index 5f5c44c..a6f4c8a 100644 --- a/src/ui/uiapp.rs +++ b/src/ui/uiapp.rs @@ -97,11 +97,11 @@ impl MyEguiApp { SyncProgress::NotStarted => ("".to_string(), false), SyncProgress::Starting => ("Starting Import".to_string(), true), SyncProgress::FoundGames { games_found } => { - (format!("Found {} games to import", games_found), true) + (format!("Found {games_found} games to import"), true) } SyncProgress::FindingImages => ("Searching for images".to_string(), true), SyncProgress::DownloadingImages { to_download } => { - (format!("Downloading {} images ", to_download), true) + (format!("Downloading {to_download} images "), true) } SyncProgress::Done => ("Done importing games".to_string(), false), }; @@ -129,7 +129,7 @@ impl MyEguiApp { .clicked() { if let Err(err) = save_settings(&self.settings, &self.platforms){ - eprintln!("Failed to save settings {:?}",err); + eprintln!("Failed to save settings {err:?}"); } self.run_sync_async(); } @@ -269,7 +269,7 @@ impl App for MyEguiApp { if ui.add(save_button).on_hover_text("Save settings").clicked() { if let Err(err) = save_settings(&self.settings, &self.platforms){ - eprintln!("Failed to save settings: {:?}",err); + eprintln!("Failed to save settings: {err:?}"); } } });