From 9e4b74f7e0f7aa1f31e6992ac7e05400f396f9a0 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Thu, 7 Aug 2025 14:00:01 +0200 Subject: [PATCH] fix: Address clippy errors Co-authored-by: Alystrasz --- src-tauri/src/development/mod.rs | 18 +++++-------- src-tauri/src/github/mod.rs | 16 +++++------ src-tauri/src/github/pull_requests.rs | 31 +++++++++------------- src-tauri/src/mod_management/legacy.rs | 6 ++--- src-tauri/src/mod_management/mod.rs | 14 +++++----- src-tauri/src/northstar/install.rs | 18 ++++++------- src-tauri/src/northstar/profile.rs | 8 +++--- src-tauri/src/platform_specific/windows.rs | 12 ++++----- src-tauri/src/util.rs | 14 +++++----- 9 files changed, 61 insertions(+), 76 deletions(-) diff --git a/src-tauri/src/development/mod.rs b/src-tauri/src/development/mod.rs index 7184904cd..4911a81e1 100644 --- a/src-tauri/src/development/mod.rs +++ b/src-tauri/src/development/mod.rs @@ -25,15 +25,13 @@ pub async fn install_git_main(game_install_path: &str) -> Result }; let extract_directory = format!( - "{}/___flightcore-temp/download-dir/launcher-pr-{}", - game_install_path, latest_commit_sha + "{game_install_path}/___flightcore-temp/download-dir/launcher-pr-{latest_commit_sha}" ); match std::fs::create_dir_all(extract_directory.clone()) { Ok(_) => (), Err(err) => { return Err(format!( - "Failed creating temporary download directory: {}", - err + "Failed creating temporary download directory: {err}" )) } }; @@ -42,7 +40,7 @@ pub async fn install_git_main(game_install_path: &str) -> Result match zip_extract::extract(std::io::Cursor::new(archive), &target_dir, true) { Ok(()) => (), Err(err) => { - return Err(format!("Failed unzip: {}", err)); + return Err(format!("Failed unzip: {err}")); } }; @@ -52,14 +50,13 @@ pub async fn install_git_main(game_install_path: &str) -> Result // - Northstar.dll let files_to_copy = vec!["NorthstarLauncher.exe", "Northstar.dll"]; for file_name in files_to_copy { - let source_file_path = format!("{}/{}", extract_directory, file_name); - let destination_file_path = format!("{}/{}", game_install_path, file_name); + let source_file_path = format!("{extract_directory}/{file_name}"); + let destination_file_path = format!("{game_install_path}/{file_name}"); match std::fs::copy(source_file_path, destination_file_path) { Ok(_result) => (), Err(err) => { return Err(format!( - "Failed to copy necessary file {} from temp dir: {}", - file_name, err + "Failed to copy necessary file {file_name} from temp dir: {err}" )) } }; @@ -70,8 +67,7 @@ pub async fn install_git_main(game_install_path: &str) -> Result Ok(()) => (), Err(err) => { return Err(format!( - "Failed to delete temporary download directory: {}", - err + "Failed to delete temporary download directory: {err}" )) } } diff --git a/src-tauri/src/github/mod.rs b/src-tauri/src/github/mod.rs index 9bc3f834e..fb2adf150 100644 --- a/src-tauri/src/github/mod.rs +++ b/src-tauri/src/github/mod.rs @@ -70,7 +70,7 @@ pub fn get_list_of_tags(project: Project) -> Result, String> { }; // Fetch the list of tags for the repository as a `Vec`. - let tags_url = format!("https://api.github.com/repos/{}/tags", repo_name); + let tags_url = format!("https://api.github.com/repos/{repo_name}/tags"); let tags: Vec = client.get(tags_url).send().unwrap().json().unwrap(); // Map each `Tag` element to a `TagWrapper` element with the desired label and `Tag` value. @@ -108,7 +108,7 @@ pub fn compare_tags_flightcore(first_tag: Tag, second_tag: Tag) -> Result = [].to_vec(); - println!("{}", repo); + println!("{repo}"); // let repo = "R2Northstar/NorthstarLauncher"; let comparison_url = format!( "https://api.github.com/repos/{}/compare/{}...{}", @@ -170,10 +170,10 @@ fn generate_flightcore_release_notes(commits: Vec) -> String { _ => "**Other:**", }; - release_notes.push_str(&format!("{}\n", section_title)); + release_notes.push_str(&format!("{section_title}\n")); for commit_message in commit_list { - release_notes.push_str(&format!("- {}\n", commit_message)); + release_notes.push_str(&format!("- {commit_message}\n")); } release_notes.push('\n'); @@ -235,10 +235,10 @@ pub fn compare_tags_northstar(first_tag: Tag, second_tag: Tag) -> Result = [].to_vec(); - println!("{}", repo); + println!("{repo}"); // let repo = "R2Northstar/NorthstarLauncher"; let comparison_url = format!( "https://api.github.com/repos/{}/compare/{}...{}", @@ -306,7 +306,7 @@ fn turn_pr_number_into_link(input: &str, repo: &str) -> String { let re = Regex::new(r"#(\d+)").unwrap(); // Generate pull request link - let pull_link = format!("https://github.com/{}/pull/", repo); - re.replace_all(input, format!("[{}#$1]({}$1)", last_line, pull_link)) + let pull_link = format!("https://github.com/{repo}/pull/"); + re.replace_all(input, format!("[{last_line}#$1]({pull_link}$1)")) .to_string() } diff --git a/src-tauri/src/github/pull_requests.rs b/src-tauri/src/github/pull_requests.rs index de733feb3..f0f15fc52 100644 --- a/src-tauri/src/github/pull_requests.rs +++ b/src-tauri/src/github/pull_requests.rs @@ -197,13 +197,12 @@ pub async fn get_launcher_download_link(commit_sha: String) -> Result serde_json::from_value(result).unwrap(), - Err(err) => return Err(format!("{}", err)), + Err(err) => return Err(format!("{err}")), }; // Cross-reference commit sha against workflow runs @@ -236,20 +235,19 @@ pub async fn get_launcher_download_link(commit_sha: String) -> Result` let mut file = match File::create(path) { - Err(why) => panic!("couldn't create {}: {}", display, why), + Err(why) => panic!("couldn't create {display}: {why}"), Ok(file) => file, }; @@ -258,7 +256,7 @@ fn add_batch_file(game_install_path: &str) { "NorthstarLauncher.exe -profile=R2Northstar-PR-test-managed-folder\r\n"; match file.write_all(batch_file_content.as_bytes()) { - Err(why) => panic!("couldn't write to {}: {}", display, why), + Err(why) => panic!("couldn't write to {display}: {why}"), Ok(_) => log::info!("successfully wrote to {}", display), } } @@ -296,8 +294,7 @@ pub async fn apply_launcher_pr( Ok(_) => (), Err(err) => { return Err(format!( - "Failed creating temporary download directory: {}", - err + "Failed creating temporary download directory: {err}" )) } }; @@ -306,7 +303,7 @@ pub async fn apply_launcher_pr( match zip_extract::extract(io::Cursor::new(archive), &target_dir, true) { Ok(()) => (), Err(err) => { - return Err(format!("Failed unzip: {}", err)); + return Err(format!("Failed unzip: {err}")); } }; @@ -316,14 +313,13 @@ pub async fn apply_launcher_pr( // - Northstar.dll let files_to_copy = vec!["NorthstarLauncher.exe", "Northstar.dll"]; for file_name in files_to_copy { - let source_file_path = format!("{}/{}", extract_directory, file_name); + let source_file_path = format!("{extract_directory}/{file_name}"); let destination_file_path = format!("{}/{}", game_install.game_path, file_name); match std::fs::copy(source_file_path, destination_file_path) { Ok(_result) => (), Err(err) => { return Err(format!( - "Failed to copy necessary file {} from temp dir: {}", - file_name, err + "Failed to copy necessary file {file_name} from temp dir: {err}" )) } }; @@ -334,8 +330,7 @@ pub async fn apply_launcher_pr( Ok(()) => (), Err(err) => { return Err(format!( - "Failed to delete temporary download directory: {}", - err + "Failed to delete temporary download directory: {err}" )) } } @@ -383,11 +378,11 @@ pub async fn apply_mods_pr( Err(err) => return Err(err.to_string()), } - let target_dir = std::path::PathBuf::from(format!("{}/mods", profile_folder)); // Doesn't need to exist + let target_dir = std::path::PathBuf::from(format!("{profile_folder}/mods")); // Doesn't need to exist match zip_extract::extract(io::Cursor::new(archive), &target_dir, true) { Ok(()) => (), Err(err) => { - return Err(format!("Failed unzip: {}", err)); + return Err(format!("Failed unzip: {err}")); } }; // Add batch file to launch right profile diff --git a/src-tauri/src/mod_management/legacy.rs b/src-tauri/src/mod_management/legacy.rs index 9cfbd8a19..a5cbc0873 100644 --- a/src-tauri/src/mod_management/legacy.rs +++ b/src-tauri/src/mod_management/legacy.rs @@ -20,8 +20,8 @@ pub struct ModJson { /// Parses `manifest.json` for Thunderstore mod string fn parse_for_thunderstore_mod_string(nsmod_path: &str) -> Result { - let manifest_json_path = format!("{}/manifest.json", nsmod_path); - let ts_author_txt_path = format!("{}/thunderstore_author.txt", nsmod_path); + let manifest_json_path = format!("{nsmod_path}/manifest.json"); + let ts_author_txt_path = format!("{nsmod_path}/thunderstore_author.txt"); // Check if `manifest.json` exists and parse let data = std::fs::read_to_string(manifest_json_path)?; @@ -71,7 +71,7 @@ pub fn parse_installed_mods( for directory in directories { let directory_str = directory.to_str().unwrap().to_string(); // Check if mod.json exists - let mod_json_path = format!("{}/mod.json", directory_str); + let mod_json_path = format!("{directory_str}/mod.json"); if !std::path::Path::new(&mod_json_path).exists() { continue; } diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs index 52ef1180d..85f30bcb8 100644 --- a/src-tauri/src/mod_management/mod.rs +++ b/src-tauri/src/mod_management/mod.rs @@ -135,7 +135,7 @@ pub fn get_enabled_mods(game_install: &GameInstall) -> Result result, - Err(err) => return Err(format!("Failed to read JSON due to: {}", err)), + Err(err) => return Err(format!("Failed to read JSON due to: {err}")), }; // Return parsed data @@ -255,7 +255,7 @@ pub fn parse_mods_in_package( for directory in directories { let directory_str = directory.to_str().unwrap().to_string(); // Check if mod.json exists - let mod_json_path = format!("{}/mod.json", directory_str); + let mod_json_path = format!("{directory_str}/mod.json"); if !std::path::Path::new(&mod_json_path).exists() { continue; } @@ -613,8 +613,7 @@ pub async fn fc_download_mod_and_install( for special_mod in MODS_WITH_SPECIAL_REQUIREMENTS { if thunderstore_mod_string.contains(special_mod) { return Err(format!( - "{} has special install requirements and cannot be installed with FlightCore", - thunderstore_mod_string + "{thunderstore_mod_string} has special install requirements and cannot be installed with FlightCore" )); } } @@ -667,7 +666,7 @@ pub async fn fc_download_mod_and_install( log::warn!("libthermite couldn't install mod {thunderstore_mod_string} due to {err:?}",); return match err { ThermiteError::SanityError(e) => Err( - format!("Mod failed sanity check during install. It's probably not correctly formatted. {}", e) + format!("Mod failed sanity check during install. It's probably not correctly formatted. {e}") ), _ => Err(err.to_string()), }; @@ -703,7 +702,7 @@ fn delete_mod_folder(ns_mod_directory: &str) -> Result<(), String> { let mod_json_path = ns_mod_dir_path.join("mod.json"); if !mod_json_path.exists() { // If it doesn't exist, return an error - return Err(format!("mod.json does not exist in {}", ns_mod_directory)); + return Err(format!("mod.json does not exist in {ns_mod_directory}")); } match std::fs::remove_dir_all(ns_mod_directory) { @@ -747,8 +746,7 @@ fn delete_package_folder(ts_package_directory: &str) -> Result<(), String> { if !mod_json_path.exists() { // If it doesn't exist, return an error return Err(format!( - "manifest.json does not exist in {}", - ts_package_directory + "manifest.json does not exist in {ts_package_directory}" )); } diff --git a/src-tauri/src/northstar/install.rs b/src-tauri/src/northstar/install.rs index 0e1df3c11..5d24d969a 100644 --- a/src-tauri/src/northstar/install.rs +++ b/src-tauri/src/northstar/install.rs @@ -84,14 +84,14 @@ async fn do_install( ) -> Result<()> { let filename = format!("northstar-{}.zip", nmod.version); let temp_dir = format!("{}/___flightcore-temp", game_install.game_path); - let download_directory = format!("{}/download-dir", temp_dir); - let extract_directory = format!("{}/extract-dir", temp_dir); + let download_directory = format!("{temp_dir}/download-dir"); + let extract_directory = format!("{temp_dir}/extract-dir"); log::info!("Attempting to create temporary directory {}", temp_dir); std::fs::create_dir_all(download_directory.clone())?; std::fs::create_dir_all(extract_directory.clone())?; - let download_path = format!("{}/{}", download_directory, filename); + let download_path = format!("{download_directory}/{filename}"); log::info!("Download path: {download_path}"); let last_emit = RefCell::new(Instant::now()); // Keep track of the last time a signal was emitted @@ -146,15 +146,13 @@ async fn do_install( // - rename the Profile // Move DLL into the default R2Northstar Profile - let old_dll_path = format!("{}/{}", extract_directory, NORTHSTAR_DLL); - let new_dll_path = format!( - "{}/{}/{}", - extract_directory, NORTHSTAR_DEFAULT_PROFILE, NORTHSTAR_DLL - ); + let old_dll_path = format!("{extract_directory}/{NORTHSTAR_DLL}"); + let new_dll_path = + format!("{extract_directory}/{NORTHSTAR_DEFAULT_PROFILE}/{NORTHSTAR_DLL}"); std::fs::rename(old_dll_path, new_dll_path)?; // rename default R2Northstar Profile to the profile we want to use - let old_profile_path = format!("{}/{}/", extract_directory, NORTHSTAR_DEFAULT_PROFILE); + let old_profile_path = format!("{extract_directory}/{NORTHSTAR_DEFAULT_PROFILE}/"); let new_profile_path = format!("{}/{}/", extract_directory, game_install.profile); std::fs::rename(old_profile_path, new_profile_path)?; } @@ -188,7 +186,7 @@ async fn do_install( // Safety check for mod.json // Just so that we won't ever have a https://github.com/ValveSoftware/steam-for-linux/issues/3671 moment - let mod_json_path = format!("{}/mod.json", path_to_delete_string); + let mod_json_path = format!("{path_to_delete_string}/mod.json"); let mod_json_path = std::path::Path::new(&mod_json_path); if !mod_json_path.exists() { diff --git a/src-tauri/src/northstar/profile.rs b/src-tauri/src/northstar/profile.rs index 26a32d6b5..f1effc935 100644 --- a/src-tauri/src/northstar/profile.rs +++ b/src-tauri/src/northstar/profile.rs @@ -80,7 +80,7 @@ pub fn validate_profile(game_install: GameInstall, profile: String) -> bool { pub fn delete_profile(game_install: GameInstall, profile: String) -> Result<(), String> { // Check if the Profile actually exists if !validate_profile(game_install.clone(), profile.clone()) { - return Err(format!("{} is not a valid Profile", profile)); + return Err(format!("{profile} is not a valid Profile")); } log::info!("Deleting Profile {}", profile); @@ -89,7 +89,7 @@ pub fn delete_profile(game_install: GameInstall, profile: String) -> Result<(), match std::fs::remove_dir_all(profile_path) { Ok(()) => Ok(()), - Err(err) => Err(format!("Failed to delete Profile: {}", err)), + Err(err) => Err(format!("Failed to delete Profile: {err}")), } } @@ -102,12 +102,12 @@ pub fn clone_profile( ) -> Result<(), String> { // Check if the old Profile already exists if !validate_profile(game_install.clone(), old_profile.clone()) { - return Err(format!("{} is not a valid Profile", old_profile)); + return Err(format!("{old_profile} is not a valid Profile")); } // Check that new Profile does not already exist if validate_profile(game_install.clone(), new_profile.clone()) { - return Err(format!("{} already exists", new_profile)); + return Err(format!("{new_profile} already exists")); } log::info!("Cloning Profile {} to {}", old_profile, new_profile); diff --git a/src-tauri/src/platform_specific/windows.rs b/src-tauri/src/platform_specific/windows.rs index fc6aab5d6..c361955fb 100644 --- a/src-tauri/src/platform_specific/windows.rs +++ b/src-tauri/src/platform_specific/windows.rs @@ -42,11 +42,11 @@ pub async fn check_cgnat() -> Result { // Check if valid IPv4 address and return early if not if response.parse::().is_err() { - return Err(format!("Not valid IPv4 address: {}", response)); + return Err(format!("Not valid IPv4 address: {response}")); } let hops_count = run_tracert(&response)?; - Ok(format!("Counted {} hops to {}", hops_count, response)) + Ok(format!("Counted {hops_count} hops to {response}")) } /// Count number of hops in tracert output @@ -82,7 +82,7 @@ fn run_tracert(target_ip: &str) -> Result { .output() { Ok(res) => res, - Err(err) => return Err(format!("Failed running tracert: {}", err)), + Err(err) => return Err(format!("Failed running tracert: {err}")), }; // Check if the command was successful @@ -90,7 +90,7 @@ fn run_tracert(target_ip: &str) -> Result { // Convert the output to a string let stdout = std::str::from_utf8(&output.stdout).expect("Invalid UTF-8 sequence in command output"); - println!("{}", stdout); + println!("{stdout}"); // Count the number of hops let hop_count = count_hops(stdout); @@ -98,7 +98,7 @@ fn run_tracert(target_ip: &str) -> Result { } else { let stderr = std::str::from_utf8(&output.stderr) .expect("Invalid UTF-8 sequence in command error output"); - println!("{}", stderr); - Err(format!("Failed collecting tracert output: {}", stderr)) + println!("{stderr}"); + Err(format!("Failed collecting tracert output: {stderr}")) } } diff --git a/src-tauri/src/util.rs b/src-tauri/src/util.rs index d2234be50..9d4d3d983 100644 --- a/src-tauri/src/util.rs +++ b/src-tauri/src/util.rs @@ -31,10 +31,10 @@ pub async fn get_flightcore_version_number() -> String { let version = env!("CARGO_PKG_VERSION"); if cfg!(debug_assertions) { // Debugging enabled - format!("v{} (debug mode)", version) + format!("v{version} (debug mode)") } else { // Debugging disabled - format!("v{}", version) + format!("v{version}") } } @@ -244,19 +244,17 @@ pub fn convert_release_candidate_number(version_number: String) -> String { let release_candidate: u32 = captures[4].parse().unwrap(); // Zero pad - let padded_release_candidate = format!("{:02}", release_candidate); + let padded_release_candidate = format!("{release_candidate:02}"); // Combine - let combined_patch_version = format!("{}{}", patch_version, padded_release_candidate); + let combined_patch_version = format!("{patch_version}{padded_release_candidate}"); // Strip leading zeroes let trimmed_combined_patch_version = combined_patch_version.trim_start_matches('0'); // Combine all - let version_number = format!( - "{}.{}.{}", - major_version, minor_version, trimmed_combined_patch_version - ); + let version_number = + format!("{major_version}.{minor_version}.{trimmed_combined_patch_version}"); return version_number; }