Write cue file
This commit is contained in:
@@ -116,7 +116,7 @@ fn process_pvd(pvd: &PrimaryVolumeDescriptor, path_table: SharedPtr<PathTable>,
|
||||
//Config pvd here
|
||||
cd_pvd.system_id = AString::from_str(PLAYSATATION_STR)?;
|
||||
cd_pvd.volume_id = DString::from_str("PSX")?;
|
||||
cd_pvd.vol_space_size.write(28 as u32);
|
||||
cd_pvd.vol_space_size.write(vol_sector_count as u32);
|
||||
|
||||
//Set PathTable values
|
||||
cd_pvd.path_table_size.write(path_table.size_bytes as u32);
|
||||
|
@@ -1,15 +1,21 @@
|
||||
use super::{Error, Sector, SectorWriter};
|
||||
use cdtypes::types::time::Time;
|
||||
use std::io::Write;
|
||||
use cdtypes::types::{cue::DataType as CueDataType, cue::Format as CueFormat, cue::Specifier as CueSpecifier, cue::writer::write_generic as cue_write_generic, time::Time};
|
||||
use std::{path::PathBuf, io::Write};
|
||||
use tool_helper::get_file_name_from_path_buf;
|
||||
|
||||
pub struct BinCueWriter {
|
||||
bin_out: std::boxed::Box<dyn Write>,
|
||||
cd_time: Time,
|
||||
bin_out: std::boxed::Box<dyn Write>,
|
||||
cd_time: Time,
|
||||
cue: Vec<CueSpecifier>,
|
||||
}
|
||||
|
||||
impl BinCueWriter {
|
||||
pub fn new<T: Write + 'static>(writer: T) -> BinCueWriter {
|
||||
BinCueWriter{bin_out: std::boxed::Box::new(writer), cd_time: Time::cd_start()}
|
||||
pub fn new<T: Write + 'static>(writer: T, cue_path: &PathBuf) -> Result<BinCueWriter, Error> {
|
||||
Ok(BinCueWriter{bin_out: std::boxed::Box::new(writer), cd_time: Time::cd_start(), cue: Self::default_cue(cue_path)?})
|
||||
}
|
||||
|
||||
pub fn write_cue<T: Write>(self, dst: T) -> Result<(), Error> {
|
||||
Ok(cue_write_generic(dst, self.cue)?)
|
||||
}
|
||||
|
||||
fn finalize(&mut self, sector: &mut Sector) -> Result<(), Error> {
|
||||
@@ -22,6 +28,15 @@ impl BinCueWriter {
|
||||
self.cd_time.add_sector()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn default_cue(cue_path: &PathBuf) -> Result<Vec<CueSpecifier>, Error> {
|
||||
let mut cue = Vec::new();
|
||||
|
||||
cue.push(CueSpecifier::File{path: get_file_name_from_path_buf(cue_path, "cue output path")?, format: CueFormat::Binary});
|
||||
cue.push(CueSpecifier::Track{number: 1, data_type: CueDataType::Mode2_2352});
|
||||
cue.push(CueSpecifier::Index{number: 1, time: Time::cue_start()});
|
||||
Ok(cue)
|
||||
}
|
||||
}
|
||||
|
||||
impl SectorWriter for BinCueWriter {
|
||||
|
@@ -38,9 +38,17 @@ pub trait SectorWriter {
|
||||
pub fn write_image(cd_desc: CDDesc, encoder: EncoderFunction, image_type: ImageType, output_path: PathBuf) -> Result<(), Error> {
|
||||
match image_type {
|
||||
ImageType::BinCue => {
|
||||
let mut writer = BinCueWriter::new(open_output_file(output_path)?);
|
||||
let cue_output_path = {
|
||||
let mut cue_output_path = output_path.clone();
|
||||
|
||||
encoder(cd_desc, &mut writer)
|
||||
cue_output_path.set_extension("cue");
|
||||
cue_output_path
|
||||
};
|
||||
|
||||
let mut writer = BinCueWriter::new(open_output_file(output_path)?, &cue_output_path)?;
|
||||
|
||||
encoder(cd_desc, &mut writer)?;
|
||||
writer.write_cue(open_output_file(cue_output_path)?)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user