🎨Converted all plugin types to interfaces.

This commit is contained in:
2017-12-26 06:05:12 +00:00
parent a002253fa4
commit f66a0bdd42
295 changed files with 9499 additions and 10414 deletions

View File

@@ -41,18 +41,17 @@ using DiscImageChef.Filters;
namespace DiscImageChef.DiscImages
{
public class UkvFdi : ImagePlugin
public class UkvFdi : IMediaImage
{
readonly byte[] signature = {0x46, 0x44, 0x49};
ImageInfo imageInfo;
// Cylinder by head, sector data matrix
byte[][][][] sectorsData;
public UkvFdi()
{
Name = "Spectrum Floppy Disk Image";
PluginUuid = new Guid("DADFC9B2-67C1-42A3-B124-825528163FC0");
ImageInfo = new ImageInfo
imageInfo = new ImageInfo
{
ReadableSectorTags = new List<SectorTagType>(),
ReadableMediaTags = new List<MediaTagType>(),
@@ -77,18 +76,22 @@ namespace DiscImageChef.DiscImages
};
}
public override string ImageFormat => "Spectrum floppy disk image";
public virtual string Name => "Spectrum Floppy Disk Image";
public virtual Guid Id => new Guid("DADFC9B2-67C1-42A3-B124-825528163FC0");
public override List<Partition> Partitions =>
public virtual string ImageFormat => "Spectrum floppy disk image";
public virtual List<Partition> Partitions =>
throw new FeatureUnsupportedImageException("Feature not supported by image format");
public override List<Track> Tracks =>
public virtual List<Track> Tracks =>
throw new FeatureUnsupportedImageException("Feature not supported by image format");
public virtual ImageInfo Info => imageInfo;
public virtual List<Session> Sessions =>
throw new FeatureUnsupportedImageException("Feature not supported by image format");
public override List<Session> Sessions =>
throw new FeatureUnsupportedImageException("Feature not supported by image format");
public override bool IdentifyImage(Filter imageFilter)
public virtual bool IdentifyImage(IFilter imageFilter)
{
Stream stream = imageFilter.GetDataForkStream();
stream.Seek(0, SeekOrigin.Begin);
@@ -107,7 +110,7 @@ namespace DiscImageChef.DiscImages
return hdr.magic.SequenceEqual(signature);
}
public override bool OpenImage(Filter imageFilter)
public virtual bool OpenImage(IFilter imageFilter)
{
Stream stream = imageFilter.GetDataForkStream();
stream.Seek(0, SeekOrigin.Begin);
@@ -133,9 +136,9 @@ namespace DiscImageChef.DiscImages
stream.Seek(hdr.descOff, SeekOrigin.Begin);
byte[] description = new byte[hdr.dataOff - hdr.descOff];
stream.Read(description, 0, description.Length);
ImageInfo.Comments = StringHandlers.CToString(description);
imageInfo.Comments = StringHandlers.CToString(description);
DicConsole.DebugWriteLine("UkvFdi plugin", "hdr.description = \"{0}\"", ImageInfo.Comments);
DicConsole.DebugWriteLine("UkvFdi plugin", "hdr.description = \"{0}\"", imageInfo.Comments);
stream.Seek(0xE + hdr.addInfoLen, SeekOrigin.Begin);
@@ -143,8 +146,8 @@ namespace DiscImageChef.DiscImages
uint[][][] sectorsOff = new uint[hdr.cylinders][][];
sectorsData = new byte[hdr.cylinders][][][];
ImageInfo.Cylinders = hdr.cylinders;
ImageInfo.Heads = hdr.heads;
imageInfo.Cylinders = hdr.cylinders;
imageInfo.Heads = hdr.heads;
// Read track descriptors
for(ushort cyl = 0; cyl < hdr.cylinders; cyl++)
@@ -193,7 +196,7 @@ namespace DiscImageChef.DiscImages
sectorsOff[cyl][head][sec] = secOff + trkOff + hdr.dataOff;
sectorsData[cyl][head][sec] = new byte[128 << n];
if(128 << n > ImageInfo.SectorSize) ImageInfo.SectorSize = (uint)(128 << n);
if(128 << n > imageInfo.SectorSize) imageInfo.SectorSize = (uint)(128 << n);
}
}
}
@@ -221,27 +224,27 @@ namespace DiscImageChef.DiscImages
else
{
sectorsData[cyl][head] = new byte[spt][];
for(int i = 0; i < spt; i++) sectorsData[cyl][head][i] = new byte[ImageInfo.SectorSize];
for(int i = 0; i < spt; i++) sectorsData[cyl][head][i] = new byte[imageInfo.SectorSize];
}
}
if(emptyCyl) ImageInfo.Cylinders--;
if(emptyCyl) imageInfo.Cylinders--;
}
// TODO: What about double sided, half track pitch compact floppies?
ImageInfo.MediaType = MediaType.CompactFloppy;
ImageInfo.ImageSize = (ulong)stream.Length - hdr.dataOff;
ImageInfo.CreationTime = imageFilter.GetCreationTime();
ImageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
ImageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
ImageInfo.SectorsPerTrack = (uint)spt;
ImageInfo.Sectors = ImageInfo.Cylinders * ImageInfo.Heads * ImageInfo.SectorsPerTrack;
ImageInfo.XmlMediaType = XmlMediaType.BlockMedia;
imageInfo.MediaType = MediaType.CompactFloppy;
imageInfo.ImageSize = (ulong)stream.Length - hdr.dataOff;
imageInfo.CreationTime = imageFilter.GetCreationTime();
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
imageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
imageInfo.SectorsPerTrack = (uint)spt;
imageInfo.Sectors = imageInfo.Cylinders * imageInfo.Heads * imageInfo.SectorsPerTrack;
imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
return true;
}
public override byte[] ReadSector(ulong sectorAddress)
public virtual byte[] ReadSector(ulong sectorAddress)
{
(ushort cylinder, byte head, byte sector) = LbaToChs(sectorAddress);
@@ -257,12 +260,12 @@ namespace DiscImageChef.DiscImages
return sectorsData[cylinder][head][sector - 1];
}
public override byte[] ReadSectors(ulong sectorAddress, uint length)
public virtual byte[] ReadSectors(ulong sectorAddress, uint length)
{
if(sectorAddress > ImageInfo.Sectors - 1)
if(sectorAddress > imageInfo.Sectors - 1)
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
if(sectorAddress + length > ImageInfo.Sectors)
if(sectorAddress + length > imageInfo.Sectors)
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
MemoryStream buffer = new MemoryStream();
@@ -277,105 +280,105 @@ namespace DiscImageChef.DiscImages
(ushort cylinder, byte head, byte sector) LbaToChs(ulong lba)
{
ushort cylinder = (ushort)(lba / (ImageInfo.Heads * ImageInfo.SectorsPerTrack));
byte head = (byte)(lba / ImageInfo.SectorsPerTrack % ImageInfo.Heads);
byte sector = (byte)(lba % ImageInfo.SectorsPerTrack + 1);
ushort cylinder = (ushort)(lba / (imageInfo.Heads * imageInfo.SectorsPerTrack));
byte head = (byte)(lba / imageInfo.SectorsPerTrack % imageInfo.Heads);
byte sector = (byte)(lba % imageInfo.SectorsPerTrack + 1);
return (cylinder, head, sector);
}
public override byte[] ReadDiskTag(MediaTagType tag)
public virtual byte[] ReadDiskTag(MediaTagType tag)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
public virtual byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSector(ulong sectorAddress, uint track)
public virtual byte[] ReadSector(ulong sectorAddress, uint track)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag)
public virtual byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
public virtual byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
public virtual byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
public virtual byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorLong(ulong sectorAddress)
public virtual byte[] ReadSectorLong(ulong sectorAddress)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorLong(ulong sectorAddress, uint track)
public virtual byte[] ReadSectorLong(ulong sectorAddress, uint track)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorsLong(ulong sectorAddress, uint length)
public virtual byte[] ReadSectorsLong(ulong sectorAddress, uint length)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
public virtual byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override List<Track> GetSessionTracks(Session session)
public virtual List<Track> GetSessionTracks(Session session)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override List<Track> GetSessionTracks(ushort session)
public virtual List<Track> GetSessionTracks(ushort session)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override bool? VerifySector(ulong sectorAddress)
public virtual bool? VerifySector(ulong sectorAddress)
{
return null;
}
public override bool? VerifySector(ulong sectorAddress, uint track)
public virtual bool? VerifySector(ulong sectorAddress, uint track)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
public virtual bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
out List<ulong> unknownLbas)
{
failingLbas = new List<ulong>();
unknownLbas = new List<ulong>();
for(ulong i = 0; i < ImageInfo.Sectors; i++) unknownLbas.Add(i);
for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i);
return null;
}
public override bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
public virtual bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
out List<ulong> unknownLbas)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override bool? VerifyMediaImage()
public virtual bool? VerifyMediaImage()
{
return null;
}