use letterbomb::generate::{IncludeBundle, make_payload_now, write_subpaths};
use letterbomb::mac::WiiMAC;
use letterbomb::region::Region;
use anyhow::anyhow;
use clap::{Arg, Command};
use letterbomb::generate::IncludeBundle::{ExcludeHackMii, IncludeHackMii};
use std::fs;
use std::path::PathBuf;
use std::str::FromStr;
fn main() -> anyhow::Result<()> {
let matches = Command::new("letterbomb")
.version(env!("CARGO_PKG_VERSION"))
.about("✉️💣 LetterBomb – a Wii hacking tool")
.author("fail0verflow, WhoAteMyButter")
.arg(
Arg::new("mac")
.help("Wii's MAC address, as in aa:bb:cc:dd:ee:ff")
.required(true)
.index(1)
.value_parser(WiiMAC::from_str),
)
.arg(
Arg::new("region")
.help("uppercase letter of Wii's region")
.required(true)
.index(2)
.value_parser(Region::from_str),
)
.arg(
Arg::new("output")
.help("where to put files")
.required(true)
.index(3)
.value_parser(PathBuf::from_str),
)
.arg(
Arg::new("bundle")
.help("include the HackMii installer")
.short('b')
.long("bundle")
.action(clap::ArgAction::SetTrue),
)
.get_matches();
let mac = matches.get_one::<WiiMAC>("mac").unwrap();
let region = matches.get_one::<Region>("region").unwrap();
let include_bundle = matches.get_flag("bundle");
let output = matches.get_one::<PathBuf>("output").unwrap();
if !output.exists() {
fs::create_dir_all(output).ok();
} else if output.is_file() {
return Err(anyhow!("output is file; will not clobber"));
}
println!("generating payload for mac {}, region {}", &mac, ®ion);
let include_bundle_enum: IncludeBundle = if include_bundle {
println!("including HackMii installer");
IncludeHackMii
} else {
ExcludeHackMii
};
println!("---");
let payload = make_payload_now(mac, region, include_bundle_enum)
.ok_or_else(|| anyhow!("could not make payload"))?;
write_subpaths(output, &payload).map_err(|e| anyhow!("could not write payload: {}", e))?;
Ok(())
}