Files
Aaru/Aaru.Filters/AppleDouble.cs

685 lines
23 KiB
C#
Raw Normal View History

2017-05-19 20:28:49 +01:00
// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : AppleDouble.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Filters.
//
// --[ Description ] ----------------------------------------------------------
//
// Provides a filter to open AppleDouble files.
//
// --[ 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
// ****************************************************************************/
2017-12-19 19:33:46 +00:00
using System;
2020-07-20 07:47:12 +01:00
using System.Diagnostics.CodeAnalysis;
using System.IO;
2017-12-19 19:33:46 +00:00
using System.Runtime.InteropServices;
using Aaru.CommonTypes.Attributes;
2021-09-16 04:42:14 +01:00
using Aaru.CommonTypes.Enums;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes.Interfaces;
2020-07-20 15:43:52 +01:00
using Aaru.Helpers;
using Aaru.Helpers.IO;
2020-02-27 00:33:26 +00:00
using Marshal = Aaru.Helpers.Marshal;
namespace Aaru.Filters;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
/// <summary>Decodes AppleDouble files</summary>
[SuppressMessage("ReSharper", "UnusedMember.Local")]
public sealed partial class AppleDouble : IFilter
{
const uint MAGIC = 0x00051607;
const uint VERSION = 0x00010000;
const uint VERSION2 = 0x00020000;
readonly byte[] _dosHome = "MS-DOS "u8.ToArray();
readonly byte[] _macintoshHome = "Macintosh "u8.ToArray();
readonly byte[] _osxHome = "Mac OS X "u8.ToArray();
readonly byte[] _proDosHome = "ProDOS "u8.ToArray();
readonly byte[] _unixHome = "Unix "u8.ToArray();
readonly byte[] _vmsHome = "VAX VMS "u8.ToArray();
Entry _dataFork;
Header _header;
string _headerPath;
Entry _rsrcFork;
2023-10-03 23:23:41 +01:00
#region IFilter Members
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public string Name => Localization.AppleDouble_Name;
2023-10-03 23:23:41 +01:00
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public Guid Id => new("1B2165EE-C9DF-4B21-BBBB-9E5892B2DF4D");
2023-10-03 23:23:41 +01:00
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public string Author => Authors.NataliaPortillo;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public void Close() {}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public string BasePath { get; private set; }
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public DateTime CreationTime { get; private set; }
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public long DataForkLength => _dataFork.length;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public Stream GetDataForkStream() => new FileStream(BasePath, FileMode.Open, FileAccess.Read);
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public string Filename => System.IO.Path.GetFileName(BasePath);
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public DateTime LastWriteTime { get; private set; }
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public long Length => _dataFork.length + _rsrcFork.length;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath);
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public string Path => BasePath;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public long ResourceForkLength => _rsrcFork.length;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public Stream GetResourceForkStream()
{
2024-05-01 04:05:22 +01:00
if(_rsrcFork.length == 0) return null;
2024-05-01 04:05:22 +01:00
return new OffsetStream(_headerPath,
FileMode.Open,
FileAccess.Read,
_rsrcFork.offset,
2022-03-06 13:29:38 +00:00
_rsrcFork.offset + _rsrcFork.length - 1);
}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool HasResourceFork => _rsrcFork.length > 0;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool Identify(byte[] buffer) => false;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool Identify(Stream stream) => false;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool Identify(string path)
{
string filename = System.IO.Path.GetFileName(path);
string filenameNoExt = System.IO.Path.GetFileNameWithoutExtension(path);
string parentFolder = System.IO.Path.GetDirectoryName(path);
2018-06-20 22:22:21 +01:00
2022-03-06 13:29:38 +00:00
parentFolder ??= "";
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
if(filename is null || filenameNoExt is null) return false;
2022-03-06 13:29:38 +00:00
// Prepend data fork name with "R."
string proDosAppleDouble = System.IO.Path.Combine(parentFolder, "R." + filename);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Prepend data fork name with '%'
string unixAppleDouble = System.IO.Path.Combine(parentFolder, "%" + filename);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Change file extension to ADF
string dosAppleDouble = System.IO.Path.Combine(parentFolder, filenameNoExt + ".ADF");
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Change file extension to adf
string dosAppleDoubleLower = System.IO.Path.Combine(parentFolder, filenameNoExt + ".adf");
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Store AppleDouble header file in ".AppleDouble" folder with same name
string netatalkAppleDouble = System.IO.Path.Combine(parentFolder, ".AppleDouble", filename);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Store AppleDouble header file in "resource.frk" folder with same name
string daveAppleDouble = System.IO.Path.Combine(parentFolder, "resource.frk", filename);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Prepend data fork name with "._"
string osxAppleDouble = System.IO.Path.Combine(parentFolder, "._" + filename);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Adds ".rsrc" extension
string unArAppleDouble = System.IO.Path.Combine(parentFolder, filename + ".rsrc");
2022-03-06 13:29:38 +00:00
// Check AppleDouble created by A/UX in ProDOS filesystem
if(File.Exists(proDosAppleDouble))
{
var prodosStream = new FileStream(proDosAppleDouble, FileMode.Open, FileAccess.Read);
if(prodosStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var prodosB = new byte[26];
prodosStream.EnsureRead(prodosB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(prodosB);
2022-03-06 13:29:38 +00:00
prodosStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
}
2022-03-06 13:29:38 +00:00
}
// Check AppleDouble created by A/UX in UFS filesystem
if(File.Exists(unixAppleDouble))
{
var unixStream = new FileStream(unixAppleDouble, FileMode.Open, FileAccess.Read);
2022-03-06 13:29:38 +00:00
if(unixStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var unixB = new byte[26];
unixStream.EnsureRead(unixB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(unixB);
2022-03-06 13:29:38 +00:00
unixStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
}
2022-03-06 13:29:38 +00:00
}
// Check AppleDouble created by A/UX in FAT filesystem
if(File.Exists(dosAppleDouble))
{
var dosStream = new FileStream(dosAppleDouble, FileMode.Open, FileAccess.Read);
2022-03-06 13:29:38 +00:00
if(dosStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var dosB = new byte[26];
dosStream.EnsureRead(dosB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(dosB);
2022-03-06 13:29:38 +00:00
dosStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
}
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
// Check AppleDouble created by A/UX in case preserving FAT filesystem
if(File.Exists(dosAppleDoubleLower))
{
var doslStream = new FileStream(dosAppleDoubleLower, FileMode.Open, FileAccess.Read);
if(doslStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var doslB = new byte[26];
doslStream.EnsureRead(doslB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(doslB);
2022-03-06 13:29:38 +00:00
doslStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
}
2022-03-06 13:29:38 +00:00
}
// Check AppleDouble created by Netatalk
if(File.Exists(netatalkAppleDouble))
{
var netatalkStream = new FileStream(netatalkAppleDouble, FileMode.Open, FileAccess.Read);
2022-03-06 13:29:38 +00:00
if(netatalkStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var netatalkB = new byte[26];
netatalkStream.EnsureRead(netatalkB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(netatalkB);
2022-03-06 13:29:38 +00:00
netatalkStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
}
2022-03-06 13:29:38 +00:00
}
// Check AppleDouble created by DAVE
if(File.Exists(daveAppleDouble))
{
var daveStream = new FileStream(daveAppleDouble, FileMode.Open, FileAccess.Read);
2022-03-06 13:29:38 +00:00
if(daveStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var daveB = new byte[26];
daveStream.EnsureRead(daveB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(daveB);
2022-03-06 13:29:38 +00:00
daveStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
}
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
// Check AppleDouble created by Mac OS X
if(File.Exists(osxAppleDouble))
{
var osxStream = new FileStream(osxAppleDouble, FileMode.Open, FileAccess.Read);
if(osxStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var osxB = new byte[26];
osxStream.EnsureRead(osxB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(osxB);
2022-03-06 13:29:38 +00:00
osxStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
}
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
// Check AppleDouble created by UnAr (from The Unarchiver)
2024-05-01 04:05:22 +01:00
if(!File.Exists(unArAppleDouble)) return false;
2022-03-06 13:29:38 +00:00
var unarStream = new FileStream(unArAppleDouble, FileMode.Open, FileAccess.Read);
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
if(unarStream.Length <= 26) return false;
2023-10-03 23:23:41 +01:00
var unarB = new byte[26];
unarStream.EnsureRead(unarB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(unarB);
2022-03-06 13:29:38 +00:00
unarStream.Close();
2020-02-29 18:03:35 +00:00
return _header is { magic: MAGIC, version: VERSION or VERSION2 };
2022-03-06 13:29:38 +00:00
}
// Now way to have two files in a single byte array
/// <inheritdoc />
public ErrorNumber Open(byte[] buffer) => ErrorNumber.NotSupported;
2022-03-06 13:29:38 +00:00
// Now way to have two files in a single stream
/// <inheritdoc />
public ErrorNumber Open(Stream stream) => ErrorNumber.NotSupported;
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public ErrorNumber Open(string path)
{
string filename = System.IO.Path.GetFileName(path);
string filenameNoExt = System.IO.Path.GetFileNameWithoutExtension(path);
string parentFolder = System.IO.Path.GetDirectoryName(path);
2022-03-06 13:29:38 +00:00
parentFolder ??= "";
2018-06-20 22:22:21 +01:00
2024-05-01 04:05:22 +01:00
if(filename is null || filenameNoExt is null) return ErrorNumber.InvalidArgument;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Prepend data fork name with "R."
string proDosAppleDouble = System.IO.Path.Combine(parentFolder, "R." + filename);
2022-03-06 13:29:38 +00:00
// Prepend data fork name with '%'
string unixAppleDouble = System.IO.Path.Combine(parentFolder, "%" + filename);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Change file extension to ADF
string dosAppleDouble = System.IO.Path.Combine(parentFolder, filenameNoExt + ".ADF");
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Change file extension to adf
string dosAppleDoubleLower = System.IO.Path.Combine(parentFolder, filenameNoExt + ".adf");
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Store AppleDouble header file in ".AppleDouble" folder with same name
string netatalkAppleDouble = System.IO.Path.Combine(parentFolder, ".AppleDouble", filename);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Store AppleDouble header file in "resource.frk" folder with same name
string daveAppleDouble = System.IO.Path.Combine(parentFolder, "resource.frk", filename);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Prepend data fork name with "._"
string osxAppleDouble = System.IO.Path.Combine(parentFolder, "._" + filename);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Adds ".rsrc" extension
string unArAppleDouble = System.IO.Path.Combine(parentFolder, filename + ".rsrc");
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
// Check AppleDouble created by A/UX in ProDOS filesystem
if(File.Exists(proDosAppleDouble))
{
var prodosStream = new FileStream(proDosAppleDouble, FileMode.Open, FileAccess.Read);
2022-03-06 13:29:38 +00:00
if(prodosStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var prodosB = new byte[26];
prodosStream.EnsureRead(prodosB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(prodosB);
2022-03-06 13:29:38 +00:00
prodosStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = proDosAppleDouble;
}
2022-03-06 13:29:38 +00:00
}
// Check AppleDouble created by A/UX in UFS filesystem
if(File.Exists(unixAppleDouble))
{
var unixStream = new FileStream(unixAppleDouble, FileMode.Open, FileAccess.Read);
2022-03-06 13:29:38 +00:00
if(unixStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var unixB = new byte[26];
unixStream.EnsureRead(unixB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(unixB);
2022-03-06 13:29:38 +00:00
unixStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = unixAppleDouble;
}
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
// Check AppleDouble created by A/UX in FAT filesystem
if(File.Exists(dosAppleDouble))
{
var dosStream = new FileStream(dosAppleDouble, FileMode.Open, FileAccess.Read);
if(dosStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var dosB = new byte[26];
dosStream.EnsureRead(dosB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(dosB);
2022-03-06 13:29:38 +00:00
dosStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = dosAppleDouble;
}
2022-03-06 13:29:38 +00:00
}
// Check AppleDouble created by A/UX in case preserving FAT filesystem
if(File.Exists(dosAppleDoubleLower))
{
var doslStream = new FileStream(dosAppleDoubleLower, FileMode.Open, FileAccess.Read);
2022-03-06 13:29:38 +00:00
if(doslStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var doslB = new byte[26];
doslStream.EnsureRead(doslB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(doslB);
2022-03-06 13:29:38 +00:00
doslStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = dosAppleDoubleLower;
}
2022-03-06 13:29:38 +00:00
}
// Check AppleDouble created by Netatalk
if(File.Exists(netatalkAppleDouble))
{
var netatalkStream = new FileStream(netatalkAppleDouble, FileMode.Open, FileAccess.Read);
2022-03-06 13:29:38 +00:00
if(netatalkStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var netatalkB = new byte[26];
netatalkStream.EnsureRead(netatalkB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(netatalkB);
2022-03-06 13:29:38 +00:00
netatalkStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = netatalkAppleDouble;
}
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
// Check AppleDouble created by DAVE
if(File.Exists(daveAppleDouble))
{
var daveStream = new FileStream(daveAppleDouble, FileMode.Open, FileAccess.Read);
if(daveStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var daveB = new byte[26];
daveStream.EnsureRead(daveB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(daveB);
2022-03-06 13:29:38 +00:00
daveStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = daveAppleDouble;
}
2022-03-06 13:29:38 +00:00
}
// Check AppleDouble created by Mac OS X
if(File.Exists(osxAppleDouble))
{
var osxStream = new FileStream(osxAppleDouble, FileMode.Open, FileAccess.Read);
2022-03-06 13:29:38 +00:00
if(osxStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var osxB = new byte[26];
osxStream.EnsureRead(osxB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(osxB);
2022-03-06 13:29:38 +00:00
osxStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = osxAppleDouble;
}
2022-03-06 13:29:38 +00:00
}
// Check AppleDouble created by UnAr (from The Unarchiver)
if(File.Exists(unArAppleDouble))
{
var unarStream = new FileStream(unArAppleDouble, FileMode.Open, FileAccess.Read);
2022-03-06 13:29:38 +00:00
if(unarStream.Length > 26)
{
2023-10-03 23:23:41 +01:00
var unarB = new byte[26];
unarStream.EnsureRead(unarB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(unarB);
2022-03-06 13:29:38 +00:00
unarStream.Close();
2024-05-01 04:05:22 +01:00
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = unArAppleDouble;
}
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
// TODO: More appropriate error
2024-05-01 04:05:22 +01:00
if(_headerPath is null) return ErrorNumber.NotSupported;
2021-09-15 13:03:42 +01:00
2022-03-06 13:29:38 +00:00
var fs = new FileStream(_headerPath, FileMode.Open, FileAccess.Read);
fs.Seek(0, SeekOrigin.Begin);
2023-10-03 23:23:41 +01:00
var hdrB = new byte[26];
fs.EnsureRead(hdrB, 0, 26);
_header = Marshal.ByteArrayToStructureBigEndian<Header>(hdrB);
2023-10-03 23:23:41 +01:00
var entries = new Entry[_header.entries];
2020-02-29 18:03:35 +00:00
2023-10-03 23:23:41 +01:00
for(var i = 0; i < _header.entries; i++)
2022-03-06 13:29:38 +00:00
{
2023-10-03 23:23:41 +01:00
var entry = new byte[12];
fs.EnsureRead(entry, 0, 12);
entries[i] = Marshal.ByteArrayToStructureBigEndian<Entry>(entry);
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
CreationTime = DateTime.UtcNow;
LastWriteTime = CreationTime;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
foreach(Entry entry in entries)
2023-10-03 23:23:41 +01:00
{
2022-03-06 13:29:38 +00:00
switch((EntryId)entry.id)
{
2022-03-06 13:29:38 +00:00
case EntryId.DataFork:
// AppleDouble have datafork in separated file
break;
case EntryId.FileDates:
fs.Seek(entry.offset, SeekOrigin.Begin);
2023-10-03 23:23:41 +01:00
var datesB = new byte[16];
fs.EnsureRead(datesB, 0, 16);
2022-03-06 13:29:38 +00:00
FileDates dates = Marshal.ByteArrayToStructureBigEndian<FileDates>(datesB);
2022-03-06 13:29:38 +00:00
CreationTime = DateHandlers.UnixUnsignedToDateTime(dates.creationDate);
LastWriteTime = DateHandlers.UnixUnsignedToDateTime(dates.modificationDate);
break;
case EntryId.FileInfo:
fs.Seek(entry.offset, SeekOrigin.Begin);
2023-10-03 23:23:41 +01:00
var finfo = new byte[entry.length];
fs.EnsureRead(finfo, 0, finfo.Length);
2022-03-06 13:29:38 +00:00
if(_macintoshHome.SequenceEqual(_header.homeFilesystem))
{
MacFileInfo macinfo = Marshal.ByteArrayToStructureBigEndian<MacFileInfo>(finfo);
2022-03-06 13:29:38 +00:00
CreationTime = DateHandlers.MacToDateTime(macinfo.creationDate);
LastWriteTime = DateHandlers.MacToDateTime(macinfo.modificationDate);
}
else if(_proDosHome.SequenceEqual(_header.homeFilesystem))
{
ProDOSFileInfo prodosinfo = Marshal.ByteArrayToStructureBigEndian<ProDOSFileInfo>(finfo);
2022-03-06 13:29:38 +00:00
CreationTime = DateHandlers.MacToDateTime(prodosinfo.creationDate);
LastWriteTime = DateHandlers.MacToDateTime(prodosinfo.modificationDate);
}
else if(_unixHome.SequenceEqual(_header.homeFilesystem))
{
UnixFileInfo unixinfo = Marshal.ByteArrayToStructureBigEndian<UnixFileInfo>(finfo);
2022-03-06 13:29:38 +00:00
CreationTime = DateHandlers.UnixUnsignedToDateTime(unixinfo.creationDate);
LastWriteTime = DateHandlers.UnixUnsignedToDateTime(unixinfo.modificationDate);
}
else if(_dosHome.SequenceEqual(_header.homeFilesystem))
{
DOSFileInfo dosinfo = Marshal.ByteArrayToStructureBigEndian<DOSFileInfo>(finfo);
2022-03-06 13:29:38 +00:00
2022-03-07 07:36:44 +00:00
LastWriteTime = DateHandlers.DosToDateTime(dosinfo.modificationDate, dosinfo.modificationTime);
2022-03-06 13:29:38 +00:00
}
break;
case EntryId.ResourceFork:
_rsrcFork = entry;
break;
}
2023-10-03 23:23:41 +01:00
}
2022-03-06 13:29:38 +00:00
_dataFork = new Entry
{
2022-03-06 13:29:38 +00:00
id = (uint)EntryId.DataFork
};
2022-03-06 13:29:38 +00:00
if(File.Exists(path))
{
2022-03-06 13:29:38 +00:00
var dataFs = new FileStream(path, FileMode.Open, FileAccess.Read);
_dataFork.length = (uint)dataFs.Length;
dataFs.Close();
}
2022-03-06 13:29:38 +00:00
fs.Close();
BasePath = path;
2022-03-06 13:29:38 +00:00
return ErrorNumber.NoError;
}
2023-10-03 23:23:41 +01:00
#endregion
#region Nested type: DOSFileInfo
2022-03-06 13:29:38 +00:00
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct DOSFileInfo
2022-03-06 13:29:38 +00:00
{
public ushort modificationDate;
public ushort modificationTime;
public ushort attributes;
2022-03-06 13:29:38 +00:00
}
2023-10-03 23:23:41 +01:00
#endregion
#region Nested type: Entry
2022-03-06 13:29:38 +00:00
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct Entry
2022-03-06 13:29:38 +00:00
{
public uint id;
public uint offset;
public uint length;
2022-03-06 13:29:38 +00:00
}
2023-10-03 23:23:41 +01:00
#endregion
#region Nested type: EntryId
enum EntryId : uint
{
Invalid = 0,
DataFork = 1,
ResourceFork = 2,
RealName = 3,
Comment = 4,
Icon = 5,
ColorIcon = 6,
FileInfo = 7,
FileDates = 8,
FinderInfo = 9,
MacFileInfo = 10,
ProDOSFileInfo = 11,
DOSFileInfo = 12,
ShortName = 13,
AfpFileInfo = 14,
DirectoryID = 15
}
#endregion
#region Nested type: FileDates
2022-03-06 13:29:38 +00:00
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct FileDates
2022-03-06 13:29:38 +00:00
{
public uint creationDate;
public uint modificationDate;
public uint backupDate;
public uint accessDate;
2022-03-06 13:29:38 +00:00
}
2023-10-03 23:23:41 +01:00
#endregion
#region Nested type: Header
2022-03-06 13:29:38 +00:00
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct Header
2022-03-06 13:29:38 +00:00
{
public uint magic;
public uint version;
2023-10-03 23:23:41 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] homeFilesystem;
public ushort entries;
2022-03-06 13:29:38 +00:00
}
2023-10-03 23:23:41 +01:00
#endregion
#region Nested type: MacFileInfo
2022-03-06 13:29:38 +00:00
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct MacFileInfo
2022-03-06 13:29:38 +00:00
{
public uint creationDate;
public uint modificationDate;
public uint backupDate;
public uint accessDate;
2022-03-06 13:29:38 +00:00
}
2023-10-03 23:23:41 +01:00
#endregion
#region Nested type: ProDOSFileInfo
2022-03-06 13:29:38 +00:00
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct ProDOSFileInfo
2022-03-06 13:29:38 +00:00
{
public uint creationDate;
public uint modificationDate;
public uint backupDate;
public ushort access;
public ushort fileType;
public uint auxType;
}
2023-10-03 23:23:41 +01:00
#endregion
#region Nested type: UnixFileInfo
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct UnixFileInfo
2023-10-03 23:23:41 +01:00
{
public uint creationDate;
public uint accessDate;
public uint modificationDate;
2023-10-03 23:23:41 +01:00
}
#endregion
2017-12-19 20:33:03 +00:00
}