Created constructor functions and paniced
This commit is contained in:
parent
a22bed930a
commit
48626728e8
|
@ -1,4 +1,7 @@
|
||||||
|
use psxcdgen_ex::types::CDDesc;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let _desc = CDDesc::new();
|
||||||
|
|
||||||
println!("Planschbecken");
|
println!("Planschbecken");
|
||||||
}
|
}
|
|
@ -1,7 +1,17 @@
|
||||||
use cdtypes::types::cdstring::DString;
|
use cdtypes::types::cdstring::DString;
|
||||||
|
use tool_helper::Error;
|
||||||
|
|
||||||
pub struct CDDesc {
|
pub struct CDDesc {
|
||||||
root: Directory
|
pub root: Directory
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CDDesc {
|
||||||
|
pub fn new() -> CDDesc {
|
||||||
|
match Directory::new("root") {
|
||||||
|
Ok(root) => CDDesc{root},
|
||||||
|
Err(error) => panic!("Creating root directory failed with: {}", error)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PVD {
|
pub struct PVD {
|
||||||
|
@ -9,22 +19,67 @@ pub struct PVD {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Directory {
|
pub struct Directory {
|
||||||
name: DirectoryName,
|
name: DirectoryName,
|
||||||
lba: Option<usize>,
|
properties: Properties,
|
||||||
length: Option<usize>,
|
data: Vec<Data>,
|
||||||
data: Vec<Data>,
|
dirs: Vec<Directory>
|
||||||
dirs: Vec<Directory>
|
}
|
||||||
|
|
||||||
|
impl Directory {
|
||||||
|
pub fn new(dir_name: &str) -> Result<Directory, Error> {
|
||||||
|
Ok(Directory{name: DirectoryName::from_str(dir_name)?, properties: Properties::default(), data: Vec::new(), dirs: Vec::new()})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
name: FileName,
|
name: FileName,
|
||||||
|
properties: Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Data {
|
||||||
|
pub fn new(file_name: &str) -> Result<Data, Error> {
|
||||||
|
Ok(Data{name: FileName::from_str(file_name)?, properties: Properties::default()})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DirectoryName {
|
pub struct DirectoryName {
|
||||||
name: DString<8>,
|
name: DString<8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DirectoryName {
|
||||||
|
pub fn from_str(str: &str) -> Result<DirectoryName, Error> {
|
||||||
|
Ok(DirectoryName{name: DString::from_str(str)?})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct FileName {
|
pub struct FileName {
|
||||||
name: DString<8>,
|
name: DString<8>,
|
||||||
ext: DString<3>
|
ext: Option<DString<3>>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FileName {
|
||||||
|
pub fn from_str(file_name: &str) -> Result<FileName, Error> {
|
||||||
|
let (name, ext) = {
|
||||||
|
let mut sub_str = file_name.split('.');
|
||||||
|
(Error::ok_or_new(sub_str.next(), || "File name can't be emplty".to_owned())?, sub_str.next())
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(FileName{name: DString::from_str(name)?, ext: {
|
||||||
|
match ext {
|
||||||
|
Some(ext) => Some(DString::from_str(ext)?),
|
||||||
|
None => None
|
||||||
|
}
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Properties {
|
||||||
|
lba: Option<usize>,
|
||||||
|
length: Option<usize>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Properties {
|
||||||
|
fn default() -> Self {
|
||||||
|
Properties{lba: None, length: None}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -6,4 +6,5 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
paste = "*"
|
cdtypes = {path = "../cdtypes"}
|
||||||
|
paste = "*"
|
|
@ -74,6 +74,12 @@ impl std::convert::From<std::io::Error> for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::convert::From<cdtypes::Error> for Error {
|
||||||
|
fn from(error: cdtypes::Error) -> Self {
|
||||||
|
Error::from_error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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(std::io::BufWriter::new(std::fs::File::create(output_path)?))),
|
||||||
|
|
Loading…
Reference in New Issue