Use error returning Open() in IFilter.

This commit is contained in:
2021-09-15 13:03:42 +01:00
parent 8982cfc8c9
commit 525fb0da2a
28 changed files with 172 additions and 177 deletions

View File

@@ -36,6 +36,7 @@ using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Helpers;
using Marshal = Aaru.Helpers.Marshal;
@@ -74,54 +75,50 @@ namespace Aaru.Filters
{
0x56, 0x41, 0x58, 0x20, 0x56, 0x4D, 0x53, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
};
string _basePath;
DateTime _creationTime;
Entry _dataFork;
Header _header;
string _headerPath;
DateTime _lastWriteTime;
bool _opened;
Entry _rsrcFork;
/// <inheritdoc />
public string Name => "AppleDouble";
/// <inheritdoc />
public Guid Id => new Guid("1B2165EE-C9DF-4B21-BBBB-9E5892B2DF4D");
public Guid Id => new("1B2165EE-C9DF-4B21-BBBB-9E5892B2DF4D");
/// <inheritdoc />
public string Author => "Natalia Portillo";
/// <inheritdoc />
public void Close() => _opened = false;
public void Close() {}
/// <inheritdoc />
public string GetBasePath() => _basePath;
public string BasePath { get; private set; }
/// <inheritdoc />
public DateTime GetCreationTime() => _creationTime;
public DateTime CreationTime { get; private set; }
/// <inheritdoc />
public long GetDataForkLength() => _dataFork.length;
public long DataForkLength => _dataFork.length;
/// <inheritdoc />
public Stream GetDataForkStream() => new FileStream(_basePath, FileMode.Open, FileAccess.Read);
public Stream GetDataForkStream() => new FileStream(BasePath, FileMode.Open, FileAccess.Read);
/// <inheritdoc />
public string GetFilename() => Path.GetFileName(_basePath);
public string Filename => System.IO.Path.GetFileName(BasePath);
/// <inheritdoc />
public DateTime GetLastWriteTime() => _lastWriteTime;
public DateTime LastWriteTime { get; private set; }
/// <inheritdoc />
public long GetLength() => _dataFork.length + _rsrcFork.length;
public long Length => _dataFork.length + _rsrcFork.length;
/// <inheritdoc />
public string GetParentFolder() => Path.GetDirectoryName(_basePath);
public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath);
/// <inheritdoc />
public string GetPath() => _basePath;
public string Path => BasePath;
/// <inheritdoc />
public long GetResourceForkLength() => _rsrcFork.length;
public long ResourceForkLength => _rsrcFork.length;
/// <inheritdoc />
public Stream GetResourceForkStream()
@@ -134,7 +131,7 @@ namespace Aaru.Filters
}
/// <inheritdoc />
public bool HasResourceFork() => _rsrcFork.length > 0;
public bool HasResourceFork => _rsrcFork.length > 0;
/// <inheritdoc />
public bool Identify(byte[] buffer) => false;
@@ -145,9 +142,9 @@ namespace Aaru.Filters
/// <inheritdoc />
public bool Identify(string path)
{
string filename = Path.GetFileName(path);
string filenameNoExt = Path.GetFileNameWithoutExtension(path);
string parentFolder = Path.GetDirectoryName(path);
string filename = System.IO.Path.GetFileName(path);
string filenameNoExt = System.IO.Path.GetFileNameWithoutExtension(path);
string parentFolder = System.IO.Path.GetDirectoryName(path);
parentFolder ??= "";
@@ -156,28 +153,28 @@ namespace Aaru.Filters
return false;
// Prepend data fork name with "R."
string proDosAppleDouble = Path.Combine(parentFolder, "R." + filename);
string proDosAppleDouble = System.IO.Path.Combine(parentFolder, "R." + filename);
// Prepend data fork name with '%'
string unixAppleDouble = Path.Combine(parentFolder, "%" + filename);
string unixAppleDouble = System.IO.Path.Combine(parentFolder, "%" + filename);
// Change file extension to ADF
string dosAppleDouble = Path.Combine(parentFolder, filenameNoExt + ".ADF");
string dosAppleDouble = System.IO.Path.Combine(parentFolder, filenameNoExt + ".ADF");
// Change file extension to adf
string dosAppleDoubleLower = Path.Combine(parentFolder, filenameNoExt + ".adf");
string dosAppleDoubleLower = System.IO.Path.Combine(parentFolder, filenameNoExt + ".adf");
// Store AppleDouble header file in ".AppleDouble" folder with same name
string netatalkAppleDouble = Path.Combine(parentFolder, ".AppleDouble", filename);
string netatalkAppleDouble = System.IO.Path.Combine(parentFolder, ".AppleDouble", filename);
// Store AppleDouble header file in "resource.frk" folder with same name
string daveAppleDouble = Path.Combine(parentFolder, "resource.frk", filename);
string daveAppleDouble = System.IO.Path.Combine(parentFolder, "resource.frk", filename);
// Prepend data fork name with "._"
string osxAppleDouble = Path.Combine(parentFolder, "._" + filename);
string osxAppleDouble = System.IO.Path.Combine(parentFolder, "._" + filename);
// Adds ".rsrc" extension
string unArAppleDouble = Path.Combine(parentFolder, filename + ".rsrc");
string unArAppleDouble = System.IO.Path.Combine(parentFolder, filename + ".rsrc");
// Check AppleDouble created by A/UX in ProDOS filesystem
if(File.Exists(proDosAppleDouble))
@@ -322,53 +319,50 @@ namespace Aaru.Filters
return _header.magic == MAGIC && (_header.version == VERSION || _header.version == VERSION2);
}
/// <inheritdoc />
public bool IsOpened() => _opened;
// Now way to have two files in a single byte array
/// <inheritdoc />
public void Open(byte[] buffer) => throw new NotSupportedException();
public Errno Open(byte[] buffer) => Errno.NotSupported;
// Now way to have two files in a single stream
/// <inheritdoc />
public void Open(Stream stream) => throw new NotSupportedException();
public Errno Open(Stream stream) => Errno.NotSupported;
/// <inheritdoc />
public void Open(string path)
public Errno Open(string path)
{
string filename = Path.GetFileName(path);
string filenameNoExt = Path.GetFileNameWithoutExtension(path);
string parentFolder = Path.GetDirectoryName(path);
string filename = System.IO.Path.GetFileName(path);
string filenameNoExt = System.IO.Path.GetFileNameWithoutExtension(path);
string parentFolder = System.IO.Path.GetDirectoryName(path);
parentFolder ??= "";
if(filename is null ||
filenameNoExt is null)
throw new ArgumentNullException(nameof(path));
return Errno.InvalidArgument;
// Prepend data fork name with "R."
string proDosAppleDouble = Path.Combine(parentFolder, "R." + filename);
string proDosAppleDouble = System.IO.Path.Combine(parentFolder, "R." + filename);
// Prepend data fork name with '%'
string unixAppleDouble = Path.Combine(parentFolder, "%" + filename);
string unixAppleDouble = System.IO.Path.Combine(parentFolder, "%" + filename);
// Change file extension to ADF
string dosAppleDouble = Path.Combine(parentFolder, filenameNoExt + ".ADF");
string dosAppleDouble = System.IO.Path.Combine(parentFolder, filenameNoExt + ".ADF");
// Change file extension to adf
string dosAppleDoubleLower = Path.Combine(parentFolder, filenameNoExt + ".adf");
string dosAppleDoubleLower = System.IO.Path.Combine(parentFolder, filenameNoExt + ".adf");
// Store AppleDouble header file in ".AppleDouble" folder with same name
string netatalkAppleDouble = Path.Combine(parentFolder, ".AppleDouble", filename);
string netatalkAppleDouble = System.IO.Path.Combine(parentFolder, ".AppleDouble", filename);
// Store AppleDouble header file in "resource.frk" folder with same name
string daveAppleDouble = Path.Combine(parentFolder, "resource.frk", filename);
string daveAppleDouble = System.IO.Path.Combine(parentFolder, "resource.frk", filename);
// Prepend data fork name with "._"
string osxAppleDouble = Path.Combine(parentFolder, "._" + filename);
string osxAppleDouble = System.IO.Path.Combine(parentFolder, "._" + filename);
// Adds ".rsrc" extension
string unArAppleDouble = Path.Combine(parentFolder, filename + ".rsrc");
string unArAppleDouble = System.IO.Path.Combine(parentFolder, filename + ".rsrc");
// Check AppleDouble created by A/UX in ProDOS filesystem
if(File.Exists(proDosAppleDouble))
@@ -514,6 +508,10 @@ namespace Aaru.Filters
}
}
// TODO: More appropriate error
if(_headerPath is null)
return Errno.NotSupported;
var fs = new FileStream(_headerPath, FileMode.Open, FileAccess.Read);
fs.Seek(0, SeekOrigin.Begin);
@@ -530,8 +528,8 @@ namespace Aaru.Filters
entries[i] = Marshal.ByteArrayToStructureBigEndian<Entry>(entry);
}
_creationTime = DateTime.UtcNow;
_lastWriteTime = _creationTime;
CreationTime = DateTime.UtcNow;
LastWriteTime = CreationTime;
foreach(Entry entry in entries)
switch((EntryId)entry.id)
@@ -546,8 +544,8 @@ namespace Aaru.Filters
FileDates dates = Marshal.ByteArrayToStructureBigEndian<FileDates>(datesB);
_creationTime = DateHandlers.UnixUnsignedToDateTime(dates.creationDate);
_lastWriteTime = DateHandlers.UnixUnsignedToDateTime(dates.modificationDate);
CreationTime = DateHandlers.UnixUnsignedToDateTime(dates.creationDate);
LastWriteTime = DateHandlers.UnixUnsignedToDateTime(dates.modificationDate);
break;
case EntryId.FileInfo:
@@ -559,28 +557,28 @@ namespace Aaru.Filters
{
MacFileInfo macinfo = Marshal.ByteArrayToStructureBigEndian<MacFileInfo>(finfo);
_creationTime = DateHandlers.MacToDateTime(macinfo.creationDate);
_lastWriteTime = DateHandlers.MacToDateTime(macinfo.modificationDate);
CreationTime = DateHandlers.MacToDateTime(macinfo.creationDate);
LastWriteTime = DateHandlers.MacToDateTime(macinfo.modificationDate);
}
else if(_proDosHome.SequenceEqual(_header.homeFilesystem))
{
ProDOSFileInfo prodosinfo = Marshal.ByteArrayToStructureBigEndian<ProDOSFileInfo>(finfo);
_creationTime = DateHandlers.MacToDateTime(prodosinfo.creationDate);
_lastWriteTime = DateHandlers.MacToDateTime(prodosinfo.modificationDate);
CreationTime = DateHandlers.MacToDateTime(prodosinfo.creationDate);
LastWriteTime = DateHandlers.MacToDateTime(prodosinfo.modificationDate);
}
else if(_unixHome.SequenceEqual(_header.homeFilesystem))
{
UnixFileInfo unixinfo = Marshal.ByteArrayToStructureBigEndian<UnixFileInfo>(finfo);
_creationTime = DateHandlers.UnixUnsignedToDateTime(unixinfo.creationDate);
_lastWriteTime = DateHandlers.UnixUnsignedToDateTime(unixinfo.modificationDate);
CreationTime = DateHandlers.UnixUnsignedToDateTime(unixinfo.creationDate);
LastWriteTime = DateHandlers.UnixUnsignedToDateTime(unixinfo.modificationDate);
}
else if(_dosHome.SequenceEqual(_header.homeFilesystem))
{
DOSFileInfo dosinfo = Marshal.ByteArrayToStructureBigEndian<DOSFileInfo>(finfo);
_lastWriteTime =
LastWriteTime =
DateHandlers.DosToDateTime(dosinfo.modificationDate, dosinfo.modificationTime);
}
@@ -604,8 +602,9 @@ namespace Aaru.Filters
}
fs.Close();
_opened = true;
_basePath = path;
BasePath = path;
return Errno.NoError;
}
enum EntryId : uint

View File

@@ -36,6 +36,7 @@ using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Helpers;
using Marshal = Aaru.Helpers.Marshal;
@@ -96,7 +97,6 @@ namespace Aaru.Filters
_isBytes = false;
_isStream = false;
_isPath = false;
Opened = false;
}
/// <inheritdoc />
@@ -217,10 +217,7 @@ namespace Aaru.Filters
}
/// <inheritdoc />
public bool Opened { get; private set; }
/// <inheritdoc />
public void Open(byte[] buffer)
public Errno Open(byte[] buffer)
{
var ms = new MemoryStream(buffer);
ms.Seek(0, SeekOrigin.Begin);
@@ -301,13 +298,14 @@ namespace Aaru.Filters
}
ms.Close();
Opened = true;
_isBytes = true;
_bytes = buffer;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(Stream stream)
public Errno Open(Stream stream)
{
stream.Seek(0, SeekOrigin.Begin);
@@ -387,13 +385,14 @@ namespace Aaru.Filters
}
stream.Seek(0, SeekOrigin.Begin);
Opened = true;
_isStream = true;
_stream = stream;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(string path)
public Errno Open(string path)
{
var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
fs.Seek(0, SeekOrigin.Begin);
@@ -474,9 +473,10 @@ namespace Aaru.Filters
}
fs.Close();
Opened = true;
_isPath = true;
BasePath = path;
return Errno.NoError;
}
enum AppleSingleEntryID : uint

View File

@@ -33,6 +33,7 @@
using System;
using System.IO;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using SharpCompress.Compressors;
using SharpCompress.Compressors.BZip2;
@@ -58,7 +59,6 @@ namespace Aaru.Filters
_dataStream?.Close();
_dataStream = null;
BasePath = null;
Opened = false;
}
/// <inheritdoc />
@@ -151,7 +151,7 @@ namespace Aaru.Filters
}
/// <inheritdoc />
public void Open(byte[] buffer)
public Errno Open(byte[] buffer)
{
_dataStream = new MemoryStream(buffer);
BasePath = null;
@@ -159,11 +159,12 @@ namespace Aaru.Filters
LastWriteTime = CreationTime;
_innerStream = new ForcedSeekStream<BZip2Stream>(_dataStream, CompressionMode.Decompress, false);
DataForkLength = _innerStream.Length;
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(Stream stream)
public Errno Open(Stream stream)
{
_dataStream = stream;
BasePath = null;
@@ -171,11 +172,12 @@ namespace Aaru.Filters
LastWriteTime = CreationTime;
_innerStream = new ForcedSeekStream<BZip2Stream>(_dataStream, CompressionMode.Decompress, false);
DataForkLength = _innerStream.Length;
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(string path)
public Errno Open(string path)
{
_dataStream = new FileStream(path, FileMode.Open, FileAccess.Read);
BasePath = System.IO.Path.GetFullPath(path);
@@ -185,7 +187,8 @@ namespace Aaru.Filters
LastWriteTime = fi.LastWriteTimeUtc;
_innerStream = new ForcedSeekStream<BZip2Stream>(_dataStream, CompressionMode.Decompress, false);
DataForkLength = _innerStream.Length;
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
@@ -218,8 +221,5 @@ namespace Aaru.Filters
/// <inheritdoc />
public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath);
/// <inheritdoc />
public bool Opened { get; private set; }
}
}

View File

@@ -34,6 +34,7 @@ using System;
using System.IO;
using System.IO.Compression;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Helpers;
namespace Aaru.Filters
@@ -59,7 +60,6 @@ namespace Aaru.Filters
_dataStream?.Close();
_dataStream = null;
BasePath = null;
Opened = false;
}
/// <inheritdoc />
@@ -109,7 +109,7 @@ namespace Aaru.Filters
}
/// <inheritdoc />
public void Open(byte[] buffer)
public Errno Open(byte[] buffer)
{
byte[] mtimeB = new byte[4];
byte[] isizeB = new byte[4];
@@ -132,11 +132,11 @@ namespace Aaru.Filters
_zStream = new ForcedSeekStream<GZipStream>(_decompressedSize, _dataStream, CompressionMode.Decompress);
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(Stream stream)
public Errno Open(Stream stream)
{
byte[] mtimeB = new byte[4];
byte[] isizeB = new byte[4];
@@ -159,11 +159,11 @@ namespace Aaru.Filters
_zStream = new ForcedSeekStream<GZipStream>(_decompressedSize, _dataStream, CompressionMode.Decompress);
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(string path)
public Errno Open(string path)
{
byte[] mtimeB = new byte[4];
byte[] isizeB = new byte[4];
@@ -185,7 +185,8 @@ namespace Aaru.Filters
CreationTime = fi.CreationTimeUtc;
LastWriteTime = DateHandlers.UnixUnsignedToDateTime(mtime);
_zStream = new ForcedSeekStream<GZipStream>(_decompressedSize, _dataStream, CompressionMode.Decompress);
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
@@ -218,8 +219,5 @@ namespace Aaru.Filters
/// <inheritdoc />
public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath);
/// <inheritdoc />
public bool Opened { get; private set; }
}
}

View File

@@ -33,6 +33,7 @@
using System;
using System.IO;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using SharpCompress.Compressors;
using SharpCompress.Compressors.LZMA;
@@ -58,7 +59,6 @@ namespace Aaru.Filters
_dataStream?.Close();
_dataStream = null;
BasePath = null;
Opened = false;
}
/// <inheritdoc />
@@ -111,7 +111,7 @@ namespace Aaru.Filters
}
/// <inheritdoc />
public void Open(byte[] buffer)
public Errno Open(byte[] buffer)
{
_dataStream = new MemoryStream(buffer);
BasePath = null;
@@ -121,11 +121,11 @@ namespace Aaru.Filters
_innerStream = new ForcedSeekStream<LZipStream>(DataForkLength, _dataStream, CompressionMode.Decompress);
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(Stream stream)
public Errno Open(Stream stream)
{
_dataStream = stream;
BasePath = null;
@@ -137,11 +137,12 @@ namespace Aaru.Filters
DataForkLength = BitConverter.ToInt64(tmp, 0);
_dataStream.Seek(0, SeekOrigin.Begin);
_innerStream = new ForcedSeekStream<LZipStream>(DataForkLength, _dataStream, CompressionMode.Decompress);
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(string path)
public Errno Open(string path)
{
_dataStream = new FileStream(path, FileMode.Open, FileAccess.Read);
BasePath = System.IO.Path.GetFullPath(path);
@@ -155,7 +156,8 @@ namespace Aaru.Filters
DataForkLength = BitConverter.ToInt64(tmp, 0);
_dataStream.Seek(0, SeekOrigin.Begin);
_innerStream = new ForcedSeekStream<LZipStream>(DataForkLength, _dataStream, CompressionMode.Decompress);
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
@@ -188,8 +190,5 @@ namespace Aaru.Filters
/// <inheritdoc />
public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath);
/// <inheritdoc />
public bool Opened { get; private set; }
}
}

View File

@@ -35,6 +35,7 @@ using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Helpers;
using Marshal = Aaru.Helpers.Marshal;
@@ -68,7 +69,6 @@ namespace Aaru.Filters
_isBytes = false;
_isStream = false;
_isPath = false;
Opened = false;
}
/// <inheritdoc />
@@ -198,10 +198,7 @@ namespace Aaru.Filters
}
/// <inheritdoc />
public bool Opened { get; private set; }
/// <inheritdoc />
public void Open(byte[] buffer)
public Errno Open(byte[] buffer)
{
var ms = new MemoryStream(buffer);
ms.Seek(0, SeekOrigin.Begin);
@@ -229,13 +226,14 @@ namespace Aaru.Filters
LastWriteTime = DateHandlers.MacToDateTime(_header.modificationTime);
ms.Close();
Opened = true;
_isBytes = true;
_bytes = buffer;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(Stream stream)
public Errno Open(Stream stream)
{
stream.Seek(0, SeekOrigin.Begin);
@@ -262,13 +260,14 @@ namespace Aaru.Filters
LastWriteTime = DateHandlers.MacToDateTime(_header.modificationTime);
stream.Seek(0, SeekOrigin.Begin);
Opened = true;
_isStream = true;
_stream = stream;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(string path)
public Errno Open(string path)
{
var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
fs.Seek(0, SeekOrigin.Begin);
@@ -296,9 +295,10 @@ namespace Aaru.Filters
LastWriteTime = DateHandlers.MacToDateTime(_header.modificationTime);
fs.Close();
Opened = true;
_isPath = true;
BasePath = path;
return Errno.NoError;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]

View File

@@ -38,6 +38,7 @@ using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Helpers;
using Marshal = System.Runtime.InteropServices.Marshal;
@@ -62,7 +63,7 @@ namespace Aaru.Filters
public string Author => "Natalia Portillo";
/// <inheritdoc />
public void Close() => Opened = false;
public void Close() {}
/// <inheritdoc />
public string BasePath { get; private set; }
@@ -170,16 +171,13 @@ namespace Aaru.Filters
}
/// <inheritdoc />
public bool Opened { get; private set; }
public Errno Open(byte[] buffer) => Errno.NotSupported;
/// <inheritdoc />
public void Open(byte[] buffer) => throw new NotSupportedException();
public Errno Open(Stream stream) => Errno.NotSupported;
/// <inheritdoc />
public void Open(Stream stream) => throw new NotSupportedException();
/// <inheritdoc />
public void Open(string path)
public Errno Open(string path)
{
string parentFolder = System.IO.Path.GetDirectoryName(path);
string baseFilename = System.IO.Path.GetFileName(path);
@@ -239,9 +237,10 @@ namespace Aaru.Filters
ResourceForkLength = new FileInfo(_rsrcPath ?? throw new InvalidOperationException()).Length;
BasePath = path;
Opened = true;
finderDatStream.Close();
return Errno.NoError;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]

View File

@@ -33,6 +33,7 @@
using System;
using System.IO;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using SharpCompress.Compressors.Xz;
namespace Aaru.Filters
@@ -57,7 +58,6 @@ namespace Aaru.Filters
_dataStream?.Close();
_dataStream = null;
BasePath = null;
Opened = false;
}
/// <inheritdoc />
@@ -123,7 +123,7 @@ namespace Aaru.Filters
}
/// <inheritdoc />
public void Open(byte[] buffer)
public Errno Open(byte[] buffer)
{
_dataStream = new MemoryStream(buffer);
BasePath = null;
@@ -131,11 +131,12 @@ namespace Aaru.Filters
LastWriteTime = CreationTime;
GuessSize();
_innerStream = new ForcedSeekStream<XZStream>(DataForkLength, _dataStream);
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(Stream stream)
public Errno Open(Stream stream)
{
_dataStream = stream;
BasePath = null;
@@ -143,11 +144,12 @@ namespace Aaru.Filters
LastWriteTime = CreationTime;
GuessSize();
_innerStream = new ForcedSeekStream<XZStream>(DataForkLength, _dataStream);
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(string path)
public Errno Open(string path)
{
_dataStream = new FileStream(path, FileMode.Open, FileAccess.Read);
BasePath = System.IO.Path.GetFullPath(path);
@@ -157,7 +159,8 @@ namespace Aaru.Filters
LastWriteTime = fi.LastWriteTimeUtc;
GuessSize();
_innerStream = new ForcedSeekStream<XZStream>(DataForkLength, _dataStream);
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
@@ -191,9 +194,6 @@ namespace Aaru.Filters
/// <inheritdoc />
public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath);
/// <inheritdoc />
public bool Opened { get; private set; }
void GuessSize()
{
DataForkLength = 0;

View File

@@ -33,6 +33,7 @@
using System;
using System.IO;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
namespace Aaru.Filters
{
@@ -55,7 +56,6 @@ namespace Aaru.Filters
_dataStream?.Close();
_dataStream = null;
BasePath = null;
Opened = false;
}
/// <inheritdoc />
@@ -83,34 +83,37 @@ namespace Aaru.Filters
public bool Identify(string path) => File.Exists(path);
/// <inheritdoc />
public void Open(byte[] buffer)
public Errno Open(byte[] buffer)
{
_dataStream = new MemoryStream(buffer);
BasePath = null;
CreationTime = DateTime.UtcNow;
LastWriteTime = CreationTime;
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(Stream stream)
public Errno Open(Stream stream)
{
_dataStream = stream;
BasePath = null;
CreationTime = DateTime.UtcNow;
LastWriteTime = CreationTime;
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
public void Open(string path)
public Errno Open(string path)
{
_dataStream = new FileStream(path, FileMode.Open, FileAccess.Read);
BasePath = System.IO.Path.GetFullPath(path);
var fi = new FileInfo(path);
CreationTime = fi.CreationTimeUtc;
LastWriteTime = fi.LastWriteTimeUtc;
Opened = true;
return Errno.NoError;
}
/// <inheritdoc />
@@ -133,8 +136,5 @@ namespace Aaru.Filters
/// <inheritdoc />
public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath);
/// <inheritdoc />
public bool Opened { get; private set; }
}
}

View File

@@ -37,6 +37,7 @@ using System.IO;
using System.Linq;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Console;
using Aaru.Filters;
using Aaru.Helpers;
@@ -126,9 +127,8 @@ namespace Aaru.DiscImages
}
var trackFilter = new ZZZNoFilter();
trackFilter.Open(trackfile);
if(!trackFilter.Opened)
if(trackFilter.Open(trackfile) != Errno.NoError)
throw new IOException("Could not open KryoFlux track file.");
_imageInfo.CreationTime = DateTime.MaxValue;

View File

@@ -369,7 +369,7 @@ namespace Aaru.DiscImages
var filters = new FiltersList();
IFilter filter = filters.GetFilter(basename + sidecar.name);
if(filter.Opened != true)
if(filter is null)
continue;
AaruConsole.DebugWriteLine("ZZZRawImage Plugin", "Found media tag {0}", sidecar.tag);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Filters;
using NUnit.Framework;
@@ -103,8 +104,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new AppleDouble();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(737280, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Filters;
using NUnit.Framework;
@@ -101,8 +102,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new AppleDouble();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(737280, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Filters;
using NUnit.Framework;
@@ -103,8 +104,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new AppleDouble();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(737280, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Filters;
using NUnit.Framework;
@@ -101,8 +102,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new AppleDouble();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(737280, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Filters;
using NUnit.Framework;
@@ -101,8 +102,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new AppleDouble();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(737280, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Filters;
using NUnit.Framework;
@@ -101,8 +102,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new AppleDouble();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(737280, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Filters;
using NUnit.Framework;
@@ -101,8 +102,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new AppleDouble();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(737280, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using NUnit.Framework;
namespace Aaru.Tests.Filters
@@ -92,8 +93,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new Aaru.Filters.AppleSingle();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(737280, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using NUnit.Framework;
namespace Aaru.Tests.Filters
@@ -81,8 +82,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new Aaru.Filters.BZip2();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(1048576, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(0, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using NUnit.Framework;
namespace Aaru.Tests.Filters
@@ -81,8 +82,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new Aaru.Filters.GZip();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(1048576, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(0, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using NUnit.Framework;
namespace Aaru.Tests.Filters
@@ -81,8 +82,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new Aaru.Filters.LZip();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(1048576, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(0, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Filters;
using NUnit.Framework;
@@ -93,8 +94,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new MacBinary();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(737280, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Filters;
using NUnit.Framework;
@@ -93,8 +94,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new MacBinary();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(737280, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Filters;
using NUnit.Framework;
@@ -93,8 +94,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new MacBinary();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(737280, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using NUnit.Framework;
namespace Aaru.Tests.Filters
@@ -94,8 +95,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new Aaru.Filters.PcExchange();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(737280, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(546, filter.ResourceForkLength);

View File

@@ -29,6 +29,7 @@
using System.IO;
using Aaru.Checksums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Filters;
using NUnit.Framework;
@@ -82,8 +83,7 @@ namespace Aaru.Tests.Filters
public void Test()
{
IFilter filter = new XZ();
filter.Open(_location);
Assert.AreEqual(true, filter.Opened);
Assert.AreEqual(Errno.NoError, filter.Open(_location));
Assert.AreEqual(1048576, filter.DataForkLength);
Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(0, filter.ResourceForkLength);