Simplified Layout code
This commit is contained in:
parent
ffd932c86e
commit
b83e0120bf
|
@ -1,55 +1,40 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub type MemoryLayout = Vec<Layout>;
|
pub type MemoryLayout = Vec<Layout>;
|
||||||
pub type MemoryLayoutMut = Vec<LayoutMut>;
|
|
||||||
|
|
||||||
macro_rules! declare_memory_layout {
|
pub struct DefaultLayout {
|
||||||
($($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),* >] {
|
impl DefaultLayout {
|
||||||
pub fn new(parent: &$($val),* CDDesc) -> Vec<[< Layout$($val:camel),* >]> {
|
pub fn new(parent: &CDDesc) -> Vec<Layout> {
|
||||||
let mut layout = Vec::new();
|
let mut layout = Vec::new();
|
||||||
|
|
||||||
layout.push([< Layout$($val:camel),* >]::SystemArea(parent.system_area.clone()));
|
layout.push(Layout::SystemArea(parent.system_area.clone()));
|
||||||
layout.push([< Layout$($val:camel),* >]::PVD(parent.pvd.clone()));
|
layout.push(Layout::PVD(parent.pvd.clone()));
|
||||||
layout.push(([< Layout$($val:camel),* >]::PathTables));
|
layout.push(Layout::PathTables);
|
||||||
|
|
||||||
[< add_dir_and_subdir $(_$val),* >](&mut layout, parent.root.clone());
|
add_dir_and_subdir(&mut layout, parent.root.clone());
|
||||||
layout
|
layout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum [< Layout$($val:camel),* >] {
|
pub enum Layout {
|
||||||
SystemArea(SharedPtr<SystemArea>),
|
SystemArea(SharedPtr<SystemArea>),
|
||||||
PVD(SharedPtr<PrimaryVolumeDescriptor>),
|
PVD(SharedPtr<PrimaryVolumeDescriptor>),
|
||||||
PathTables,
|
PathTables,
|
||||||
Directory(SharedPtr<Directory>),
|
Directory(SharedPtr<Directory>),
|
||||||
File(SharedPtr<File>)
|
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_memory_layout!(mut);
|
fn add_dir_and_subdir(layout: &mut Vec<Layout>, dir: SharedPtr<Directory>) {
|
||||||
declare_memory_layout!();
|
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;
|
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 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 tool_helper::Error;
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
|
@ -32,10 +32,6 @@ impl CDDesc {
|
||||||
layout::DefaultLayout::new(self)
|
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) {
|
pub fn add_dir(&mut self, dir: Directory) {
|
||||||
self.root.borrow_mut().add_dir(dir);
|
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();});
|
Self::for_each_dir_mut(self.root.clone(), &|dir| {dir.update_content_size();});
|
||||||
|
|
||||||
// Now layout iterate?
|
// 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 {
|
fn update_lba(properties: &mut Properties, cur_lba: usize, content_size: usize) -> usize {
|
||||||
properties.lba = cur_lba;
|
properties.lba = cur_lba;
|
||||||
cur_lba + properties.sector_count_xa_data(content_size)
|
cur_lba + properties.sector_count_xa_data(content_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
match element {
|
match element {
|
||||||
LayoutMut::SystemArea(system_area) => {
|
Layout::SystemArea(system_area) => {
|
||||||
let mut system_area = system_area.borrow_mut();
|
let mut system_area = system_area.borrow_mut();
|
||||||
cur_lba = update_lba(&mut system_area.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
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();
|
let mut pvd = pvd.borrow_mut();
|
||||||
cur_lba = update_lba(&mut pvd.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
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);
|
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();
|
let mut dir = dir.borrow_mut();
|
||||||
cur_lba = update_lba(&mut dir.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW)
|
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();
|
let mut file = file.borrow_mut();
|
||||||
cur_lba = update_lba(&mut file.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
cur_lba = update_lba(&mut file.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue