Files
Aaru/Aaru.Images/ZZZRawImage/Identify.cs

144 lines
5.1 KiB
C#
Raw Permalink Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Identify.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disk image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Identifies 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
// ****************************************************************************/
using System.IO;
using System.Linq;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
namespace Aaru.Images;
2022-03-06 13:29:38 +00:00
public sealed partial class ZZZRawImage
{
2023-10-03 23:34:59 +01:00
#region IWritableOpticalImage Members
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool Identify(IFilter imageFilter)
{
2022-03-06 13:29:38 +00:00
_extension = Path.GetExtension(imageFilter.Filename)?.ToLower();
2022-03-06 13:29:38 +00:00
switch(_extension)
{
2023-10-03 23:34:59 +01:00
case ".1kn":
return imageFilter.DataForkLength % 1024 == 0;
case ".2kn":
return imageFilter.DataForkLength % 2048 == 0;
case ".4kn":
return imageFilter.DataForkLength % 4096 == 0;
case ".8kn":
return imageFilter.DataForkLength % 8192 == 0;
case ".16kn":
return imageFilter.DataForkLength % 16384 == 0;
case ".32kn":
return imageFilter.DataForkLength % 32768 == 0;
case ".64kn":
return imageFilter.DataForkLength % 65536 == 0;
2022-03-06 13:29:38 +00:00
case ".512":
2023-10-03 23:34:59 +01:00
case ".512e":
return imageFilter.DataForkLength % 512 == 0;
case ".128":
return imageFilter.DataForkLength % 128 == 0;
case ".256":
return imageFilter.DataForkLength % 256 == 0;
case ".toast" when imageFilter.DataForkLength % 2048 == 0:
return true;
case ".toast" when imageFilter.DataForkLength % 2056 == 0:
return true;
case ".raw" when imageFilter.DataForkLength % 2064 == 0:
return true;
// Handle this properly on Open()
//case ".toast" when imageFilter.DataForkLength % 2336 == 0: return true;
case ".2352" or ".toast"
when imageFilter.DataForkLength % 2352 == 0 && imageFilter.DataForkLength <= 846720000:
2022-03-06 13:29:38 +00:00
case ".2448" when imageFilter.DataForkLength % 2448 == 0 && imageFilter.DataForkLength <= 881280000:
2023-10-03 23:34:59 +01:00
var sync = new byte[12];
Stream stream = imageFilter.GetDataForkStream();
stream.Position = 0;
stream.EnsureRead(sync, 0, 12);
2020-02-29 18:03:35 +00:00
2020-07-20 21:11:32 +01:00
return _cdSync.SequenceEqual(sync);
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
// Check if file is not multiple of 512
2024-05-01 04:05:22 +01:00
if(imageFilter.DataForkLength % 512 == 0) return true;
2022-03-06 13:29:38 +00:00
2024-05-01 04:05:22 +01:00
if(_extension == ".hdf" && imageFilter.DataForkLength % 256 == 0) return true;
2022-03-06 13:29:38 +00:00
// Only for single track data CDs
2023-10-03 23:34:59 +01:00
if(imageFilter.DataForkLength % 2352 == 0 && imageFilter.DataForkLength <= 846720000 ||
imageFilter.DataForkLength % 2448 == 0 && imageFilter.DataForkLength <= 881280000)
2022-03-06 13:29:38 +00:00
{
2023-10-03 23:34:59 +01:00
var sync = new byte[12];
2022-03-06 13:29:38 +00:00
Stream stream = imageFilter.GetDataForkStream();
stream.Position = 0;
stream.EnsureRead(sync, 0, 12);
2022-03-06 13:29:38 +00:00
return _cdSync.SequenceEqual(sync);
}
// Check known disk sizes with sectors smaller than 512
switch(imageFilter.DataForkLength)
{
2024-05-01 04:05:22 +01:00
#region Commodore
2023-10-03 23:34:59 +01:00
2022-03-06 13:29:38 +00:00
case 174848:
case 175531:
case 197376:
case 351062:
case 822400:
2023-10-03 23:34:59 +01:00
2024-05-01 04:05:22 +01:00
#endregion Commodore
2022-03-06 13:29:38 +00:00
case 81664:
case 116480:
case 242944:
case 256256:
case 287488:
case 306432:
case 495872:
case 988416:
case 995072:
case 1021696:
case 1146624:
case 1177344:
case 1222400:
case 1304320:
2023-10-03 23:34:59 +01:00
case 1255168:
return true;
default:
return false;
}
}
2023-10-03 23:34:59 +01:00
#endregion
}