Support writing LBA information into main file

This commit is contained in:
2023-02-03 13:22:17 +01:00
parent 2297996d58
commit 09f1ece6bb
7 changed files with 97 additions and 47 deletions

View File

@@ -8,5 +8,6 @@ edition = "2021"
[dependencies]
byteorder = "*"
cdtypes = {path = "../cdtypes"}
envmnt = "*"
lz4 = "*"
paste = "*"

View File

@@ -1,4 +1,5 @@
use std::{boxed::Box, io::{BufReader, BufWriter, Read, Write}, path::PathBuf};
use envmnt::{ExpandOptions, ExpansionType};
pub mod bits;
pub mod compress;
@@ -22,6 +23,20 @@ macro_rules! format_if_error {
};
}
#[macro_export]
macro_rules! format_if_error_drop_cause {
($result:expr, $format_text:literal) => {
tool_helper::callback_if_any_error($result, |error_text| {
format!($format_text)
})
};
($result:expr, $format_text:literal, $($arg:expr)*) => {
tool_helper::callback_if_any_error($result, |error_text| {
format!($format_text, $($arg),*)
})
};
}
pub struct Error {
pub exit_code: i32,
pub text: String,
@@ -123,6 +138,10 @@ pub fn callback_if_any_error<F: Fn(String) -> String, T, E: std::string::ToStrin
}
}
pub fn path_with_env_from(path: &str) -> PathBuf {
PathBuf::from(envmnt::expand(path, Some(ExpandOptions{expansion_type: Some(ExpansionType::All), default_to_empty: false})))
}
pub fn open_output_file(output_path: &PathBuf) -> Result<BufWriter<std::fs::File>, Error> {
Ok(std::io::BufWriter::new(std::fs::File::create(output_path)?))
}