mirror of
https://github.com/NinjaCheetah/rustii.git
synced 2026-03-03 03:15:28 -05:00
Everything but the no-shared flag is working right now. Getting no-shared to work properly will take a little more work because right now there's nothing to guarantee that the content records are synced between the TMD and content objects in a title. This means that updating any content in a title will result in the records being out of sync and the written TMD will not match the actual state of the content when it was dumped. To mitigate this, I intend on making the content records in the content struct a reference to the content records in the TMD, so that they are the same object and therefore always in sync.
54 lines
1.9 KiB
Rust
54 lines
1.9 KiB
Rust
// archive/ash.rs from ruswtii (c) 2025 NinjaCheetah & Contributors
|
|
// https://github.com/NinjaCheetah/rustwii
|
|
//
|
|
// Code for the ASH decompression command in the rustwii 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 rustwii::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.file_name().unwrap()).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(())
|
|
}
|