diff --git a/src/Tools/psxcdgen_ex/src/lib.rs b/src/Tools/psxcdgen_ex/src/lib.rs index 028acab7..d2f93eed 100644 --- a/src/Tools/psxcdgen_ex/src/lib.rs +++ b/src/Tools/psxcdgen_ex/src/lib.rs @@ -161,7 +161,7 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<(CDDesc, match file.kind { config_reader::FileKind::Regular => (types::File::new_regular(file.common.name.as_str(), read_file(&file.path)?)?, false), config_reader::FileKind::Main(lba_source) => (types::overlay::load_for_main(file.common.name.as_str(), read_file(&file.path)?, lba_source)?, true), - config_reader::FileKind::Overlay(lba_source) => (types::overlay::load_from(file.common.name.as_str(), &file.path, lba_source)?, true), + config_reader::FileKind::Overlay(lba_source) => (types::overlay::load_from(file.common.name.as_str(), &file.path, lba_source)?, true), } }; diff --git a/src/Tools/psxcdgen_ex/src/types/overlay/mod.rs b/src/Tools/psxcdgen_ex/src/types/overlay/mod.rs index 140e7824..74feb9f4 100644 --- a/src/Tools/psxcdgen_ex/src/types/overlay/mod.rs +++ b/src/Tools/psxcdgen_ex/src/types/overlay/mod.rs @@ -2,7 +2,7 @@ use super::{bits::{Bit, BitRange}, layout::Layout, File, FileSystemMap}; use super::super::encoder::LengthCalculatorFunction; use std::path::PathBuf; use no_comment::{IntoWithoutComments as _, languages}; -use tool_helper::{Error, format_if_error, read_file, format_if_error_drop_cause}; +use tool_helper::{Error, format_if_error, read_file, read_file_to_string, format_if_error_drop_cause}; pub type LBANameVec = Vec; @@ -121,7 +121,7 @@ fn load_lba_names(lba_source: PathBuf) -> Result { Ok(file[start..end].to_owned()) } - let file = std::fs::read_to_string(&lba_source)?.chars().without_comments(languages::c()).collect::(); + let file = read_file_to_string(&lba_source)?.chars().without_comments(languages::c()).collect::(); let file = get_part_of_interest(file, &lba_source)?; let mut lba_names = Vec::new(); diff --git a/src/Tools/tool_helper/src/lib.rs b/src/Tools/tool_helper/src/lib.rs index 105e214c..bc5bc548 100644 --- a/src/Tools/tool_helper/src/lib.rs +++ b/src/Tools/tool_helper/src/lib.rs @@ -184,11 +184,18 @@ pub fn input_to_vec(input: Input) -> Result, Error> { pub fn read_file(file_path: &PathBuf) -> Result, Error> { match std::fs::read(file_path) { - Ok(data) => { - Ok(data) - }, - Err(error) => { - Err(Error::from_text(format!("Failed reading file {} with error: \"{}\"", file_path.display(), error))) - } + Ok(data) => Ok(data), + Err(error) => create_file_read_error(file_path, error), } +} + +pub fn read_file_to_string(file_path: &PathBuf) -> Result { + match std::fs::read_to_string(file_path) { + Ok(string) => Ok(string), + Err(error) => create_file_read_error(file_path, error), + } +} + +fn create_file_read_error(file_path: &PathBuf, error: std::io::Error) -> Result { + Err(Error::from_text(format!("Failed reading file {} with error: \"{}\"", file_path.display(), error))) } \ No newline at end of file