Write cue file
This commit is contained in:
parent
01aaddca59
commit
1109de55a5
|
@ -1,8 +1,12 @@
|
||||||
use std::{fs::File, io::Write};
|
use std::{fs::File, io::Write};
|
||||||
use super::{{super::super::Error}, *};
|
use super::{{super::super::Error}, *};
|
||||||
|
|
||||||
pub fn write(mut file: File, data: Vec<Specifier>) -> Result<(), Error> {
|
pub fn write(file: File, data: Vec<Specifier>) -> Result<(), Error> {
|
||||||
fn write_indent(file: &mut File, specifier: &Specifier) -> Result<(), Error> {
|
write_generic(file, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_generic<T: Write>(mut dst: T, data: Vec<Specifier>) -> Result<(), Error> {
|
||||||
|
fn write_indent<T: Write>(dst: &mut T, specifier: &Specifier) -> Result<(), Error> {
|
||||||
let indent = {
|
let indent = {
|
||||||
match specifier {
|
match specifier {
|
||||||
Specifier::File{..} => 0,
|
Specifier::File{..} => 0,
|
||||||
|
@ -11,14 +15,16 @@ pub fn write(mut file: File, data: Vec<Specifier>) -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(file, "{:indent$}", " ")?;
|
if indent > 0 {
|
||||||
|
write!(dst, "{:indent$}", " ")?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
for specifier in data {
|
for specifier in data {
|
||||||
write_indent(&mut file, &specifier)?;
|
write_indent(&mut dst, &specifier)?;
|
||||||
|
|
||||||
write!(file, "{}\n", specifier)?;
|
write!(dst, "{}\n", specifier)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -116,7 +116,7 @@ fn process_pvd(pvd: &PrimaryVolumeDescriptor, path_table: SharedPtr<PathTable>,
|
||||||
//Config pvd here
|
//Config pvd here
|
||||||
cd_pvd.system_id = AString::from_str(PLAYSATATION_STR)?;
|
cd_pvd.system_id = AString::from_str(PLAYSATATION_STR)?;
|
||||||
cd_pvd.volume_id = DString::from_str("PSX")?;
|
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
|
//Set PathTable values
|
||||||
cd_pvd.path_table_size.write(path_table.size_bytes as u32);
|
cd_pvd.path_table_size.write(path_table.size_bytes as u32);
|
||||||
|
|
|
@ -1,15 +1,21 @@
|
||||||
use super::{Error, Sector, SectorWriter};
|
use super::{Error, Sector, SectorWriter};
|
||||||
use cdtypes::types::time::Time;
|
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::io::Write;
|
use std::{path::PathBuf, io::Write};
|
||||||
|
use tool_helper::get_file_name_from_path_buf;
|
||||||
|
|
||||||
pub struct BinCueWriter {
|
pub struct BinCueWriter {
|
||||||
bin_out: std::boxed::Box<dyn Write>,
|
bin_out: std::boxed::Box<dyn Write>,
|
||||||
cd_time: Time,
|
cd_time: Time,
|
||||||
|
cue: Vec<CueSpecifier>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BinCueWriter {
|
impl BinCueWriter {
|
||||||
pub fn new<T: Write + 'static>(writer: T) -> BinCueWriter {
|
pub fn new<T: Write + 'static>(writer: T, cue_path: &PathBuf) -> Result<BinCueWriter, Error> {
|
||||||
BinCueWriter{bin_out: std::boxed::Box::new(writer), cd_time: Time::cd_start()}
|
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> {
|
fn finalize(&mut self, sector: &mut Sector) -> Result<(), Error> {
|
||||||
|
@ -22,6 +28,15 @@ impl BinCueWriter {
|
||||||
self.cd_time.add_sector()?;
|
self.cd_time.add_sector()?;
|
||||||
Ok(())
|
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 {
|
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> {
|
pub fn write_image(cd_desc: CDDesc, encoder: EncoderFunction, image_type: ImageType, output_path: PathBuf) -> Result<(), Error> {
|
||||||
match image_type {
|
match image_type {
|
||||||
ImageType::BinCue => {
|
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)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue