More cleanups in builder.. this thing is a mess now.

This commit is contained in:
Bas Wiel, van de 2024-04-30 18:42:06 +02:00
parent ad5aec9f3e
commit 1df8ef06ee
1 changed files with 18 additions and 53 deletions

View File

@ -54,46 +54,29 @@ impl DiskBuilder {
/// 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();
pub fn build(&mut self) -> Result<(), std::io::Error> {
let osdownloader = ZipDownloader::from_url(
&operating_system.get_download_url(),
&self.operating_system.get_download_url(),
Some(&format!(
"Downloading {}",
&operating_system.get_friendlyname()
&self.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())?;
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 mut filesystem = Fat::new(&disk, &root_partition, Some(operating_system))?;
let vbr = Vbr::from_os(&operating_system, &filesystem);
disk.write_os_bootcode()?;
disk.write_partition_table()?;
disk.write_boot_signature()?;
disk.write_sector(vbr.as_bytes(), 1)?;
let vbr = Vbr::from_os(&self.operating_system, &self.filesystem);
self.disk.write_os_bootcode()?;
self.disk.write_partition_table()?;
self.disk.write_boot_signature()?;
self.disk.write_sector(vbr.as_bytes(), 1)?;
let commandcom = Some(
osdownloader
.get_file_by_name(operating_system.get_commandcom().as_str())
.unwrap()
.get_bytes(),
)
.unwrap()
.to_vec();
let iosys = Some(
osdownloader
.get_file_by_name(operating_system.get_iosys().as_str())
.get_file_by_name(self.operating_system.get_iosys().as_str())
.unwrap()
.get_bytes(),
)
@ -101,46 +84,28 @@ impl DiskBuilder {
.to_vec();
let msdossys = Some(
osdownloader
.get_file_by_name(operating_system.get_msdossys().as_str())
.get_file_by_name(self.operating_system.get_msdossys().as_str())
.unwrap()
.get_bytes(),
)
.unwrap()
.to_vec();
filesystem.mkfile(
self.filesystem.mkfile(
None,
operating_system.get_iosys().as_str(),
self.operating_system.get_iosys().as_str(),
iosys.as_slice(),
)?;
filesystem.mkfile(
self.filesystem.mkfile(
None,
operating_system.get_msdossys().as_str(),
self.operating_system.get_msdossys().as_str(),
msdossys.as_slice(),
)?;
filesystem.write_file(
commandcom.as_slice(),
operating_system.get_commandcom().as_str(),
None,
Some(DirEntryType::File),
&root_partition,
&mut disk,
)?;
for file in gamefiles {
filesystem.write_file(
file.get_bytes(),
file.get_name(),
None,
None,
&root_partition,
&mut disk,
)?;
}
// filesystem.mkdir(None, "DOS")?;
//filesystem.mkdir(None,"GAME")?;
// Last action: write the allocation table copies to the disk
filesystem.write_allocation_tables(&root_partition, &mut disk)?;
filesystem.write_dirs(None, &root_partition, &mut disk)?;
disk.commit_storage()?;
self.filesystem.write_allocation_tables(&self.partition, &mut self.disk)?;
self.filesystem.write_dirs(None, &self.partition, &mut self.disk)?;
self.disk.commit_storage()?;
Ok(())
}