diff --git a/.idea/.idea.DiscImageChef/.idea/contentModel.xml b/.idea/.idea.DiscImageChef/.idea/contentModel.xml index 570672a31..ec75100f7 100644 --- a/.idea/.idea.DiscImageChef/.idea/contentModel.xml +++ b/.idea/.idea.DiscImageChef/.idea/contentModel.xml @@ -125,6 +125,8 @@ + + @@ -615,6 +617,7 @@ + @@ -676,6 +679,7 @@ + @@ -686,6 +690,7 @@ + @@ -696,6 +701,7 @@ + @@ -705,7 +711,7 @@ - + @@ -728,6 +734,7 @@ + @@ -755,7 +762,7 @@ - + @@ -802,7 +809,7 @@ - + @@ -825,6 +832,7 @@ + @@ -835,6 +843,7 @@ + @@ -856,6 +865,7 @@ + @@ -883,7 +893,7 @@ - + @@ -923,6 +933,7 @@ + @@ -943,6 +954,7 @@ + @@ -954,6 +966,7 @@ + @@ -1018,6 +1031,7 @@ + @@ -1029,6 +1043,7 @@ + @@ -1047,6 +1062,7 @@ + @@ -1135,6 +1151,7 @@ + diff --git a/DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj b/DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj index 03d3dafbf..7800e7082 100644 --- a/DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj +++ b/DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj @@ -74,6 +74,8 @@ + + diff --git a/DiscImageChef.CommonTypes/Interfaces/IMediaImage.cs b/DiscImageChef.CommonTypes/Interfaces/IMediaImage.cs index 16ff53c39..b02a10e6f 100644 --- a/DiscImageChef.CommonTypes/Interfaces/IMediaImage.cs +++ b/DiscImageChef.CommonTypes/Interfaces/IMediaImage.cs @@ -135,28 +135,5 @@ namespace DiscImageChef.CommonTypes.Interfaces /// Starting sector address (LBA). /// How many sectors to read. byte[] ReadSectorsLong(ulong sectorAddress, uint length); - - /// - /// Verifies a sector. - /// - /// True if correct, false if incorrect, null if uncheckable. - /// Sector address (LBA). - bool? VerifySector(ulong sectorAddress); - - /// - /// Verifies several sectors. - /// - /// True if all are correct, false if any is incorrect, null if any is uncheckable. - /// Starting sector address (LBA). - /// How many sectors to read. - /// List of incorrect sectors - /// List of uncheckable sectors - bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, out List unknownLbas); - - /// - /// Verifies media image internal checksum. - /// - /// True if correct, false if incorrect, null if there is no internal checksum available - bool? VerifyMediaImage(); } } \ No newline at end of file diff --git a/DiscImageChef.CommonTypes/Interfaces/IOpticalMediaImage.cs b/DiscImageChef.CommonTypes/Interfaces/IOpticalMediaImage.cs index a99beab79..7cb50c838 100644 --- a/DiscImageChef.CommonTypes/Interfaces/IOpticalMediaImage.cs +++ b/DiscImageChef.CommonTypes/Interfaces/IOpticalMediaImage.cs @@ -45,7 +45,7 @@ namespace DiscImageChef.CommonTypes.Interfaces /// /// Abstract class to implement disk image reading plugins. /// - public interface IOpticalMediaImage : IMediaImage, IPartitionableMediaImage + public interface IOpticalMediaImage : IMediaImage, IPartitionableMediaImage, IVerifiableSectorsImage { /// /// Gets the disc track extents (start, length). diff --git a/DiscImageChef.CommonTypes/Interfaces/IVerifiableImage.cs b/DiscImageChef.CommonTypes/Interfaces/IVerifiableImage.cs new file mode 100644 index 000000000..af6d77eda --- /dev/null +++ b/DiscImageChef.CommonTypes/Interfaces/IVerifiableImage.cs @@ -0,0 +1,50 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : IVerifiableImage.cs +// Author(s) : Natalia Portillo +// +// Component : Disc image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Defines interface to be implemented by image plugins that can verify the +// image itself. +// +// --[ License ] -------------------------------------------------------------- +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +namespace DiscImageChef.CommonTypes.Interfaces +{ + public interface IVerifiableImage + { + /// + /// Verifies media image internal checksum. + /// + /// True if correct, false if incorrect, null if there is no internal checksum available + bool? VerifyMediaImage(); + } +} \ No newline at end of file diff --git a/DiscImageChef.CommonTypes/Interfaces/IVerifiableSectorsImage.cs b/DiscImageChef.CommonTypes/Interfaces/IVerifiableSectorsImage.cs new file mode 100644 index 000000000..f9da0d59a --- /dev/null +++ b/DiscImageChef.CommonTypes/Interfaces/IVerifiableSectorsImage.cs @@ -0,0 +1,63 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : IVerifiableSectorsImage.cs +// Author(s) : Natalia Portillo +// +// Component : Disc image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Defines interface to be implemented by image plugins that can verify the +// sectors contained in the image. +// +// --[ License ] -------------------------------------------------------------- +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System.Collections.Generic; + +namespace DiscImageChef.CommonTypes.Interfaces +{ + public interface IVerifiableSectorsImage + { + /// + /// Verifies a sector. + /// + /// True if correct, false if incorrect, null if uncheckable. + /// Sector address (LBA). + bool? VerifySector(ulong sectorAddress); + + /// + /// Verifies several sectors. + /// + /// True if all are correct, false if any is incorrect, null if any is uncheckable. + /// Starting sector address (LBA). + /// How many sectors to read. + /// List of incorrect sectors + /// List of uncheckable sectors + bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, out List unknownLbas); + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/Alcohol120/Read.cs b/DiscImageChef.DiscImages/Alcohol120/Read.cs index 551ac7f4d..a171bf1ea 100644 --- a/DiscImageChef.DiscImages/Alcohol120/Read.cs +++ b/DiscImageChef.DiscImages/Alcohol120/Read.cs @@ -36,7 +36,6 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; -using DiscImageChef.Checksums; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -638,25 +637,14 @@ namespace DiscImageChef.DiscImages } } - public byte[] ReadSector(ulong sectorAddress) - { - return ReadSectors(sectorAddress, 1); - } + public byte[] ReadSector(ulong sectorAddress) => ReadSectors(sectorAddress, 1); - public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) - { - return ReadSectorsTag(sectorAddress, 1, tag); - } + public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) => ReadSectorsTag(sectorAddress, 1, tag); - public byte[] ReadSector(ulong sectorAddress, uint track) - { - return ReadSectors(sectorAddress, 1, track); - } + public byte[] ReadSector(ulong sectorAddress, uint track) => ReadSectors(sectorAddress, 1, track); - public byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag) - { - return ReadSectorsTag(sectorAddress, 1, track, tag); - } + public byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag) => + ReadSectorsTag(sectorAddress, 1, track, tag); public byte[] ReadSectors(ulong sectorAddress, uint length) { @@ -1108,15 +1096,9 @@ namespace DiscImageChef.DiscImages return buffer; } - public byte[] ReadSectorLong(ulong sectorAddress) - { - return ReadSectorsLong(sectorAddress, 1); - } + public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); - public byte[] ReadSectorLong(ulong sectorAddress, uint track) - { - return ReadSectorsLong(sectorAddress, 1, track); - } + public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track); public byte[] ReadSectorsLong(ulong sectorAddress, uint length) { @@ -1248,82 +1230,5 @@ namespace DiscImageChef.DiscImages return tracks; } - - public bool? VerifySector(ulong sectorAddress) - { - byte[] buffer = ReadSectorLong(sectorAddress); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySector(ulong sectorAddress, uint track) - { - byte[] buffer = ReadSectorLong(sectorAddress, track); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length, track); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifyMediaImage() - { - return null; - } } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/Alcohol120/Verify.cs b/DiscImageChef.DiscImages/Alcohol120/Verify.cs new file mode 100644 index 000000000..357520454 --- /dev/null +++ b/DiscImageChef.DiscImages/Alcohol120/Verify.cs @@ -0,0 +1,113 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies Alcohol 120% format disc images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using DiscImageChef.Checksums; + +namespace DiscImageChef.DiscImages +{ + public partial class Alcohol120 + { + public bool? VerifySector(ulong sectorAddress) + { + byte[] buffer = ReadSectorLong(sectorAddress); + return CdChecksums.CheckCdSector(buffer); + } + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length, track); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySector(ulong sectorAddress, uint track) + { + byte[] buffer = ReadSectorLong(sectorAddress, track); + return CdChecksums.CheckCdSector(buffer); + } + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/Anex86/Read.cs b/DiscImageChef.DiscImages/Anex86/Read.cs index ab72fc15b..d4758e0b9 100644 --- a/DiscImageChef.DiscImages/Anex86/Read.cs +++ b/DiscImageChef.DiscImages/Anex86/Read.cs @@ -31,7 +31,6 @@ // ****************************************************************************/ using System; -using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using DiscImageChef.CommonTypes; @@ -60,8 +59,8 @@ namespace DiscImageChef.DiscImages handle.Free(); imageInfo.MediaType = Geometry.GetMediaType(((ushort)fdihdr.cylinders, (byte)fdihdr.heads, - (ushort)fdihdr.spt, (uint)fdihdr.bps, MediaEncoding.MFM, - false)); + (ushort)fdihdr.spt, (uint)fdihdr.bps, MediaEncoding.MFM, + false)); if(imageInfo.MediaType == MediaType.Unknown) imageInfo.MediaType = MediaType.GENERIC_HDD; DicConsole.DebugWriteLine("Anex86 plugin", "MediaType: {0}", imageInfo.MediaType); @@ -102,19 +101,5 @@ namespace DiscImageChef.DiscImages return buffer; } - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/Apple2MG/Unsupported.cs b/DiscImageChef.DiscImages/Apple2MG/Unsupported.cs index 0263c66ed..89e475f7b 100644 --- a/DiscImageChef.DiscImages/Apple2MG/Unsupported.cs +++ b/DiscImageChef.DiscImages/Apple2MG/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/AppleDOS/Unsupported.cs b/DiscImageChef.DiscImages/AppleDOS/Unsupported.cs index 8d0db3470..83cc67cfa 100644 --- a/DiscImageChef.DiscImages/AppleDOS/Unsupported.cs +++ b/DiscImageChef.DiscImages/AppleDOS/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -38,21 +37,6 @@ namespace DiscImageChef.DiscImages { public partial class AppleDos { - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - - for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; - public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); diff --git a/DiscImageChef.DiscImages/AppleNIB/Unsupported.cs b/DiscImageChef.DiscImages/AppleNIB/Unsupported.cs index d1d20429f..b5845bba3 100644 --- a/DiscImageChef.DiscImages/AppleNIB/Unsupported.cs +++ b/DiscImageChef.DiscImages/AppleNIB/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -40,19 +39,5 @@ namespace DiscImageChef.DiscImages { public byte[] ReadDiskTag(MediaTagType tag) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/Apridisk/Unsupported.cs b/DiscImageChef.DiscImages/Apridisk/Unsupported.cs index 3bb3aa6f9..af6da3804 100644 --- a/DiscImageChef.DiscImages/Apridisk/Unsupported.cs +++ b/DiscImageChef.DiscImages/Apridisk/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/BLU/BLU.cs b/DiscImageChef.DiscImages/BLU/BLU.cs index 26529039f..f37a6174b 100644 --- a/DiscImageChef.DiscImages/BLU/BLU.cs +++ b/DiscImageChef.DiscImages/BLU/BLU.cs @@ -38,7 +38,7 @@ using DiscImageChef.CommonTypes.Structs; namespace DiscImageChef.DiscImages { - public partial class Blu : IWritableImage + public partial class Blu : IWritableImage, IVerifiableSectorsImage { IFilter bluImageFilter; int bptag; diff --git a/DiscImageChef.DiscImages/BLU/Read.cs b/DiscImageChef.DiscImages/BLU/Read.cs index 4ae3f6111..43e876573 100644 --- a/DiscImageChef.DiscImages/BLU/Read.cs +++ b/DiscImageChef.DiscImages/BLU/Read.cs @@ -31,7 +31,6 @@ // ****************************************************************************/ using System; -using System.Collections.Generic; using System.IO; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; @@ -220,19 +219,5 @@ namespace DiscImageChef.DiscImages return buffer; } - - // TODO: Check tag checkums - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - - for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); - - return null; - } } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/BLU/Unsupported.cs b/DiscImageChef.DiscImages/BLU/Unsupported.cs index ea2f4da10..7565ffb40 100644 --- a/DiscImageChef.DiscImages/BLU/Unsupported.cs +++ b/DiscImageChef.DiscImages/BLU/Unsupported.cs @@ -39,7 +39,5 @@ namespace DiscImageChef.DiscImages { public byte[] ReadDiskTag(MediaTagType tag) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/BLU/Verify.cs b/DiscImageChef.DiscImages/BLU/Verify.cs new file mode 100644 index 000000000..b953700c0 --- /dev/null +++ b/DiscImageChef.DiscImages/BLU/Verify.cs @@ -0,0 +1,53 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies DiscJuggler disc images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System.Collections.Generic; + +namespace DiscImageChef.DiscImages +{ + public partial class Blu + { + // TODO: Check tag checkums + public bool? VerifySector(ulong sectorAddress) => null; + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) + { + failingLbas = new List(); + unknownLbas = new List(); + + for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); + + return null; + } + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/BlindWrite4/Read.cs b/DiscImageChef.DiscImages/BlindWrite4/Read.cs index 87e28f513..a05c5ff7a 100644 --- a/DiscImageChef.DiscImages/BlindWrite4/Read.cs +++ b/DiscImageChef.DiscImages/BlindWrite4/Read.cs @@ -36,7 +36,6 @@ using System.Globalization; using System.IO; using System.Linq; using System.Text; -using DiscImageChef.Checksums; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -1032,79 +1031,5 @@ namespace DiscImageChef.DiscImages { return Tracks.Where(track => track.TrackSession == session).ToList(); } - - public bool? VerifySector(ulong sectorAddress) - { - byte[] buffer = ReadSectorLong(sectorAddress); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySector(ulong sectorAddress, uint track) - { - byte[] buffer = ReadSectorLong(sectorAddress, track); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length, track); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/BlindWrite4/Verify.cs b/DiscImageChef.DiscImages/BlindWrite4/Verify.cs new file mode 100644 index 000000000..e5cfbe4bd --- /dev/null +++ b/DiscImageChef.DiscImages/BlindWrite4/Verify.cs @@ -0,0 +1,113 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies BlindWrite 4 format disc images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using DiscImageChef.Checksums; + +namespace DiscImageChef.DiscImages +{ + public partial class BlindWrite4 + { + public bool? VerifySector(ulong sectorAddress) + { + byte[] buffer = ReadSectorLong(sectorAddress); + return CdChecksums.CheckCdSector(buffer); + } + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length, track); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySector(ulong sectorAddress, uint track) + { + byte[] buffer = ReadSectorLong(sectorAddress, track); + return CdChecksums.CheckCdSector(buffer); + } + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/BlindWrite5/Read.cs b/DiscImageChef.DiscImages/BlindWrite5/Read.cs index cc0af12d8..344c3a048 100644 --- a/DiscImageChef.DiscImages/BlindWrite5/Read.cs +++ b/DiscImageChef.DiscImages/BlindWrite5/Read.cs @@ -37,7 +37,6 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; -using DiscImageChef.Checksums; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -1582,79 +1581,5 @@ namespace DiscImageChef.DiscImages { return Tracks.Where(dicTrack => dicTrack.TrackSession == session).ToList(); } - - public bool? VerifySector(ulong sectorAddress) - { - byte[] buffer = ReadSectorLong(sectorAddress); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySector(ulong sectorAddress, uint track) - { - byte[] buffer = ReadSectorLong(sectorAddress, track); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length, track); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/BlindWrite5/Verify.cs b/DiscImageChef.DiscImages/BlindWrite5/Verify.cs new file mode 100644 index 000000000..f85dbe3fb --- /dev/null +++ b/DiscImageChef.DiscImages/BlindWrite5/Verify.cs @@ -0,0 +1,113 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies BlindWrite 5 disc images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using DiscImageChef.Checksums; + +namespace DiscImageChef.DiscImages +{ + public partial class BlindWrite5 + { + public bool? VerifySector(ulong sectorAddress) + { + byte[] buffer = ReadSectorLong(sectorAddress); + return CdChecksums.CheckCdSector(buffer); + } + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length, track); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySector(ulong sectorAddress, uint track) + { + byte[] buffer = ReadSectorLong(sectorAddress, track); + return CdChecksums.CheckCdSector(buffer); + } + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/CDRDAO/Read.cs b/DiscImageChef.DiscImages/CDRDAO/Read.cs index a9c199637..7cca3d148 100644 --- a/DiscImageChef.DiscImages/CDRDAO/Read.cs +++ b/DiscImageChef.DiscImages/CDRDAO/Read.cs @@ -36,7 +36,6 @@ using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; -using DiscImageChef.Checksums; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -1186,77 +1185,5 @@ namespace DiscImageChef.DiscImages throw new ImageNotSupportedException("Session does not exist in disc image"); } - - public bool? VerifySector(ulong sectorAddress) - { - byte[] buffer = ReadSectorLong(sectorAddress); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySector(ulong sectorAddress, uint track) - { - byte[] buffer = ReadSectorLong(sectorAddress, track); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length, track); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/CDRDAO/Verify.cs b/DiscImageChef.DiscImages/CDRDAO/Verify.cs new file mode 100644 index 000000000..952a4ee0e --- /dev/null +++ b/DiscImageChef.DiscImages/CDRDAO/Verify.cs @@ -0,0 +1,113 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies cdrdao cuesheets (toc/bin). +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using DiscImageChef.Checksums; + +namespace DiscImageChef.DiscImages +{ + public partial class Cdrdao + { + public bool? VerifySector(ulong sectorAddress) + { + byte[] buffer = ReadSectorLong(sectorAddress); + return CdChecksums.CheckCdSector(buffer); + } + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length, track); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySector(ulong sectorAddress, uint track) + { + byte[] buffer = ReadSectorLong(sectorAddress, track); + return CdChecksums.CheckCdSector(buffer); + } + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/CDRWin/CDRWin.cs b/DiscImageChef.DiscImages/CDRWin/CDRWin.cs index 0db8acfc5..47ce5084c 100644 --- a/DiscImageChef.DiscImages/CDRWin/CDRWin.cs +++ b/DiscImageChef.DiscImages/CDRWin/CDRWin.cs @@ -39,7 +39,7 @@ using DiscImageChef.CommonTypes.Structs; namespace DiscImageChef.DiscImages { // TODO: Implement track flags - public partial class CdrWin : IWritableOpticalImage + public partial class CdrWin : IWritableOpticalImage, IVerifiableImage { IFilter cdrwinFilter; StreamReader cueStream; diff --git a/DiscImageChef.DiscImages/CHD/CHD.cs b/DiscImageChef.DiscImages/CHD/CHD.cs index 3f056f672..5a40ca2a2 100644 --- a/DiscImageChef.DiscImages/CHD/CHD.cs +++ b/DiscImageChef.DiscImages/CHD/CHD.cs @@ -40,7 +40,7 @@ using DiscImageChef.CommonTypes.Structs; namespace DiscImageChef.DiscImages { // TODO: Implement PCMCIA support - public partial class Chd : IOpticalMediaImage + public partial class Chd : IOpticalMediaImage, IVerifiableImage { /// "MComprHD" readonly byte[] chdTag = {0x4D, 0x43, 0x6F, 0x6D, 0x70, 0x72, 0x48, 0x44}; diff --git a/DiscImageChef.DiscImages/CHD/Read.cs b/DiscImageChef.DiscImages/CHD/Read.cs index 64a030c7b..05dc73700 100644 --- a/DiscImageChef.DiscImages/CHD/Read.cs +++ b/DiscImageChef.DiscImages/CHD/Read.cs @@ -37,7 +37,6 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; -using DiscImageChef.Checksums; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -1069,107 +1068,6 @@ namespace DiscImageChef.DiscImages return true; } - public bool? VerifySector(ulong sectorAddress) - { - if(isHdd) return null; - - byte[] buffer = ReadSectorLong(sectorAddress); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySector(ulong sectorAddress, uint track) - { - if(isHdd) - throw new FeaturedNotSupportedByDiscImageException("Cannot access optical tracks on a hard disk image"); - - return VerifySector(GetAbsoluteSector(sectorAddress, track)); - } - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - unknownLbas = new List(); - failingLbas = new List(); - if(isHdd) return null; - - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, - out List unknownLbas) - { - unknownLbas = new List(); - failingLbas = new List(); - if(isHdd) return null; - - byte[] buffer = ReadSectorsLong(sectorAddress, length, track); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifyMediaImage() - { - byte[] calculated; - if(mapVersion >= 3) - { - Sha1Context sha1Ctx = new Sha1Context(); - for(uint i = 0; i < totalHunks; i++) sha1Ctx.Update(GetHunk(i)); - - calculated = sha1Ctx.Final(); - } - else - { - Md5Context md5Ctx = new Md5Context(); - for(uint i = 0; i < totalHunks; i++) md5Ctx.Update(GetHunk(i)); - - calculated = md5Ctx.Final(); - } - - return expectedChecksum.SequenceEqual(calculated); - } - public byte[] ReadSector(ulong sectorAddress) { if(sectorAddress > imageInfo.Sectors - 1) diff --git a/DiscImageChef.DiscImages/CHD/Verify.cs b/DiscImageChef.DiscImages/CHD/Verify.cs new file mode 100644 index 000000000..5b37bd8cd --- /dev/null +++ b/DiscImageChef.DiscImages/CHD/Verify.cs @@ -0,0 +1,144 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies MAME Compressed Hunks of Data disk images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq; +using DiscImageChef.Checksums; +using DiscImageChef.CommonTypes.Exceptions; + +namespace DiscImageChef.DiscImages +{ + public partial class Chd + { + public bool? VerifySector(ulong sectorAddress) + { + if(isHdd) return null; + + byte[] buffer = ReadSectorLong(sectorAddress); + return CdChecksums.CheckCdSector(buffer); + } + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) + { + unknownLbas = new List(); + failingLbas = new List(); + if(isHdd) return null; + + byte[] buffer = ReadSectorsLong(sectorAddress, length); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, + out List unknownLbas) + { + unknownLbas = new List(); + failingLbas = new List(); + if(isHdd) return null; + + byte[] buffer = ReadSectorsLong(sectorAddress, length, track); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifyMediaImage() + { + byte[] calculated; + if(mapVersion >= 3) + { + Sha1Context sha1Ctx = new Sha1Context(); + for(uint i = 0; i < totalHunks; i++) sha1Ctx.Update(GetHunk(i)); + + calculated = sha1Ctx.Final(); + } + else + { + Md5Context md5Ctx = new Md5Context(); + for(uint i = 0; i < totalHunks; i++) md5Ctx.Update(GetHunk(i)); + + calculated = md5Ctx.Final(); + } + + return expectedChecksum.SequenceEqual(calculated); + } + + public bool? VerifySector(ulong sectorAddress, uint track) + { + if(isHdd) + throw new FeaturedNotSupportedByDiscImageException("Cannot access optical tracks on a hard disk image"); + + return VerifySector(GetAbsoluteSector(sectorAddress, track)); + } + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/CPCDSK/Unsupported.cs b/DiscImageChef.DiscImages/CPCDSK/Unsupported.cs index b2ba527ce..f349bcca3 100644 --- a/DiscImageChef.DiscImages/CPCDSK/Unsupported.cs +++ b/DiscImageChef.DiscImages/CPCDSK/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -46,23 +45,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, - out List unknownLbas) => - throw new FeatureUnsupportedImageException("Feature not supported by image format"); } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/CisCopy/Unsupported.cs b/DiscImageChef.DiscImages/CisCopy/Unsupported.cs index cfc56a397..400c12016 100644 --- a/DiscImageChef.DiscImages/CisCopy/Unsupported.cs +++ b/DiscImageChef.DiscImages/CisCopy/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,20 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadDiskTag(MediaTagType tag) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - - for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/CloneCD/Read.cs b/DiscImageChef.DiscImages/CloneCD/Read.cs index a9bd2b4d8..056686bc7 100644 --- a/DiscImageChef.DiscImages/CloneCD/Read.cs +++ b/DiscImageChef.DiscImages/CloneCD/Read.cs @@ -35,7 +35,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; -using DiscImageChef.Checksums; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -1142,77 +1141,5 @@ namespace DiscImageChef.DiscImages { return Tracks.Where(track => track.TrackSession == session).ToList(); } - - public bool? VerifySector(ulong sectorAddress) - { - byte[] buffer = ReadSectorLong(sectorAddress); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySector(ulong sectorAddress, uint track) - { - byte[] buffer = ReadSectorLong(sectorAddress, track); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length, track); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/CloneCD/Verify.cs b/DiscImageChef.DiscImages/CloneCD/Verify.cs new file mode 100644 index 000000000..8f670ddfd --- /dev/null +++ b/DiscImageChef.DiscImages/CloneCD/Verify.cs @@ -0,0 +1,113 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies CloneCD disc images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using DiscImageChef.Checksums; + +namespace DiscImageChef.DiscImages +{ + public partial class CloneCd + { + public bool? VerifySector(ulong sectorAddress) + { + byte[] buffer = ReadSectorLong(sectorAddress); + return CdChecksums.CheckCdSector(buffer); + } + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length, track); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySector(ulong sectorAddress, uint track) + { + byte[] buffer = ReadSectorLong(sectorAddress, track); + return CdChecksums.CheckCdSector(buffer); + } + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/CopyQM/CopyQM.cs b/DiscImageChef.DiscImages/CopyQM/CopyQM.cs index a0087d3e8..5ed75e645 100644 --- a/DiscImageChef.DiscImages/CopyQM/CopyQM.cs +++ b/DiscImageChef.DiscImages/CopyQM/CopyQM.cs @@ -38,7 +38,7 @@ using DiscImageChef.CommonTypes.Structs; namespace DiscImageChef.DiscImages { - public partial class CopyQm : IMediaImage + public partial class CopyQm : IMediaImage, IVerifiableImage { uint calculatedDataCrc; byte[] decodedDisk; diff --git a/DiscImageChef.DiscImages/CopyQM/Unsupported.cs b/DiscImageChef.DiscImages/CopyQM/Unsupported.cs index ac1e9eb22..0d0b04da8 100644 --- a/DiscImageChef.DiscImages/CopyQM/Unsupported.cs +++ b/DiscImageChef.DiscImages/CopyQM/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,18 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadDiskTag(MediaTagType tag) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - - for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); - - return null; - } } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/D88/Unsupported.cs b/DiscImageChef.DiscImages/D88/Unsupported.cs index 452ca1b4e..1f78523bf 100644 --- a/DiscImageChef.DiscImages/D88/Unsupported.cs +++ b/DiscImageChef.DiscImages/D88/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/DART/Unsupported.cs b/DiscImageChef.DiscImages/DART/Unsupported.cs index daf7bc6f0..d9e28e012 100644 --- a/DiscImageChef.DiscImages/DART/Unsupported.cs +++ b/DiscImageChef.DiscImages/DART/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -40,19 +39,5 @@ namespace DiscImageChef.DiscImages { public byte[] ReadDiskTag(MediaTagType tag) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/DIM/Unsupported.cs b/DiscImageChef.DiscImages/DIM/Unsupported.cs index f017ba964..fbde286d8 100644 --- a/DiscImageChef.DiscImages/DIM/Unsupported.cs +++ b/DiscImageChef.DiscImages/DIM/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/DiscFerret/DiscFerret.cs b/DiscImageChef.DiscImages/DiscFerret/DiscFerret.cs index ca5b97250..ba846787a 100644 --- a/DiscImageChef.DiscImages/DiscFerret/DiscFerret.cs +++ b/DiscImageChef.DiscImages/DiscFerret/DiscFerret.cs @@ -37,7 +37,7 @@ using DiscImageChef.CommonTypes.Structs; namespace DiscImageChef.DiscImages { - public partial class DiscFerret : IMediaImage + public partial class DiscFerret : IMediaImage, IVerifiableSectorsImage { ImageInfo imageInfo; // TODO: These variables have been made public so create-sidecar can access to this information until I define an API >4.0 diff --git a/DiscImageChef.DiscImages/DiscFerret/Read.cs b/DiscImageChef.DiscImages/DiscFerret/Read.cs index ed3ce1703..faa708e27 100644 --- a/DiscImageChef.DiscImages/DiscFerret/Read.cs +++ b/DiscImageChef.DiscImages/DiscFerret/Read.cs @@ -132,12 +132,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new NotImplementedException("Flux decoding is not yet implemented."); - - public bool? VerifySector(ulong sectorAddress) => - throw new NotImplementedException("Flux decoding is not yet implemented."); - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) => - throw new NotImplementedException("Flux decoding is not yet implemented."); } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/DiscFerret/Unsupported.cs b/DiscImageChef.DiscImages/DiscFerret/Verify.cs similarity index 69% rename from DiscImageChef.DiscImages/DiscFerret/Unsupported.cs rename to DiscImageChef.DiscImages/DiscFerret/Verify.cs index 21903c34f..2e1fce550 100644 --- a/DiscImageChef.DiscImages/DiscFerret/Unsupported.cs +++ b/DiscImageChef.DiscImages/DiscFerret/Verify.cs @@ -1,15 +1,15 @@ -// /*************************************************************************** +// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // -// Filename : Unsupported.cs +// Filename : Verify.cs // Author(s) : Natalia Portillo // // Component : Disk image plugins. // // --[ Description ] ---------------------------------------------------------- // -// Contains features unsupported by DiscFerret flux images. +// Verifies DiscFerret disk images. // // --[ License ] -------------------------------------------------------------- // @@ -30,13 +30,18 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using DiscImageChef.CommonTypes.Exceptions; +using System; +using System.Collections.Generic; namespace DiscImageChef.DiscImages { public partial class DiscFerret { - public bool? VerifyMediaImage() => - throw new FeatureUnsupportedImageException("Feature not supported by image format"); + public bool? VerifySector(ulong sectorAddress) => + throw new NotImplementedException("Flux decoding is not yet implemented."); + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) => + throw new NotImplementedException("Flux decoding is not yet implemented."); } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj b/DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj index a81b5beb7..6dc7ba929 100644 --- a/DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj +++ b/DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj @@ -66,6 +66,7 @@ + @@ -111,6 +112,7 @@ + @@ -118,11 +120,13 @@ + + @@ -130,7 +134,7 @@ - + @@ -147,6 +151,7 @@ + @@ -158,7 +163,7 @@ - + @@ -198,7 +203,7 @@ - + @@ -215,6 +220,7 @@ + @@ -222,6 +228,7 @@ + @@ -237,6 +244,7 @@ + @@ -260,7 +268,7 @@ - + @@ -282,6 +290,7 @@ + @@ -303,6 +312,7 @@ + @@ -311,6 +321,7 @@ + @@ -357,6 +368,7 @@ + @@ -366,6 +378,7 @@ + @@ -379,6 +392,7 @@ + @@ -443,6 +457,7 @@ + diff --git a/DiscImageChef.DiscImages/DiscImageChef/DiscImageChef.cs b/DiscImageChef.DiscImages/DiscImageChef/DiscImageChef.cs index 6492d63cb..c8f9900fc 100644 --- a/DiscImageChef.DiscImages/DiscImageChef/DiscImageChef.cs +++ b/DiscImageChef.DiscImages/DiscImageChef/DiscImageChef.cs @@ -81,7 +81,7 @@ using SharpCompress.Compressors.LZMA; namespace DiscImageChef.DiscImages { - public partial class DiscImageChef : IWritableOpticalImage + public partial class DiscImageChef : IWritableOpticalImage, IVerifiableImage { bool alreadyWrittenZero; /// Cache of uncompressed blocks. diff --git a/DiscImageChef.DiscImages/DiscJuggler/DiscJuggler.cs b/DiscImageChef.DiscImages/DiscJuggler/DiscJuggler.cs index 957905adc..0be08bec3 100644 --- a/DiscImageChef.DiscImages/DiscJuggler/DiscJuggler.cs +++ b/DiscImageChef.DiscImages/DiscJuggler/DiscJuggler.cs @@ -40,7 +40,7 @@ namespace DiscImageChef.DiscImages { // Support separate data files? Never seen a DiscJuggler image using them anyways... // TODO: Too many unknowns to make this writable - public partial class DiscJuggler : IMediaImage + public partial class DiscJuggler : IOpticalMediaImage { byte[] cdtext; ImageInfo imageInfo; diff --git a/DiscImageChef.DiscImages/DiscJuggler/Read.cs b/DiscImageChef.DiscImages/DiscJuggler/Read.cs index 6b45340e5..60cbfaf93 100644 --- a/DiscImageChef.DiscImages/DiscJuggler/Read.cs +++ b/DiscImageChef.DiscImages/DiscJuggler/Read.cs @@ -35,7 +35,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using DiscImageChef.Checksums; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -1011,79 +1010,5 @@ namespace DiscImageChef.DiscImages { return Tracks.Where(track => track.TrackSession == session).ToList(); } - - public bool? VerifySector(ulong sectorAddress) - { - byte[] buffer = ReadSectorLong(sectorAddress); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySector(ulong sectorAddress, uint track) - { - byte[] buffer = ReadSectorLong(sectorAddress, track); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length, track); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/DiscJuggler/Verify.cs b/DiscImageChef.DiscImages/DiscJuggler/Verify.cs new file mode 100644 index 000000000..e19496d95 --- /dev/null +++ b/DiscImageChef.DiscImages/DiscJuggler/Verify.cs @@ -0,0 +1,113 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies DiscJuggler disc images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using DiscImageChef.Checksums; + +namespace DiscImageChef.DiscImages +{ + public partial class DiscJuggler + { + public bool? VerifySector(ulong sectorAddress) + { + byte[] buffer = ReadSectorLong(sectorAddress); + return CdChecksums.CheckCdSector(buffer); + } + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length, track); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySector(ulong sectorAddress, uint track) + { + byte[] buffer = ReadSectorLong(sectorAddress, track); + return CdChecksums.CheckCdSector(buffer); + } + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/DiskCopy42/DiskCopy42.cs b/DiscImageChef.DiscImages/DiskCopy42/DiskCopy42.cs index 2e3f13986..d2722b3aa 100644 --- a/DiscImageChef.DiscImages/DiskCopy42/DiskCopy42.cs +++ b/DiscImageChef.DiscImages/DiskCopy42/DiskCopy42.cs @@ -41,7 +41,7 @@ namespace DiscImageChef.DiscImages { // Checked using several images and strings inside Apple's DiskImages.framework [SuppressMessage("ReSharper", "InconsistentNaming")] - public partial class DiskCopy42 : IWritableImage + public partial class DiskCopy42 : IWritableImage, IVerifiableImage { /// Bytes per tag, should be 12 uint bptag; diff --git a/DiscImageChef.DiscImages/DiskCopy42/Read.cs b/DiscImageChef.DiscImages/DiskCopy42/Read.cs index 9d3353e5e..e1c8c6fb4 100644 --- a/DiscImageChef.DiscImages/DiskCopy42/Read.cs +++ b/DiscImageChef.DiscImages/DiskCopy42/Read.cs @@ -391,37 +391,6 @@ namespace DiscImageChef.DiscImages return true; } - public bool? VerifyMediaImage() - { - byte[] data = new byte[header.DataSize]; - byte[] tags = new byte[header.TagSize]; - uint tagsChk = 0; - - DicConsole.DebugWriteLine("DC42 plugin", "Reading data"); - Stream datastream = dc42ImageFilter.GetDataForkStream(); - datastream.Seek(dataOffset, SeekOrigin.Begin); - datastream.Read(data, 0, (int)header.DataSize); - - DicConsole.DebugWriteLine("DC42 plugin", "Calculating data checksum"); - uint dataChk = DC42CheckSum(data); - DicConsole.DebugWriteLine("DC42 plugin", "Calculated data checksum = 0x{0:X8}", dataChk); - DicConsole.DebugWriteLine("DC42 plugin", "Stored data checksum = 0x{0:X8}", header.DataChecksum); - - if(header.TagSize <= 0) return dataChk == header.DataChecksum && tagsChk == header.TagChecksum; - - DicConsole.DebugWriteLine("DC42 plugin", "Reading tags"); - Stream tagstream = dc42ImageFilter.GetDataForkStream(); - tagstream.Seek(tagOffset, SeekOrigin.Begin); - tagstream.Read(tags, 0, (int)header.TagSize); - - DicConsole.DebugWriteLine("DC42 plugin", "Calculating tag checksum"); - tagsChk = DC42CheckSum(tags); - DicConsole.DebugWriteLine("DC42 plugin", "Calculated tag checksum = 0x{0:X8}", tagsChk); - DicConsole.DebugWriteLine("DC42 plugin", "Stored tag checksum = 0x{0:X8}", header.TagChecksum); - - return dataChk == header.DataChecksum && tagsChk == header.TagChecksum; - } - public byte[] ReadSector(ulong sectorAddress) => ReadSectors(sectorAddress, 1); public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) => ReadSectorsTag(sectorAddress, 1, tag); diff --git a/DiscImageChef.DiscImages/DiskCopy42/Unsupported.cs b/DiscImageChef.DiscImages/DiskCopy42/Unsupported.cs index b07cf39dc..9fc999c79 100644 --- a/DiscImageChef.DiscImages/DiskCopy42/Unsupported.cs +++ b/DiscImageChef.DiscImages/DiskCopy42/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -38,19 +37,6 @@ namespace DiscImageChef.DiscImages { public partial class DiskCopy42 { - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - - for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); - - return null; - } - public byte[] ReadDiskTag(MediaTagType tag) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); } diff --git a/DiscImageChef.DiscImages/DiskCopy42/Verify.cs b/DiscImageChef.DiscImages/DiskCopy42/Verify.cs new file mode 100644 index 000000000..87c884de9 --- /dev/null +++ b/DiscImageChef.DiscImages/DiskCopy42/Verify.cs @@ -0,0 +1,71 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies Apple DiskCopy 4.2 disk images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System.IO; +using DiscImageChef.Console; + +namespace DiscImageChef.DiscImages +{ + public partial class DiskCopy42 + { + public bool? VerifyMediaImage() + { + byte[] data = new byte[header.DataSize]; + byte[] tags = new byte[header.TagSize]; + uint tagsChk = 0; + + DicConsole.DebugWriteLine("DC42 plugin", "Reading data"); + Stream datastream = dc42ImageFilter.GetDataForkStream(); + datastream.Seek(dataOffset, SeekOrigin.Begin); + datastream.Read(data, 0, (int)header.DataSize); + + DicConsole.DebugWriteLine("DC42 plugin", "Calculating data checksum"); + uint dataChk = DC42CheckSum(data); + DicConsole.DebugWriteLine("DC42 plugin", "Calculated data checksum = 0x{0:X8}", dataChk); + DicConsole.DebugWriteLine("DC42 plugin", "Stored data checksum = 0x{0:X8}", header.DataChecksum); + + if(header.TagSize <= 0) return dataChk == header.DataChecksum && tagsChk == header.TagChecksum; + + DicConsole.DebugWriteLine("DC42 plugin", "Reading tags"); + Stream tagstream = dc42ImageFilter.GetDataForkStream(); + tagstream.Seek(tagOffset, SeekOrigin.Begin); + tagstream.Read(tags, 0, (int)header.TagSize); + + DicConsole.DebugWriteLine("DC42 plugin", "Calculating tag checksum"); + tagsChk = DC42CheckSum(tags); + DicConsole.DebugWriteLine("DC42 plugin", "Calculated tag checksum = 0x{0:X8}", tagsChk); + DicConsole.DebugWriteLine("DC42 plugin", "Stored tag checksum = 0x{0:X8}", header.TagChecksum); + + return dataChk == header.DataChecksum && tagsChk == header.TagChecksum; + } + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/DriDiskCopy/Unsupported.cs b/DiscImageChef.DiscImages/DriDiskCopy/Unsupported.cs index 01a83280a..a04e68bc8 100644 --- a/DiscImageChef.DiscImages/DriDiskCopy/Unsupported.cs +++ b/DiscImageChef.DiscImages/DriDiskCopy/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,20 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadDiskTag(MediaTagType tag) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - - for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/GDI/Read.cs b/DiscImageChef.DiscImages/GDI/Read.cs index 0e5496ace..91166e8ee 100644 --- a/DiscImageChef.DiscImages/GDI/Read.cs +++ b/DiscImageChef.DiscImages/GDI/Read.cs @@ -35,7 +35,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; -using DiscImageChef.Checksums; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -759,79 +758,5 @@ namespace DiscImageChef.DiscImages return tracks; } - - public bool? VerifySector(ulong sectorAddress) - { - byte[] buffer = ReadSectorLong(sectorAddress); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySector(ulong sectorAddress, uint track) - { - byte[] buffer = ReadSectorLong(sectorAddress, track); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length, track); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/GDI/Verify.cs b/DiscImageChef.DiscImages/GDI/Verify.cs new file mode 100644 index 000000000..c6154db94 --- /dev/null +++ b/DiscImageChef.DiscImages/GDI/Verify.cs @@ -0,0 +1,113 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies Dreamcast GDI disc images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using DiscImageChef.Checksums; + +namespace DiscImageChef.DiscImages +{ + public partial class Gdi + { + public bool? VerifySector(ulong sectorAddress) + { + byte[] buffer = ReadSectorLong(sectorAddress); + return CdChecksums.CheckCdSector(buffer); + } + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length, track); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySector(ulong sectorAddress, uint track) + { + byte[] buffer = ReadSectorLong(sectorAddress, track); + return CdChecksums.CheckCdSector(buffer); + } + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/HDCopy/Unsupported.cs b/DiscImageChef.DiscImages/HDCopy/Unsupported.cs index 4500ec1c0..0eeb3abdd 100644 --- a/DiscImageChef.DiscImages/HDCopy/Unsupported.cs +++ b/DiscImageChef.DiscImages/HDCopy/Unsupported.cs @@ -31,7 +31,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -53,19 +52,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/IMD/Unsupported.cs b/DiscImageChef.DiscImages/IMD/Unsupported.cs index ca652d0c1..fa599b13a 100644 --- a/DiscImageChef.DiscImages/IMD/Unsupported.cs +++ b/DiscImageChef.DiscImages/IMD/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,20 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadDiskTag(MediaTagType tag) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - - for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/KryoFlux/KryoFlux.cs b/DiscImageChef.DiscImages/KryoFlux/KryoFlux.cs index d50852a65..57d5daca3 100644 --- a/DiscImageChef.DiscImages/KryoFlux/KryoFlux.cs +++ b/DiscImageChef.DiscImages/KryoFlux/KryoFlux.cs @@ -39,7 +39,7 @@ using DiscImageChef.CommonTypes.Structs; namespace DiscImageChef.DiscImages { [SuppressMessage("ReSharper", "InconsistentNaming")] - public partial class KryoFlux : IMediaImage + public partial class KryoFlux : IMediaImage, IVerifiableSectorsImage { // TODO: These variables have been made public so create-sidecar can access to this information until I define an API >4.0 public SortedDictionary tracks; diff --git a/DiscImageChef.DiscImages/KryoFlux/Read.cs b/DiscImageChef.DiscImages/KryoFlux/Read.cs index a83e7e0aa..7c21b5cba 100644 --- a/DiscImageChef.DiscImages/KryoFlux/Read.cs +++ b/DiscImageChef.DiscImages/KryoFlux/Read.cs @@ -254,12 +254,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new NotImplementedException("Flux decoding is not yet implemented."); - - public bool? VerifySector(ulong sectorAddress) => - throw new NotImplementedException("Flux decoding is not yet implemented."); - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) => - throw new NotImplementedException("Flux decoding is not yet implemented."); } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/KryoFlux/Verify.cs b/DiscImageChef.DiscImages/KryoFlux/Verify.cs new file mode 100644 index 000000000..4fcf08999 --- /dev/null +++ b/DiscImageChef.DiscImages/KryoFlux/Verify.cs @@ -0,0 +1,47 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies KryoFlux STREAM images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; + +namespace DiscImageChef.DiscImages +{ + public partial class KryoFlux + { + public bool? VerifySector(ulong sectorAddress) => + throw new NotImplementedException("Flux decoding is not yet implemented."); + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) => + throw new NotImplementedException("Flux decoding is not yet implemented."); + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/MaxiDisk/Unsupported.cs b/DiscImageChef.DiscImages/MaxiDisk/Unsupported.cs index 9bd79b7af..e597a3455 100644 --- a/DiscImageChef.DiscImages/MaxiDisk/Unsupported.cs +++ b/DiscImageChef.DiscImages/MaxiDisk/Unsupported.cs @@ -30,10 +30,8 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; -using DiscImageChef.CommonTypes.Structs; namespace DiscImageChef.DiscImages { @@ -53,26 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadDiskTag(MediaTagType tag) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - - for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; - - public List GetSessionTracks(Session session) => - throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public List GetSessionTracks(ushort session) => - throw new FeatureUnsupportedImageException("Feature not supported by image format"); } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/NDIF/Unsupported.cs b/DiscImageChef.DiscImages/NDIF/Unsupported.cs index 0e3a3402e..8e0b197a7 100644 --- a/DiscImageChef.DiscImages/NDIF/Unsupported.cs +++ b/DiscImageChef.DiscImages/NDIF/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/NHDr0/Unsupported.cs b/DiscImageChef.DiscImages/NHDr0/Unsupported.cs index d7b49418a..71353bbaf 100644 --- a/DiscImageChef.DiscImages/NHDr0/Unsupported.cs +++ b/DiscImageChef.DiscImages/NHDr0/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/Nero/Read.cs b/DiscImageChef.DiscImages/Nero/Read.cs index 53c401369..1065d37f0 100644 --- a/DiscImageChef.DiscImages/Nero/Read.cs +++ b/DiscImageChef.DiscImages/Nero/Read.cs @@ -35,7 +35,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using DiscImageChef.Checksums; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -1373,79 +1372,5 @@ namespace DiscImageChef.DiscImages { return Tracks.Where(track => track.TrackSession == session).ToList(); } - - public bool? VerifySector(ulong sectorAddress) - { - byte[] buffer = ReadSectorLong(sectorAddress); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySector(ulong sectorAddress, uint track) - { - byte[] buffer = ReadSectorLong(sectorAddress, track); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, - out List unknownLbas) - { - byte[] buffer = ReadSectorsLong(sectorAddress, length, track); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/Nero/Verify.cs b/DiscImageChef.DiscImages/Nero/Verify.cs new file mode 100644 index 000000000..bada5837e --- /dev/null +++ b/DiscImageChef.DiscImages/Nero/Verify.cs @@ -0,0 +1,113 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies Nero Burning ROM disc images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using DiscImageChef.Checksums; + +namespace DiscImageChef.DiscImages +{ + public partial class Nero + { + public bool? VerifySector(ulong sectorAddress) + { + byte[] buffer = ReadSectorLong(sectorAddress); + return CdChecksums.CheckCdSector(buffer); + } + + public bool? VerifySector(ulong sectorAddress, uint track) + { + byte[] buffer = ReadSectorLong(sectorAddress, track); + return CdChecksums.CheckCdSector(buffer); + } + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, + out List unknownLbas) + { + byte[] buffer = ReadSectorsLong(sectorAddress, length, track); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/Parallels/Unsupported.cs b/DiscImageChef.DiscImages/Parallels/Unsupported.cs index 1b4ff8887..421a84027 100644 --- a/DiscImageChef.DiscImages/Parallels/Unsupported.cs +++ b/DiscImageChef.DiscImages/Parallels/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/PartClone/PartClone.cs b/DiscImageChef.DiscImages/PartClone/PartClone.cs index 3f8f0734d..0cd941a32 100644 --- a/DiscImageChef.DiscImages/PartClone/PartClone.cs +++ b/DiscImageChef.DiscImages/PartClone/PartClone.cs @@ -39,7 +39,7 @@ using DiscImageChef.CommonTypes.Structs; namespace DiscImageChef.DiscImages { - public partial class PartClone : IMediaImage + public partial class PartClone : IMediaImage, IVerifiableImage { // The used block "bitmap" uses one byte per block // TODO: Convert on-image bytemap to on-memory bitmap diff --git a/DiscImageChef.DiscImages/PartClone/Unsupported.cs b/DiscImageChef.DiscImages/PartClone/Unsupported.cs index d3e145541..e09ccd783 100644 --- a/DiscImageChef.DiscImages/PartClone/Unsupported.cs +++ b/DiscImageChef.DiscImages/PartClone/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,20 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - // TODO: All blocks contain a CRC32 that's incompatible with current implementation. Need to check for compatibility. - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/CDRDAO/Unsupported.cs b/DiscImageChef.DiscImages/PartClone/Verify.cs similarity index 81% rename from DiscImageChef.DiscImages/CDRDAO/Unsupported.cs rename to DiscImageChef.DiscImages/PartClone/Verify.cs index c39fe2bcd..cc4cef12c 100644 --- a/DiscImageChef.DiscImages/CDRDAO/Unsupported.cs +++ b/DiscImageChef.DiscImages/PartClone/Verify.cs @@ -1,15 +1,15 @@ -// /*************************************************************************** +// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // -// Filename : Unsupported.cs +// Filename : Verify.cs // Author(s) : Natalia Portillo // // Component : Disk image plugins. // // --[ Description ] ---------------------------------------------------------- // -// Contains features unsupported by cdrdao cuesheets (toc/bin). +// Verifies partclone disc images. // // --[ License ] -------------------------------------------------------------- // @@ -32,8 +32,9 @@ namespace DiscImageChef.DiscImages { - public partial class Cdrdao + public partial class PartClone { + // TODO: All blocks contain a CRC32 that's incompatible with current implementation. Need to check for compatibility. public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/Partimage/Partimage.cs b/DiscImageChef.DiscImages/Partimage/Partimage.cs index a9424b717..152df7850 100644 --- a/DiscImageChef.DiscImages/Partimage/Partimage.cs +++ b/DiscImageChef.DiscImages/Partimage/Partimage.cs @@ -41,7 +41,7 @@ using DiscImageChef.CommonTypes.Structs; namespace DiscImageChef.DiscImages { - public partial class Partimage : IMediaImage + public partial class Partimage : IMediaImage, IVerifiableImage { byte[] bitmap; PartimageMainHeader cMainHeader; diff --git a/DiscImageChef.DiscImages/Partimage/Unsupported.cs b/DiscImageChef.DiscImages/Partimage/Unsupported.cs index 60263adca..e07026642 100644 --- a/DiscImageChef.DiscImages/Partimage/Unsupported.cs +++ b/DiscImageChef.DiscImages/Partimage/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,20 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - // TODO: All blocks contain a CRC32 that's incompatible with current implementation. Need to check for compatibility. - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/KryoFlux/Unsupported.cs b/DiscImageChef.DiscImages/Partimage/Verify.cs similarity index 77% rename from DiscImageChef.DiscImages/KryoFlux/Unsupported.cs rename to DiscImageChef.DiscImages/Partimage/Verify.cs index 1937696cd..ee92f5177 100644 --- a/DiscImageChef.DiscImages/KryoFlux/Unsupported.cs +++ b/DiscImageChef.DiscImages/Partimage/Verify.cs @@ -1,15 +1,15 @@ -// /*************************************************************************** +// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // -// Filename : Unsupported.cs +// Filename : Verify.cs // Author(s) : Natalia Portillo // // Component : Disk image plugins. // // --[ Description ] ---------------------------------------------------------- // -// Contains features unsupported by KryoFlux STREAM images. +// Verifies partimage disk images. // // --[ License ] -------------------------------------------------------------- // @@ -30,13 +30,11 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using DiscImageChef.CommonTypes.Exceptions; - namespace DiscImageChef.DiscImages { - public partial class KryoFlux + public partial class Partimage { - public bool? VerifyMediaImage() => - throw new FeatureUnsupportedImageException("Feature not supported by image format"); + // TODO: All blocks contain a CRC32 that's incompatible with current implementation. Need to check for compatibility. + public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/QCOW/Unsupported.cs b/DiscImageChef.DiscImages/QCOW/Unsupported.cs index d086c3f7e..8e90cf201 100644 --- a/DiscImageChef.DiscImages/QCOW/Unsupported.cs +++ b/DiscImageChef.DiscImages/QCOW/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/QCOW2/Unsupported.cs b/DiscImageChef.DiscImages/QCOW2/Unsupported.cs index 4a6c91001..e9a50c9b7 100644 --- a/DiscImageChef.DiscImages/QCOW2/Unsupported.cs +++ b/DiscImageChef.DiscImages/QCOW2/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/QED/Unsupported.cs b/DiscImageChef.DiscImages/QED/Unsupported.cs index e8da84bbf..90c3ebe13 100644 --- a/DiscImageChef.DiscImages/QED/Unsupported.cs +++ b/DiscImageChef.DiscImages/QED/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/RayDIM/Unsupported.cs b/DiscImageChef.DiscImages/RayDIM/Unsupported.cs index a9afb9b1e..dbfa1f030 100644 --- a/DiscImageChef.DiscImages/RayDIM/Unsupported.cs +++ b/DiscImageChef.DiscImages/RayDIM/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -38,21 +37,6 @@ namespace DiscImageChef.DiscImages { public partial class RayDim { - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - - for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; - public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); diff --git a/DiscImageChef.DiscImages/RsIde/Unsupported.cs b/DiscImageChef.DiscImages/RsIde/Unsupported.cs index bddf8a432..243cf80e7 100644 --- a/DiscImageChef.DiscImages/RsIde/Unsupported.cs +++ b/DiscImageChef.DiscImages/RsIde/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -49,19 +48,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/SaveDskF/Read.cs b/DiscImageChef.DiscImages/SaveDskF/Read.cs index ff9527a2e..356f0ae5e 100644 --- a/DiscImageChef.DiscImages/SaveDskF/Read.cs +++ b/DiscImageChef.DiscImages/SaveDskF/Read.cs @@ -108,7 +108,7 @@ namespace DiscImageChef.DiscImages imageInfo.SectorSize = header.sectorSize; imageInfo.MediaType = Geometry.GetMediaType((header.cylinders, (byte)header.heads, header.sectorsPerTrack, - header.sectorSize, MediaEncoding.MFM, false)); + header.sectorSize, MediaEncoding.MFM, false)); imageInfo.XmlMediaType = XmlMediaType.BlockMedia; @@ -133,8 +133,6 @@ namespace DiscImageChef.DiscImages return true; } - public bool? VerifyMediaImage() => calculatedChk == header.checksum; - public byte[] ReadSector(ulong sectorAddress) => ReadSectors(sectorAddress, 1); public byte[] ReadSectors(ulong sectorAddress, uint length) diff --git a/DiscImageChef.DiscImages/SaveDskF/SaveDskF.cs b/DiscImageChef.DiscImages/SaveDskF/SaveDskF.cs index 288f3611e..df364651c 100644 --- a/DiscImageChef.DiscImages/SaveDskF/SaveDskF.cs +++ b/DiscImageChef.DiscImages/SaveDskF/SaveDskF.cs @@ -38,7 +38,7 @@ using DiscImageChef.CommonTypes.Structs; namespace DiscImageChef.DiscImages { - public partial class SaveDskF : IWritableImage + public partial class SaveDskF : IWritableImage, IVerifiableImage { uint calculatedChk; byte[] decodedDisk; diff --git a/DiscImageChef.DiscImages/SaveDskF/Unsupported.cs b/DiscImageChef.DiscImages/SaveDskF/Unsupported.cs index bf7799bba..d14c350ca 100644 --- a/DiscImageChef.DiscImages/SaveDskF/Unsupported.cs +++ b/DiscImageChef.DiscImages/SaveDskF/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -38,19 +37,6 @@ namespace DiscImageChef.DiscImages { public partial class SaveDskF { - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - - for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); - - return null; - } - public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); diff --git a/DiscImageChef.DiscImages/CloneCD/Unsupported.cs b/DiscImageChef.DiscImages/SaveDskF/Verify.cs similarity index 83% rename from DiscImageChef.DiscImages/CloneCD/Unsupported.cs rename to DiscImageChef.DiscImages/SaveDskF/Verify.cs index d5071a415..7348449c3 100644 --- a/DiscImageChef.DiscImages/CloneCD/Unsupported.cs +++ b/DiscImageChef.DiscImages/SaveDskF/Verify.cs @@ -1,15 +1,15 @@ -// /*************************************************************************** +// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // -// Filename : Unsupported.cs +// Filename : Verify.cs // Author(s) : Natalia Portillo // // Component : Disk image plugins. // // --[ Description ] ---------------------------------------------------------- // -// Contains features unsupported by CloneCD disc images. +// Verifies IBM SaveDskF disk images. // // --[ License ] -------------------------------------------------------------- // @@ -32,8 +32,8 @@ namespace DiscImageChef.DiscImages { - public partial class CloneCd + public partial class SaveDskF { - public bool? VerifyMediaImage() => null; + public bool? VerifyMediaImage() => calculatedChk == header.checksum; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/SuperCardPro/Read.cs b/DiscImageChef.DiscImages/SuperCardPro/Read.cs index 0ea70b225..d647919ad 100644 --- a/DiscImageChef.DiscImages/SuperCardPro/Read.cs +++ b/DiscImageChef.DiscImages/SuperCardPro/Read.cs @@ -247,27 +247,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new NotImplementedException("Flux decoding is not yet implemented."); - - public bool? VerifySector(ulong sectorAddress) => - throw new NotImplementedException("Flux decoding is not yet implemented."); - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) => - throw new NotImplementedException("Flux decoding is not yet implemented."); - - public bool? VerifyMediaImage() - { - if(Header.flags.HasFlag(ScpFlags.Writable)) return null; - - byte[] wholeFile = new byte[scpStream.Length]; - uint sum = 0; - - scpStream.Position = 0; - scpStream.Read(wholeFile, 0, wholeFile.Length); - - for(int i = 0x10; i < wholeFile.Length; i++) sum += wholeFile[i]; - - return Header.checksum == sum; - } } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/SuperCardPro/SuperCardPro.cs b/DiscImageChef.DiscImages/SuperCardPro/SuperCardPro.cs index 8570dc5fc..1456dcbd7 100644 --- a/DiscImageChef.DiscImages/SuperCardPro/SuperCardPro.cs +++ b/DiscImageChef.DiscImages/SuperCardPro/SuperCardPro.cs @@ -38,7 +38,7 @@ using DiscImageChef.CommonTypes.Structs; namespace DiscImageChef.DiscImages { - public partial class SuperCardPro : IMediaImage + public partial class SuperCardPro : IMediaImage, IVerifiableImage, IVerifiableSectorsImage { // TODO: These variables have been made public so create-sidecar can access to this information until I define an API >4.0 public ScpHeader Header; diff --git a/DiscImageChef.DiscImages/SuperCardPro/Verify.cs b/DiscImageChef.DiscImages/SuperCardPro/Verify.cs new file mode 100644 index 000000000..32fb4b52b --- /dev/null +++ b/DiscImageChef.DiscImages/SuperCardPro/Verify.cs @@ -0,0 +1,62 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies SuperCardPro flux images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; + +namespace DiscImageChef.DiscImages +{ + public partial class SuperCardPro + { + public bool? VerifyMediaImage() + { + if(Header.flags.HasFlag(ScpFlags.Writable)) return null; + + byte[] wholeFile = new byte[scpStream.Length]; + uint sum = 0; + + scpStream.Position = 0; + scpStream.Read(wholeFile, 0, wholeFile.Length); + + for(int i = 0x10; i < wholeFile.Length; i++) sum += wholeFile[i]; + + return Header.checksum == sum; + } + + public bool? VerifySector(ulong sectorAddress) => + throw new NotImplementedException("Flux decoding is not yet implemented."); + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) => + throw new NotImplementedException("Flux decoding is not yet implemented."); + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/T98/Unsupported.cs b/DiscImageChef.DiscImages/T98/Unsupported.cs index c3510daf1..348fe0eb6 100644 --- a/DiscImageChef.DiscImages/T98/Unsupported.cs +++ b/DiscImageChef.DiscImages/T98/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/TeleDisk/Read.cs b/DiscImageChef.DiscImages/TeleDisk/Read.cs index 7f5351831..df452b263 100644 --- a/DiscImageChef.DiscImages/TeleDisk/Read.cs +++ b/DiscImageChef.DiscImages/TeleDisk/Read.cs @@ -31,7 +31,6 @@ // ****************************************************************************/ using System; -using System.Collections.Generic; using System.IO; using System.Text; using DiscImageChef.CommonTypes.Enums; @@ -523,23 +522,6 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => ReadSectors(sectorAddress, length); - public bool? VerifySector(ulong sectorAddress) => !sectorsWhereCrcHasFailed.Contains(sectorAddress); - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - - for(ulong i = sectorAddress; i < sectorAddress + length; i++) - if(sectorsWhereCrcHasFailed.Contains(sectorAddress)) - failingLbas.Add(sectorAddress); - - return failingLbas.Count <= 0; - } - - public bool? VerifyMediaImage() => aDiskCrcHasFailed; - public byte[] ReadDiskTag(MediaTagType tag) { if(tag != MediaTagType.Floppy_LeadOut) diff --git a/DiscImageChef.DiscImages/TeleDisk/TeleDisk.cs b/DiscImageChef.DiscImages/TeleDisk/TeleDisk.cs index b5e1a8301..bb3484003 100644 --- a/DiscImageChef.DiscImages/TeleDisk/TeleDisk.cs +++ b/DiscImageChef.DiscImages/TeleDisk/TeleDisk.cs @@ -40,7 +40,7 @@ namespace DiscImageChef.DiscImages { // Created following notes from Dave Dunfield // http://www.classiccmp.org/dunfield/img54306/td0notes.txt - public partial class TeleDisk : IMediaImage + public partial class TeleDisk : IMediaImage, IVerifiableImage, IVerifiableSectorsImage { bool aDiskCrcHasFailed; byte[] commentBlock; diff --git a/DiscImageChef.DiscImages/TeleDisk/Verify.cs b/DiscImageChef.DiscImages/TeleDisk/Verify.cs new file mode 100644 index 000000000..e3dc16aee --- /dev/null +++ b/DiscImageChef.DiscImages/TeleDisk/Verify.cs @@ -0,0 +1,56 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies Sydex TeleDisk disk images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System.Collections.Generic; + +namespace DiscImageChef.DiscImages +{ + public partial class TeleDisk + { + public bool? VerifyMediaImage() => aDiskCrcHasFailed; + + public bool? VerifySector(ulong sectorAddress) => !sectorsWhereCrcHasFailed.Contains(sectorAddress); + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) + { + failingLbas = new List(); + unknownLbas = new List(); + + for(ulong i = sectorAddress; i < sectorAddress + length; i++) + if(sectorsWhereCrcHasFailed.Contains(sectorAddress)) + failingLbas.Add(sectorAddress); + + return failingLbas.Count <= 0; + } + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/UDIF/Unsupported.cs b/DiscImageChef.DiscImages/UDIF/Unsupported.cs index 397d9c727..ea73bd436 100644 --- a/DiscImageChef.DiscImages/UDIF/Unsupported.cs +++ b/DiscImageChef.DiscImages/UDIF/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/UkvFdi/Unsupported.cs b/DiscImageChef.DiscImages/UkvFdi/Unsupported.cs index 072de8214..715e6a33f 100644 --- a/DiscImageChef.DiscImages/UkvFdi/Unsupported.cs +++ b/DiscImageChef.DiscImages/UkvFdi/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/VDI/Unsupported.cs b/DiscImageChef.DiscImages/VDI/Unsupported.cs index bf986e44c..a806a26bc 100644 --- a/DiscImageChef.DiscImages/VDI/Unsupported.cs +++ b/DiscImageChef.DiscImages/VDI/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/VHD/Unsupported.cs b/DiscImageChef.DiscImages/VHD/Unsupported.cs index e8a63aeb6..16a37385a 100644 --- a/DiscImageChef.DiscImages/VHD/Unsupported.cs +++ b/DiscImageChef.DiscImages/VHD/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/VHDX/Unsupported.cs b/DiscImageChef.DiscImages/VHDX/Unsupported.cs index d1aea5311..9db371178 100644 --- a/DiscImageChef.DiscImages/VHDX/Unsupported.cs +++ b/DiscImageChef.DiscImages/VHDX/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/VMware/Unsupported.cs b/DiscImageChef.DiscImages/VMware/Unsupported.cs index 0ba52fed0..43e6e1e63 100644 --- a/DiscImageChef.DiscImages/VMware/Unsupported.cs +++ b/DiscImageChef.DiscImages/VMware/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/Virtual98/Unsupported.cs b/DiscImageChef.DiscImages/Virtual98/Unsupported.cs index 3c43a48bb..0ec6dada2 100644 --- a/DiscImageChef.DiscImages/Virtual98/Unsupported.cs +++ b/DiscImageChef.DiscImages/Virtual98/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/WCDiskImage/Unsupported.cs b/DiscImageChef.DiscImages/WCDiskImage/Unsupported.cs index 5b2b43748..d02084a3f 100644 --- a/DiscImageChef.DiscImages/WCDiskImage/Unsupported.cs +++ b/DiscImageChef.DiscImages/WCDiskImage/Unsupported.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System.Collections.Generic; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -52,19 +51,5 @@ namespace DiscImageChef.DiscImages public byte[] ReadSectorsLong(ulong sectorAddress, uint length) => throw new FeatureUnsupportedImageException("Feature not supported by image format"); - - public bool? VerifySector(ulong sectorAddress) => null; - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - failingLbas = new List(); - unknownLbas = new List(); - for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i); - - return null; - } - - public bool? VerifyMediaImage() => null; } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/ZZZRawImage/Read.cs b/DiscImageChef.DiscImages/ZZZRawImage/Read.cs index cc9dc6914..c4310d806 100644 --- a/DiscImageChef.DiscImages/ZZZRawImage/Read.cs +++ b/DiscImageChef.DiscImages/ZZZRawImage/Read.cs @@ -35,7 +35,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml.Serialization; -using DiscImageChef.Checksums; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Exceptions; @@ -1013,104 +1012,6 @@ namespace DiscImageChef.DiscImages return buffer; } - public bool? VerifySector(ulong sectorAddress) - { - if(!rawCompactDisc) return null; - - byte[] buffer = ReadSectorLong(sectorAddress); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySector(ulong sectorAddress, uint track) - { - if(!rawCompactDisc) return null; - - byte[] buffer = ReadSectorLong(sectorAddress, track); - return CdChecksums.CheckCdSector(buffer); - } - - public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, - out List unknownLbas) - { - if(!rawCompactDisc) - { - failingLbas = new List(); - unknownLbas = new List(); - - for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); - - return null; - } - - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, - out List unknownLbas) - { - if(!rawCompactDisc) - { - failingLbas = new List(); - unknownLbas = new List(); - - for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); - - return null; - } - - byte[] buffer = ReadSectorsLong(sectorAddress, length, track); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; - failingLbas = new List(); - unknownLbas = new List(); - - for(int i = 0; i < length; i++) - { - Array.Copy(buffer, i * bps, sector, 0, bps); - bool? sectorStatus = CdChecksums.CheckCdSector(sector); - - switch(sectorStatus) - { - case null: - unknownLbas.Add((ulong)i + sectorAddress); - break; - case false: - failingLbas.Add((ulong)i + sectorAddress); - break; - } - } - - if(unknownLbas.Count > 0) return null; - - return failingLbas.Count <= 0; - } - - public bool? VerifyMediaImage() => null; - public List GetSessionTracks(Session session) { if(imageInfo.XmlMediaType != XmlMediaType.OpticalDisc) diff --git a/DiscImageChef.DiscImages/ZZZRawImage/Verify.cs b/DiscImageChef.DiscImages/ZZZRawImage/Verify.cs new file mode 100644 index 000000000..a27d32b13 --- /dev/null +++ b/DiscImageChef.DiscImages/ZZZRawImage/Verify.cs @@ -0,0 +1,137 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Verify.cs +// Author(s) : Natalia Portillo +// +// Component : Disk image plugins. +// +// --[ Description ] ---------------------------------------------------------- +// +// Verifies raw image, that is, user data sector by sector copy. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using DiscImageChef.Checksums; + +namespace DiscImageChef.DiscImages +{ + public partial class ZZZRawImage + { + public bool? VerifySector(ulong sectorAddress) + { + if(!rawCompactDisc) return null; + + byte[] buffer = ReadSectorLong(sectorAddress); + return CdChecksums.CheckCdSector(buffer); + } + + public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, + out List unknownLbas) + { + if(!rawCompactDisc) + { + failingLbas = new List(); + unknownLbas = new List(); + + for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); + + return null; + } + + byte[] buffer = ReadSectorsLong(sectorAddress, length); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List failingLbas, + out List unknownLbas) + { + if(!rawCompactDisc) + { + failingLbas = new List(); + unknownLbas = new List(); + + for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i); + + return null; + } + + byte[] buffer = ReadSectorsLong(sectorAddress, length, track); + int bps = (int)(buffer.Length / length); + byte[] sector = new byte[bps]; + failingLbas = new List(); + unknownLbas = new List(); + + for(int i = 0; i < length; i++) + { + Array.Copy(buffer, i * bps, sector, 0, bps); + bool? sectorStatus = CdChecksums.CheckCdSector(sector); + + switch(sectorStatus) + { + case null: + unknownLbas.Add((ulong)i + sectorAddress); + break; + case false: + failingLbas.Add((ulong)i + sectorAddress); + break; + } + } + + if(unknownLbas.Count > 0) return null; + + return failingLbas.Count <= 0; + } + + public bool? VerifySector(ulong sectorAddress, uint track) + { + if(!rawCompactDisc) return null; + + byte[] buffer = ReadSectorLong(sectorAddress, track); + return CdChecksums.CheckCdSector(buffer); + } + } +} \ No newline at end of file diff --git a/DiscImageChef.Gui/Forms/frmImageVerify.xeto.cs b/DiscImageChef.Gui/Forms/frmImageVerify.xeto.cs index f63d8c122..5942f4112 100644 --- a/DiscImageChef.Gui/Forms/frmImageVerify.xeto.cs +++ b/DiscImageChef.Gui/Forms/frmImageVerify.xeto.cs @@ -64,6 +64,11 @@ namespace DiscImageChef.Gui.Forms stkProgress.Visible = true; lblProgress2.Visible = false; + chkVerifySectors.Visible = inputFormat as IOpticalMediaImage != null || + inputFormat as IVerifiableSectorsImage != null; + + // TODO: Do not offer the option to use this form if the image does not support any kind of verification + new Thread(DoWork).Start(); } @@ -76,7 +81,8 @@ namespace DiscImageChef.Gui.Forms long unknownSectors = 0; bool formatHasTracks; - IOpticalMediaImage inputOptical = inputFormat as IOpticalMediaImage; + IOpticalMediaImage inputOptical = inputFormat as IOpticalMediaImage; + IVerifiableSectorsImage verifiableSectorsImage = inputFormat as IVerifiableSectorsImage; try { formatHasTracks = inputOptical?.Tracks?.Count > 0; } catch { formatHasTracks = false; } @@ -110,46 +116,56 @@ namespace DiscImageChef.Gui.Forms if(chkVerifyImage.Checked == true) { - Application.Instance.Invoke(() => - { - lblProgress.Text = "Checking media image..."; - if(chkVerifySectors.Checked == true) prgProgress.Value = 1; - else prgProgress.Indeterminate = true; - - prgProgress2.Indeterminate = true; - }); - - DateTime startCheck = DateTime.UtcNow; - bool? discCheckStatus = inputFormat.VerifyMediaImage(); - DateTime endCheck = DateTime.UtcNow; - - TimeSpan checkTime = endCheck - startCheck; - - Application.Instance.Invoke(() => - { - lblImageResult.Visible = true; - switch(discCheckStatus) + if(!(inputFormat is IVerifiableImage verifiableImage)) + Application.Instance.Invoke(() => { - case true: - lblImageResult.Text = "Disc image checksums are correct"; - break; - case false: - lblImageResult.Text = "Disc image checksums are incorrect"; - break; - case null: - lblImageResult.Text = "Disc image does not contain checksums"; - break; - } - }); + lblImageResult.Visible = true; + lblImageResult.Text = "Disc image does not support verification."; + }); + else + { + Application.Instance.Invoke(() => + { + lblProgress.Text = "Checking media image..."; + if(chkVerifySectors.Checked == true) prgProgress.Value = 1; + else prgProgress.Indeterminate = true; - correctDisc = discCheckStatus; - DicConsole.VerboseWriteLine("Checking disc image checksums took {0} seconds", checkTime.TotalSeconds); + prgProgress2.Indeterminate = true; + }); + + DateTime startCheck = DateTime.UtcNow; + bool? discCheckStatus = verifiableImage.VerifyMediaImage(); + DateTime endCheck = DateTime.UtcNow; + + TimeSpan checkTime = endCheck - startCheck; + + Application.Instance.Invoke(() => + { + lblImageResult.Visible = true; + switch(discCheckStatus) + { + case true: + lblImageResult.Text = "Disc image checksums are correct"; + break; + case false: + lblImageResult.Text = "Disc image checksums are incorrect"; + break; + case null: + lblImageResult.Text = "Disc image does not contain checksums"; + break; + } + }); + + correctDisc = discCheckStatus; + DicConsole.VerboseWriteLine("Checking disc image checksums took {0} seconds", + checkTime.TotalSeconds); + } } if(chkVerifySectors.Checked == true) { - DateTime startCheck; - DateTime endCheck; + DateTime startCheck = DateTime.Now; + DateTime endCheck = startCheck; List failingLbas = new List(); List unknownLbas = new List(); @@ -232,7 +248,7 @@ namespace DiscImageChef.Gui.Forms endCheck = DateTime.UtcNow; } - else + else if(!(verifiableSectorsImage is null)) { ulong remainingSectors = inputFormat.Info.Sectors; ulong currentSector = 0; @@ -262,9 +278,11 @@ namespace DiscImageChef.Gui.Forms List tempunknownLbas; if(remainingSectors < 512) - inputFormat.VerifySectors(currentSector, (uint)remainingSectors, out tempfailingLbas, - out tempunknownLbas); - else inputFormat.VerifySectors(currentSector, 512, out tempfailingLbas, out tempunknownLbas); + verifiableSectorsImage.VerifySectors(currentSector, (uint)remainingSectors, + out tempfailingLbas, out tempunknownLbas); + else + verifiableSectorsImage.VerifySectors(currentSector, 512, out tempfailingLbas, + out tempunknownLbas); failingLbas.AddRange(tempfailingLbas); diff --git a/DiscImageChef/Commands/Verify.cs b/DiscImageChef/Commands/Verify.cs index 919c49e48..2ad457734 100644 --- a/DiscImageChef/Commands/Verify.cs +++ b/DiscImageChef/Commands/Verify.cs @@ -128,10 +128,19 @@ namespace DiscImageChef.Commands bool? correctSectors = null; long unknownSectors = 0; + IVerifiableImage verifiableImage = inputFormat as IVerifiableImage; + IVerifiableSectorsImage verifiableSectorsImage = inputFormat as IVerifiableSectorsImage; + + if(verifiableImage is null && verifiableSectorsImage is null) + { + DicConsole.ErrorWriteLine("The specified image does not support any kind of verification"); + return (int)ErrorNumber.NotVerificable; + } + if(verifyDisc) { DateTime startCheck = DateTime.UtcNow; - bool? discCheckStatus = inputFormat.VerifyMediaImage(); + bool? discCheckStatus = verifiableImage.VerifyMediaImage(); DateTime endCheck = DateTime.UtcNow; TimeSpan checkTime = endCheck - startCheck; @@ -155,8 +164,8 @@ namespace DiscImageChef.Commands if(verifySectors) { - DateTime startCheck; - DateTime endCheck; + DateTime startCheck = DateTime.Now; + DateTime endCheck = startCheck; List failingLbas = new List(); List unknownLbas = new List(); @@ -208,7 +217,7 @@ namespace DiscImageChef.Commands endCheck = DateTime.UtcNow; } - else + else if(verifiableSectorsImage != null) { ulong remainingSectors = inputFormat.Info.Sectors; ulong currentSector = 0; @@ -222,9 +231,11 @@ namespace DiscImageChef.Commands List tempunknownLbas; if(remainingSectors < 512) - inputFormat.VerifySectors(currentSector, (uint)remainingSectors, out tempfailingLbas, - out tempunknownLbas); - else inputFormat.VerifySectors(currentSector, 512, out tempfailingLbas, out tempunknownLbas); + verifiableSectorsImage.VerifySectors(currentSector, (uint)remainingSectors, + out tempfailingLbas, out tempunknownLbas); + else + verifiableSectorsImage.VerifySectors(currentSector, 512, out tempfailingLbas, + out tempunknownLbas); failingLbas.AddRange(tempfailingLbas);