mirror of
https://github.com/NinjaCheetah/rustii.git
synced 2025-06-05 23:11:02 -04:00
Improved error handling for fakesign CLI command
This commit is contained in:
parent
85f3f028d4
commit
d9e8465f0c
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
*Like rusty but it's rustii because the Wii? Get it?*
|
*Like rusty but it's rustii because the Wii? Get it?*
|
||||||
|
|
||||||
|
[](https://github.com/NinjaCheetah/rustii/actions/workflows/rust.yml)
|
||||||
|
|
||||||
rustii is a library and command line tool written in Rust for handling the various files and formats found on the Wii. rustii is a port of my other library, [libWiiPy](https://github.com/NinjaCheetah/libWiiPy), which aims to accomplish the same goal in Python. Compared to libWiiPy, rustii is in its very early stages of development and is missing most of the features present in its Python counterpart. The goal is for rustii and libWiiPy to eventually have feature parity, with the rustii CLI acting as a drop-in replacement for the (comparatively much less efficient) [WiiPy](https://github.com/NinjaCheetah/WiiPy) CLI.
|
rustii is a library and command line tool written in Rust for handling the various files and formats found on the Wii. rustii is a port of my other library, [libWiiPy](https://github.com/NinjaCheetah/libWiiPy), which aims to accomplish the same goal in Python. Compared to libWiiPy, rustii is in its very early stages of development and is missing most of the features present in its Python counterpart. The goal is for rustii and libWiiPy to eventually have feature parity, with the rustii CLI acting as a drop-in replacement for the (comparatively much less efficient) [WiiPy](https://github.com/NinjaCheetah/WiiPy) CLI.
|
||||||
|
|
||||||
I'm still very new to Rust, so pardon any messy code or confusing API decisions you may find. libWiiPy started off like that, too.
|
I'm still very new to Rust, so pardon any messy code or confusing API decisions you may find. libWiiPy started off like that, too.
|
||||||
|
@ -60,7 +60,7 @@ fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(Commands::Fakesign { input, output }) => {
|
Some(Commands::Fakesign { input, output }) => {
|
||||||
fakesign::fakesign(input, output)
|
fakesign::fakesign(input, output)?
|
||||||
},
|
},
|
||||||
Some(Commands::Info { input }) => {
|
Some(Commands::Info { input }) => {
|
||||||
info::info(input)
|
info::info(input)
|
||||||
|
@ -5,13 +5,14 @@
|
|||||||
|
|
||||||
use std::{str, fs};
|
use std::{str, fs};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use anyhow::{bail, Context, Result};
|
||||||
use rustii::{title, title::tmd, title::ticket};
|
use rustii::{title, title::tmd, title::ticket};
|
||||||
use crate::filetypes::{WiiFileType, identify_file_type};
|
use crate::filetypes::{WiiFileType, identify_file_type};
|
||||||
|
|
||||||
pub fn fakesign(input: &str, output: &Option<String>) {
|
pub fn fakesign(input: &str, output: &Option<String>) -> Result<()> {
|
||||||
let in_path = Path::new(input);
|
let in_path = Path::new(input);
|
||||||
if !in_path.exists() {
|
if !in_path.exists() {
|
||||||
panic!("Error: Input file does not exist.");
|
bail!("Input file \"{}\" does not exist.", in_path.display());
|
||||||
}
|
}
|
||||||
match identify_file_type(input) {
|
match identify_file_type(input) {
|
||||||
Some(WiiFileType::Wad) => {
|
Some(WiiFileType::Wad) => {
|
||||||
@ -21,10 +22,11 @@ pub fn fakesign(input: &str, output: &Option<String>) {
|
|||||||
PathBuf::from(input)
|
PathBuf::from(input)
|
||||||
};
|
};
|
||||||
// Load WAD into a Title instance, then fakesign it.
|
// Load WAD into a Title instance, then fakesign it.
|
||||||
let mut title = title::Title::from_bytes(fs::read(in_path).unwrap().as_slice()).expect("could not read WAD file");
|
let mut title = title::Title::from_bytes(fs::read(in_path).with_context(|| "Could not open WAD file for reading.")?.as_slice())
|
||||||
title.fakesign().expect("could not fakesign WAD");
|
.with_context(|| "The provided WAD file could not be parsed, and is likely invalid.")?;
|
||||||
|
title.fakesign().with_context(|| "An unknown error occurred while fakesigning the provided WAD.")?;
|
||||||
// Write output file.
|
// Write output file.
|
||||||
fs::write(out_path, title.to_wad().unwrap().to_bytes().expect("could not create output WAD")).expect("could not write output WAD file");
|
fs::write(out_path, title.to_wad()?.to_bytes()?).with_context(|| "Could not open output file for writing.")?;
|
||||||
println!("WAD fakesigned!");
|
println!("WAD fakesigned!");
|
||||||
},
|
},
|
||||||
Some(WiiFileType::Tmd) => {
|
Some(WiiFileType::Tmd) => {
|
||||||
@ -34,10 +36,11 @@ pub fn fakesign(input: &str, output: &Option<String>) {
|
|||||||
PathBuf::from(input)
|
PathBuf::from(input)
|
||||||
};
|
};
|
||||||
// Load TMD into a TMD instance, then fakesign it.
|
// Load TMD into a TMD instance, then fakesign it.
|
||||||
let mut tmd = tmd::TMD::from_bytes(fs::read(in_path).unwrap().as_slice()).expect("could not read TMD file");
|
let mut tmd = tmd::TMD::from_bytes(fs::read(in_path).with_context(|| "Could not open TMD file for reading.")?.as_slice())
|
||||||
tmd.fakesign().expect("could not fakesign TMD");
|
.with_context(|| "The provided TMD file could not be parsed, and is likely invalid.")?;
|
||||||
|
tmd.fakesign().with_context(|| "An unknown error occurred while fakesigning the provided TMD.")?;
|
||||||
// Write output file.
|
// Write output file.
|
||||||
fs::write(out_path, tmd.to_bytes().expect("could not create output TMD")).expect("could not write output TMD file");
|
fs::write(out_path, tmd.to_bytes()?).with_context(|| "Could not open output file for writing.")?;
|
||||||
println!("TMD fakesigned!");
|
println!("TMD fakesigned!");
|
||||||
},
|
},
|
||||||
Some(WiiFileType::Ticket) => {
|
Some(WiiFileType::Ticket) => {
|
||||||
@ -47,14 +50,16 @@ pub fn fakesign(input: &str, output: &Option<String>) {
|
|||||||
PathBuf::from(input)
|
PathBuf::from(input)
|
||||||
};
|
};
|
||||||
// Load Ticket into a Ticket instance, then fakesign it.
|
// Load Ticket into a Ticket instance, then fakesign it.
|
||||||
let mut ticket = ticket::Ticket::from_bytes(fs::read(in_path).unwrap().as_slice()).expect("could not read Ticket file");
|
let mut ticket = ticket::Ticket::from_bytes(fs::read(in_path).with_context(|| "Could not open Ticket file for reading.")?.as_slice())
|
||||||
ticket.fakesign().expect("could not fakesign Ticket");
|
.with_context(|| "The provided Ticket file could not be parsed, and is likely invalid.")?;
|
||||||
|
ticket.fakesign().with_context(|| "An unknown error occurred while fakesigning the provided Ticket.")?;
|
||||||
// Write output file.
|
// Write output file.
|
||||||
fs::write(out_path, ticket.to_bytes().expect("could not create output Ticket")).expect("could not write output Ticket file");
|
fs::write(out_path, ticket.to_bytes()?).with_context(|| "Could not open output file for writing.")?;
|
||||||
println!("Ticket fakesigned!");
|
println!("Ticket fakesigned!");
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
panic!("Error: You can only fakesign TMDs, Tickets, and WADs!");
|
bail!("You can only fakesign TMDs, Tickets, and WADs!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ pub fn convert_wad(input: &str, target: &ConvertTargets, output: &Option<String>
|
|||||||
Target::Vwii => PathBuf::from(format!("{}_vWii", in_path.file_stem().unwrap().to_str().unwrap())).with_extension("wad"),
|
Target::Vwii => PathBuf::from(format!("{}_vWii", in_path.file_stem().unwrap().to_str().unwrap())).with_extension("wad"),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut title = title::Title::from_bytes(fs::read(in_path)?.as_slice()).with_context(|| "The provided WAD file could not be loaded, and is likely invalid.")?;
|
let mut title = title::Title::from_bytes(fs::read(in_path)?.as_slice()).with_context(|| "The provided WAD file could not be parsed, and is likely invalid.")?;
|
||||||
// Bail if the WAD is already using the selected encryption.
|
// Bail if the WAD is already using the selected encryption.
|
||||||
if matches!(target, Target::Dev) && title.ticket.is_dev() {
|
if matches!(target, Target::Dev) && title.ticket.is_dev() {
|
||||||
bail!("This is already a development WAD!");
|
bail!("This is already a development WAD!");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user