mirror of
https://github.com/NinjaCheetah/rustii.git
synced 2025-06-05 23:11:02 -04:00
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
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:
parent
3178063a07
commit
ac1368053b
@ -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);
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ impl TMD {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
pub fn region(&self) -> &str {
|
||||
match self.region {
|
||||
0 => "JPN",
|
||||
@ -300,7 +300,7 @@ impl TMD {
|
||||
_ => "Unknown",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn title_type(&self) -> TitleType {
|
||||
match hex::encode(self.title_id)[..8].to_string().as_str() {
|
||||
"00000001" => TitleType::System,
|
||||
@ -313,7 +313,7 @@ impl TMD {
|
||||
_ => TitleType::Unknown,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn content_type(&self, index: usize) -> ContentType {
|
||||
// Find possible content indices, because the provided one could exist while the indices
|
||||
// are out of order, which could cause problems finding the content.
|
||||
@ -329,8 +329,8 @@ impl TMD {
|
||||
ContentType::DLC => ContentType::DLC,
|
||||
ContentType::Shared => ContentType::Shared,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn check_access_right(&self, right: AccessRight) -> bool {
|
||||
match right {
|
||||
AccessRight::AHB => (self.access_rights & (1 << 0)) != 0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user