From 63e875cce4037142c805efed25101ed7d62f8efd Mon Sep 17 00:00:00 2001 From: SzymekkYT <69077038+Szymekk44@users.noreply.github.com> Date: Sat, 21 Sep 2024 13:25:12 +0200 Subject: [PATCH] Disk formatting type as enum --- source/Cosmos.System2/FileSystem/Disk.cs | 13 +++---------- .../Cosmos.System2/FileSystem/FAT/FatFileSystem.cs | 14 +++++--------- source/Cosmos.System2/FileSystem/FileSystem.cs | 3 ++- .../FileSystem/ISO9660/ISO9660FileSystem.cs | 2 +- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/source/Cosmos.System2/FileSystem/Disk.cs b/source/Cosmos.System2/FileSystem/Disk.cs index a69292c0f3..75c9802b01 100644 --- a/source/Cosmos.System2/FileSystem/Disk.cs +++ b/source/Cosmos.System2/FileSystem/Disk.cs @@ -263,21 +263,14 @@ public void Clear() } } - public void FormatPartition(int index, string format, bool quick = true) + public void FormatPartition(int index, FileSystemType format, bool quick = true) { var part = Partitions[index]; var xSize = (long)(Host.BlockCount * Host.BlockSize / 1024 / 1024); - if (format.StartsWith("FAT")) - { - FatFileSystem.CreateFatFileSystem(part.Host, VFSManager.GetNextFilesystemLetter() + ":\\", xSize, format); - Mount(); - } - else - { - throw new NotImplementedException(format + " formatting not supported."); - } + FatFileSystem.CreateFatFileSystem(part.Host, VFSManager.GetNextFilesystemLetter() + ":\\", xSize, format); + Mount(); } private readonly FileSystem[] mountedPartitions = new FileSystem[4]; diff --git a/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs b/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs index 40ba64c891..b87b53bf35 100644 --- a/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs +++ b/source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs @@ -766,7 +766,7 @@ public FatFileSystem(Partition aDevice, string aRootPath, long aSize, bool fileS /// /// /// Thrown on fatal error. - public static FatFileSystem CreateFatFileSystem(Partition aDevice, string aRootPath, long aSize, string aDriveFormat) + public static FatFileSystem CreateFatFileSystem(Partition aDevice, string aRootPath, long aSize, FileSystemType aDriveFormat) { if (aDevice == null) { @@ -1465,7 +1465,7 @@ internal enum FatTypeEnum /// Thrown on fatal error. /// Thrown when the data in aData is corrupted. /// Thrown when FAT type is unknown. - public override void Format(string aDriveFormat, bool aQuick) + public override void Format(FileSystemType aDriveFormat, bool aQuick) { /* Parmaters check */ if (Device == null) @@ -1473,22 +1473,18 @@ public override void Format(string aDriveFormat, bool aQuick) throw new ArgumentNullException(nameof(Device)); } - if (aDriveFormat == "FAT32") + if (aDriveFormat == FileSystemType.FAT32) { mFatType = FatTypeEnum.Fat32; } - else if (aDriveFormat == "FAT16") + else if (aDriveFormat == FileSystemType.FAT16) { throw new NotImplementedException("FAT16 formatting not supported yet."); } - else if (aDriveFormat == "FAT12") + else if (aDriveFormat == FileSystemType.FAT12) { throw new NotImplementedException("FAT12 formatting not supported yet."); } - else - { - throw new Exception("Unknown FAT type."); - } /* FAT Configuration */ BytesPerSector = (uint)Device.BlockSize; diff --git a/source/Cosmos.System2/FileSystem/FileSystem.cs b/source/Cosmos.System2/FileSystem/FileSystem.cs index 64c0db0593..69532c78bb 100644 --- a/source/Cosmos.System2/FileSystem/FileSystem.cs +++ b/source/Cosmos.System2/FileSystem/FileSystem.cs @@ -252,6 +252,7 @@ protected FileSystem(Partition aDevice, string aRootPath, long aSize) /// Thrown on fatal error. /// Thrown when the data in aData is corrupted. /// Thrown when FAT type is unknown. - public abstract void Format(string aDriveFormat, bool aQuick); + public abstract void Format(FileSystemType aDriveFormat, bool aQuick); } + public enum FileSystemType { FAT12, FAT16, FAT32 } } diff --git a/source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs b/source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs index 96ed44c18b..0da1e90f24 100644 --- a/source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs +++ b/source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs @@ -243,7 +243,7 @@ public override void DeleteFile(DirectoryEntry aPath) { throw new NotImplementedException("Read only file system"); } - public override void Format(string aDriveFormat, bool aQuick) + public override void Format(FileSystemType aDriveFormat, bool aQuick) { throw new NotImplementedException(); }