Clean up the creation of sysfiles.

This commit is contained in:
Bas Wiel, van de 2024-05-02 10:45:40 +02:00
parent 07422362d3
commit cd90f16f8d
1 changed files with 36 additions and 33 deletions

View File

@ -47,13 +47,35 @@ impl DiskBuilder {
}
/// Copy a file from a downloaded ZIP to the VHD
pub fn copy_file(&mut self, downloader: &ZipDownloader, filename: &str) {}
pub fn copy_file(
&mut self,
downloader: &ZipDownloader,
filename: &str,
) -> Result<(), std::io::Error> {
if let Some(source_file) = downloader.get_file_by_name(filename) {
self.filesystem
.mkfile(None, source_file.get_name(), source_file.get_bytes())?;
Ok(())
} else {
// If the file was not found, nothing essentially bad happens. Just continue and do nothing for now.
Ok(())
}
}
/// Copy a system file from a downloaed ZIP to the VHD
pub fn copy_sysfile(&mut self, downloader: &ZipDownloader, filename: &str) {}
/// Copy a directory a downloaded ZIP to the VHD
pub fn copy_directory(&mut self, downloader: &ZipDownloader) {}
pub fn copy_sysfile(
&mut self,
downloader: &ZipDownloader,
filename: &str,
) -> Result<(), std::io::Error> {
if let Some(source_file) = downloader.get_file_by_name(filename) {
self.filesystem
.mksysfile(source_file.get_name(), source_file.get_bytes())?;
Ok(())
} else {
Ok(())
}
}
/// 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.
@ -77,37 +99,18 @@ impl DiskBuilder {
self.disk.write_boot_signature()?;
self.disk.write_sector(vbr.as_bytes(), 1)?;
let iosys = Some(
osdownloader
.get_file_by_name(self.operating_system.get_iosys().as_str())
.unwrap()
.get_bytes(),
)
.unwrap()
.to_vec();
let msdossys = Some(
osdownloader
.get_file_by_name(self.operating_system.get_msdossys().as_str())
.unwrap()
.get_bytes(),
)
.unwrap()
.to_vec();
self.filesystem.mkfile(
None,
self.operating_system.get_iosys().as_str(),
iosys.as_slice(),
)?;
self.filesystem.mkfile(
None,
self.operating_system.get_msdossys().as_str(),
msdossys.as_slice(),
)?;
// Install the required components for a bootable operating system
self.copy_sysfile(&osdownloader, &self.operating_system.get_iosys())?;
self.copy_sysfile(&osdownloader, &self.operating_system.get_msdossys())?;
self.copy_file(&osdownloader, &self.operating_system.get_commandcom())?;
// filesystem.mkdir(None, "DOS")?;
//filesystem.mkdir(None,"GAME")?;
// Last action: write the allocation table copies to the disk
self.filesystem.write_allocation_tables(&self.partition, &mut self.disk)?;
self.filesystem.write_dirs(None, &self.partition, &mut self.disk)?;
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(())
}