Function libxivdat::xiv_macro::read_macro_content[][src]

pub fn read_macro_content<P: AsRef<Path>>(
    path: P
) -> Result<Vec<Macro>, DATError>
Expand description

Reads all Macros from a specified DAT file, returning a Vec of them. This performs only one read operation on the underlying file, loading the entire content into memory to prevent repeat file access. This is similar to read_content(), but returns a Vec<Macro> instead of raw bytes. A valid macro file should always contain 100 macros, but this function will attempt to read files of other sizes.

Errors

Returns DATError::IncorrectType if the file appears to be of a type other than DATType::Macro.

Returns a DATError::Overflow or DATError::Underflow if a macro section content block does not match the expected length specified in the section header.

Returns a DATError::BadEncoding if a macro title or line does not contain valid utf8 text.

Returns a DATError::BadHeader if the specified file does not have a valid DAT header.

If an I/O error occurs while reading the file, a DATError::FileIO error will be returned wrapping the underlying FS error.

Examples

use libxivdat::xiv_macro::read_macro_content;
use libxivdat::xiv_macro::icon::MacroIcon;

let macro_contents = read_macro_content("./resources/TEST_MACRO.DAT").unwrap();

assert_eq!(macro_contents[0].title, "0");
assert_eq!(macro_contents[0].lines[0], "DefaultIcon");
assert_eq!(macro_contents[0].get_icon().unwrap(), MacroIcon::DefaultIcon);

assert_eq!(macro_contents[1].title, "1");
assert_eq!(macro_contents[1].lines[0], "DPS1");
assert_eq!(macro_contents[1].get_icon().unwrap(), MacroIcon::DPS1);