🎨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

@@ -46,7 +46,7 @@ namespace DiscImageChef.DiscImages
{
// TODO: Doesn't support compositing from several files
// TODO: Doesn't support silences that are not in files
public class Cdrdao : ImagePlugin
public class Cdrdao : IMediaImage
{
/// <summary>Audio track, 2352 bytes/sector</summary>
const string CDRDAO_TRACK_TYPE_AUDIO = "AUDIO";
@@ -103,8 +103,9 @@ namespace DiscImageChef.DiscImages
const string REGEX_LANGUAGE_MAP = @"^\s*LANGUAGE_MAP\s*\{";
const string REGEX_LANGUAGE_MAPPING = @"^\s*(?<code>\d+)\s?\:\s?(?<language>\d+|\w+)";
Filter cdrdaoFilter;
IFilter cdrdaoFilter;
CdrdaoDisc discimage;
ImageInfo imageInfo;
Stream imageStream;
/// <summary>Dictionary, index is track #, value is TrackFile</summary>
Dictionary<uint, ulong> offsetmap;
@@ -113,9 +114,7 @@ namespace DiscImageChef.DiscImages
public Cdrdao()
{
Name = "CDRDAO tocfile";
PluginUuid = new Guid("04D7BA12-1BE8-44D4-97A4-1B48A505463E");
ImageInfo = new ImageInfo
imageInfo = new ImageInfo
{
ReadableSectorTags = new List<SectorTagType>(),
ReadableMediaTags = new List<MediaTagType>(),
@@ -137,11 +136,16 @@ namespace DiscImageChef.DiscImages
};
}
public override string ImageFormat => "CDRDAO tocfile";
public virtual ImageInfo Info => imageInfo;
public override List<Partition> Partitions => partitions;
public virtual string Name => "CDRDAO tocfile";
public virtual Guid Id => new Guid("04D7BA12-1BE8-44D4-97A4-1B48A505463E");
public override List<Track> Tracks
public virtual string ImageFormat => "CDRDAO tocfile";
public virtual List<Partition> Partitions => partitions;
public virtual List<Track> Tracks
{
get
{
@@ -187,9 +191,9 @@ namespace DiscImageChef.DiscImages
}
}
public override List<Session> Sessions => throw new NotImplementedException();
public virtual List<Session> Sessions => throw new NotImplementedException();
public override bool IdentifyImage(Filter imageFilter)
public virtual bool IdentifyImage(IFilter imageFilter)
{
try
{
@@ -244,7 +248,7 @@ namespace DiscImageChef.DiscImages
}
}
public override bool OpenImage(Filter imageFilter)
public virtual bool OpenImage(IFilter imageFilter)
{
if(imageFilter == null) return false;
@@ -830,93 +834,93 @@ namespace DiscImageChef.DiscImages
foreach(CdrdaoTrack track in discimage.Tracks)
{
ImageInfo.ImageSize += track.Bps * track.Sectors;
ImageInfo.Sectors += track.Sectors;
imageInfo.ImageSize += track.Bps * track.Sectors;
imageInfo.Sectors += track.Sectors;
}
if(discimage.Disktype == MediaType.CDG || discimage.Disktype == MediaType.CDEG ||
discimage.Disktype == MediaType.CDMIDI)
ImageInfo.SectorSize = 2448; // CD+G subchannels ARE user data, as CD+G are useless without them
imageInfo.SectorSize = 2448; // CD+G subchannels ARE user data, as CD+G are useless without them
else if(discimage.Disktype != MediaType.CDROMXA && discimage.Disktype != MediaType.CDDA &&
discimage.Disktype != MediaType.CDI &&
discimage.Disktype != MediaType.CDPLUS) ImageInfo.SectorSize = 2048; // Only data tracks
else ImageInfo.SectorSize = 2352; // All others
discimage.Disktype != MediaType.CDPLUS) imageInfo.SectorSize = 2048; // Only data tracks
else imageInfo.SectorSize = 2352; // All others
if(discimage.Mcn != null) ImageInfo.ReadableMediaTags.Add(MediaTagType.CD_MCN);
if(discimage.Mcn != null) imageInfo.ReadableMediaTags.Add(MediaTagType.CD_MCN);
ImageInfo.Application = "CDRDAO";
imageInfo.Application = "CDRDAO";
ImageInfo.CreationTime = imageFilter.GetCreationTime();
ImageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
imageInfo.CreationTime = imageFilter.GetCreationTime();
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
ImageInfo.Comments = discimage.Comment;
ImageInfo.MediaSerialNumber = discimage.Mcn;
ImageInfo.MediaBarcode = discimage.Barcode;
ImageInfo.MediaType = discimage.Disktype;
imageInfo.Comments = discimage.Comment;
imageInfo.MediaSerialNumber = discimage.Mcn;
imageInfo.MediaBarcode = discimage.Barcode;
imageInfo.MediaType = discimage.Disktype;
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdTrackFlags);
imageInfo.ReadableSectorTags.Add(SectorTagType.CdTrackFlags);
foreach(CdrdaoTrack track in discimage.Tracks)
{
if(track.Subchannel)
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubchannel))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubchannel);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubchannel))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubchannel);
switch(track.Tracktype)
{
case CDRDAO_TRACK_TYPE_AUDIO:
{
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdTrackIsrc))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdTrackIsrc);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdTrackIsrc))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdTrackIsrc);
break;
}
case CDRDAO_TRACK_TYPE_MODE2:
case CDRDAO_TRACK_TYPE_MODE2_MIX:
{
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
break;
}
case CDRDAO_TRACK_TYPE_MODE2_RAW:
{
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
break;
}
case CDRDAO_TRACK_TYPE_MODE1_RAW:
{
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEcc))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEcc);
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccP))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccP);
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccQ))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccQ);
if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEcc))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEcc);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccP))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccP);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccQ))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccQ);
if(!imageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc))
imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
break;
}
}
}
ImageInfo.XmlMediaType = XmlMediaType.OpticalDisc;
imageInfo.XmlMediaType = XmlMediaType.OpticalDisc;
DicConsole.VerboseWriteLine("CDRDAO image describes a disc of type {0}", ImageInfo.MediaType);
if(!string.IsNullOrEmpty(ImageInfo.Comments))
DicConsole.VerboseWriteLine("CDRDAO comments: {0}", ImageInfo.Comments);
DicConsole.VerboseWriteLine("CDRDAO image describes a disc of type {0}", imageInfo.MediaType);
if(!string.IsNullOrEmpty(imageInfo.Comments))
DicConsole.VerboseWriteLine("CDRDAO comments: {0}", imageInfo.Comments);
return true;
}
@@ -929,7 +933,7 @@ namespace DiscImageChef.DiscImages
}
}
public override byte[] ReadDiskTag(MediaTagType tag)
public virtual byte[] ReadDiskTag(MediaTagType tag)
{
switch(tag)
{
@@ -944,27 +948,27 @@ namespace DiscImageChef.DiscImages
}
}
public override byte[] ReadSector(ulong sectorAddress)
public virtual byte[] ReadSector(ulong sectorAddress)
{
return ReadSectors(sectorAddress, 1);
}
public override byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
public virtual byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
{
return ReadSectorsTag(sectorAddress, 1, tag);
}
public override byte[] ReadSector(ulong sectorAddress, uint track)
public virtual byte[] ReadSector(ulong sectorAddress, uint track)
{
return ReadSectors(sectorAddress, 1, track);
}
public override byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag)
public virtual byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag)
{
return ReadSectorsTag(sectorAddress, 1, track, tag);
}
public override byte[] ReadSectors(ulong sectorAddress, uint length)
public virtual byte[] ReadSectors(ulong sectorAddress, uint length)
{
foreach(KeyValuePair<uint, ulong> kvp in from kvp in offsetmap
where sectorAddress >= kvp.Value
@@ -977,7 +981,7 @@ namespace DiscImageChef.DiscImages
throw new ArgumentOutOfRangeException(nameof(sectorAddress), $"Sector address {sectorAddress} not found");
}
public override byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
public virtual byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
{
foreach(KeyValuePair<uint, ulong> kvp in from kvp in offsetmap
where sectorAddress >= kvp.Value
@@ -990,7 +994,7 @@ namespace DiscImageChef.DiscImages
throw new ArgumentOutOfRangeException(nameof(sectorAddress), $"Sector address {sectorAddress} not found");
}
public override byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
public virtual byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
{
CdrdaoTrack dicTrack = new CdrdaoTrack {Sequence = 0};
@@ -1082,7 +1086,7 @@ namespace DiscImageChef.DiscImages
return buffer;
}
public override byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
public virtual byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
{
CdrdaoTrack dicTrack = new CdrdaoTrack {Sequence = 0};
@@ -1248,17 +1252,17 @@ namespace DiscImageChef.DiscImages
return buffer;
}
public override byte[] ReadSectorLong(ulong sectorAddress)
public virtual byte[] ReadSectorLong(ulong sectorAddress)
{
return ReadSectorsLong(sectorAddress, 1);
}
public override byte[] ReadSectorLong(ulong sectorAddress, uint track)
public virtual byte[] ReadSectorLong(ulong sectorAddress, uint track)
{
return ReadSectorsLong(sectorAddress, 1, track);
}
public override byte[] ReadSectorsLong(ulong sectorAddress, uint length)
public virtual byte[] ReadSectorsLong(ulong sectorAddress, uint length)
{
foreach(KeyValuePair<uint, ulong> kvp in from kvp in offsetmap
where sectorAddress >= kvp.Value
@@ -1271,7 +1275,7 @@ namespace DiscImageChef.DiscImages
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
}
public override byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
public virtual byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
{
CdrdaoTrack dicTrack = new CdrdaoTrack {Sequence = 0};
@@ -1354,31 +1358,31 @@ namespace DiscImageChef.DiscImages
return buffer;
}
public override List<Track> GetSessionTracks(Session session)
public virtual List<Track> GetSessionTracks(Session session)
{
return GetSessionTracks(session.SessionSequence);
}
public override List<Track> GetSessionTracks(ushort session)
public virtual List<Track> GetSessionTracks(ushort session)
{
if(session == 1) return Tracks;
throw new ImageNotSupportedException("Session does not exist in disc image");
}
public override bool? VerifySector(ulong sectorAddress)
public virtual bool? VerifySector(ulong sectorAddress)
{
byte[] buffer = ReadSectorLong(sectorAddress);
return CdChecksums.CheckCdSector(buffer);
}
public override bool? VerifySector(ulong sectorAddress, uint track)
public virtual bool? VerifySector(ulong sectorAddress, uint track)
{
byte[] buffer = ReadSectorLong(sectorAddress, track);
return CdChecksums.CheckCdSector(buffer);
}
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)
{
byte[] buffer = ReadSectorsLong(sectorAddress, length);
@@ -1408,7 +1412,7 @@ namespace DiscImageChef.DiscImages
return failingLbas.Count <= 0;
}
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)
{
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
@@ -1438,7 +1442,7 @@ namespace DiscImageChef.DiscImages
return failingLbas.Count <= 0;
}
public override bool? VerifyMediaImage()
public virtual bool? VerifyMediaImage()
{
return null;
}
@@ -1497,7 +1501,7 @@ namespace DiscImageChef.DiscImages
/// <summary>Track #</summary>
public uint Sequence;
/// <summary>Filter of file containing track</summary>
public Filter Datafilter;
public IFilter Datafilter;
/// <summary>Path of file containing track</summary>
public string Datafile;
/// <summary>Offset of track start in file</summary>