Files
Aaru/DiscImageChef.DiscImages/DART/Identify.cs

92 lines
3.2 KiB
C#
Raw Normal View History

// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Identify.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disk image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Identifies Apple Disk Archival/Retrieval Tool format.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2018-12-29 17:34:38 +00:00
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
using System.IO;
using System.Runtime.InteropServices;
using DiscImageChef.CommonTypes.Interfaces;
namespace DiscImageChef.DiscImages
{
public partial class Dart
{
public bool Identify(IFilter imageFilter)
{
Stream stream = imageFilter.GetDataForkStream();
if(stream.Length < 84) return false;
DartHeader header = new DartHeader();
stream.Seek(0, SeekOrigin.Begin);
byte[] headerB = new byte[Marshal.SizeOf(header)];
stream.Read(headerB, 0, Marshal.SizeOf(header));
2019-02-27 08:49:42 +00:00
header = Helpers.Marshal.ByteArrayToStructureBigEndian<DartHeader>(headerB);
if(header.srcCmp > COMPRESS_NONE) return false;
int expectedMaxSize = 84 + header.srcSize * 2 * 524;
switch(header.srcType)
{
case DISK_MAC:
if(header.srcSize != SIZE_MAC_SS && header.srcSize != SIZE_MAC) return false;
break;
case DISK_LISA:
if(header.srcSize != SIZE_LISA) return false;
break;
case DISK_APPLE2:
if(header.srcSize != SIZE_APPLE2) return false;
break;
case DISK_MAC_HD:
if(header.srcSize != SIZE_MAC_HD) return false;
expectedMaxSize += 64;
break;
case DISK_DOS:
if(header.srcSize != SIZE_DOS) return false;
break;
case DISK_DOS_HD:
if(header.srcSize != SIZE_DOS_HD) return false;
expectedMaxSize += 64;
break;
default: return false;
}
return stream.Length <= expectedMaxSize;
}
}
}