Fix for possible crash when getting info for some TMDs

This commit is contained in:
Campbell 2025-04-01 21:09:54 -04:00
parent e147a953a5
commit 97fe838b8c
Signed by: NinjaCheetah
GPG Key ID: B547958AF96ED344
3 changed files with 31 additions and 7 deletions

View File

@ -26,12 +26,11 @@ fn print_tmd_info(tmd: tmd::TMD, cert: Option<cert::Certificate>) {
} else {
println!(" Title ID: {}", hex::encode(tmd.title_id).to_uppercase());
}
if hex::encode(tmd.title_id)[..8].eq("00000001") {
let converted_ver = versions::dec_to_standard(tmd.title_version, &hex::encode(tmd.title_id), Some(tmd.is_vwii != 0));
if hex::encode(tmd.title_id).eq("0000000100000001") {
println!(" Title Version: {} (boot2v{})", tmd.title_version, tmd.title_version);
} else {
println!(" Title Version: {} ({})", tmd.title_version, versions::dec_to_standard(tmd.title_version, &hex::encode(tmd.title_id), Some(tmd.is_vwii != 0)).unwrap());
}
} else if hex::encode(tmd.title_id)[..8].eq("00000001") && converted_ver.is_some() {
println!(" Title Version: {} ({})", tmd.title_version, converted_ver.unwrap());
} else {
println!(" Title Version: {}", tmd.title_version);
}

View File

@ -46,6 +46,9 @@ fn main() {
match &cli.command {
Some(Commands::Wad { command }) => {
match command {
Some(wad::Commands::Convert { input, output }) => {
wad::convert_wad(input, output)
},
Some(wad::Commands::Pack { input, output}) => {
wad::pack_wad(input, output)
},

View File

@ -5,7 +5,7 @@
use std::{str, fs};
use std::path::{Path, PathBuf};
use clap::Subcommand;
use clap::{Subcommand, Args};
use glob::glob;
use rustii::title::{cert, tmd, ticket, content, wad};
use rustii::title;
@ -13,18 +13,40 @@ use rustii::title;
#[derive(Subcommand)]
#[command(arg_required_else_help = true)]
pub enum Commands {
/// Re-encrypt a WAD file with a different key
Convert {
/// The path to the WAD to convert
input: String,
/// An (optional) WAD name; defaults to <input name>_<new type>.wad
#[arg(short, long)]
output: Option<String>,
},
/// Pack a directory into a WAD file
Pack {
/// The directory to pack into a WAD
input: String,
/// The name of the packed WAD file
output: String
},
/// Unpack a WAD file into a directory
Unpack {
/// The path to the WAD to unpack
input: String,
/// The directory to extract the WAD to
output: String
}
}
#[derive(Args)]
#[group(multiple = false, required = true)]
struct ConvertTargets {
}
pub fn convert_wad(input: &str, output: &Option<String>) {
todo!();
}
pub fn pack_wad(input: &str, output: &str) {
let in_path = Path::new(input);
if !in_path.exists() {