pub struct ModuleFile {
pub files: Vec<ModuleFileEntry>,
/* private fields */
}
Expand description
Module structure which contains the layout of the entire module file.
Fields§
§files: Vec<ModuleFileEntry>
Metadata regarding compression and layout of files (tags).
Implementations§
source§impl ModuleFile
impl ModuleFile
pub fn new() -> Self
sourcepub fn read(&mut self, file_path: String) -> Result<(), Error>
pub fn read(&mut self, file_path: String) -> Result<(), Error>
Reads the module file from the given file path. This function reads the entire structure of the module file. It also calculates and stores important offsets within the file.
§Arguments
file_path
- A string slice that holds the path to the module file.
§Returns
Returns Ok(())
if the read operation is successful, or an Error
containing
the I/O error if any reading operation fails.
sourcepub fn read_tag(&mut self, index: u32) -> Result<(), Error>
pub fn read_tag(&mut self, index: u32) -> Result<(), Error>
Reads a specific tag from the module file.
This function reads a specific tag from the module file based on the provided index.
It checks if the tag is not a resource tag (indicated by a tag_id
of -1) and then reads
the tag data from the module file. It also utilizes the HD1 stream if the file entry has
the flag set for it and the stream is loaded.
§Arguments
index
- The index of the file entry to read the tag from. This index corresponds to the position of the file entry in thefiles
vector.
§Returns
Returns Ok(())
if the read operation is successful, or an Error
containing
the I/O error if any reading operation fails.
sourcepub fn read_tag_from_id(
&mut self,
global_id: i32,
) -> Result<Option<usize>, Error>
pub fn read_tag_from_id( &mut self, global_id: i32, ) -> Result<Option<usize>, Error>
Searches for the index of the tag given the global_id
.
This function searches for the index of a tag in the files
vector using the provided
global_id
. If the tag is found, it reads the tag using the read_tag
function and
stores it in the index.
§Arguments
global_id
- The global tag ID of the file to find. This ID is used to identify the specific tag within the module file.
§Returns
Returns the index of the file if successful, wrapped in Some(usize)
. If the tag is not
found, it returns None
. Any I/O error encountered during the operation is also returned
if it occurs.
sourcepub fn read_resources(
&mut self,
index: u32,
) -> Result<Vec<&ModuleFileEntry>, Error>
pub fn read_resources( &mut self, index: u32, ) -> Result<Vec<&ModuleFileEntry>, Error>
Reads the resources referenced by a module entry.
This function reads the resources referenced by a specific module entry. It retrieves
the resources based on the provided index and returns them as a vector of references
to ModuleFileEntry
.
§Arguments
index
- Index of the file to read the resources of. This index corresponds to the position of the file entry in thefiles
vector.
§Returns
Returns Ok(Vec<&ModuleFileEntry>)
if the read operation is successful, containing a
vector of references to ModuleFileEntry
. If the requested resource wasn’t found in
the module, an anyhow::Error
is returned.