mirror of
https://github.com/G2-Games/lbee-utils.git
synced 2025-04-18 23:02:56 -05:00
Applied clippy suggestions, ran cargo fmt
This commit is contained in:
parent
b74dc0344e
commit
01fdb340fa
7 changed files with 59 additions and 33 deletions
|
@ -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> {
|
||||
let (compressed_data, compressed_info) = compress2(&bitmap);
|
||||
let (compressed_data, compressed_info) = compress2(bitmap);
|
||||
|
||||
compressed_info.write_into(output)?;
|
||||
|
||||
|
|
|
@ -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<u8> {
|
||||
&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
|
||||
}
|
||||
|
|
|
@ -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::{
|
||||
|
|
|
@ -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,9 +158,8 @@ 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(),
|
||||
))
|
||||
let cz =
|
||||
cz::CzFile::decode(&mut std::io::Cursor::new(entry.as_bytes()))
|
||||
.unwrap();
|
||||
image::save_buffer_with_format(
|
||||
path,
|
||||
|
@ -166,8 +167,9 @@ impl eframe::App for PakExplorer {
|
|||
cz.header().width() as u32,
|
||||
cz.header().height() as u32,
|
||||
image::ColorType::Rgba8,
|
||||
image::ImageFormat::Png
|
||||
).unwrap();
|
||||
image::ImageFormat::Png,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<P: ?Sized + AsRef<Path>>(
|
|||
}
|
||||
|
||||
// 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)?;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue