You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let data = fs::read(format!("{}/{:08X}.app", in_path.display(), content.index)).expect("could not read required content");
190
-
content_region.load_content(&data, content.indexasusize, tik.dec_title_key()).expect("failed to load content into ContentRegion");
191
+
let data = fs::read(format!("{}/{:08X}.app", in_path.display(), content.index)).with_context(|| format!("Could not open content file \"{:08X}.app\" for reading.", content.index))?;
.expect("failed to load content into ContentRegion, this is probably because content was modified which isn't supported yet");
191
194
}
192
-
let wad = wad::WAD::from_parts(&cert_chain,&[],&tik,&tmd,&content_region,&footer).expect("failed to create WAD");
195
+
let wad = wad::WAD::from_parts(&cert_chain,&[],&tik,&tmd,&content_region,&footer).with_context(|| "An unknown error occurred while building a WAD from the input files.")?;
bail!("Source WAD \"{}\" could not be found.", input);
217
+
}
218
+
let wad_file = fs::read(in_path).with_context(|| format!("Failed to open WAD file \"{}\" for reading.", in_path.display()))?;
219
+
let title = title::Title::from_bytes(&wad_file).with_context(|| format!("The provided WAD file \"{}\" appears to be invalid.", in_path.display()))?;
212
220
let tid = hex::encode(title.tmd.title_id);
213
221
// Create output directory if it doesn't exist.
214
-
if !Path::new(output).exists(){
215
-
fs::create_dir(output).expect("could not create output directory");
216
-
}
217
222
let out_path = Path::new(output);
223
+
if !Path::new(out_path).exists(){
224
+
fs::create_dir(out_path).with_context(|| format!("The output directory \"{}\" could not be created.", out_path.display()))?;
225
+
}
218
226
// Write out all WAD components.
219
227
let tmd_file_name = format!("{}.tmd", tid);
220
-
fs::write(Path::join(out_path, tmd_file_name), title.tmd.to_bytes().unwrap()).expect("could not write TMD file");
228
+
fs::write(Path::join(out_path, tmd_file_name.clone()), title.tmd.to_bytes()?).with_context(|| format!("Failed to open TMD file\"{}\" for writing.", tmd_file_name))?;
221
229
let ticket_file_name = format!("{}.tik", tid);
222
-
fs::write(Path::join(out_path, ticket_file_name), title.ticket.to_bytes().unwrap()).expect("could not write Ticket file");
230
+
fs::write(Path::join(out_path, ticket_file_name.clone()), title.ticket.to_bytes()?).with_context(|| format!("Failed to open Ticket file\"{}\" for writing.", ticket_file_name))?;
223
231
let cert_file_name = format!("{}.cert", tid);
224
-
fs::write(Path::join(out_path, cert_file_name), title.cert_chain.to_bytes().unwrap()).expect("could not write Cert file");
232
+
fs::write(Path::join(out_path, cert_file_name.clone()), title.cert_chain.to_bytes()?).with_context(|| format!("Failed to open certificate chain file\"{}\" for writing.", cert_file_name))?;
225
233
let meta_file_name = format!("{}.footer", tid);
226
-
fs::write(Path::join(out_path, meta_file_name), title.meta()).expect("could not write footer file");
234
+
fs::write(Path::join(out_path, meta_file_name.clone()), title.meta()).with_context(|| format!("Failed to open footer file\"{}\" for writing.", meta_file_name))?;
227
235
// Iterate over contents, decrypt them, and write them out.
228
236
for i in0..title.tmd.num_contents{
229
237
let content_file_name = format!("{:08X}.app", title.content.content_records[i asusize].index);
230
-
let dec_content = title.get_content_by_index(i asusize).unwrap();
let dec_content = title.get_content_by_index(i asusize).with_context(|| format!("Failed to unpack content with Content ID {:08X}.", title.content.content_records[i asusize].content_id))?;
239
+
fs::write(Path::join(out_path, content_file_name), dec_content).with_context(|| format!("Failed to open content file \"{:08X}.app\" for writing.", title.content.content_records[i asusize].content_id))?;
0 commit comments