You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.0 KiB
31 lines
1.0 KiB
use std::path;
|
|
|
|
use nom::Err::{Error as NomError, Failure as NomFailure};
|
|
|
|
use crate::parsers::param;
|
|
use crate::unpackers::errors::UnpackError;
|
|
use crate::utils::fs as utils_fs;
|
|
use crate::utils::str as utils_str;
|
|
|
|
pub fn load_param_file(param_path: &str) -> Result<param::Param, UnpackError> {
|
|
let param_data = utils_fs::open_file_to_vec(path::Path::new(param_path))?;
|
|
Ok(load_param(¶m_data)?)
|
|
}
|
|
|
|
pub fn load_param(param_data: &[u8]) -> Result<param::Param, UnpackError> {
|
|
match param::parse(param_data) {
|
|
Ok((_, result)) => Ok(result),
|
|
Err(NomError(e)) | Err(NomFailure(e)) => Err(UnpackError::parsing_err("PARAM", e.1)),
|
|
Err(e) => Err(UnpackError::Unknown(format!("Unknown error: {:?}", e))),
|
|
}
|
|
}
|
|
|
|
pub fn print_param_no_data(param: ¶m::Param) {
|
|
println!("{} -- {}", param.header.param_type,
|
|
utils_str::n_plural(param.header.num_rows as i32, "row", "rows"));
|
|
|
|
for row in ¶m.rows {
|
|
println!(" - [{}] {}", row.id, row.name.as_ref().unwrap_or(&String::from("<noname>")));
|
|
}
|
|
}
|