From 525fb0da2a6f22da16b80468ca1a7e3ac88814e2 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 15 Sep 2021 13:03:42 +0100 Subject: [PATCH] Use error returning Open() in IFilter. --- Aaru.CommonTypes | 2 +- Aaru.Filters/AppleDouble.cs | 125 +++++++++++----------- Aaru.Filters/AppleSingle.cs | 20 ++-- Aaru.Filters/BZip2.cs | 20 ++-- Aaru.Filters/GZip.cs | 18 ++-- Aaru.Filters/LZip.cs | 19 ++-- Aaru.Filters/MacBinary.cs | 20 ++-- Aaru.Filters/PCExchange.cs | 15 ++- Aaru.Filters/XZ.cs | 20 ++-- Aaru.Filters/ZZZNoFilter.cs | 20 ++-- Aaru.Images/KryoFlux/Read.cs | 4 +- Aaru.Images/ZZZRawImage/Read.cs | 2 +- Aaru.Tests/Filters/AppleDoubleDave.cs | 4 +- Aaru.Tests/Filters/AppleDoubleDos.cs | 4 +- Aaru.Tests/Filters/AppleDoubleNetatalk.cs | 4 +- Aaru.Tests/Filters/AppleDoubleOsX.cs | 4 +- Aaru.Tests/Filters/AppleDoubleProDos.cs | 4 +- Aaru.Tests/Filters/AppleDoubleUnAr.cs | 4 +- Aaru.Tests/Filters/AppleDoubleUnix.cs | 4 +- Aaru.Tests/Filters/AppleSingle.cs | 4 +- Aaru.Tests/Filters/BZip2.cs | 4 +- Aaru.Tests/Filters/GZip.cs | 4 +- Aaru.Tests/Filters/LZip.cs | 4 +- Aaru.Tests/Filters/MacBinary1.cs | 4 +- Aaru.Tests/Filters/MacBinary2.cs | 4 +- Aaru.Tests/Filters/MacBinary3.cs | 4 +- Aaru.Tests/Filters/PCExchange.cs | 4 +- Aaru.Tests/Filters/XZ.cs | 4 +- 28 files changed, 172 insertions(+), 177 deletions(-) diff --git a/Aaru.CommonTypes b/Aaru.CommonTypes index 2631f4308..2f1d93ffa 160000 --- a/Aaru.CommonTypes +++ b/Aaru.CommonTypes @@ -1 +1 @@ -Subproject commit 2631f4308be47cad47e802af1f7ea648063f51ca +Subproject commit 2f1d93ffa76621527d0710fbab216e8199898dc3 diff --git a/Aaru.Filters/AppleDouble.cs b/Aaru.Filters/AppleDouble.cs index dce5593ec..b618319a0 100644 --- a/Aaru.Filters/AppleDouble.cs +++ b/Aaru.Filters/AppleDouble.cs @@ -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; + Entry _dataFork; + Header _header; + string _headerPath; + Entry _rsrcFork; /// public string Name => "AppleDouble"; /// - public Guid Id => new Guid("1B2165EE-C9DF-4B21-BBBB-9E5892B2DF4D"); + public Guid Id => new("1B2165EE-C9DF-4B21-BBBB-9E5892B2DF4D"); /// public string Author => "Natalia Portillo"; /// - public void Close() => _opened = false; + public void Close() {} /// - public string GetBasePath() => _basePath; + public string BasePath { get; private set; } /// - public DateTime GetCreationTime() => _creationTime; + public DateTime CreationTime { get; private set; } /// - public long GetDataForkLength() => _dataFork.length; + public long DataForkLength => _dataFork.length; /// - public Stream GetDataForkStream() => new FileStream(_basePath, FileMode.Open, FileAccess.Read); + public Stream GetDataForkStream() => new FileStream(BasePath, FileMode.Open, FileAccess.Read); /// - public string GetFilename() => Path.GetFileName(_basePath); + public string Filename => System.IO.Path.GetFileName(BasePath); /// - public DateTime GetLastWriteTime() => _lastWriteTime; + public DateTime LastWriteTime { get; private set; } /// - public long GetLength() => _dataFork.length + _rsrcFork.length; + public long Length => _dataFork.length + _rsrcFork.length; /// - public string GetParentFolder() => Path.GetDirectoryName(_basePath); + public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath); /// - public string GetPath() => _basePath; + public string Path => BasePath; /// - public long GetResourceForkLength() => _rsrcFork.length; + public long ResourceForkLength => _rsrcFork.length; /// public Stream GetResourceForkStream() @@ -134,7 +131,7 @@ namespace Aaru.Filters } /// - public bool HasResourceFork() => _rsrcFork.length > 0; + public bool HasResourceFork => _rsrcFork.length > 0; /// public bool Identify(byte[] buffer) => false; @@ -145,9 +142,9 @@ namespace Aaru.Filters /// 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); } - /// - public bool IsOpened() => _opened; - // Now way to have two files in a single byte array /// - 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 /// - public void Open(Stream stream) => throw new NotSupportedException(); + public Errno Open(Stream stream) => Errno.NotSupported; /// - 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); } - _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(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(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(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(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(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 diff --git a/Aaru.Filters/AppleSingle.cs b/Aaru.Filters/AppleSingle.cs index 99b9b9f1c..5e51c185c 100644 --- a/Aaru.Filters/AppleSingle.cs +++ b/Aaru.Filters/AppleSingle.cs @@ -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; } /// @@ -217,10 +217,7 @@ namespace Aaru.Filters } /// - public bool Opened { get; private set; } - - /// - 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; } /// - 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; } /// - 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 diff --git a/Aaru.Filters/BZip2.cs b/Aaru.Filters/BZip2.cs index f32d82a9f..54234627a 100644 --- a/Aaru.Filters/BZip2.cs +++ b/Aaru.Filters/BZip2.cs @@ -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; } /// @@ -151,7 +151,7 @@ namespace Aaru.Filters } /// - 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(_dataStream, CompressionMode.Decompress, false); DataForkLength = _innerStream.Length; - Opened = true; + + return Errno.NoError; } /// - 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(_dataStream, CompressionMode.Decompress, false); DataForkLength = _innerStream.Length; - Opened = true; + + return Errno.NoError; } /// - 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(_dataStream, CompressionMode.Decompress, false); DataForkLength = _innerStream.Length; - Opened = true; + + return Errno.NoError; } /// @@ -218,8 +221,5 @@ namespace Aaru.Filters /// public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath); - - /// - public bool Opened { get; private set; } } } \ No newline at end of file diff --git a/Aaru.Filters/GZip.cs b/Aaru.Filters/GZip.cs index b1e5aa99d..445d2ae9c 100644 --- a/Aaru.Filters/GZip.cs +++ b/Aaru.Filters/GZip.cs @@ -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; } /// @@ -109,7 +109,7 @@ namespace Aaru.Filters } /// - 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(_decompressedSize, _dataStream, CompressionMode.Decompress); - Opened = true; + return Errno.NoError; } /// - 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(_decompressedSize, _dataStream, CompressionMode.Decompress); - Opened = true; + return Errno.NoError; } /// - 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(_decompressedSize, _dataStream, CompressionMode.Decompress); - Opened = true; + + return Errno.NoError; } /// @@ -218,8 +219,5 @@ namespace Aaru.Filters /// public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath); - - /// - public bool Opened { get; private set; } } } \ No newline at end of file diff --git a/Aaru.Filters/LZip.cs b/Aaru.Filters/LZip.cs index af0bcd561..5fcc7a6c7 100644 --- a/Aaru.Filters/LZip.cs +++ b/Aaru.Filters/LZip.cs @@ -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; } /// @@ -111,7 +111,7 @@ namespace Aaru.Filters } /// - 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(DataForkLength, _dataStream, CompressionMode.Decompress); - Opened = true; + return Errno.NoError; } /// - 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(DataForkLength, _dataStream, CompressionMode.Decompress); - Opened = true; + + return Errno.NoError; } /// - 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(DataForkLength, _dataStream, CompressionMode.Decompress); - Opened = true; + + return Errno.NoError; } /// @@ -188,8 +190,5 @@ namespace Aaru.Filters /// public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath); - - /// - public bool Opened { get; private set; } } } \ No newline at end of file diff --git a/Aaru.Filters/MacBinary.cs b/Aaru.Filters/MacBinary.cs index cac0416d9..bf4f774ff 100644 --- a/Aaru.Filters/MacBinary.cs +++ b/Aaru.Filters/MacBinary.cs @@ -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; } /// @@ -198,10 +198,7 @@ namespace Aaru.Filters } /// - public bool Opened { get; private set; } - - /// - 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; } /// - 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; } /// - 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)] diff --git a/Aaru.Filters/PCExchange.cs b/Aaru.Filters/PCExchange.cs index 9e8a51b13..3a22d9d2e 100644 --- a/Aaru.Filters/PCExchange.cs +++ b/Aaru.Filters/PCExchange.cs @@ -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"; /// - public void Close() => Opened = false; + public void Close() {} /// public string BasePath { get; private set; } @@ -170,16 +171,13 @@ namespace Aaru.Filters } /// - public bool Opened { get; private set; } + public Errno Open(byte[] buffer) => Errno.NotSupported; /// - public void Open(byte[] buffer) => throw new NotSupportedException(); + public Errno Open(Stream stream) => Errno.NotSupported; /// - public void Open(Stream stream) => throw new NotSupportedException(); - - /// - 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)] diff --git a/Aaru.Filters/XZ.cs b/Aaru.Filters/XZ.cs index 3c36b57b1..a7ae23b9d 100644 --- a/Aaru.Filters/XZ.cs +++ b/Aaru.Filters/XZ.cs @@ -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; } /// @@ -123,7 +123,7 @@ namespace Aaru.Filters } /// - 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(DataForkLength, _dataStream); - Opened = true; + + return Errno.NoError; } /// - 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(DataForkLength, _dataStream); - Opened = true; + + return Errno.NoError; } /// - 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(DataForkLength, _dataStream); - Opened = true; + + return Errno.NoError; } /// @@ -191,9 +194,6 @@ namespace Aaru.Filters /// public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath); - /// - public bool Opened { get; private set; } - void GuessSize() { DataForkLength = 0; diff --git a/Aaru.Filters/ZZZNoFilter.cs b/Aaru.Filters/ZZZNoFilter.cs index 8ea7fb626..38a2ee8c5 100644 --- a/Aaru.Filters/ZZZNoFilter.cs +++ b/Aaru.Filters/ZZZNoFilter.cs @@ -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; } /// @@ -83,34 +83,37 @@ namespace Aaru.Filters public bool Identify(string path) => File.Exists(path); /// - 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; } /// - public void Open(Stream stream) + public Errno Open(Stream stream) { _dataStream = stream; BasePath = null; CreationTime = DateTime.UtcNow; LastWriteTime = CreationTime; - Opened = true; + + return Errno.NoError; } /// - 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; } /// @@ -133,8 +136,5 @@ namespace Aaru.Filters /// public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath); - - /// - public bool Opened { get; private set; } } } \ No newline at end of file diff --git a/Aaru.Images/KryoFlux/Read.cs b/Aaru.Images/KryoFlux/Read.cs index 3e6c773b4..c4c6e261e 100644 --- a/Aaru.Images/KryoFlux/Read.cs +++ b/Aaru.Images/KryoFlux/Read.cs @@ -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; diff --git a/Aaru.Images/ZZZRawImage/Read.cs b/Aaru.Images/ZZZRawImage/Read.cs index a70b9050b..c134dd360 100644 --- a/Aaru.Images/ZZZRawImage/Read.cs +++ b/Aaru.Images/ZZZRawImage/Read.cs @@ -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); diff --git a/Aaru.Tests/Filters/AppleDoubleDave.cs b/Aaru.Tests/Filters/AppleDoubleDave.cs index 847f79b05..e36846725 100644 --- a/Aaru.Tests/Filters/AppleDoubleDave.cs +++ b/Aaru.Tests/Filters/AppleDoubleDave.cs @@ -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); diff --git a/Aaru.Tests/Filters/AppleDoubleDos.cs b/Aaru.Tests/Filters/AppleDoubleDos.cs index 9b82104a4..a3256cc6d 100644 --- a/Aaru.Tests/Filters/AppleDoubleDos.cs +++ b/Aaru.Tests/Filters/AppleDoubleDos.cs @@ -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); diff --git a/Aaru.Tests/Filters/AppleDoubleNetatalk.cs b/Aaru.Tests/Filters/AppleDoubleNetatalk.cs index 68e549725..83cad70ab 100644 --- a/Aaru.Tests/Filters/AppleDoubleNetatalk.cs +++ b/Aaru.Tests/Filters/AppleDoubleNetatalk.cs @@ -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); diff --git a/Aaru.Tests/Filters/AppleDoubleOsX.cs b/Aaru.Tests/Filters/AppleDoubleOsX.cs index 94ab243b5..7c06c3f0c 100644 --- a/Aaru.Tests/Filters/AppleDoubleOsX.cs +++ b/Aaru.Tests/Filters/AppleDoubleOsX.cs @@ -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); diff --git a/Aaru.Tests/Filters/AppleDoubleProDos.cs b/Aaru.Tests/Filters/AppleDoubleProDos.cs index 13442b88a..c49fac505 100644 --- a/Aaru.Tests/Filters/AppleDoubleProDos.cs +++ b/Aaru.Tests/Filters/AppleDoubleProDos.cs @@ -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); diff --git a/Aaru.Tests/Filters/AppleDoubleUnAr.cs b/Aaru.Tests/Filters/AppleDoubleUnAr.cs index 917ff8220..ba284b3d1 100644 --- a/Aaru.Tests/Filters/AppleDoubleUnAr.cs +++ b/Aaru.Tests/Filters/AppleDoubleUnAr.cs @@ -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); diff --git a/Aaru.Tests/Filters/AppleDoubleUnix.cs b/Aaru.Tests/Filters/AppleDoubleUnix.cs index 45d1d7ca4..070c43e80 100644 --- a/Aaru.Tests/Filters/AppleDoubleUnix.cs +++ b/Aaru.Tests/Filters/AppleDoubleUnix.cs @@ -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); diff --git a/Aaru.Tests/Filters/AppleSingle.cs b/Aaru.Tests/Filters/AppleSingle.cs index 14fbb1fb6..5705fb562 100644 --- a/Aaru.Tests/Filters/AppleSingle.cs +++ b/Aaru.Tests/Filters/AppleSingle.cs @@ -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); diff --git a/Aaru.Tests/Filters/BZip2.cs b/Aaru.Tests/Filters/BZip2.cs index 92f729d87..bce5693c4 100644 --- a/Aaru.Tests/Filters/BZip2.cs +++ b/Aaru.Tests/Filters/BZip2.cs @@ -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); diff --git a/Aaru.Tests/Filters/GZip.cs b/Aaru.Tests/Filters/GZip.cs index e409d23f2..878f2ea3c 100644 --- a/Aaru.Tests/Filters/GZip.cs +++ b/Aaru.Tests/Filters/GZip.cs @@ -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); diff --git a/Aaru.Tests/Filters/LZip.cs b/Aaru.Tests/Filters/LZip.cs index 141c66272..6564496ab 100644 --- a/Aaru.Tests/Filters/LZip.cs +++ b/Aaru.Tests/Filters/LZip.cs @@ -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); diff --git a/Aaru.Tests/Filters/MacBinary1.cs b/Aaru.Tests/Filters/MacBinary1.cs index 74fceee98..b264818d5 100644 --- a/Aaru.Tests/Filters/MacBinary1.cs +++ b/Aaru.Tests/Filters/MacBinary1.cs @@ -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); diff --git a/Aaru.Tests/Filters/MacBinary2.cs b/Aaru.Tests/Filters/MacBinary2.cs index 40294f2ea..477a14da1 100644 --- a/Aaru.Tests/Filters/MacBinary2.cs +++ b/Aaru.Tests/Filters/MacBinary2.cs @@ -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); diff --git a/Aaru.Tests/Filters/MacBinary3.cs b/Aaru.Tests/Filters/MacBinary3.cs index bd7c3e5c0..10208ac50 100644 --- a/Aaru.Tests/Filters/MacBinary3.cs +++ b/Aaru.Tests/Filters/MacBinary3.cs @@ -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); diff --git a/Aaru.Tests/Filters/PCExchange.cs b/Aaru.Tests/Filters/PCExchange.cs index 30e3ca71d..892e59cf5 100644 --- a/Aaru.Tests/Filters/PCExchange.cs +++ b/Aaru.Tests/Filters/PCExchange.cs @@ -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); diff --git a/Aaru.Tests/Filters/XZ.cs b/Aaru.Tests/Filters/XZ.cs index 63a5e2a0e..cc1e640e8 100644 --- a/Aaru.Tests/Filters/XZ.cs +++ b/Aaru.Tests/Filters/XZ.cs @@ -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);