More generalization of code paths.

This commit is contained in:
Bas Wiel, van de 2024-04-30 18:34:53 +02:00
parent 5398bc36c4
commit ad5aec9f3e
3 changed files with 41 additions and 18 deletions

View File

@ -6,7 +6,11 @@ use crate::{
Disk,
},
downloader::{file::DownloadedFile, ZipDownloader},
fat::{direntry::{DirEntry, DirEntryType}, vbr::Vbr, Fat},
fat::{
direntry::{DirEntry, DirEntryType},
vbr::Vbr,
Fat,
},
manifest::Manifest,
os::OperatingSystem,
};
@ -16,42 +20,53 @@ pub struct DiskBuilder {
filesystem: Fat,
operating_system: OperatingSystem,
disk: Disk,
partition: Partition,
}
impl DiskBuilder {
/// Create a new filesystem
/// Create a new builder
pub fn new(manifest: &Manifest) -> Result<Self, std::io::Error> {
// Gather what we need from the manifest and instantiate structs as needed
let mut disk = Disk::new(manifest.disktype.as_str(), manifest.os.as_str())?;
let operating_system = OperatingSystem::from_str(manifest.os.as_str()).unwrap();
disk.attach(manifest.diskname.as_str())?;
disk.set_geometry(manifest.disksize)?;
let root_partition =
Partition::fill_disk(&disk, Some(Self::derive_partition_type(manifest)))?;
disk.partition_table
.add_partition(root_partition.clone(), Some(0))?;
let filesystem = Fat::new(&disk, &root_partition, Some(operating_system))?;
// Return the completed disk builder instance
Ok(DiskBuilder {
disk,
filesystem: Fat::new(&disk, partition, os)?,
filesystem,
partition: root_partition,
operating_system,
})
}
/// Copy a file from ZIP to VHD
pub fn copy_file(file: &DownloadedFile, directory: Option<&mut DirEntry>, partition: &Partition, disk: &mut Disk) {
let allocated_clusters =
let new_file = DirEntry::new(file.get_name(), DirEntryType::File, None, allocated_clusters, file_size, data)
}
/// Copy a file from a downloaded ZIP to the VHD
pub fn copy_file(&mut self, downloader: &ZipDownloader) {}
/// Copy a directory a downloaded ZIP to the VHD
pub fn copy_directory(&mut self, downloader: &ZipDownloader) {}
/// The builder is the struct that does all manner of validation before trying to
/// create a Disk so that what we create will make sense.
pub fn build(manifest: &Manifest) -> Result<(), std::io::Error> {
let operating_system = OperatingSystem::from_str(manifest.os.as_str()).unwrap();
let mut gamedownloader = ZipDownloader::new();
let mut osdownloader = ZipDownloader::new();
gamedownloader.download_zip(
"https://dosk8s-dist.area536.com/alleycat.zip",
Some("Downloading Alley Cat"),
)?;
osdownloader.download_zip(
"https://dosk8s-dist.area536.com/ibm-pc-dos-200.zip",
let osdownloader = ZipDownloader::from_url(
&operating_system.get_download_url(),
Some(&format!(
"Downloading {}",
operating_system.get_friendlyname()
&operating_system.get_friendlyname()
)),
)?;
let gamedownloader = ZipDownloader::from_url(
"https://dosk8s-dis.area536.com/alleycat.zip",
Some("Downloading Alley Cat"),
)?;
let gamefiles = gamedownloader.get_files();
let mut disk = Disk::new(manifest.disktype.as_str(), manifest.os.as_str())?;
disk.attach(manifest.diskname.as_str())?;

View File

@ -41,7 +41,7 @@ fn main() {
print_header();
println!("{}", manifest.get_metadata());
println!("{}", manifest);
DiskBuilder::build(&manifest).expect("Failed building the disk.");
let builder = DiskBuilder::new(&manifest).expect("Failed to create a DiskBuilder for this manifest.");
}
Commands::Analyze { name } => {
print_header();

View File

@ -195,6 +195,14 @@ impl OperatingSystem {
}
}
/// Return the default download URL for an operating system zipfile
pub fn get_download_url(&self) -> String {
match self {
Self::IBMDOS200 => "https://dosk8s-dist.area536.com/ibm-pc-dos-200.zip".to_string(),
_ => "https://dosk8s-dist.area536.com/none.zip".to_string(), // Not working yet!
}
}
/// Return the friendly name for the operating system
pub fn get_friendlyname(&self) -> String {
match self {