Read in LBA file path from header file
This commit is contained in:
parent
4c07721d45
commit
415dcf1ee0
|
@ -6,9 +6,10 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
byteorder = "*"
|
byteorder = "*"
|
||||||
cdtypes = {path = "../cdtypes"}
|
cdtypes = {path = "../cdtypes"}
|
||||||
clap = {version = "*", features = ["derive"]}
|
clap = {version = "*", features = ["derive"]}
|
||||||
paste = "*"
|
no-comment = "*"
|
||||||
roxmltree = "*"
|
paste = "*"
|
||||||
tool_helper = {path = "../tool_helper"}
|
roxmltree = "*"
|
||||||
|
tool_helper = {path = "../tool_helper"}
|
||||||
|
|
|
@ -117,8 +117,8 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<(CDDesc,
|
||||||
config_reader::DirMember::File(file) => {
|
config_reader::DirMember::File(file) => {
|
||||||
let (mut desc_file, needs_treatment) = {
|
let (mut desc_file, needs_treatment) = {
|
||||||
match file.kind {
|
match file.kind {
|
||||||
config_reader::FileKind::Regular => (types::File::new_regular(file.common.name.as_str(), read_file(&file.path)?)?, false),
|
config_reader::FileKind::Regular => (types::File::new_regular(file.common.name.as_str(), read_file(&file.path)?)?, false),
|
||||||
config_reader::FileKind::Overlay(_) => (types::overlay::load_from(file.common.name.as_str(), file.path)?, true)
|
config_reader::FileKind::Overlay(lba_source) => (types::overlay::load_from(file.common.name.as_str(), file.path, lba_source)?, true)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
use super::File;
|
use super::File;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
|
use no_comment::{IntoWithoutComments as _, languages};
|
||||||
use tool_helper::{Error, format_if_error, read_file};
|
use tool_helper::{Error, format_if_error, read_file};
|
||||||
|
|
||||||
|
pub type LBANameVec = Vec<String>;
|
||||||
|
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
struct OverlayHeader {
|
struct OverlayHeader {
|
||||||
pub start_adr: u32,
|
pub start_adr: u32,
|
||||||
|
@ -16,7 +19,15 @@ impl OverlayHeader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_from(file_name: &str, file_path: PathBuf) -> Result<File, Error> {
|
pub fn load_from(file_name: &str, file_path: PathBuf, lba_source: PathBuf) -> Result<File, Error> {
|
||||||
|
let content = load_content(&file_path)?;
|
||||||
|
let _ = load_lba_names(lba_source)?;
|
||||||
|
let content_size = format_if_error!(tool_helper::compress::lz4(&content, 16), "Compressing {} failed with \"{error_text}\"", file_path.to_string_lossy())?.len();
|
||||||
|
|
||||||
|
Ok(File::new_overlay(file_name, content, content_size)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_content(file_path: &PathBuf) -> Result<Vec<u8>, Error> {
|
||||||
let overlay_header_size = std::mem::size_of::<OverlayHeader>();
|
let overlay_header_size = std::mem::size_of::<OverlayHeader>();
|
||||||
let mut content = read_file(&file_path)?;
|
let mut content = read_file(&file_path)?;
|
||||||
|
|
||||||
|
@ -38,6 +49,38 @@ pub fn load_from(file_name: &str, file_path: PathBuf) -> Result<File, Error> {
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let content_size = format_if_error!(tool_helper::compress::lz4(&content, 16), "Compressing {} failed with \"{error_text}\"", file_path.to_string_lossy())?.len();
|
Ok(content)
|
||||||
Ok(File::new_overlay(file_name, content, content_size)?)
|
}
|
||||||
|
|
||||||
|
fn load_lba_names(lba_source: PathBuf) -> Result<LBANameVec, Error> {
|
||||||
|
const LBA_DECLARATION:&'static str = "__jabyengine_request_lba_for";
|
||||||
|
fn get_part_of_interest(file: String, lba_source: &PathBuf) -> Result<String, Error> {
|
||||||
|
const LBA_START_POINT:&'static str = "__jabyengine_start_lba_request";
|
||||||
|
const LBA_END_POINT:&'static str = "__jabyengine_end_lba_request";
|
||||||
|
|
||||||
|
let start = file.find(LBA_START_POINT).ok_or_else(|| {
|
||||||
|
Error::from_text(format!("No LBA start found in file {}", lba_source.to_string_lossy()))
|
||||||
|
})? + LBA_START_POINT.len();
|
||||||
|
|
||||||
|
let end = file.find(LBA_END_POINT).ok_or_else(|| {
|
||||||
|
Error::from_text(format!("No LBA end found in file {}", lba_source.to_string_lossy()))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(file[start..end].to_owned())
|
||||||
|
}
|
||||||
|
|
||||||
|
let file = std::fs::read_to_string(&lba_source)?.chars().without_comments(languages::c()).collect::<String>();
|
||||||
|
let file = get_part_of_interest(file, &lba_source)?;
|
||||||
|
let mut lba_names = Vec::new();
|
||||||
|
|
||||||
|
for pair in file.split(LBA_DECLARATION) {
|
||||||
|
if let Some(mut start) = pair.find('"') {
|
||||||
|
start += 1;
|
||||||
|
if let Some(end) = pair[start..].find('"') {
|
||||||
|
lba_names.push(pair[start..(start + end)].to_owned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(lba_names)
|
||||||
}
|
}
|
Loading…
Reference in New Issue