Read Overlay header
This commit is contained in:
parent
4025ce8318
commit
54a460b514
|
@ -6,6 +6,7 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
byteorder = "*"
|
||||
cdtypes = {path = "../cdtypes"}
|
||||
clap = {version = "*", features = ["derive"]}
|
||||
paste = "*"
|
||||
|
|
|
@ -60,7 +60,11 @@ fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(),
|
|||
}
|
||||
|
||||
fn parse_overlay_file(file: roxmltree::Node, is_hidden: bool) -> Result<File, Error> {
|
||||
parse_regular_file(file, is_hidden)
|
||||
Ok(File{
|
||||
common: read_common_properties(&file, is_hidden)?,
|
||||
path: PathBuf::from(file.text().unwrap_or_default()),
|
||||
kind: FileKind::Overlay
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_file_system(cur_node: roxmltree::Node, root: &mut Directory, mut is_hidden: bool) -> Result<(), Error> {
|
||||
|
|
|
@ -313,6 +313,9 @@ fn process_file(file: &File, sec_writer: &mut dyn SectorWriter) -> Result<(), Er
|
|||
let content_sectors = {
|
||||
match &file.content {
|
||||
FileType::Regular(raw) => builder::create_xa_data_for_vec(None, raw),
|
||||
FileType::Overlay(_) => {
|
||||
return Err(Error::not_implemented("process_file for Overlay in psx.rs"));
|
||||
}
|
||||
}
|
||||
};
|
||||
let content_sector_count = content_sectors.len();
|
||||
|
|
|
@ -116,8 +116,8 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<CDDesc, E
|
|||
config_reader::DirMember::File(file) => {
|
||||
let mut desc_file = {
|
||||
match file.kind {
|
||||
config_reader::FileKind::Regular => types::File::new_regular(file.common.name.as_str(), read_file(file.path)?)?,
|
||||
config_reader::FileKind::Overlay => types::File::new_regular(file.common.name.as_str(), read_file(file.path)?)?,
|
||||
config_reader::FileKind::Regular => types::File::new_regular(file.common.name.as_str(), read_file(&file.path)?)?,
|
||||
config_reader::FileKind::Overlay => types::overlay::load_from(file.path)?,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
pub (super) mod helper;
|
||||
pub mod layout;
|
||||
pub mod file_map;
|
||||
pub mod overlay;
|
||||
|
||||
use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord, path_table::PathTableL};
|
||||
use file_map::FileSystemMap;
|
||||
|
@ -172,7 +173,8 @@ impl std::fmt::Display for Directory {
|
|||
}
|
||||
|
||||
pub(super) enum FileType {
|
||||
Regular(Vec<u8>)
|
||||
Regular(Vec<u8>),
|
||||
Overlay(Vec<u8>),
|
||||
}
|
||||
|
||||
pub struct File {
|
||||
|
@ -185,10 +187,14 @@ pub struct File {
|
|||
impl File {
|
||||
pub fn new_regular(file_name: &str, content: Vec<u8>) -> Result<File, Error> {
|
||||
let content_size = content.len();
|
||||
let mut file = File{name: FileName::from_str(file_name)?, properties: Properties::default(), parent_properties: None, content: FileType::Regular(content)};
|
||||
|
||||
file.properties.size_bytes = content_size;
|
||||
Ok(file)
|
||||
Self::new_from_content(file_name, FileType::Regular(content), content_size)
|
||||
}
|
||||
|
||||
pub fn new_overlay(file_name: &str, content: Vec<u8>) -> Result<File, Error> {
|
||||
let content_size = content.len();
|
||||
|
||||
Self::new_from_content(file_name, FileType::Overlay(content), content_size)
|
||||
}
|
||||
|
||||
pub fn get_track_rel_lba(&self) -> usize {
|
||||
|
@ -198,6 +204,13 @@ impl File {
|
|||
pub fn get_extended_size(&self) -> usize {
|
||||
self.properties.get_padded_size()
|
||||
}
|
||||
|
||||
fn new_from_content(file_name: &str, content: FileType, content_size: usize) -> Result<File, Error> {
|
||||
let mut file = File{name: FileName::from_str(file_name)?, properties: Properties::default(), parent_properties: None, content: content};
|
||||
|
||||
file.properties.size_bytes = content_size;
|
||||
Ok(file)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for File {
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
use super::File;
|
||||
use std::path::PathBuf;
|
||||
use byteorder::{ByteOrder, BigEndian, LittleEndian};
|
||||
use tool_helper::{Error, format_if_error, read_file};
|
||||
|
||||
#[repr(packed)]
|
||||
struct OverlayHeader {
|
||||
pub start_adr: u32,
|
||||
pub _lba_count: u16,
|
||||
}
|
||||
|
||||
impl OverlayHeader {
|
||||
pub fn lba_count_offset() -> usize {
|
||||
let dummy = OverlayHeader{start_adr: 0, _lba_count: 0}.start_adr;
|
||||
std::mem::size_of_val(&dummy)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_from(file_path: PathBuf) -> Result<File, Error> {
|
||||
let content = read_file(&file_path)?;
|
||||
|
||||
if content.len() < std::mem::size_of::<OverlayHeader>() {
|
||||
return Err(Error::from_text(format!("Overlay {} has no header!", file_path.to_string_lossy())));
|
||||
}
|
||||
|
||||
let lba_count = LittleEndian::read_u16(&content[OverlayHeader::lba_count_offset()..]);
|
||||
println!("Dino: {}", lba_count);
|
||||
|
||||
Err(Error::not_implemented("load_from overlay"))
|
||||
}
|
|
@ -162,8 +162,8 @@ pub fn input_to_vec(input: Input) -> Result<Vec<u8>, Error> {
|
|||
Ok(data)
|
||||
}
|
||||
|
||||
pub fn read_file(file_path: PathBuf) -> Result<Vec<u8>, Error> {
|
||||
match std::fs::read(&file_path) {
|
||||
pub fn read_file(file_path: &PathBuf) -> Result<Vec<u8>, Error> {
|
||||
match std::fs::read(file_path) {
|
||||
Ok(data) => {
|
||||
Ok(data)
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue