Add 'Main' file type to support lba for them
This commit is contained in:
parent
c8deff527f
commit
aeb09855ff
|
@ -22,7 +22,7 @@ pub struct CommonProperties {
|
||||||
|
|
||||||
pub enum FileKind {
|
pub enum FileKind {
|
||||||
Regular,
|
Regular,
|
||||||
RegularLBA(PathBuf),
|
Main(PathBuf),
|
||||||
Overlay(PathBuf)
|
Overlay(PathBuf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,23 +53,27 @@ fn parse_description(description: roxmltree::Node, config: &mut Configuration) {
|
||||||
|
|
||||||
fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(), Error> {
|
fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(), Error> {
|
||||||
fn parse_regular_file(file: roxmltree::Node, is_hidden: bool) -> Result<File, Error> {
|
fn parse_regular_file(file: roxmltree::Node, is_hidden: bool) -> Result<File, Error> {
|
||||||
let kind = {
|
|
||||||
if let Some(path) = file.attribute(attribute_names::LBA_SOURCE) {
|
|
||||||
FileKind::RegularLBA(PathBuf::from(path))
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
FileKind::Regular
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(File{
|
Ok(File{
|
||||||
common: read_common_properties(&file, is_hidden)?,
|
common: read_common_properties(&file, is_hidden)?,
|
||||||
path: PathBuf::from(file.text().unwrap_or_default()),
|
path: PathBuf::from(file.text().unwrap_or_default()),
|
||||||
kind
|
kind: FileKind::Regular
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_main_file(file: roxmltree::Node, is_hidden: bool) -> Result<File, Error> {
|
||||||
|
if let Some(lba_path) = file.attribute(attribute_names::LBA_SOURCE) {
|
||||||
|
Ok(File{
|
||||||
|
common: read_common_properties(&file, is_hidden)?,
|
||||||
|
path: PathBuf::from(file.text().unwrap_or_default()),
|
||||||
|
kind: FileKind::Main(PathBuf::from(lba_path))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
parse_regular_file(file, is_hidden)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_overlay_file(file: roxmltree::Node, is_hidden: bool) -> Result<File, Error> {
|
fn parse_overlay_file(file: roxmltree::Node, is_hidden: bool) -> Result<File, Error> {
|
||||||
Ok(File{
|
Ok(File{
|
||||||
common: read_common_properties(&file, is_hidden)?,
|
common: read_common_properties(&file, is_hidden)?,
|
||||||
|
@ -83,6 +87,7 @@ fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(),
|
||||||
if node.is_element() {
|
if node.is_element() {
|
||||||
match node.tag_name().name() {
|
match node.tag_name().name() {
|
||||||
"File" => root.add_file(parse_regular_file(node, is_hidden)?),
|
"File" => root.add_file(parse_regular_file(node, is_hidden)?),
|
||||||
|
"Main" => root.add_file(parse_main_file(node, is_hidden)?),
|
||||||
"Overlay" => root.add_file(parse_overlay_file(node, is_hidden)?),
|
"Overlay" => root.add_file(parse_overlay_file(node, is_hidden)?),
|
||||||
"Directory" => {
|
"Directory" => {
|
||||||
is_hidden |= parse_boolean_attribute(&node, attribute_names::HIDDEN)?;
|
is_hidden |= parse_boolean_attribute(&node, attribute_names::HIDDEN)?;
|
||||||
|
|
|
@ -329,8 +329,8 @@ fn process_file(file: &File, sec_writer: &mut dyn SectorWriter) -> Result<(), Er
|
||||||
let content_sectors = {
|
let content_sectors = {
|
||||||
match &file.content {
|
match &file.content {
|
||||||
FileType::Regular(raw) => builder::create_xa_data_for_vec(None, raw),
|
FileType::Regular(raw) => builder::create_xa_data_for_vec(None, raw),
|
||||||
FileType::RegularOverlay(_, _) => {
|
FileType::Main(_, _) => {
|
||||||
return Err(Error::from_str("Trying to encode an unprocssed regular overlay file"));
|
return Err(Error::from_str("Trying to encode an unprocssed main file"));
|
||||||
},
|
},
|
||||||
FileType::Overlay(_, _) => {
|
FileType::Overlay(_, _) => {
|
||||||
return Err(Error::from_str("Trying to encode an unprocessed overlay file"));
|
return Err(Error::from_str("Trying to encode an unprocessed overlay file"));
|
||||||
|
|
|
@ -38,8 +38,8 @@ pub fn process_files(file_map: FileSystemMap, lba_embedded_files: LBAEmbeddedFil
|
||||||
|
|
||||||
Some(new_content)
|
Some(new_content)
|
||||||
},
|
},
|
||||||
FileType::RegularOverlay(_, _) => {
|
FileType::Main(_, _) => {
|
||||||
return Err(Error::not_implemented("process_files => RegularOverlay"));
|
return Err(Error::not_implemented("process_files => FileType::Main"));
|
||||||
},
|
},
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<(CDDesc,
|
||||||
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::RegularLBA(lba_source) => (types::overlay::dino_wuff(file.common.name.as_str(), read_file(&file.path)?, lba_source)?, true),
|
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),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -177,7 +177,7 @@ impl std::fmt::Display for Directory {
|
||||||
|
|
||||||
pub(super) enum FileType {
|
pub(super) enum FileType {
|
||||||
Regular(Vec<u8>),
|
Regular(Vec<u8>),
|
||||||
RegularOverlay(Vec<u8>, overlay::LBANameVec),
|
Main(Vec<u8>, overlay::LBANameVec),
|
||||||
Overlay(Vec<u8>, overlay::LBANameVec),
|
Overlay(Vec<u8>, overlay::LBANameVec),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,10 +195,10 @@ impl File {
|
||||||
Self::new_from_content(file_name, FileType::Regular(content), content_size)
|
Self::new_from_content(file_name, FileType::Regular(content), content_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_regular_overlay(file_name: &str, content: Vec<u8>, lba_names: overlay::LBANameVec) -> Result<File, Error> {
|
pub fn new_main(file_name: &str, content: Vec<u8>, lba_names: overlay::LBANameVec) -> Result<File, Error> {
|
||||||
let content_size = content.len();
|
let content_size = content.len();
|
||||||
|
|
||||||
Self::new_from_content(file_name, FileType::RegularOverlay(content, lba_names), content_size)
|
Self::new_from_content(file_name, FileType::Main(content, lba_names), content_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_overlay(file_name: &str, content: Vec<u8>, lba_names: overlay::LBANameVec, content_size: usize) -> Result<File, Error> {
|
pub fn new_overlay(file_name: &str, content: Vec<u8>, lba_names: overlay::LBANameVec, content_size: usize) -> Result<File, Error> {
|
||||||
|
|
|
@ -52,8 +52,8 @@ pub fn load_from(file_name: &str, file_path: PathBuf, lba_source: PathBuf) -> Re
|
||||||
Ok(File::new_overlay(file_name, content, lba_names, content_size)?)
|
Ok(File::new_overlay(file_name, content, lba_names, content_size)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dino_wuff(file_name: &str, content: Vec<u8>, lba_source: PathBuf) -> Result<File, Error> {
|
pub fn load_for_main(file_name: &str, content: Vec<u8>, lba_source: PathBuf) -> Result<File, Error> {
|
||||||
File::new_regular_overlay(file_name, content, load_lba_names(lba_source)?)
|
File::new_main(file_name, content, load_lba_names(lba_source)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_content(content: &mut Vec<u8>, lba_names: &LBANameVec, file_map: &FileSystemMap, length_func: LengthCalculatorFunction) -> Result<Vec<u8>, Error> {
|
pub fn update_content(content: &mut Vec<u8>, lba_names: &LBANameVec, file_map: &FileSystemMap, length_func: LengthCalculatorFunction) -> Result<Vec<u8>, Error> {
|
||||||
|
|
Loading…
Reference in New Issue