mirror of
https://github.com/NinjaCheetah/rustii.git
synced 2026-03-03 03:15:28 -05: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> {
|
||||
|
||||
Reference in New Issue
Block a user