Prepare bin/cue writer
This commit is contained in:
parent
7aa2f4851e
commit
fe5c70507a
|
@ -0,0 +1 @@
|
||||||
|
pub mod psx;
|
|
@ -0,0 +1,25 @@
|
||||||
|
use std::io::Write;
|
||||||
|
use super::{Error, SectorWriter};
|
||||||
|
|
||||||
|
pub struct BinCueWriter {
|
||||||
|
_bin_out: std::boxed::Box<dyn Write>,
|
||||||
|
sector_count: usize
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BinCueWriter {
|
||||||
|
pub fn new<T: Write + 'static>(writer: T) -> BinCueWriter {
|
||||||
|
BinCueWriter{_bin_out: std::boxed::Box::new(writer), sector_count: 0}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SectorWriter for BinCueWriter {
|
||||||
|
fn write(&mut self) -> Result<(), Error> {
|
||||||
|
self.sector_count += 1;
|
||||||
|
|
||||||
|
Err(Error::not_implemented("write for BinCueWriter"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sector_written_count(&self) -> usize {
|
||||||
|
self.sector_count
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
pub mod bin_cue;
|
||||||
|
|
||||||
|
use bin_cue::BinCueWriter;
|
||||||
|
use super::types::CDDesc;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use tool_helper::{Error, open_output_file};
|
||||||
|
|
||||||
|
pub enum ImageType {
|
||||||
|
BinCue
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait SectorWriter {
|
||||||
|
fn write(&mut self) -> Result<(), Error>;
|
||||||
|
fn sector_written_count(&self) -> usize;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_image(_cd_desc: CDDesc, image_type: ImageType, output_path: PathBuf) -> Result<(), Error> {
|
||||||
|
match image_type {
|
||||||
|
ImageType::BinCue => {
|
||||||
|
let mut _writer = BinCueWriter::new(open_output_file(output_path)?);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1,2 @@
|
||||||
|
pub mod file_writer;
|
||||||
pub mod types;
|
pub mod types;
|
|
@ -1,4 +1,5 @@
|
||||||
use psxcdgen_ex::types::{layout::Layout, CDDesc, File, Directory};
|
use psxcdgen_ex::{file_writer::{ImageType, write_image}, types::{layout::Layout, CDDesc, File, Directory}};
|
||||||
|
use std::{path::PathBuf, str::FromStr};
|
||||||
use tool_helper::Error;
|
use tool_helper::Error;
|
||||||
|
|
||||||
fn make_file(name: &str) -> Result<File, Error> {
|
fn make_file(name: &str) -> Result<File, Error> {
|
||||||
|
@ -53,7 +54,7 @@ fn run_main() -> Result<(), Error> {
|
||||||
println!("{}", rand_item.0);
|
println!("{}", rand_item.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
write_image(desc, ImageType::BinCue, PathBuf::from_str("planschi.bin")?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{boxed::Box, io::{Read, Write}, path::PathBuf};
|
use std::{boxed::Box, io::{BufReader, BufWriter, Read, Write}, path::PathBuf};
|
||||||
|
|
||||||
pub mod bits;
|
pub mod bits;
|
||||||
pub mod raw;
|
pub mod raw;
|
||||||
|
@ -80,17 +80,27 @@ impl std::convert::From<cdtypes::Error> for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::convert::From<std::convert::Infallible> for Error {
|
||||||
|
fn from(error: std::convert::Infallible) -> Self {
|
||||||
|
Error::from_error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn open_output_file(output_path: PathBuf) -> Result<BufWriter<std::fs::File>, Error> {
|
||||||
|
Ok(std::io::BufWriter::new(std::fs::File::create(output_path)?))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn open_output(output_file: Option<PathBuf>) -> Result<Output, Error> {
|
pub fn open_output(output_file: Option<PathBuf>) -> Result<Output, Error> {
|
||||||
match output_file {
|
match output_file {
|
||||||
Some(output_path) => Ok(Box::new(std::io::BufWriter::new(std::fs::File::create(output_path)?))),
|
Some(output_path) => Ok(Box::new(open_output_file(output_path)?)),
|
||||||
None => Ok(Box::new(std::io::BufWriter::new(std::io::stdout()))),
|
None => Ok(Box::new(BufWriter::new(std::io::stdout()))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_input(input_file: Option<PathBuf>) -> Result<Input, Error> {
|
pub fn open_input(input_file: Option<PathBuf>) -> Result<Input, Error> {
|
||||||
match input_file {
|
match input_file {
|
||||||
Some(input_path) => Ok(Box::new(std::io::BufReader::new(std::fs::File::open(input_path)?))),
|
Some(input_path) => Ok(Box::new(BufReader::new(std::fs::File::open(input_path)?))),
|
||||||
None => Ok(Box::new(std::io::BufReader::new(std::io::stdin()))),
|
None => Ok(Box::new(BufReader::new(std::io::stdin()))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue