Have encoder and writer in place

This commit is contained in:
Jaby 2022-10-18 22:23:32 +02:00
parent fe5c70507a
commit 1a3da8f412
6 changed files with 19 additions and 8 deletions

View File

@ -1 +1,5 @@
pub mod psx;
use super::{file_writer::SectorWriter, types::{CDDesc, Error}};
pub mod psx;
pub type EncoderFunction = fn(CDDesc, &mut dyn SectorWriter) -> Result<(), Error>;

View File

@ -0,0 +1,5 @@
use super::{SectorWriter, {CDDesc, Error}};
pub fn encode_psx_image(_: CDDesc, _: &mut dyn SectorWriter) -> Result<(), Error> {
Err(Error::not_implemented("encode_psx_image"))
}

View File

@ -1,7 +1,7 @@
pub mod bin_cue;
use super::{encoder::EncoderFunction, types::CDDesc};
use bin_cue::BinCueWriter;
use super::types::CDDesc;
use std::path::PathBuf;
use tool_helper::{Error, open_output_file};
@ -14,12 +14,12 @@ pub trait SectorWriter {
fn sector_written_count(&self) -> usize;
}
pub fn write_image(_cd_desc: CDDesc, 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 {
ImageType::BinCue => {
let mut _writer = BinCueWriter::new(open_output_file(output_path)?);
let mut writer = BinCueWriter::new(open_output_file(output_path)?);
Ok(())
encoder(cd_desc, &mut writer)
}
}
}

View File

@ -1,2 +1,3 @@
pub mod encoder;
pub mod file_writer;
pub mod types;

View File

@ -1,4 +1,4 @@
use psxcdgen_ex::{file_writer::{ImageType, write_image}, types::{layout::Layout, CDDesc, File, Directory}};
use psxcdgen_ex::{encoder::psx::encode_psx_image, file_writer::{ImageType, write_image}, types::{layout::Layout, CDDesc, File, Directory}};
use std::{path::PathBuf, str::FromStr};
use tool_helper::Error;
@ -54,7 +54,8 @@ fn run_main() -> Result<(), Error> {
println!("{}", rand_item.0);
}
write_image(desc, ImageType::BinCue, PathBuf::from_str("planschi.bin")?)
println!("\n<== Planschbecken ==>\nStart encoding");
write_image(desc, encode_psx_image, ImageType::BinCue, PathBuf::from_str("planschi.bin")?)
}
fn main() {

View File

@ -5,9 +5,9 @@ pub mod file_map;
use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord, helper::{round_bytes_mode2_form1, sector_count_mode2_form1}, sector::*, path_table::PathTableL};
use file_map::FileSystemMap;
use layout::Layout;
use tool_helper::Error;
use std::{cell::RefCell, rc::Rc};
pub use tool_helper::Error;
pub type SharedPtr<T> = Rc<RefCell<T>>;
pub fn new_shared_ptr<T>(value: T) -> SharedPtr<T> {