Applied clippy suggestions, ran cargo fmt

This commit is contained in:
G2-Games 2024-11-14 13:04:15 -06:00
parent b74dc0344e
commit 01fdb340fa
7 changed files with 59 additions and 33 deletions

View file

@ -15,7 +15,7 @@ pub fn decode<T: Seek + Read>(bytes: &mut T) -> Result<Vec<u8>, CzError> {
} }
pub fn encode<T: Write>(output: &mut T, bitmap: &[u8]) -> Result<(), CzError> { pub fn encode<T: Write>(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)?; compressed_info.write_into(output)?;

View file

@ -58,6 +58,10 @@ impl Entry {
self.length as usize self.length as usize
} }
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Get the raw byte data of an [`Entry`] /// Get the raw byte data of an [`Entry`]
pub fn as_bytes(&self) -> &Vec<u8> { pub fn as_bytes(&self) -> &Vec<u8> {
&self.data &self.data
@ -66,7 +70,7 @@ impl Entry {
pub fn display_name(&self) -> String { pub fn display_name(&self) -> String {
let mut name = self.name().clone().unwrap_or(self.id().to_string()); let mut name = self.name().clone().unwrap_or(self.id().to_string());
let entry_type = self.file_type(); let entry_type = self.file_type();
name.push_str(&entry_type.extension()); name.push_str(entry_type.extension());
name name
} }

View file

@ -1,7 +1,7 @@
pub mod entry; pub mod entry;
pub mod header; pub mod header;
use byteorder_lite::{LE, ReadBytesExt, WriteBytesExt}; use byteorder_lite::{ReadBytesExt, WriteBytesExt, LE};
use header::Header; use header::Header;
use log::{debug, info}; use log::{debug, info};
use std::{ use std::{

View file

@ -1,7 +1,9 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use colog; 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 log::error;
use luca_pak::{entry::EntryType, Pak}; use luca_pak::{entry::EntryType, Pak};
use std::fs; use std::fs;
@ -156,18 +158,18 @@ impl eframe::App for PakExplorer {
.set_file_name(display_name) .set_file_name(display_name)
.save_file() .save_file()
{ {
let cz = cz::CzFile::decode(&mut std::io::Cursor::new( let cz =
entry.as_bytes(), cz::CzFile::decode(&mut std::io::Cursor::new(entry.as_bytes()))
)) .unwrap();
.unwrap();
image::save_buffer_with_format( image::save_buffer_with_format(
path, path,
cz.as_raw(), cz.as_raw(),
cz.header().width() as u32, cz.header().width() as u32,
cz.header().height() as u32, cz.header().height() as u32,
image::ColorType::Rgba8, image::ColorType::Rgba8,
image::ImageFormat::Png image::ImageFormat::Png,
).unwrap(); )
.unwrap();
} }
} }

View file

@ -8,10 +8,16 @@ fn main() {
let si = SysinfoBuilder::all_sysinfo().unwrap(); let si = SysinfoBuilder::all_sysinfo().unwrap();
Emitter::default() Emitter::default()
.add_instructions(&build).unwrap() .add_instructions(&build)
.add_instructions(&cargo).unwrap() .unwrap()
.add_instructions(&gitcl).unwrap() .add_instructions(&cargo)
.add_instructions(&rustc).unwrap() .unwrap()
.add_instructions(&si).unwrap() .add_instructions(&gitcl)
.emit().unwrap(); .unwrap()
.add_instructions(&rustc)
.unwrap()
.add_instructions(&si)
.unwrap()
.emit()
.unwrap();
} }

View file

@ -4,7 +4,9 @@ use image::ColorType;
use lbee_utils::version; use lbee_utils::version;
use owo_colors::OwoColorize; use owo_colors::OwoColorize;
use std::{ 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 /// 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().width() as u32,
cz.header().height() as u32, cz.header().height() as u32,
ColorType::Rgba8, ColorType::Rgba8,
image::ImageFormat::Png image::ImageFormat::Png,
).unwrap(); )
.unwrap();
} }
} else { } else {
let cz = cz::open(input).unwrap(); let cz = cz::open(input).unwrap();
@ -165,8 +168,9 @@ fn main() {
cz.header().width() as u32, cz.header().width() as u32,
cz.header().height() as u32, cz.header().height() as u32,
ColorType::Rgba8, ColorType::Rgba8,
image::ImageFormat::Png image::ImageFormat::Png,
).unwrap(); )
.unwrap();
} else { } else {
let file_stem = PathBuf::from(input.file_name().unwrap()); let file_stem = PathBuf::from(input.file_name().unwrap());
image::save_buffer_with_format( image::save_buffer_with_format(
@ -175,8 +179,9 @@ fn main() {
cz.header().width() as u32, cz.header().width() as u32,
cz.header().height() as u32, cz.header().height() as u32,
ColorType::Rgba8, ColorType::Rgba8,
image::ImageFormat::Png image::ImageFormat::Png,
).unwrap(); )
.unwrap();
} }
} }
} }
@ -261,7 +266,7 @@ fn main() {
input, input,
output, output,
version, version,
depth depth,
} => { } => {
if !input.exists() { if !input.exists() {
pretty_error("The original file provided does not exist"); pretty_error("The original file provided does not exist");
@ -272,11 +277,17 @@ fn main() {
match CzVersion::try_from(*v) { match CzVersion::try_from(*v) {
Ok(v) => v, Ok(v) => v,
Err(_) => { 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); 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 ext_string = output.extension().unwrap().to_string_lossy();
let last_char = ext_string.chars().last().unwrap(); let last_char = ext_string.chars().last().unwrap();
match CzVersion::try_from(last_char) { match CzVersion::try_from(last_char) {
@ -284,7 +295,7 @@ fn main() {
Err(e) => { Err(e) => {
pretty_error(&format!("Invalid CZ type: {}", e)); pretty_error(&format!("Invalid CZ type: {}", e));
exit(1); exit(1);
}, }
} }
} else { } else {
pretty_error("CZ version not specified or not parseable from file path"); pretty_error("CZ version not specified or not parseable from file path");
@ -296,7 +307,7 @@ fn main() {
Err(e) => { Err(e) => {
pretty_error(&format!("Could not open input file: {e}")); pretty_error(&format!("Could not open input file: {e}"));
exit(1); exit(1);
}, }
}; };
let image_depth = image.color(); let image_depth = image.color();
@ -305,11 +316,14 @@ fn main() {
version, version,
image.width() as u16, image.width() as u16,
image.height() as u16, image.height() as u16,
image.to_rgba8().into_vec() image.to_rgba8().into_vec(),
); );
if let Some(d) = *depth { if let Some(d) = *depth {
if !(d == 8 || d == 24 || d == 32) { 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); exit(1);
} }
cz.header_mut().set_depth(d); cz.header_mut().set_depth(d);
@ -339,7 +353,7 @@ fn replace_cz<P: ?Sized + AsRef<Path>>(
} }
// Open the replacement image and convert it to RGBA8 // 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 // Open the original CZ file
let mut cz = cz::open(&path)?; let mut cz = cz::open(&path)?;

View file

@ -2,8 +2,8 @@ use clap::{
error::{Error, ErrorKind}, error::{Error, ErrorKind},
Parser, Subcommand, Parser, Subcommand,
}; };
use luca_pak::Pak;
use lbee_utils::version; use lbee_utils::version;
use luca_pak::Pak;
use std::{fs, path::PathBuf, process::exit}; use std::{fs, path::PathBuf, process::exit};
/// Utility to maniuplate PAK archive files from the LUCA System game engine by /// Utility to maniuplate PAK archive files from the LUCA System game engine by