mirror of
https://github.com/NinjaCheetah/rustii.git
synced 2026-03-17 06:47:49 -04:00
Added rustii CLI command to replace content in a WAD
Also added required library features to make this possible. Rust makes the whole "getting content's index from its CID" thing so much easier.
This commit is contained in:
@@ -110,6 +110,20 @@ impl ContentRegion {
|
||||
}
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
/// Gets the index of content using its Content ID.
|
||||
pub fn get_index_from_cid(&self, cid: u32) -> Result<usize, ContentError> {
|
||||
// Use fancy Rust find and map methods to find the index matching the provided CID. Take
|
||||
// that libWiiPy!
|
||||
let content_index = self.content_records.iter()
|
||||
.find(|record| record.content_id == cid)
|
||||
.map(|record| record.index);
|
||||
if let Some(index) = content_index {
|
||||
Ok(index as usize)
|
||||
} else {
|
||||
Err(ContentError::CIDNotFound(cid))
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the encrypted content file from the ContentRegion at the specified index.
|
||||
pub fn get_enc_content_by_index(&self, index: usize) -> Result<Vec<u8>, ContentError> {
|
||||
|
||||
@@ -135,8 +135,8 @@ impl Title {
|
||||
/// Sets the content at the specified index to the provided decrypted content. This content will
|
||||
/// have its size and hash saved into the matching record. Optionally, a new Content ID or
|
||||
/// content type can be provided, with the existing values being preserved by default.
|
||||
pub fn set_content(&mut self, content: &[u8], index: usize) -> Result<(), TitleError> {
|
||||
self.content.set_content(content, index, None, None, self.ticket.dec_title_key())?;
|
||||
pub fn set_content(&mut self, content: &[u8], index: usize, cid: Option<u32>, content_type: Option<tmd::ContentType>) -> Result<(), TitleError> {
|
||||
self.content.set_content(content, index, cid, content_type, self.ticket.dec_title_key())?;
|
||||
self.tmd.content_records = self.content.content_records.clone();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user