2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2016-09-05 17:37:31 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : ZZZNoFilter.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-12-19 10:45:18 +00:00
|
|
|
// Copyright © 2011-2025 Natalia Portillo
|
2016-09-05 17:37:31 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2021-09-16 04:42:14 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Filters;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
/// <summary>No filter for reading files not recognized by any filter</summary>
|
|
|
|
|
public sealed class ZZZNoFilter : IFilter
|
2016-09-05 17:37:31 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
Stream _dataStream;
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2023-10-03 23:23:41 +01:00
|
|
|
#region IFilter Members
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
2022-11-28 10:15:47 +00:00
|
|
|
public string Name => Localization.ZZZNoFilter_Name;
|
2023-10-03 23:23:41 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Guid Id => new("12345678-AAAA-BBBB-CCCC-123456789000");
|
2023-10-03 23:23:41 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
2022-11-28 10:15:47 +00:00
|
|
|
public string Author => Authors.NataliaPortillo;
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
|
|
|
|
_dataStream?.Close();
|
|
|
|
|
_dataStream = null;
|
|
|
|
|
BasePath = null;
|
|
|
|
|
}
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public string BasePath { get; private set; }
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Stream GetDataForkStream() => _dataStream;
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public string Path => BasePath;
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Stream GetResourceForkStream() => null;
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public bool HasResourceFork => false;
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
2022-11-13 20:46:24 +00:00
|
|
|
public bool Identify(byte[] buffer) => buffer is { Length: > 0 };
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
2022-11-13 20:46:24 +00:00
|
|
|
public bool Identify(Stream stream) => stream is { Length: > 0 };
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public bool Identify(string path) => File.Exists(path);
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber Open(byte[] buffer)
|
|
|
|
|
{
|
|
|
|
|
_dataStream = new MemoryStream(buffer);
|
|
|
|
|
BasePath = null;
|
|
|
|
|
CreationTime = DateTime.UtcNow;
|
|
|
|
|
LastWriteTime = CreationTime;
|
2021-09-15 13:03:42 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber Open(Stream stream)
|
|
|
|
|
{
|
|
|
|
|
_dataStream = stream;
|
|
|
|
|
BasePath = null;
|
|
|
|
|
CreationTime = DateTime.UtcNow;
|
|
|
|
|
LastWriteTime = CreationTime;
|
2021-09-15 13:03:42 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
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;
|
2021-09-15 13:03:42 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public DateTime CreationTime { get; private set; }
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public long DataForkLength => _dataStream.Length;
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public DateTime LastWriteTime { get; private set; }
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public long Length => _dataStream.Length;
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public long ResourceForkLength => 0;
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public string Filename => System.IO.Path.GetFileName(BasePath);
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public string ParentFolder => System.IO.Path.GetDirectoryName(BasePath);
|
2023-10-03 23:23:41 +01:00
|
|
|
|
|
|
|
|
#endregion
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|