Create dummy files for writing
This commit is contained in:
parent
941642bb4a
commit
c34777b7b7
|
@ -1,22 +1,29 @@
|
|||
use psxcdgen_ex::types::{layout::Layout, CDDesc, File, Directory};
|
||||
use tool_helper::Error;
|
||||
|
||||
fn make_file(name: &str) -> Result<File, Error> {
|
||||
let mut name = name.to_owned();
|
||||
|
||||
name.push_str(".txt");
|
||||
File::new_regular(name.as_ref(), "Planschbecken sind planschig und so".to_owned().into_bytes())
|
||||
}
|
||||
|
||||
fn populate() -> Result<CDDesc, Error> {
|
||||
let mut desc = CDDesc::new();
|
||||
let file = File::new("Planschi.jpg")?;
|
||||
let file2 = File::new("Wuff.png")?;
|
||||
let file = make_file("Planschi")?;
|
||||
let file2 = make_file("Wuff")?;
|
||||
let folder = {
|
||||
let mut folder = Directory::new("Sub")?;
|
||||
let sub_folder = {
|
||||
let mut folder = Directory::new("SubSub")?;
|
||||
|
||||
folder.add_file(File::new("Blubb.bin")?);
|
||||
folder.add_file(make_file("Blubb")?);
|
||||
folder
|
||||
};
|
||||
|
||||
folder.add_dir(sub_folder);
|
||||
folder.add_file(File::new("Schwimm.jpg")?);
|
||||
folder.add_file(File::new("Miau.png")?);
|
||||
folder.add_file(make_file("Schwimm")?);
|
||||
folder.add_file(make_file("Miau")?);
|
||||
folder
|
||||
};
|
||||
|
||||
|
|
|
@ -192,19 +192,29 @@ impl std::fmt::Display for Directory {
|
|||
}
|
||||
}
|
||||
|
||||
enum FileType {
|
||||
Regular(Vec<u8>)
|
||||
}
|
||||
|
||||
pub struct File {
|
||||
pub name: FileName,
|
||||
pub properties: Properties,
|
||||
_content: Vec<u8>
|
||||
content: FileType
|
||||
}
|
||||
|
||||
impl File {
|
||||
pub fn new(file_name: &str) -> Result<File, Error> {
|
||||
Ok(File{name: FileName::from_str(file_name)?, properties: Properties::default(), _content: Vec::new()})
|
||||
pub fn new_regular(file_name: &str, content: Vec<u8>) -> Result<File, Error> {
|
||||
Ok(File{name: FileName::from_str(file_name)?, properties: Properties::default(), content: FileType::Regular(content)})
|
||||
}
|
||||
|
||||
pub fn get_sector_count(&self) -> usize {
|
||||
self.properties.sector_count_xa_data(0)
|
||||
let content_size = {
|
||||
match &self.content {
|
||||
FileType::Regular(content) => content.len()
|
||||
}
|
||||
};
|
||||
|
||||
self.properties.sector_count_xa_data(content_size)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue