From 01fdb340fa95d41576d24a73b92be403f34ecf98 Mon Sep 17 00:00:00 2001 From: G2-Games Date: Thu, 14 Nov 2024 13:04:15 -0600 Subject: [PATCH] Applied clippy suggestions, ran `cargo fmt` --- cz/src/formats/cz2.rs | 2 +- luca_pak/src/entry.rs | 6 +++++- luca_pak/src/lib.rs | 2 +- pak_explorer/src/main.rs | 16 ++++++++------ utils/build.rs | 18 ++++++++++------ utils/src/bin/czutil.rs | 46 ++++++++++++++++++++++++++-------------- utils/src/bin/pakutil.rs | 2 +- 7 files changed, 59 insertions(+), 33 deletions(-) diff --git a/cz/src/formats/cz2.rs b/cz/src/formats/cz2.rs index 451f79b..54a2d25 100644 --- a/cz/src/formats/cz2.rs +++ b/cz/src/formats/cz2.rs @@ -15,7 +15,7 @@ pub fn decode(bytes: &mut T) -> Result, CzError> { } pub fn encode(output: &mut T, bitmap: &[u8]) -> Result<(), CzError> { - let (compressed_data, compressed_info) = compress2(&bitmap); + let (compressed_data, compressed_info) = compress2(bitmap); compressed_info.write_into(output)?; diff --git a/luca_pak/src/entry.rs b/luca_pak/src/entry.rs index a365ff9..1ba23f6 100644 --- a/luca_pak/src/entry.rs +++ b/luca_pak/src/entry.rs @@ -58,6 +58,10 @@ impl Entry { self.length as usize } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// Get the raw byte data of an [`Entry`] pub fn as_bytes(&self) -> &Vec { &self.data @@ -66,7 +70,7 @@ impl Entry { pub fn display_name(&self) -> String { let mut name = self.name().clone().unwrap_or(self.id().to_string()); let entry_type = self.file_type(); - name.push_str(&entry_type.extension()); + name.push_str(entry_type.extension()); name } diff --git a/luca_pak/src/lib.rs b/luca_pak/src/lib.rs index 4a692ea..5ac0e5b 100644 --- a/luca_pak/src/lib.rs +++ b/luca_pak/src/lib.rs @@ -1,7 +1,7 @@ pub mod entry; pub mod header; -use byteorder_lite::{LE, ReadBytesExt, WriteBytesExt}; +use byteorder_lite::{ReadBytesExt, WriteBytesExt, LE}; use header::Header; use log::{debug, info}; use std::{ diff --git a/pak_explorer/src/main.rs b/pak_explorer/src/main.rs index 0968e3b..900a4d8 100644 --- a/pak_explorer/src/main.rs +++ b/pak_explorer/src/main.rs @@ -1,7 +1,9 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release use colog; -use eframe::egui::{self, ColorImage, Image, TextureFilter, TextureHandle, TextureOptions, ThemePreference}; +use eframe::egui::{ + self, ColorImage, Image, TextureFilter, TextureHandle, TextureOptions, ThemePreference, +}; use log::error; use luca_pak::{entry::EntryType, Pak}; use std::fs; @@ -156,18 +158,18 @@ impl eframe::App for PakExplorer { .set_file_name(display_name) .save_file() { - let cz = cz::CzFile::decode(&mut std::io::Cursor::new( - entry.as_bytes(), - )) - .unwrap(); + let cz = + cz::CzFile::decode(&mut std::io::Cursor::new(entry.as_bytes())) + .unwrap(); image::save_buffer_with_format( path, cz.as_raw(), cz.header().width() as u32, cz.header().height() as u32, image::ColorType::Rgba8, - image::ImageFormat::Png - ).unwrap(); + image::ImageFormat::Png, + ) + .unwrap(); } } diff --git a/utils/build.rs b/utils/build.rs index 776aa2f..f0b4e51 100644 --- a/utils/build.rs +++ b/utils/build.rs @@ -8,10 +8,16 @@ fn main() { let si = SysinfoBuilder::all_sysinfo().unwrap(); Emitter::default() - .add_instructions(&build).unwrap() - .add_instructions(&cargo).unwrap() - .add_instructions(&gitcl).unwrap() - .add_instructions(&rustc).unwrap() - .add_instructions(&si).unwrap() - .emit().unwrap(); + .add_instructions(&build) + .unwrap() + .add_instructions(&cargo) + .unwrap() + .add_instructions(&gitcl) + .unwrap() + .add_instructions(&rustc) + .unwrap() + .add_instructions(&si) + .unwrap() + .emit() + .unwrap(); } diff --git a/utils/src/bin/czutil.rs b/utils/src/bin/czutil.rs index 3dfbfe9..9669373 100644 --- a/utils/src/bin/czutil.rs +++ b/utils/src/bin/czutil.rs @@ -4,7 +4,9 @@ use image::ColorType; use lbee_utils::version; use owo_colors::OwoColorize; use std::{ - ascii::AsciiExt, fs, path::{Path, PathBuf}, process::exit + fs, + path::{Path, PathBuf}, + process::exit, }; /// Utility to maniuplate CZ image files from the LUCA System game engine by @@ -152,8 +154,9 @@ fn main() { cz.header().width() as u32, cz.header().height() as u32, ColorType::Rgba8, - image::ImageFormat::Png - ).unwrap(); + image::ImageFormat::Png, + ) + .unwrap(); } } else { let cz = cz::open(input).unwrap(); @@ -165,8 +168,9 @@ fn main() { cz.header().width() as u32, cz.header().height() as u32, ColorType::Rgba8, - image::ImageFormat::Png - ).unwrap(); + image::ImageFormat::Png, + ) + .unwrap(); } else { let file_stem = PathBuf::from(input.file_name().unwrap()); image::save_buffer_with_format( @@ -175,8 +179,9 @@ fn main() { cz.header().width() as u32, cz.header().height() as u32, ColorType::Rgba8, - image::ImageFormat::Png - ).unwrap(); + image::ImageFormat::Png, + ) + .unwrap(); } } } @@ -261,7 +266,7 @@ fn main() { input, output, version, - depth + depth, } => { if !input.exists() { pretty_error("The original file provided does not exist"); @@ -272,11 +277,17 @@ fn main() { match CzVersion::try_from(*v) { Ok(v) => v, Err(_) => { - pretty_error(&format!("Invalid CZ version {}; must be 0, 1, 2, 3, or 4", v)); + pretty_error(&format!( + "Invalid CZ version {}; must be 0, 1, 2, 3, or 4", + v + )); exit(1); - }, + } } - } else if output.extension().is_some_and(|e| e.to_ascii_lowercase().to_string_lossy().starts_with("cz")) { + } else if output + .extension() + .is_some_and(|e| e.to_ascii_lowercase().to_string_lossy().starts_with("cz")) + { let ext_string = output.extension().unwrap().to_string_lossy(); let last_char = ext_string.chars().last().unwrap(); match CzVersion::try_from(last_char) { @@ -284,7 +295,7 @@ fn main() { Err(e) => { pretty_error(&format!("Invalid CZ type: {}", e)); exit(1); - }, + } } } else { pretty_error("CZ version not specified or not parseable from file path"); @@ -296,7 +307,7 @@ fn main() { Err(e) => { pretty_error(&format!("Could not open input file: {e}")); exit(1); - }, + } }; let image_depth = image.color(); @@ -305,11 +316,14 @@ fn main() { version, image.width() as u16, image.height() as u16, - image.to_rgba8().into_vec() + image.to_rgba8().into_vec(), ); if let Some(d) = *depth { if !(d == 8 || d == 24 || d == 32) { - pretty_error(&format!("The color depth provided is not valid. Choose from: {}", "8, 24, or 32".bright_magenta())); + pretty_error(&format!( + "The color depth provided is not valid. Choose from: {}", + "8, 24, or 32".bright_magenta() + )); exit(1); } cz.header_mut().set_depth(d); @@ -339,7 +353,7 @@ fn replace_cz>( } // Open the replacement image and convert it to RGBA8 - let repl_img = image::open(&replacement_path)?.to_rgba8(); + let repl_img = image::open(replacement_path)?.to_rgba8(); // Open the original CZ file let mut cz = cz::open(&path)?; diff --git a/utils/src/bin/pakutil.rs b/utils/src/bin/pakutil.rs index bf1f5a2..e070032 100644 --- a/utils/src/bin/pakutil.rs +++ b/utils/src/bin/pakutil.rs @@ -2,8 +2,8 @@ use clap::{ error::{Error, ErrorKind}, Parser, Subcommand, }; -use luca_pak::Pak; use lbee_utils::version; +use luca_pak::Pak; use std::{fs, path::PathBuf, process::exit}; /// Utility to maniuplate PAK archive files from the LUCA System game engine by