Prepare parsing license file

This commit is contained in:
jaby 2022-11-15 04:24:46 +01:00
parent 39747613bc
commit bac2d93234
4 changed files with 45 additions and 5 deletions

View File

@ -34,6 +34,16 @@ pub fn create_xa_data_for_raw(mut sub_mode: SubMode, data: &[u8; Mode2Form1::DAT
sector
}
pub fn create_xa_audio_for_raw(mut sub_mode: SubMode, data: &[u8; Mode2Form2::DATA_SIZE]) -> Mode2Form2 {
let mut sector = Mode2Form2::new();
sub_mode.set_audio();
sector.sub_header.sub_mode = sub_mode;
sector.data = *data;
sector
}
pub fn create_xa_data_for<T>(sub_mode: SubMode, data: &T) -> Mode2Form1 {
create_xa_data_for_raw(sub_mode, unsafe {std::mem::transmute::<&T, &[u8; Mode2Form1::DATA_SIZE]>(data)})
}
@ -76,6 +86,10 @@ pub fn create_xa_data_zero() -> Mode2Form1 {
create_xa_data_for_raw(SubMode::default_form1(), &[0u8; Mode2Form1::DATA_SIZE])
}
pub fn create_xa_audio_zero() -> Mode2Form2 {
create_xa_audio_for_raw(SubMode::default_form2(), &[0u8; Mode2Form2::DATA_SIZE])
}
fn copy_array<'a, T, const SIZE:usize>(dst: &mut [T; SIZE], src: &'a [T]) -> &'a [T] {
let data_size = {
if src.len() > SIZE {

View File

@ -93,9 +93,34 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit
return Err(Error::from_text(format!("System Area required to start at sector 0 of Track - found LBA: {}", system_area_lba)));
}
for _ in 0..SYSTEM_AREA_SECTOR_COUNT {
sec_writer.write_cd_xa_data(builder::create_xa_data_zero())?;
if system_area.license_data.is_empty() {
// No license specified - filling it with zeros
for _ in 0..SYSTEM_AREA_SECTOR_COUNT {
sec_writer.write_cd_xa_data(builder::create_xa_data_zero())?;
}
}
else {
for _ in 0..4 {
sec_writer.write_cd_xa_data(builder::create_xa_data_zero())?;
}
// Read from CD License file
for _ in 0..8 {
sec_writer.write_cd_xa_data(builder::create_xa_data_zero())?;
}
for _ in 0..4 {
let sector = {
let mut sector = builder::create_xa_audio_zero();
sector.sub_header.sub_mode.clear_audio();
sector
};
sec_writer.write_cd_xa_audio(sector)?;
}
}
Ok(())
}

View File

@ -43,8 +43,8 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<CDDesc, E
cd_desc.pvd.borrow_mut().set_publisher(publisher);
}
if let Some(_) = config.license_path {
println!("Warning: Ignoring License path for now");
if let Some(license_path) = config.license_path {
cd_desc.system_area.borrow_mut().license_data = read_file(license_path)?;
}
parse_dir(&mut cd_desc.root.borrow_mut(), config.root)?;

View File

@ -57,11 +57,12 @@ impl CDDesc {
pub struct SystemArea {
pub(in super) track_rel_lba: usize,
pub(in super) license_data: Vec<u8>,
}
impl SystemArea {
pub fn new() -> SystemArea {
SystemArea{track_rel_lba: 0}
SystemArea{track_rel_lba: 0, license_data: Vec::new()}
}
}