Simplified Layout code
This commit is contained in:
parent
9e037d98f1
commit
2c11e52f14
|
@ -1,55 +1,40 @@
|
|||
use super::*;
|
||||
|
||||
pub type MemoryLayout = Vec<Layout>;
|
||||
pub type MemoryLayoutMut = Vec<LayoutMut>;
|
||||
pub type MemoryLayout = Vec<Layout>;
|
||||
|
||||
macro_rules! declare_memory_layout {
|
||||
($($val:ident),*) => {
|
||||
/*
|
||||
Creates Layout(Mut)
|
||||
- add $($val),* to toggle mut
|
||||
- add $($val:camel),* inside paste::item to make NameMut or Name
|
||||
*/
|
||||
paste::item! {
|
||||
pub struct [< DefaultLayout$($val:camel),* >] {
|
||||
}
|
||||
|
||||
impl [< DefaultLayout$($val:camel),* >] {
|
||||
pub fn new(parent: &$($val),* CDDesc) -> Vec<[< Layout$($val:camel),* >]> {
|
||||
let mut layout = Vec::new();
|
||||
|
||||
layout.push([< Layout$($val:camel),* >]::SystemArea(parent.system_area.clone()));
|
||||
layout.push([< Layout$($val:camel),* >]::PVD(parent.pvd.clone()));
|
||||
layout.push(([< Layout$($val:camel),* >]::PathTables));
|
||||
|
||||
[< add_dir_and_subdir $(_$val),* >](&mut layout, parent.root.clone());
|
||||
layout
|
||||
}
|
||||
}
|
||||
|
||||
pub enum [< Layout$($val:camel),* >] {
|
||||
SystemArea(SharedPtr<SystemArea>),
|
||||
PVD(SharedPtr<PrimaryVolumeDescriptor>),
|
||||
PathTables,
|
||||
Directory(SharedPtr<Directory>),
|
||||
File(SharedPtr<File>)
|
||||
}
|
||||
|
||||
fn [< add_dir_and_subdir $(_$val),* >]<'a>(layout: &mut Vec<[< Layout$($val:camel),* >]>, dir: SharedPtr<Directory>) {
|
||||
layout.push([< Layout$($val:camel),* >]::Directory(dir.clone()));
|
||||
|
||||
let $($val),* dir = dir.[< borrow $(_$val),* >]();
|
||||
for file in dir.files.[< iter$(_$val),* >]() {
|
||||
layout.push([< Layout$($val:camel),* >]::File(file.clone()));
|
||||
}
|
||||
|
||||
for dir in dir.dirs.[< iter$(_$val),* >]() {
|
||||
[< add_dir_and_subdir $(_$val),* >](layout, dir.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
pub struct DefaultLayout {
|
||||
}
|
||||
|
||||
declare_memory_layout!(mut);
|
||||
declare_memory_layout!();
|
||||
impl DefaultLayout {
|
||||
pub fn new(parent: &CDDesc) -> Vec<Layout> {
|
||||
let mut layout = Vec::new();
|
||||
|
||||
layout.push(Layout::SystemArea(parent.system_area.clone()));
|
||||
layout.push(Layout::PVD(parent.pvd.clone()));
|
||||
layout.push(Layout::PathTables);
|
||||
|
||||
add_dir_and_subdir(&mut layout, parent.root.clone());
|
||||
layout
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Layout {
|
||||
SystemArea(SharedPtr<SystemArea>),
|
||||
PVD(SharedPtr<PrimaryVolumeDescriptor>),
|
||||
PathTables,
|
||||
Directory(SharedPtr<Directory>),
|
||||
File(SharedPtr<File>)
|
||||
}
|
||||
|
||||
fn add_dir_and_subdir(layout: &mut Vec<Layout>, dir: SharedPtr<Directory>) {
|
||||
layout.push(Layout::Directory(dir.clone()));
|
||||
|
||||
let dir = dir.borrow();
|
||||
for file in dir.files.iter() {
|
||||
layout.push(Layout::File(file.clone()));
|
||||
}
|
||||
|
||||
for dir in dir.dirs.iter() {
|
||||
add_dir_and_subdir(layout, dir.clone());
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ mod helper;
|
|||
pub mod layout;
|
||||
|
||||
use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord, helper::{round_bytes_mode2_form1, sector_count_mode2_form1}, sector::*, path_table::PathTableL};
|
||||
use layout::LayoutMut;
|
||||
use layout::Layout;
|
||||
use tool_helper::Error;
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
|
@ -32,10 +32,6 @@ impl CDDesc {
|
|||
layout::DefaultLayout::new(self)
|
||||
}
|
||||
|
||||
pub fn get_memory_layout_mut(&mut self) -> layout::MemoryLayoutMut {
|
||||
layout::DefaultLayoutMut::new(self)
|
||||
}
|
||||
|
||||
pub fn add_dir(&mut self, dir: Directory) {
|
||||
self.root.borrow_mut().add_dir(dir);
|
||||
}
|
||||
|
@ -61,29 +57,29 @@ impl CDDesc {
|
|||
Self::for_each_dir_mut(self.root.clone(), &|dir| {dir.update_content_size();});
|
||||
|
||||
// Now layout iterate?
|
||||
for element in self.get_memory_layout_mut() {
|
||||
for element in self.get_memory_layout() {
|
||||
fn update_lba(properties: &mut Properties, cur_lba: usize, content_size: usize) -> usize {
|
||||
properties.lba = cur_lba;
|
||||
cur_lba + properties.sector_count_xa_data(content_size)
|
||||
}
|
||||
|
||||
match element {
|
||||
LayoutMut::SystemArea(system_area) => {
|
||||
Layout::SystemArea(system_area) => {
|
||||
let mut system_area = system_area.borrow_mut();
|
||||
cur_lba = update_lba(&mut system_area.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
||||
},
|
||||
LayoutMut::PVD(pvd) => {
|
||||
Layout::PVD(pvd) => {
|
||||
let mut pvd = pvd.borrow_mut();
|
||||
cur_lba = update_lba(&mut pvd.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
||||
},
|
||||
LayoutMut::PathTables => {
|
||||
Layout::PathTables => {
|
||||
cur_lba = update_lba(&mut path_table_properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
||||
},
|
||||
LayoutMut::Directory(dir) => {
|
||||
Layout::Directory(dir) => {
|
||||
let mut dir = dir.borrow_mut();
|
||||
cur_lba = update_lba(&mut dir.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW)
|
||||
},
|
||||
LayoutMut::File(file) => {
|
||||
Layout::File(file) => {
|
||||
let mut file = file.borrow_mut();
|
||||
cur_lba = update_lba(&mut file.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue