mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
General refactor and cleanup.
This commit is contained in:
@@ -109,10 +109,12 @@ public sealed class AppleDouble : IFilter
|
||||
/// <inheritdoc />
|
||||
public Stream GetResourceForkStream()
|
||||
{
|
||||
if(_rsrcFork.length == 0)
|
||||
return null;
|
||||
if(_rsrcFork.length == 0) return null;
|
||||
|
||||
return new OffsetStream(_headerPath, FileMode.Open, FileAccess.Read, _rsrcFork.offset,
|
||||
return new OffsetStream(_headerPath,
|
||||
FileMode.Open,
|
||||
FileAccess.Read,
|
||||
_rsrcFork.offset,
|
||||
_rsrcFork.offset + _rsrcFork.length - 1);
|
||||
}
|
||||
|
||||
@@ -134,8 +136,7 @@ public sealed class AppleDouble : IFilter
|
||||
|
||||
parentFolder ??= "";
|
||||
|
||||
if(filename is null || filenameNoExt is null)
|
||||
return false;
|
||||
if(filename is null || filenameNoExt is null) return false;
|
||||
|
||||
// Prepend data fork name with "R."
|
||||
string proDosAppleDouble = System.IO.Path.Combine(parentFolder, "R." + filename);
|
||||
@@ -173,8 +174,7 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(prodosB);
|
||||
prodosStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
return true;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,8 +190,7 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(unixB);
|
||||
unixStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
return true;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,8 +206,7 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(dosB);
|
||||
dosStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
return true;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,8 +222,7 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(doslB);
|
||||
doslStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
return true;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,8 +238,7 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(netatalkB);
|
||||
netatalkStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
return true;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,8 +254,7 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(daveB);
|
||||
daveStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
return true;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,19 +270,16 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(osxB);
|
||||
osxStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
return true;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check AppleDouble created by UnAr (from The Unarchiver)
|
||||
if(!File.Exists(unArAppleDouble))
|
||||
return false;
|
||||
if(!File.Exists(unArAppleDouble)) return false;
|
||||
|
||||
var unarStream = new FileStream(unArAppleDouble, FileMode.Open, FileAccess.Read);
|
||||
|
||||
if(unarStream.Length <= 26)
|
||||
return false;
|
||||
if(unarStream.Length <= 26) return false;
|
||||
|
||||
var unarB = new byte[26];
|
||||
unarStream.EnsureRead(unarB, 0, 26);
|
||||
@@ -314,8 +306,7 @@ public sealed class AppleDouble : IFilter
|
||||
|
||||
parentFolder ??= "";
|
||||
|
||||
if(filename is null || filenameNoExt is null)
|
||||
return ErrorNumber.InvalidArgument;
|
||||
if(filename is null || filenameNoExt is null) return ErrorNumber.InvalidArgument;
|
||||
|
||||
// Prepend data fork name with "R."
|
||||
string proDosAppleDouble = System.IO.Path.Combine(parentFolder, "R." + filename);
|
||||
@@ -353,8 +344,7 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(prodosB);
|
||||
prodosStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
_headerPath = proDosAppleDouble;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = proDosAppleDouble;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,8 +360,7 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(unixB);
|
||||
unixStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
_headerPath = unixAppleDouble;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = unixAppleDouble;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,8 +376,7 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(dosB);
|
||||
dosStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
_headerPath = dosAppleDouble;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = dosAppleDouble;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,8 +392,7 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(doslB);
|
||||
doslStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
_headerPath = dosAppleDoubleLower;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = dosAppleDoubleLower;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,8 +408,7 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(netatalkB);
|
||||
netatalkStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
_headerPath = netatalkAppleDouble;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = netatalkAppleDouble;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,8 +424,7 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(daveB);
|
||||
daveStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
_headerPath = daveAppleDouble;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = daveAppleDouble;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,8 +440,7 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(osxB);
|
||||
osxStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
_headerPath = osxAppleDouble;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = osxAppleDouble;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,14 +456,12 @@ public sealed class AppleDouble : IFilter
|
||||
_header = Marshal.ByteArrayToStructureBigEndian<Header>(unarB);
|
||||
unarStream.Close();
|
||||
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 })
|
||||
_headerPath = unArAppleDouble;
|
||||
if(_header is { magic: MAGIC, version: VERSION or VERSION2 }) _headerPath = unArAppleDouble;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: More appropriate error
|
||||
if(_headerPath is null)
|
||||
return ErrorNumber.NotSupported;
|
||||
if(_headerPath is null) return ErrorNumber.NotSupported;
|
||||
|
||||
var fs = new FileStream(_headerPath, FileMode.Open, FileAccess.Read);
|
||||
fs.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
@@ -97,18 +97,18 @@ public sealed class AppleSingle : IFilter
|
||||
/// <inheritdoc />
|
||||
public Stream GetDataForkStream()
|
||||
{
|
||||
if(_dataFork.length == 0)
|
||||
return null;
|
||||
if(_dataFork.length == 0) return null;
|
||||
|
||||
if(_isBytes)
|
||||
return new OffsetStream(_bytes, _dataFork.offset, _dataFork.offset + _dataFork.length - 1);
|
||||
if(_isBytes) return new OffsetStream(_bytes, _dataFork.offset, _dataFork.offset + _dataFork.length - 1);
|
||||
|
||||
if(_isStream)
|
||||
return new OffsetStream(_stream, _dataFork.offset, _dataFork.offset + _dataFork.length - 1);
|
||||
if(_isStream) return new OffsetStream(_stream, _dataFork.offset, _dataFork.offset + _dataFork.length - 1);
|
||||
|
||||
if(_isPath)
|
||||
{
|
||||
return new OffsetStream(BasePath, FileMode.Open, FileAccess.Read, _dataFork.offset,
|
||||
return new OffsetStream(BasePath,
|
||||
FileMode.Open,
|
||||
FileAccess.Read,
|
||||
_dataFork.offset,
|
||||
_dataFork.offset + _dataFork.length - 1);
|
||||
}
|
||||
|
||||
@@ -136,18 +136,18 @@ public sealed class AppleSingle : IFilter
|
||||
/// <inheritdoc />
|
||||
public Stream GetResourceForkStream()
|
||||
{
|
||||
if(_rsrcFork.length == 0)
|
||||
return null;
|
||||
if(_rsrcFork.length == 0) return null;
|
||||
|
||||
if(_isBytes)
|
||||
return new OffsetStream(_bytes, _rsrcFork.offset, _rsrcFork.offset + _rsrcFork.length - 1);
|
||||
if(_isBytes) return new OffsetStream(_bytes, _rsrcFork.offset, _rsrcFork.offset + _rsrcFork.length - 1);
|
||||
|
||||
if(_isStream)
|
||||
return new OffsetStream(_stream, _rsrcFork.offset, _rsrcFork.offset + _rsrcFork.length - 1);
|
||||
if(_isStream) return new OffsetStream(_stream, _rsrcFork.offset, _rsrcFork.offset + _rsrcFork.length - 1);
|
||||
|
||||
if(_isPath)
|
||||
{
|
||||
return new OffsetStream(BasePath, FileMode.Open, FileAccess.Read, _rsrcFork.offset,
|
||||
return new OffsetStream(BasePath,
|
||||
FileMode.Open,
|
||||
FileAccess.Read,
|
||||
_rsrcFork.offset,
|
||||
_rsrcFork.offset + _rsrcFork.length - 1);
|
||||
}
|
||||
|
||||
@@ -160,8 +160,7 @@ public sealed class AppleSingle : IFilter
|
||||
/// <inheritdoc />
|
||||
public bool Identify(byte[] buffer)
|
||||
{
|
||||
if(buffer == null || buffer.Length < 26)
|
||||
return false;
|
||||
if(buffer == null || buffer.Length < 26) return false;
|
||||
|
||||
var hdrB = new byte[26];
|
||||
Array.Copy(buffer, 0, hdrB, 0, 26);
|
||||
@@ -173,8 +172,7 @@ public sealed class AppleSingle : IFilter
|
||||
/// <inheritdoc />
|
||||
public bool Identify(Stream stream)
|
||||
{
|
||||
if(stream == null || stream.Length < 26)
|
||||
return false;
|
||||
if(stream == null || stream.Length < 26) return false;
|
||||
|
||||
var hdrB = new byte[26];
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
@@ -187,13 +185,11 @@ public sealed class AppleSingle : IFilter
|
||||
/// <inheritdoc />
|
||||
public bool Identify(string path)
|
||||
{
|
||||
if(!File.Exists(path))
|
||||
return false;
|
||||
if(!File.Exists(path)) return false;
|
||||
|
||||
var fstream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
|
||||
if(fstream.Length < 26)
|
||||
return false;
|
||||
if(fstream.Length < 26) return false;
|
||||
|
||||
var hdrB = new byte[26];
|
||||
fstream.EnsureRead(hdrB, 0, 26);
|
||||
|
||||
@@ -87,8 +87,7 @@ public class BZip2 : IFilter
|
||||
if(buffer[0] != 0x42 || buffer[1] != 0x5A || buffer[2] != 0x68 || buffer[3] < 0x31 || buffer[3] > 0x39)
|
||||
return false;
|
||||
|
||||
if(buffer.Length <= 512)
|
||||
return true;
|
||||
if(buffer.Length <= 512) return true;
|
||||
|
||||
return buffer[^512] != 0x6B || buffer[^511] != 0x6F || buffer[^510] != 0x6C || buffer[^509] != 0x79;
|
||||
}
|
||||
@@ -105,8 +104,7 @@ public class BZip2 : IFilter
|
||||
if(buffer[0] != 0x42 || buffer[1] != 0x5A || buffer[2] != 0x68 || buffer[3] < 0x31 || buffer[3] > 0x39)
|
||||
return false;
|
||||
|
||||
if(stream.Length <= 512)
|
||||
return true;
|
||||
if(stream.Length <= 512) return true;
|
||||
|
||||
stream.Seek(-512, SeekOrigin.End);
|
||||
stream.EnsureRead(buffer, 0, 4);
|
||||
@@ -119,8 +117,7 @@ public class BZip2 : IFilter
|
||||
/// <inheritdoc />
|
||||
public bool Identify(string path)
|
||||
{
|
||||
if(!File.Exists(path))
|
||||
return false;
|
||||
if(!File.Exists(path)) return false;
|
||||
|
||||
var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
var buffer = new byte[4];
|
||||
@@ -132,8 +129,7 @@ public class BZip2 : IFilter
|
||||
if(buffer[0] != 0x42 || buffer[1] != 0x5A || buffer[2] != 0x68 || buffer[3] < 0x31 || buffer[3] > 0x39)
|
||||
return false;
|
||||
|
||||
if(stream.Length <= 512)
|
||||
return true;
|
||||
if(stream.Length <= 512) return true;
|
||||
|
||||
stream.Seek(-512, SeekOrigin.End);
|
||||
stream.EnsureRead(buffer, 0, 4);
|
||||
@@ -204,8 +200,7 @@ public class BZip2 : IFilter
|
||||
{
|
||||
get
|
||||
{
|
||||
if(BasePath?.EndsWith(".bz2", StringComparison.InvariantCultureIgnoreCase) == true)
|
||||
return BasePath[..^4];
|
||||
if(BasePath?.EndsWith(".bz2", StringComparison.InvariantCultureIgnoreCase) == true) return BasePath[..^4];
|
||||
|
||||
return BasePath?.EndsWith(".bzip2", StringComparison.InvariantCultureIgnoreCase) == true
|
||||
? BasePath[..^6]
|
||||
|
||||
@@ -100,8 +100,7 @@ public sealed class GZip : IFilter
|
||||
/// <inheritdoc />
|
||||
public bool Identify(string path)
|
||||
{
|
||||
if(!File.Exists(path))
|
||||
return false;
|
||||
if(!File.Exists(path)) return false;
|
||||
|
||||
var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
var buffer = new byte[3];
|
||||
@@ -214,8 +213,7 @@ public sealed class GZip : IFilter
|
||||
{
|
||||
get
|
||||
{
|
||||
if(BasePath?.EndsWith(".gz", StringComparison.InvariantCultureIgnoreCase) == true)
|
||||
return BasePath[..^3];
|
||||
if(BasePath?.EndsWith(".gz", StringComparison.InvariantCultureIgnoreCase) == true) return BasePath[..^3];
|
||||
|
||||
return BasePath?.EndsWith(".gzip", StringComparison.InvariantCultureIgnoreCase) == true
|
||||
? BasePath[..^5]
|
||||
|
||||
@@ -104,8 +104,7 @@ public sealed class LZip : IFilter
|
||||
/// <inheritdoc />
|
||||
public bool Identify(string path)
|
||||
{
|
||||
if(!File.Exists(path))
|
||||
return false;
|
||||
if(!File.Exists(path)) return false;
|
||||
|
||||
var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
var buffer = new byte[5];
|
||||
@@ -187,8 +186,7 @@ public sealed class LZip : IFilter
|
||||
{
|
||||
get
|
||||
{
|
||||
if(BasePath?.EndsWith(".lz", StringComparison.InvariantCultureIgnoreCase) == true)
|
||||
return BasePath[..^3];
|
||||
if(BasePath?.EndsWith(".lz", StringComparison.InvariantCultureIgnoreCase) == true) return BasePath[..^3];
|
||||
|
||||
return BasePath?.EndsWith(".lzip", StringComparison.InvariantCultureIgnoreCase) == true
|
||||
? BasePath[..^5]
|
||||
|
||||
@@ -88,18 +88,18 @@ public sealed class MacBinary : IFilter
|
||||
/// <inheritdoc />
|
||||
public Stream GetDataForkStream()
|
||||
{
|
||||
if(_header.dataLength == 0)
|
||||
return null;
|
||||
if(_header.dataLength == 0) return null;
|
||||
|
||||
if(_isBytes)
|
||||
return new OffsetStream(_bytes, _dataForkOff, _dataForkOff + _header.dataLength - 1);
|
||||
if(_isBytes) return new OffsetStream(_bytes, _dataForkOff, _dataForkOff + _header.dataLength - 1);
|
||||
|
||||
if(_isStream)
|
||||
return new OffsetStream(_stream, _dataForkOff, _dataForkOff + _header.dataLength - 1);
|
||||
if(_isStream) return new OffsetStream(_stream, _dataForkOff, _dataForkOff + _header.dataLength - 1);
|
||||
|
||||
if(_isPath)
|
||||
{
|
||||
return new OffsetStream(BasePath, FileMode.Open, FileAccess.Read, _dataForkOff,
|
||||
return new OffsetStream(BasePath,
|
||||
FileMode.Open,
|
||||
FileAccess.Read,
|
||||
_dataForkOff,
|
||||
_dataForkOff + _header.dataLength - 1);
|
||||
}
|
||||
|
||||
@@ -127,18 +127,18 @@ public sealed class MacBinary : IFilter
|
||||
/// <inheritdoc />
|
||||
public Stream GetResourceForkStream()
|
||||
{
|
||||
if(_header.resourceLength == 0)
|
||||
return null;
|
||||
if(_header.resourceLength == 0) return null;
|
||||
|
||||
if(_isBytes)
|
||||
return new OffsetStream(_bytes, _rsrcForkOff, _rsrcForkOff + _header.resourceLength - 1);
|
||||
if(_isBytes) return new OffsetStream(_bytes, _rsrcForkOff, _rsrcForkOff + _header.resourceLength - 1);
|
||||
|
||||
if(_isStream)
|
||||
return new OffsetStream(_stream, _rsrcForkOff, _rsrcForkOff + _header.resourceLength - 1);
|
||||
if(_isStream) return new OffsetStream(_stream, _rsrcForkOff, _rsrcForkOff + _header.resourceLength - 1);
|
||||
|
||||
if(_isPath)
|
||||
{
|
||||
return new OffsetStream(BasePath, FileMode.Open, FileAccess.Read, _rsrcForkOff,
|
||||
return new OffsetStream(BasePath,
|
||||
FileMode.Open,
|
||||
FileAccess.Read,
|
||||
_rsrcForkOff,
|
||||
_rsrcForkOff + _header.resourceLength - 1);
|
||||
}
|
||||
|
||||
@@ -151,8 +151,7 @@ public sealed class MacBinary : IFilter
|
||||
/// <inheritdoc />
|
||||
public bool Identify(byte[] buffer)
|
||||
{
|
||||
if(buffer == null || buffer.Length < 128)
|
||||
return false;
|
||||
if(buffer == null || buffer.Length < 128) return false;
|
||||
|
||||
var hdrB = new byte[128];
|
||||
Array.Copy(buffer, 0, hdrB, 0, 128);
|
||||
@@ -170,8 +169,7 @@ public sealed class MacBinary : IFilter
|
||||
/// <inheritdoc />
|
||||
public bool Identify(Stream stream)
|
||||
{
|
||||
if(stream == null || stream.Length < 128)
|
||||
return false;
|
||||
if(stream == null || stream.Length < 128) return false;
|
||||
|
||||
var hdrB = new byte[128];
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
@@ -190,13 +188,11 @@ public sealed class MacBinary : IFilter
|
||||
/// <inheritdoc />
|
||||
public bool Identify(string path)
|
||||
{
|
||||
if(!File.Exists(path))
|
||||
return false;
|
||||
if(!File.Exists(path)) return false;
|
||||
|
||||
var fstream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
|
||||
if(fstream.Length < 128)
|
||||
return false;
|
||||
if(fstream.Length < 128) return false;
|
||||
|
||||
var hdrB = new byte[128];
|
||||
fstream.EnsureRead(hdrB, 0, 128);
|
||||
@@ -226,14 +222,12 @@ public sealed class MacBinary : IFilter
|
||||
uint blocks = 1;
|
||||
blocks += (uint)(_header.secondaryHeaderLength / 128);
|
||||
|
||||
if(_header.secondaryHeaderLength % 128 > 0)
|
||||
blocks++;
|
||||
if(_header.secondaryHeaderLength % 128 > 0) blocks++;
|
||||
|
||||
_dataForkOff = blocks * 128;
|
||||
blocks += _header.dataLength / 128;
|
||||
|
||||
if(_header.dataLength % 128 > 0)
|
||||
blocks++;
|
||||
if(_header.dataLength % 128 > 0) blocks++;
|
||||
|
||||
_rsrcForkOff = blocks * 128;
|
||||
|
||||
@@ -260,14 +254,12 @@ public sealed class MacBinary : IFilter
|
||||
uint blocks = 1;
|
||||
blocks += (uint)(_header.secondaryHeaderLength / 128);
|
||||
|
||||
if(_header.secondaryHeaderLength % 128 > 0)
|
||||
blocks++;
|
||||
if(_header.secondaryHeaderLength % 128 > 0) blocks++;
|
||||
|
||||
_dataForkOff = blocks * 128;
|
||||
blocks += _header.dataLength / 128;
|
||||
|
||||
if(_header.dataLength % 128 > 0)
|
||||
blocks++;
|
||||
if(_header.dataLength % 128 > 0) blocks++;
|
||||
|
||||
_rsrcForkOff = blocks * 128;
|
||||
|
||||
@@ -295,14 +287,12 @@ public sealed class MacBinary : IFilter
|
||||
uint blocks = 1;
|
||||
blocks += (uint)(_header.secondaryHeaderLength / 128);
|
||||
|
||||
if(_header.secondaryHeaderLength % 128 > 0)
|
||||
blocks++;
|
||||
if(_header.secondaryHeaderLength % 128 > 0) blocks++;
|
||||
|
||||
_dataForkOff = blocks * 128;
|
||||
blocks += _header.dataLength / 128;
|
||||
|
||||
if(_header.dataLength % 128 > 0)
|
||||
blocks++;
|
||||
if(_header.dataLength % 128 > 0) blocks++;
|
||||
|
||||
_rsrcForkOff = blocks * 128;
|
||||
|
||||
@@ -360,7 +350,7 @@ public sealed class MacBinary : IFilter
|
||||
/// <summary>0x65, Low byte of Finder flags</summary>
|
||||
public readonly byte finderFlags2;
|
||||
|
||||
#region MacBinary III
|
||||
#region MacBinary III
|
||||
|
||||
/// <summary>0x66, magic identifier, "mBIN"</summary>
|
||||
public readonly uint magic;
|
||||
@@ -369,14 +359,14 @@ public sealed class MacBinary : IFilter
|
||||
/// <summary>0x6B, fdXFlags from fxInfo, extended Mac OS 8 finder flags</summary>
|
||||
public readonly byte fdXFlags;
|
||||
|
||||
#endregion MacBinary III
|
||||
#endregion MacBinary III
|
||||
|
||||
/// <summary>0x6C, unused</summary>
|
||||
public readonly ulong reserved;
|
||||
/// <summary>0x74, Total unpacked files</summary>
|
||||
public readonly uint totalPackedFiles;
|
||||
|
||||
#region MacBinary II
|
||||
#region MacBinary II
|
||||
|
||||
/// <summary>0x78, Length of secondary header</summary>
|
||||
public readonly ushort secondaryHeaderLength;
|
||||
@@ -387,7 +377,7 @@ public sealed class MacBinary : IFilter
|
||||
/// <summary>0x7C, CRC of previous bytes</summary>
|
||||
public readonly short crc;
|
||||
|
||||
#endregion MacBinary II
|
||||
#endregion MacBinary II
|
||||
|
||||
/// <summary>0x7E, Reserved for computer type and OS ID</summary>
|
||||
public readonly short computerID;
|
||||
|
||||
@@ -118,18 +118,17 @@ public sealed class PcExchange : IFilter
|
||||
|
||||
parentFolder ??= "";
|
||||
|
||||
if(!File.Exists(System.IO.Path.Combine(parentFolder, FINDER_INFO)))
|
||||
return false;
|
||||
if(!File.Exists(System.IO.Path.Combine(parentFolder, FINDER_INFO))) return false;
|
||||
|
||||
if(!Directory.Exists(System.IO.Path.Combine(parentFolder, RESOURCES)))
|
||||
return false;
|
||||
if(!Directory.Exists(System.IO.Path.Combine(parentFolder, RESOURCES))) return false;
|
||||
|
||||
string baseFilename = System.IO.Path.GetFileName(path);
|
||||
|
||||
var dataFound = false;
|
||||
var rsrcFound = false;
|
||||
|
||||
var finderDatStream = new FileStream(System.IO.Path.Combine(parentFolder, FINDER_INFO), FileMode.Open,
|
||||
var finderDatStream = new FileStream(System.IO.Path.Combine(parentFolder, FINDER_INFO),
|
||||
FileMode.Open,
|
||||
FileAccess.Read);
|
||||
|
||||
while(finderDatStream.Position + 0x5C <= finderDatStream.Length)
|
||||
@@ -153,8 +152,7 @@ public sealed class PcExchange : IFilter
|
||||
|
||||
string dosNameLow = dosName.ToLower(CultureInfo.CurrentCulture);
|
||||
|
||||
if(baseFilename != macName && baseFilename != dosName && baseFilename != dosNameLow)
|
||||
continue;
|
||||
if(baseFilename != macName && baseFilename != dosName && baseFilename != dosNameLow) continue;
|
||||
|
||||
dataFound |=
|
||||
File.Exists(System.IO.Path.Combine(parentFolder, macName ?? throw new InvalidOperationException())) ||
|
||||
@@ -186,7 +184,8 @@ public sealed class PcExchange : IFilter
|
||||
|
||||
parentFolder ??= "";
|
||||
|
||||
var finderDatStream = new FileStream(System.IO.Path.Combine(parentFolder, FINDER_INFO), FileMode.Open,
|
||||
var finderDatStream = new FileStream(System.IO.Path.Combine(parentFolder, FINDER_INFO),
|
||||
FileMode.Open,
|
||||
FileAccess.Read);
|
||||
|
||||
while(finderDatStream.Position + 0x5C <= finderDatStream.Length)
|
||||
@@ -209,8 +208,7 @@ public sealed class PcExchange : IFilter
|
||||
|
||||
string dosNameLow = dosName.ToLower(CultureInfo.CurrentCulture);
|
||||
|
||||
if(baseFilename != macName && baseFilename != dosName && baseFilename != dosNameLow)
|
||||
continue;
|
||||
if(baseFilename != macName && baseFilename != dosName && baseFilename != dosNameLow) continue;
|
||||
|
||||
if(File.Exists(System.IO.Path.Combine(parentFolder, macName ?? throw new InvalidOperationException())))
|
||||
_dataPath = System.IO.Path.Combine(parentFolder, macName);
|
||||
|
||||
@@ -97,8 +97,7 @@ public sealed class XZ : IFilter
|
||||
var buffer = new byte[6];
|
||||
var footer = new byte[2];
|
||||
|
||||
if(stream.Length < 8)
|
||||
return false;
|
||||
if(stream.Length < 8) return false;
|
||||
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
stream.EnsureRead(buffer, 0, 6);
|
||||
@@ -119,15 +118,13 @@ public sealed class XZ : IFilter
|
||||
/// <inheritdoc />
|
||||
public bool Identify(string path)
|
||||
{
|
||||
if(!File.Exists(path))
|
||||
return false;
|
||||
if(!File.Exists(path)) return false;
|
||||
|
||||
var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
var buffer = new byte[6];
|
||||
var footer = new byte[2];
|
||||
|
||||
if(stream.Length < 8)
|
||||
return false;
|
||||
if(stream.Length < 8) return false;
|
||||
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
stream.EnsureRead(buffer, 0, 6);
|
||||
@@ -206,8 +203,7 @@ public sealed class XZ : IFilter
|
||||
{
|
||||
get
|
||||
{
|
||||
if(BasePath?.EndsWith(".xz", StringComparison.InvariantCultureIgnoreCase) == true)
|
||||
return BasePath[..^3];
|
||||
if(BasePath?.EndsWith(".xz", StringComparison.InvariantCultureIgnoreCase) == true) return BasePath[..^3];
|
||||
|
||||
return BasePath?.EndsWith(".xzip", StringComparison.InvariantCultureIgnoreCase) == true
|
||||
? BasePath[..^5]
|
||||
@@ -266,8 +262,7 @@ public sealed class XZ : IFilter
|
||||
|
||||
while((buf[i++] & 0x80) == 0x80)
|
||||
{
|
||||
if(i >= sizeMax || buf[i] == 0x00)
|
||||
return 0;
|
||||
if(i >= sizeMax || buf[i] == 0x00) return 0;
|
||||
|
||||
num |= (ulong)(buf[i] & 0x7F) << i * 7;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user