mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
🎨Remove chains of if-else to get media type from it's geometry, plus add
a geometry class with a list of known geometries and ❤️LINQ❤️ queries.
This commit is contained in:
@@ -43,30 +43,30 @@ namespace DiscImageChef.DiscImages
|
||||
public class MaxiDisk : IMediaImage
|
||||
{
|
||||
/// <summary>Disk image file</summary>
|
||||
IFilter hdkImageFilter;
|
||||
IFilter hdkImageFilter;
|
||||
ImageInfo imageInfo;
|
||||
|
||||
public MaxiDisk()
|
||||
{
|
||||
imageInfo = new ImageInfo
|
||||
{
|
||||
ReadableSectorTags = new List<SectorTagType>(),
|
||||
ReadableMediaTags = new List<MediaTagType>(),
|
||||
HasPartitions = false,
|
||||
HasSessions = false,
|
||||
Application = "MAXI Disk",
|
||||
Creator = null,
|
||||
Comments = null,
|
||||
MediaManufacturer = null,
|
||||
MediaModel = null,
|
||||
MediaSerialNumber = null,
|
||||
MediaBarcode = null,
|
||||
MediaPartNumber = null,
|
||||
MediaSequence = 0,
|
||||
LastMediaSequence = 0,
|
||||
DriveManufacturer = null,
|
||||
DriveModel = null,
|
||||
DriveSerialNumber = null,
|
||||
ReadableSectorTags = new List<SectorTagType>(),
|
||||
ReadableMediaTags = new List<MediaTagType>(),
|
||||
HasPartitions = false,
|
||||
HasSessions = false,
|
||||
Application = "MAXI Disk",
|
||||
Creator = null,
|
||||
Comments = null,
|
||||
MediaManufacturer = null,
|
||||
MediaModel = null,
|
||||
MediaSerialNumber = null,
|
||||
MediaBarcode = null,
|
||||
MediaPartNumber = null,
|
||||
MediaSequence = 0,
|
||||
LastMediaSequence = 0,
|
||||
DriveManufacturer = null,
|
||||
DriveModel = null,
|
||||
DriveSerialNumber = null,
|
||||
DriveFirmwareRevision = null
|
||||
};
|
||||
}
|
||||
@@ -74,7 +74,7 @@ namespace DiscImageChef.DiscImages
|
||||
public ImageInfo Info => imageInfo;
|
||||
|
||||
public string Name => "MAXI Disk image";
|
||||
public Guid Id => new Guid("D27D924A-7034-466E-ADE1-B81EF37E469E");
|
||||
public Guid Id => new Guid("D27D924A-7034-466E-ADE1-B81EF37E469E");
|
||||
|
||||
public string ImageFormat => "MAXI Disk";
|
||||
|
||||
@@ -102,10 +102,10 @@ namespace DiscImageChef.DiscImages
|
||||
HdkHeader tmpHeader = (HdkHeader)Marshal.PtrToStructure(ftrPtr, typeof(HdkHeader));
|
||||
Marshal.FreeHGlobal(ftrPtr);
|
||||
|
||||
DicConsole.DebugWriteLine("MAXI Disk plugin", "tmp_header.unknown = {0}", tmpHeader.unknown);
|
||||
DicConsole.DebugWriteLine("MAXI Disk plugin", "tmp_header.diskType = {0}", tmpHeader.diskType);
|
||||
DicConsole.DebugWriteLine("MAXI Disk plugin", "tmp_header.heads = {0}", tmpHeader.heads);
|
||||
DicConsole.DebugWriteLine("MAXI Disk plugin", "tmp_header.cylinders = {0}", tmpHeader.cylinders);
|
||||
DicConsole.DebugWriteLine("MAXI Disk plugin", "tmp_header.unknown = {0}", tmpHeader.unknown);
|
||||
DicConsole.DebugWriteLine("MAXI Disk plugin", "tmp_header.diskType = {0}", tmpHeader.diskType);
|
||||
DicConsole.DebugWriteLine("MAXI Disk plugin", "tmp_header.heads = {0}", tmpHeader.heads);
|
||||
DicConsole.DebugWriteLine("MAXI Disk plugin", "tmp_header.cylinders = {0}", tmpHeader.cylinders);
|
||||
DicConsole.DebugWriteLine("MAXI Disk plugin", "tmp_header.bytesPerSector = {0}", tmpHeader.bytesPerSector);
|
||||
DicConsole.DebugWriteLine("MAXI Disk plugin", "tmp_header.sectorsPerTrack = {0}",
|
||||
tmpHeader.sectorsPerTrack);
|
||||
@@ -166,67 +166,22 @@ namespace DiscImageChef.DiscImages
|
||||
|
||||
if(expectedFileSize != stream.Length) return false;
|
||||
|
||||
imageInfo.Cylinders = tmpHeader.cylinders;
|
||||
imageInfo.Heads = tmpHeader.heads;
|
||||
imageInfo.Cylinders = tmpHeader.cylinders;
|
||||
imageInfo.Heads = tmpHeader.heads;
|
||||
imageInfo.SectorsPerTrack = tmpHeader.sectorsPerTrack;
|
||||
imageInfo.Sectors = (ulong)(tmpHeader.heads * tmpHeader.cylinders * tmpHeader.sectorsPerTrack);
|
||||
imageInfo.SectorSize = (uint)(128 << tmpHeader.bytesPerSector);
|
||||
imageInfo.Sectors = (ulong)(tmpHeader.heads * tmpHeader.cylinders * tmpHeader.sectorsPerTrack);
|
||||
imageInfo.SectorSize = (uint)(128 << tmpHeader.bytesPerSector);
|
||||
|
||||
hdkImageFilter = imageFilter;
|
||||
|
||||
imageInfo.ImageSize = (ulong)(stream.Length - 8);
|
||||
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
||||
imageInfo.ImageSize = (ulong)(stream.Length - 8);
|
||||
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
||||
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
||||
|
||||
if(imageInfo.Heads == 2 && imageInfo.Cylinders == 80 && imageInfo.SectorsPerTrack == 15 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.DOS_525_HD;
|
||||
else if(imageInfo.Heads == 2 && imageInfo.Cylinders == 80 && imageInfo.SectorsPerTrack == 16 &&
|
||||
imageInfo.SectorSize == 256) imageInfo.MediaType = MediaType.ACORN_525_DS_DD;
|
||||
else if(imageInfo.Heads == 1 && imageInfo.Cylinders == 80 && imageInfo.SectorsPerTrack == 16 &&
|
||||
imageInfo.SectorSize == 256) imageInfo.MediaType = MediaType.ACORN_525_SS_DD_80;
|
||||
else if(imageInfo.Heads == 1 && imageInfo.Cylinders == 80 && imageInfo.SectorsPerTrack == 10 &&
|
||||
imageInfo.SectorSize == 256) imageInfo.MediaType = MediaType.ACORN_525_SS_SD_80;
|
||||
else if(imageInfo.Heads == 2 && imageInfo.Cylinders == 77 && imageInfo.SectorsPerTrack == 8 &&
|
||||
imageInfo.SectorSize == 1024) imageInfo.MediaType = MediaType.NEC_525_HD;
|
||||
else if(imageInfo.Heads == 1 && imageInfo.Cylinders == 40 && imageInfo.SectorsPerTrack == 8 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.DOS_525_SS_DD_8;
|
||||
else if(imageInfo.Heads == 1 && imageInfo.Cylinders == 40 && imageInfo.SectorsPerTrack == 9 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.DOS_525_SS_DD_9;
|
||||
else if(imageInfo.Heads == 2 && imageInfo.Cylinders == 40 && imageInfo.SectorsPerTrack == 8 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.DOS_525_DS_DD_8;
|
||||
else if(imageInfo.Heads == 2 && imageInfo.Cylinders == 40 && imageInfo.SectorsPerTrack == 9 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.DOS_525_DS_DD_9;
|
||||
else if(imageInfo.Heads == 1 && imageInfo.Cylinders == 40 && imageInfo.SectorsPerTrack == 18 &&
|
||||
imageInfo.SectorSize == 128) imageInfo.MediaType = MediaType.ATARI_525_SD;
|
||||
else if(imageInfo.Heads == 1 && imageInfo.Cylinders == 40 && imageInfo.SectorsPerTrack == 26 &&
|
||||
imageInfo.SectorSize == 128) imageInfo.MediaType = MediaType.ATARI_525_ED;
|
||||
else if(imageInfo.Heads == 1 && imageInfo.Cylinders == 40 && imageInfo.SectorsPerTrack == 18 &&
|
||||
imageInfo.SectorSize == 256) imageInfo.MediaType = MediaType.ATARI_525_DD;
|
||||
else if(imageInfo.Heads == 2 && imageInfo.Cylinders == 80 && imageInfo.SectorsPerTrack == 36 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.DOS_35_ED;
|
||||
else if(imageInfo.Heads == 2 && imageInfo.Cylinders == 80 && imageInfo.SectorsPerTrack == 18 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.DOS_35_HD;
|
||||
else if(imageInfo.Heads == 2 && imageInfo.Cylinders == 80 && imageInfo.SectorsPerTrack == 21 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.DMF;
|
||||
else if(imageInfo.Heads == 2 && imageInfo.Cylinders == 82 && imageInfo.SectorsPerTrack == 21 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.DMF_82;
|
||||
else if(imageInfo.Heads == 2 && imageInfo.Cylinders == 77 && imageInfo.SectorsPerTrack == 8 &&
|
||||
imageInfo.SectorSize == 1024) imageInfo.MediaType = MediaType.NEC_35_HD_8;
|
||||
else if(imageInfo.Heads == 2 && imageInfo.Cylinders == 80 && imageInfo.SectorsPerTrack == 15 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.NEC_35_HD_15;
|
||||
else if(imageInfo.Heads == 2 && imageInfo.Cylinders == 80 && imageInfo.SectorsPerTrack == 9 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.DOS_35_DS_DD_9;
|
||||
else if(imageInfo.Heads == 2 && imageInfo.Cylinders == 80 && imageInfo.SectorsPerTrack == 8 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.DOS_35_DS_DD_8;
|
||||
else if(imageInfo.Heads == 1 && imageInfo.Cylinders == 80 && imageInfo.SectorsPerTrack == 9 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.DOS_35_SS_DD_9;
|
||||
else if(imageInfo.Heads == 1 && imageInfo.Cylinders == 80 && imageInfo.SectorsPerTrack == 8 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.DOS_35_SS_DD_8;
|
||||
else if(imageInfo.Heads == 2 && imageInfo.Cylinders == 80 && imageInfo.SectorsPerTrack == 5 &&
|
||||
imageInfo.SectorSize == 1024) imageInfo.MediaType = MediaType.ACORN_35_DS_DD;
|
||||
else if(imageInfo.Heads == 1 && imageInfo.Cylinders == 70 && imageInfo.SectorsPerTrack == 9 &&
|
||||
imageInfo.SectorSize == 512) imageInfo.MediaType = MediaType.Apricot_35;
|
||||
else imageInfo.MediaType = MediaType.Unknown;
|
||||
imageInfo.MediaType =
|
||||
Geometry.GetMediaType(((ushort)imageInfo.Cylinders, (byte)imageInfo.Heads,
|
||||
(ushort)imageInfo.SectorsPerTrack, imageInfo.SectorSize, MediaEncoding.MFM, false
|
||||
));
|
||||
|
||||
imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
|
||||
|
||||
@@ -244,7 +199,7 @@ namespace DiscImageChef.DiscImages
|
||||
}
|
||||
|
||||
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
||||
out List<ulong> unknownLbas)
|
||||
out List<ulong> unknownLbas)
|
||||
{
|
||||
failingLbas = new List<ulong>();
|
||||
unknownLbas = new List<ulong>();
|
||||
@@ -255,7 +210,7 @@ namespace DiscImageChef.DiscImages
|
||||
}
|
||||
|
||||
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
||||
out List<ulong> unknownLbas)
|
||||
out List<ulong> unknownLbas)
|
||||
{
|
||||
failingLbas = new List<ulong>();
|
||||
unknownLbas = new List<ulong>();
|
||||
@@ -292,7 +247,7 @@ namespace DiscImageChef.DiscImages
|
||||
|
||||
Stream stream = hdkImageFilter.GetDataForkStream();
|
||||
stream.Seek((long)(8 + sectorAddress * imageInfo.SectorSize), SeekOrigin.Begin);
|
||||
stream.Read(buffer, 0, (int)(length * imageInfo.SectorSize));
|
||||
stream.Read(buffer, 0, (int)(length * imageInfo.SectorSize));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
@@ -372,17 +327,17 @@ namespace DiscImageChef.DiscImages
|
||||
|
||||
enum HdkDiskTypes : byte
|
||||
{
|
||||
Dos360 = 0,
|
||||
Maxi420 = 1,
|
||||
Dos720 = 2,
|
||||
Maxi800 = 3,
|
||||
Dos1200 = 4,
|
||||
Dos360 = 0,
|
||||
Maxi420 = 1,
|
||||
Dos720 = 2,
|
||||
Maxi800 = 3,
|
||||
Dos1200 = 4,
|
||||
Maxi1400 = 5,
|
||||
Dos1440 = 6,
|
||||
Mac1440 = 7,
|
||||
Dos1440 = 6,
|
||||
Mac1440 = 7,
|
||||
Maxi1600 = 8,
|
||||
Dmf = 9,
|
||||
Dos2880 = 10,
|
||||
Dmf = 9,
|
||||
Dos2880 = 10,
|
||||
Maxi3200 = 11
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user