From b94957a952f0aa06b8895fd58d3fa7543aadf9a5 Mon Sep 17 00:00:00 2001 From: objz Date: Sat, 11 Jul 2026 15:46:07 +0200 Subject: [PATCH] fix: formatting --- src/config/mod.rs | 15 +++++---- src/instance/content/mods.rs | 17 ++++++---- src/instance/import/mrpack.rs | 30 +++++++++-------- src/instance/launch/mod.rs | 14 ++++---- src/instance/manager.rs | 4 ++- src/net/forge.rs | 61 ++++++++++++++++++++++++----------- 6 files changed, 87 insertions(+), 54 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 28b9097..f2f7737 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -23,13 +23,14 @@ fn ensure_config_exists() -> PathBuf { let config_path = get_config_path().join("config.toml"); if !config_path.exists() { if let Some(parent) = config_path.parent() - && let Err(e) = fs::create_dir_all(parent) { - tracing::warn!( - "Failed to create config directory {}: {}", - parent.display(), - e - ); - } + && let Err(e) = fs::create_dir_all(parent) + { + tracing::warn!( + "Failed to create config directory {}: {}", + parent.display(), + e + ); + } match fs::write(&config_path, include_str!("../../assets/config.toml")) { Ok(()) => tracing::debug!("Wrote default config to {}", config_path.display()), Err(e) => tracing::warn!( diff --git a/src/instance/content/mods.rs b/src/instance/content/mods.rs index e480b2c..22e3d4a 100644 --- a/src/instance/content/mods.rs +++ b/src/instance/content/mods.rs @@ -462,13 +462,16 @@ fn quadrant_cell(pixels: [[u8; 3]; 4]) -> IconCell { let bg = pixels[pair.0]; let fg = pixels[pair.1]; - let mask = pixels.iter().enumerate().fold(0_u8, |mask, (index, pixel)| { - if color_distance(*pixel, fg) <= color_distance(*pixel, bg) { - mask | (1 << index) - } else { - mask - } - }); + let mask = pixels + .iter() + .enumerate() + .fold(0_u8, |mask, (index, pixel)| { + if color_distance(*pixel, fg) <= color_distance(*pixel, bg) { + mask | (1 << index) + } else { + mask + } + }); let symbol = match mask { 0 => ' ', 1 => '\u{2598}', diff --git a/src/instance/import/mrpack.rs b/src/instance/import/mrpack.rs index e76f8b4..9680230 100644 --- a/src/instance/import/mrpack.rs +++ b/src/instance/import/mrpack.rs @@ -145,13 +145,14 @@ async fn download_mod_files( let completed = completed.clone(); tasks.spawn(async move { if let Some(parent) = dest.parent() - && let Err(e) = tokio::fs::create_dir_all(parent).await { - tracing::warn!( - "Failed to create mod download directory {}: {}", - parent.display(), - e - ); - } + && let Err(e) = tokio::fs::create_dir_all(parent).await + { + tracing::warn!( + "Failed to create mod download directory {}: {}", + parent.display(), + e + ); + } progress::set_sub_action(filename); tracing::trace!("Downloading .mrpack file to {}", dest.display()); crate::net::download_file(&client, &url, &dest, |_, _| {}).await?; @@ -183,13 +184,14 @@ async fn download_mod_files( let completed = completed.clone(); tasks.spawn(async move { if let Some(parent) = dest.parent() - && let Err(e) = tokio::fs::create_dir_all(parent).await { - tracing::warn!( - "Failed to create mod download directory {}: {}", - parent.display(), - e - ); - } + && let Err(e) = tokio::fs::create_dir_all(parent).await + { + tracing::warn!( + "Failed to create mod download directory {}: {}", + parent.display(), + e + ); + } progress::set_sub_action(filename); tracing::trace!("Downloading .mrpack file to {}", dest.display()); crate::net::download_file(&client, &url, &dest, |_, _| {}).await?; diff --git a/src/instance/launch/mod.rs b/src/instance/launch/mod.rs index 252329a..82208b9 100644 --- a/src/instance/launch/mod.rs +++ b/src/instance/launch/mod.rs @@ -28,17 +28,13 @@ pub enum LaunchError { Json(#[from] serde_json::Error), #[error("{0} launch is not yet supported")] NotSupported(String), - #[error( - "This instance requires Java {required}, but rmcl is using Java {detected}: {java}" - )] + #[error("This instance requires Java {required}, but rmcl is using Java {detected}: {java}")] JavaTooOld { java: String, required: u32, detected: u32, }, - #[error( - "This instance requires Java {required}, but rmcl could not check {java}: {reason}" - )] + #[error("This instance requires Java {required}, but rmcl could not check {java}: {reason}")] JavaCheckFailed { java: String, required: u32, @@ -414,7 +410,11 @@ pub async fn build_launch_invocation( // so we check there first. let has_local_libs = matches!(config.loader, ModLoader::Forge | ModLoader::NeoForge); let local_lib_dir = minecraft_dir.join("libraries"); - let library_directory = if has_local_libs { &local_lib_dir } else { &lib_dir }; + let library_directory = if has_local_libs { + &local_lib_dir + } else { + &lib_dir + }; let mut classpath: Vec = Vec::new(); for lib in &merged_profile.libraries { diff --git a/src/instance/manager.rs b/src/instance/manager.rs index 396ea0d..0998194 100644 --- a/src/instance/manager.rs +++ b/src/instance/manager.rs @@ -254,7 +254,9 @@ impl InstanceManager { .await .map_err(|e| match e { InstallError::Download(net_error) => InstanceError::Download(net_error), - InstallError::Installer(installer_error) => InstanceError::InstallerError(installer_error), + InstallError::Installer(installer_error) => { + InstanceError::InstallerError(installer_error) + } })?; let config = InstanceConfig { diff --git a/src/net/forge.rs b/src/net/forge.rs index e25e3eb..85d884c 100644 --- a/src/net/forge.rs +++ b/src/net/forge.rs @@ -227,38 +227,58 @@ pub(crate) async fn install_forge_from_profile( let file = std::fs::File::open(installer_path) .map_err(|e| InstallError::Installer(InstallerError::Io(e)))?; - let mut archive = zip::ZipArchive::new(file) - .map_err(|e| InstallError::Installer(InstallerError::Profile(format!("Failed to open installer as ZIP: {e}"))))?; + let mut archive = zip::ZipArchive::new(file).map_err(|e| { + InstallError::Installer(InstallerError::Profile(format!( + "Failed to open installer as ZIP: {e}" + ))) + })?; let profile_data: serde_json::Value = { let entry = archive.by_name("install_profile.json").map_err(|e| { - InstallError::Installer(InstallerError::Profile(format!("install_profile.json not found in installer: {e}"))) + InstallError::Installer(InstallerError::Profile(format!( + "install_profile.json not found in installer: {e}" + ))) })?; - serde_json::from_reader(entry) - .map_err(|e| InstallError::Installer(InstallerError::Profile(format!("Failed to parse install_profile.json: {e}"))))? + serde_json::from_reader(entry).map_err(|e| { + InstallError::Installer(InstallerError::Profile(format!( + "Failed to parse install_profile.json: {e}" + ))) + })? }; - let version_info = profile_data - .get("versionInfo") - .ok_or_else(|| InstallError::Installer(InstallerError::Profile("install_profile.json missing versionInfo".into())))?; - let install_info = profile_data - .get("install") - .ok_or_else(|| InstallError::Installer(InstallerError::Profile("install_profile.json missing install section".into())))?; + let version_info = profile_data.get("versionInfo").ok_or_else(|| { + InstallError::Installer(InstallerError::Profile( + "install_profile.json missing versionInfo".into(), + )) + })?; + let install_info = profile_data.get("install").ok_or_else(|| { + InstallError::Installer(InstallerError::Profile( + "install_profile.json missing install section".into(), + )) + })?; let libraries = version_info .get("libraries") .and_then(|v| v.as_array()) - .ok_or_else(|| InstallError::Installer(InstallerError::Profile("missing versionInfo.libraries".into())))?; + .ok_or_else(|| { + InstallError::Installer(InstallerError::Profile( + "missing versionInfo.libraries".into(), + )) + })?; let file_path = install_info .get("filePath") .and_then(|v| v.as_str()) - .ok_or_else(|| InstallError::Installer(InstallerError::Profile("missing install.filePath".into())))?; + .ok_or_else(|| { + InstallError::Installer(InstallerError::Profile("missing install.filePath".into())) + })?; let install_path_coord = install_info .get("path") .and_then(|v| v.as_str()) - .ok_or_else(|| InstallError::Installer(InstallerError::Profile("missing install.path".into())))?; + .ok_or_else(|| { + InstallError::Installer(InstallerError::Profile("missing install.path".into())) + })?; // extract the universal jar to the correct maven location let universal_maven_path = @@ -300,12 +320,14 @@ pub(crate) async fn install_forge_from_profile( // in mojang's modern version metadata, so we fetch those too. let libraries_dir = meta_dir.join("libraries"); for lib in libraries { - let name = lib.get("name").and_then(|v| v.as_str()).unwrap_or_default(); + let name = lib.get("name").and_then(|v| v.as_str()).unwrap_or_default(); let maven_path = match crate::net::maven_coord_to_path(name) { Some(p) => p, None => { - return Err(InstallError::Installer(InstallerError::Profile(format!("Invalid Maven coordinate: {name}")))); + return Err(InstallError::Installer(InstallerError::Profile(format!( + "Invalid Maven coordinate: {name}" + )))); } }; @@ -341,8 +363,11 @@ pub(crate) async fn install_forge_from_profile( // and whitespace may differ from the original installer JSON because // the source is a serde_json::Value (which doesn't preserve order), // but no field is silently dropped. - let serialized = serde_json::to_vec(version_info) - .map_err(|e| InstallError::Installer(InstallerError::Profile(format!("Failed to serialize Forge profile: {e}"))))?; + let serialized = serde_json::to_vec(version_info).map_err(|e| { + InstallError::Installer(InstallerError::Profile(format!( + "Failed to serialize Forge profile: {e}" + ))) + })?; crate::instance::loader::save_profile_bytes(meta_dir, profile_filename, &serialized) .map_err(|e| InstallError::Installer(InstallerError::Io(e)))?; Ok(())