Abstract the OS naming, remove some unneeded crud.

This commit is contained in:
Bas Wiel, van de 2024-04-29 11:12:03 +02:00
parent 1a5a33a3a6
commit d08d32352b
3 changed files with 17 additions and 18 deletions

View File

@ -18,6 +18,7 @@ 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();
let mut gamedownloader = ZipDownloader::new();
let mut osdownloader = ZipDownloader::new();
gamedownloader.download_zip(
@ -26,10 +27,12 @@ impl DiskBuilder {
)?;
osdownloader.download_zip(
"https://dosk8s-dist.area536.com/ibm-pc-dos-200.zip",
Some("Downloading IBM PC-DOS 2.00"),
Some(&format!(
"Downloading {}",
operating_system.get_friendlyname()
)),
)?;
let gamefiles = gamedownloader.get_files();
let operating_system = OperatingSystem::from_str(manifest.os.as_str()).unwrap();
let mut disk = Disk::new(manifest.disktype.as_str(), manifest.os.as_str())?;
disk.attach(manifest.diskname.as_str())?;
disk.set_geometry(manifest.disksize)?;
@ -73,15 +76,11 @@ impl DiskBuilder {
None,
operating_system.get_iosys().as_str(),
iosys.as_slice(),
&root_partition,
&mut disk,
)?;
filesystem.mkfile(
None,
operating_system.get_msdossys().as_str(),
msdossys.as_slice(),
&root_partition,
&mut disk,
)?;
filesystem.write_file(
commandcom.as_slice(),
@ -101,7 +100,7 @@ impl DiskBuilder {
&mut disk,
)?;
}
filesystem.mkdir(None, "DOS")?;
// 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)?;

View File

@ -341,8 +341,6 @@ impl Fat {
parent: Option<&mut DirEntry>,
filename: &str,
data: &[u8],
partition: &Partition,
disk: &mut Disk,
) -> Result<(), std::io::Error> {
// 1. Allocate the required number of clusters on the allocation table
let bytes_per_cluster = self.sectors_per_cluster as usize * 512;

View File

@ -23,15 +23,7 @@ impl FromStr for OperatingSystem {
impl fmt::Display for OperatingSystem {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Iterate over each partition in the partition table
match self {
OperatingSystem::UNKNOWN => write!(f, "Unknown operating system"),
OperatingSystem::NONE => write!(f, "No operating system found"),
OperatingSystem::IBMDOS200 => write!(f, "IBM PC DOS 2.00"),
OperatingSystem::MSDOS211CBM => {
write!(f, "MS-DOS 2.11 (Commodore Business Machines OEM version)")
}
}
write!(f, "{}", self.get_friendlyname())
}
}
@ -202,4 +194,14 @@ impl OperatingSystem {
_ => "COMMAND.COM".to_string(),
}
}
/// Return the friendly name for the operating system
pub fn get_friendlyname(&self) -> String {
match self {
Self::IBMDOS200 => "IBM PC DOS 2.00".to_string(),
Self::MSDOS211CBM => "MS-DOS 2.11 CBM OEM edition".to_string(),
Self::UNKNOWN => "Unknown operating system".to_string(),
Self::NONE => "No operating system".to_string(),
}
}
}