// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : ZZZNoFilter.cs // Author(s) : Natalia Portillo // // Component : Filters. // // --[ Description ] ---------------------------------------------------------- // // Provides a filter to open single files. // // --[ License ] -------------------------------------------------------------- // // This library is free software; you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 2.1 of the // License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, see . // // ---------------------------------------------------------------------------- // Copyright © 2011-2025 Natalia Portillo // ****************************************************************************/ using System; using System.IO; using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Interfaces; namespace Aaru.Filters; /// /// No filter for reading files not recognized by any filter public sealed class ZZZNoFilter : IFilter { Stream _dataStream; #region IFilter Members /// public string Name => Localization.ZZZNoFilter_Name; /// public Guid Id => new("12345678-AAAA-BBBB-CCCC-123456789000"); /// public string Author => Authors.NataliaPortillo; /// public void Close() { _dataStream?.Close(); _dataStream = null; BasePath = null; } /// public string BasePath { get; private set; } /// public Stream GetDataForkStream() => _dataStream; /// public string Path => BasePath; /// public Stream GetResourceForkStream() => null; /// public bool HasResourceFork => false; /// public bool Identify(byte[] buffer) => buffer is { Length: > 0 }; /// public bool Identify(Stream stream) => stream is { Length: > 0 }; /// public bool Identify(string path) => File.Exists(path); /// public ErrorNumber Open(byte[] buffer) { _dataStream = new MemoryStream(buffer); BasePath = null; CreationTime = DateTime.UtcNow; LastWriteTime = CreationTime; return ErrorNumber.NoError; } /// public ErrorNumber Open(Stream stream) { _dataStream = stream; BasePath = null; CreationTime = DateTime.UtcNow; LastWriteTime = CreationTime; return ErrorNumber.NoError; } /// public ErrorNumber 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; return ErrorNumber.NoError; } /// public DateTime CreationTime { get; private set; } /// public long DataForkLength => _dataStream.Length; /// public DateTime LastWriteTime { get; private set; } /// public long Length => _dataStream.Length; /// public long ResourceForkLength => 0; /// public string Filename => System.IO.Path.GetFileName(BasePath); /// public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath); #endregion }