Added title size calculation methods (sizes now shown in info as well)
Some checks are pending
Build rustii / build-linux-x86_64 (push) Waiting to run
Build rustii / build-macos-arm64 (push) Waiting to run
Build rustii / build-macos-x86_64 (push) Waiting to run
Build rustii / build-windows-x86_64 (push) Waiting to run

This commit is contained in:
Campbell 2025-03-25 21:33:41 -04:00
parent 3178063a07
commit ac1368053b
Signed by: NinjaCheetah
GPG Key ID: 39C2500E1778B156
3 changed files with 41 additions and 9 deletions

View File

@ -102,12 +102,16 @@ fn print_wad_info(wad: wad::WAD) {
wad::WADType::ImportBoot => { println!(" WAD Type: boot2") },
wad::WADType::Installable => { println!(" WAD Type: Standard Installable") },
}
println!(" Installed Size: WIP blocks");
println!(" Installed Size (MB): WIP MB");
// Create a Title for size info, signing info and TMD/Ticket info.
let title = title::Title::from_wad(&wad).unwrap();
let min_size_blocks = title.title_size_blocks(None).unwrap();
let max_size_blocks = title.title_size_blocks(Some(true)).unwrap();
println!(" Installed Size: {}-{} blocks", min_size_blocks, max_size_blocks);
let min_size = title.title_size(None).unwrap() as f64 / 1048576.0;
let max_size = title.title_size(Some(true)).unwrap() as f64 / 1048576.0;
println!(" Installed Size (MB): {:.2}-{:.2} MB", min_size, max_size);
println!(" Has Meta/Footer: {}", wad.meta_size() != 0);
println!(" Has CRL: {}", wad.crl_size() != 0);
// Create a Title for signing info and TMD/Ticket info.
let title = title::Title::from_wad(&wad).unwrap();
println!(" Fakesigned: {}", title.is_fakesigned());
println!();
print_ticket_info(title.ticket);

View File

@ -110,6 +110,34 @@ impl Title {
Ok(content)
}
/// Gets the installed size of the title, in bytes. Use the optional parameter "absolute" to set
/// whether shared content should be included in this total or not.
pub fn title_size(&self, absolute: Option<bool>) -> Result<usize, TitleError> {
let mut title_size: usize = 0;
// Get the TMD and Ticket size by dumping them and measuring their length for the most
// accurate results.
title_size += self.tmd.to_bytes().map_err(|x| TitleError::TMDError(tmd::TMDError::IOError(x)))?.len();
title_size += self.ticket.to_bytes().map_err(|x| TitleError::TicketError(ticket::TicketError::IOError(x)))?.len();
for record in &self.tmd.content_records {
if matches!(record.content_type, tmd::ContentType::Shared) {
if absolute == Some(true) {
title_size += record.content_size as usize;
}
}
else {
title_size += record.content_size as usize;
}
}
Ok(title_size)
}
/// Gets the installed size of the title, in blocks. Use the optional parameter "absolute" to
/// set whether shared content should be included in this total or not.
pub fn title_size_blocks(&self, absolute: Option<bool>) -> Result<usize, TitleError> {
let title_size_bytes = self.title_size(absolute)?;
Ok((title_size_bytes as f64 / 131072.0).ceil() as usize)
}
pub fn cert_chain(&self) -> Vec<u8> {
self.cert_chain.clone()
}