mirror of
https://github.com/NinjaCheetah/rustii.git
synced 2026-03-04 11:55:27 -05:00
Added ASH decompression, added corresponding CLI command
Also cleaned up some minor parts of the LZ77 (de)compression library and CLI code
This commit is contained in:
53
src/bin/rustii/archive/ash.rs
Normal file
53
src/bin/rustii/archive/ash.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
// archive/ash.rs from rustii (c) 2025 NinjaCheetah & Contributors
|
||||
// https://github.com/NinjaCheetah/rustii
|
||||
//
|
||||
// Code for the ASH decompression command in the rustii CLI.
|
||||
// Might even have the compression command someday if I ever write the compression code!
|
||||
|
||||
use std::{str, fs};
|
||||
use std::path::{Path, PathBuf};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use clap::Subcommand;
|
||||
use rustii::archive::ash;
|
||||
|
||||
#[derive(Subcommand)]
|
||||
#[command(arg_required_else_help = true)]
|
||||
pub enum Commands {
|
||||
/// Compress a file with ASH compression (NOT IMPLEMENTED)
|
||||
Compress {
|
||||
/// The path to the file to compress
|
||||
input: String,
|
||||
/// An optional output name; defaults to <input name>.ash
|
||||
#[arg(short, long)]
|
||||
output: Option<String>,
|
||||
},
|
||||
/// Decompress an ASH-compressed file
|
||||
Decompress {
|
||||
/// The path to the file to decompress
|
||||
input: String,
|
||||
/// An optional output name; defaults to <input name>.out
|
||||
#[arg(short, long)]
|
||||
output: Option<String>,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compress_ash(_input: &str, _output: &Option<String>) -> Result<()> {
|
||||
todo!();
|
||||
}
|
||||
|
||||
pub fn decompress_ash(input: &str, output: &Option<String>) -> Result<()> {
|
||||
let in_path = Path::new(input);
|
||||
if !in_path.exists() {
|
||||
bail!("Compressed file \"{}\" could not be found.", in_path.display());
|
||||
}
|
||||
let compressed = fs::read(in_path)?;
|
||||
let decompressed = ash::decompress_ash(&compressed, None, None).with_context(|| "An unknown error occurred while decompressing the data.")?;
|
||||
let out_path = if output.is_some() {
|
||||
PathBuf::from(output.clone().unwrap())
|
||||
} else {
|
||||
PathBuf::from(in_path).with_extension(format!("{}.out", in_path.extension().unwrap_or("".as_ref()).to_str().unwrap()))
|
||||
};
|
||||
fs::write(out_path.clone(), decompressed)?;
|
||||
println!("Successfully decompressed ASH file to \"{}\"!", out_path.display());
|
||||
Ok(())
|
||||
}
|
||||
@@ -12,7 +12,7 @@ use rustii::archive::lz77;
|
||||
#[derive(Subcommand)]
|
||||
#[command(arg_required_else_help = true)]
|
||||
pub enum Commands {
|
||||
/// Compress a file with LZ77 compression (NOT IMPLEMENTED)
|
||||
/// Compress a file with LZ77 compression
|
||||
Compress {
|
||||
/// The path to the file to compress
|
||||
input: String,
|
||||
@@ -40,9 +40,10 @@ pub fn compress_lz77(input: &str, output: &Option<String>) -> Result<()> {
|
||||
let out_path = if output.is_some() {
|
||||
PathBuf::from(output.clone().unwrap())
|
||||
} else {
|
||||
PathBuf::from(in_path).with_extension("lz77")
|
||||
PathBuf::from(in_path).with_extension(format!("{}.lz77", in_path.extension().unwrap_or("".as_ref()).to_str().unwrap()))
|
||||
};
|
||||
fs::write(out_path, compressed)?;
|
||||
fs::write(out_path.clone(), compressed)?;
|
||||
println!("Successfully compressed file to \"{}\"!", out_path.display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -56,8 +57,9 @@ pub fn decompress_lz77(input: &str, output: &Option<String>) -> Result<()> {
|
||||
let out_path = if output.is_some() {
|
||||
PathBuf::from(output.clone().unwrap())
|
||||
} else {
|
||||
PathBuf::from(in_path).with_extension("out")
|
||||
PathBuf::from(in_path).with_extension(format!("{}.out", in_path.extension().unwrap_or("".as_ref()).to_str().unwrap()))
|
||||
};
|
||||
fs::write(out_path, decompressed)?;
|
||||
fs::write(out_path.clone(), decompressed)?;
|
||||
println!("Successfully decompressed LZ77 file to \"{}\"!", out_path.display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// archive/mod.rs from rustii (c) 2025 NinjaCheetah & Contributors
|
||||
// https://github.com/NinjaCheetah/rustii
|
||||
|
||||
pub mod ash;
|
||||
pub mod lz77;
|
||||
|
||||
@@ -21,6 +21,11 @@ struct Cli {
|
||||
#[derive(Subcommand)]
|
||||
#[command(arg_required_else_help = true)]
|
||||
enum Commands {
|
||||
/// Decompress data using ASH compression
|
||||
Ash {
|
||||
#[command(subcommand)]
|
||||
command: archive::ash::Commands,
|
||||
},
|
||||
/// Fakesign a TMD, Ticket, or WAD (trucha bug)
|
||||
Fakesign {
|
||||
/// The path to a TMD, Ticket, or WAD
|
||||
@@ -50,6 +55,16 @@ fn main() -> Result<()> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
match &cli.command {
|
||||
Some(Commands::Ash { command }) => {
|
||||
match command {
|
||||
archive::ash::Commands::Compress { input, output } => {
|
||||
archive::ash::compress_ash(input, output)?
|
||||
},
|
||||
archive::ash::Commands::Decompress { input, output } => {
|
||||
archive::ash::decompress_ash(input, output)?
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(Commands::Fakesign { input, output }) => {
|
||||
title::fakesign::fakesign(input, output)?
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user