Files
Aaru.CommonTypes/Interfaces/IArchive.cs

198 lines
10 KiB
C#
Raw Normal View History

2019-08-15 22:35:57 +02:00
// /***************************************************************************
2020-02-27 12:31:21 +00:00
// Aaru Data Preservation Suite
2019-08-15 22:35:57 +02:00
// ----------------------------------------------------------------------------
//
// Filename : IArchive.cs
// Author(s) : Michael Drüing <michael@drueing.de>
//
// Component : Archives.
//
// --[ Description ] ----------------------------------------------------------
//
2020-03-11 21:56:46 +00:00
// Defines the interface for implementing archive plugins.
2019-08-15 22:35:57 +02:00
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2018-2019 Michael Drüing
2020-01-03 17:51:28 +00:00
// Copyright © 2011-2020 Natalia Portillo
2019-08-15 22:35:57 +02:00
// ****************************************************************************/
using System;
using System.Collections.Generic;
2019-11-03 01:41:48 +00:00
using System.IO;
2019-08-15 22:35:57 +02:00
2020-02-27 00:33:15 +00:00
namespace Aaru.CommonTypes.Interfaces
2019-08-15 22:35:57 +02:00
{
[Flags]
public enum ArchiveSupportedFeature : uint
{
2019-11-03 01:41:48 +00:00
/// <summary>The archive supports filenames for its entries. If this flag is not set, files can only be accessed by number.</summary>
2020-02-29 18:03:24 +00:00
SupportsFilenames = 1 << 0,
/// <summary>
2019-11-03 01:41:48 +00:00
/// The archive supports compression. If this flag is not set, compressed and uncompressed lengths are always the
/// same.
2019-08-15 22:35:57 +02:00
/// </summary>
2020-02-29 18:03:24 +00:00
SupportsCompression = 1 << 1,
/// <summary>
2019-11-03 01:41:48 +00:00
/// The archive supports subdirectories. If this flag is not set, all filenames are guaranteed to not contain any
/// "/" character.
2019-08-15 22:35:57 +02:00
/// </summary>
2020-02-29 18:03:24 +00:00
SupportsSubdirectories = 1 << 2,
/// <summary>
2019-11-03 01:41:48 +00:00
/// The archive supports explicit entries for directories (like Zip, for example). If this flag is not set,
/// directories are implicit by the relative name of the files.
2019-08-15 22:35:57 +02:00
/// </summary>
2019-11-25 00:54:31 +00:00
HasExplicitDirectories = 1 << 3,
/// <summary>The archive stores a timestamp with each entry if this flag is set.</summary>
HasEntryTimestamp = 1 << 4,
/// <summary>If this flag is set, individual files or the whole archive might be encrypted or password-protected.</summary>
2019-11-03 01:41:48 +00:00
SupportsProtection = 1 << 5, // TODO: not implemented yet
2019-08-15 22:35:57 +02:00
2019-11-03 01:41:48 +00:00
/// <summary>If this flag is set, the archive supports returning extended attributes (Xattrs) for each entry.</summary>
SupportsXAttrs = 1 << 6
}
2019-08-15 22:35:57 +02:00
public interface IArchive
{
/// <summary>Descriptive name of the plugin</summary>
string Name { get; }
/// <summary>Unique UUID of the plugin</summary>
Guid Id { get; }
2019-11-03 01:41:48 +00:00
/// <summary>Identifies if the specified path contains data recognizable by this archive instance</summary>
2019-08-15 22:35:57 +02:00
/// <param name="path">Path.</param>
bool Identify(string path);
2019-11-03 01:41:48 +00:00
/// <summary>Identifies if the specified stream contains data recognizable by this archive instance</summary>
2019-08-15 22:35:57 +02:00
/// <param name="stream">Stream.</param>
bool Identify(Stream stream);
2019-11-03 01:41:48 +00:00
/// <summary>Identifies if the specified buffer contains data recognizable by this archive instance</summary>
2019-08-15 22:35:57 +02:00
/// <param name="buffer">Buffer.</param>
bool Identify(byte[] buffer);
2019-11-03 01:41:48 +00:00
/// <summary>Opens the specified path with this archive instance</summary>
2019-08-15 22:35:57 +02:00
/// <param name="path">Path.</param>
void Open(string path);
2019-11-03 01:41:48 +00:00
/// <summary>Opens the specified stream with this archive instance</summary>
2019-08-15 22:35:57 +02:00
/// <param name="stream">Stream.</param>
void Open(Stream stream);
2019-11-03 01:41:48 +00:00
/// <summary>Opens the specified buffer with this archive instance</summary>
2019-08-15 22:35:57 +02:00
/// <param name="buffer">Buffer.</param>
void Open(byte[] buffer);
/// <summary>
/// Returns true if the archive has a file/stream/buffer currently opened and no
/// <see cref="M:Aaru.Filters.Filter.Close" /> has been issued.
2019-08-15 22:35:57 +02:00
/// </summary>
bool IsOpened();
2019-11-03 01:41:48 +00:00
/// <summary>Closes all opened streams.</summary>
2019-08-15 22:35:57 +02:00
void Close();
2019-11-03 01:41:48 +00:00
/// <summary>Return a bitfield indicating the features supported by this archive type.</summary>
2019-08-15 22:35:57 +02:00
/// <returns>The <c>ArchiveSupportedFeature</c> bitfield.</returns>
/// <remarks>
2019-11-03 01:41:48 +00:00
/// This should be a constant, tied to the archive type, not to the particular features used by the
/// currently-opened archive file.
2019-08-15 22:35:57 +02:00
/// </remarks>
ArchiveSupportedFeature GetArchiveFeatures();
2019-11-03 01:41:48 +00:00
/// <summary>Gets the number of entries (i.e. files) that are contained in this archive.</summary>
2019-08-15 22:35:57 +02:00
/// <remarks>
2019-11-03 01:41:48 +00:00
/// Entries in this context can also mean directories or volume labels, for some types of archives that store
/// these explicitly. Do not rely on all entries being regular files!
2019-08-15 22:35:57 +02:00
/// </remarks>
/// <returns>The number of files.</returns>
int GetNumberOfEntries();
2019-11-03 01:41:48 +00:00
/// <summary>Gets the file name (and path) of the given entry in the archive.</summary>
2019-08-15 22:35:57 +02:00
/// <remarks>
2019-11-03 01:41:48 +00:00
/// The path components are separated by a forward slash "/". <br /> The path should not start with a leading
/// slash (i.e. it should be relative, not absolute).
2019-08-15 22:35:57 +02:00
/// </remarks>
2019-11-03 01:41:48 +00:00
/// <seealso cref="Stat(int)" />
2019-08-15 22:35:57 +02:00
/// <param name="entryNumber">The entry in the archive for which to return the file name.</param>
/// <returns>The file name, with (relative) path</returns>
string GetFilename(int entryNumber);
/// <summary>
2019-11-03 01:41:48 +00:00
/// Gets the entry number for a particular file path in the archive. <c>fileName</c> is the relative path of the
/// file in the archive. If the file cannot be found, -1 is returned.
2019-08-15 22:35:57 +02:00
/// </summary>
/// <remarks>
2019-11-03 01:41:48 +00:00
/// The path should be relative (no leading slash), using regular slashes as path separator, and be normalized,
/// i.e. no "foo//bar" or "foo/../bar" path components.
2019-08-15 22:35:57 +02:00
/// </remarks>
/// <param name="fileName">The relative path for which to get the entry number.</param>
/// <param name="caseInsensitiveMatch">If set, do a case insensitive matching and return the first file that matches.</param>
/// <returns>The number of the entry corresponding to the given path, or -1 if the path does not exist.</returns>
int GetEntryNumber(string fileName, bool caseInsensitiveMatch);
2019-11-03 01:41:48 +00:00
/// <summary>Gets the (compressed) size of the given entry.</summary>
2019-08-15 22:35:57 +02:00
/// <param name="entryNumber">The entry for which to get the compressed size.</param>
/// <returns>The compressed size of the entry, or 0 if the entry is not a regular file.</returns>
2019-11-03 01:41:48 +00:00
/// <remarks>The return value is equal to the return value of <c>GetUncompressedSize()</c> if the file is not compressed.</remarks>
/// <seealso cref="GetUncompressedSize(int)" />
2019-08-15 22:35:57 +02:00
long GetCompressedSize(int entryNumber);
2019-11-03 01:41:48 +00:00
/// <summary>Gets the uncompressed size of the given entry.</summary>
2019-08-15 22:35:57 +02:00
/// <param name="entryNumber">The entry for which to get the uncompressed size.</param>
/// <returns>The uncompressed size of the entry, or 0 if the entry is not a regular file.</returns>
2019-11-03 01:41:48 +00:00
/// <remarks>The return value is equal to the return value of <c>GetCompressedSize()</c> if the file is not compressed.</remarks>
/// <seealso cref="GetCompressedSize(int)" />
2019-08-15 22:35:57 +02:00
long GetUncompressedSize(int entryNumber);
2019-11-03 01:41:48 +00:00
/// <summary>Gets the attributes of a file or directory.</summary>
/// <seealso cref="Stat(int)" />
2019-08-15 22:35:57 +02:00
/// <returns>Error number.</returns>
/// <param name="entryNumber">The entry in the archive for which to retreive the attributes.</param>
/// <returns>File attributes, or zero if the archive does not support attributes.</returns>
FileAttributes GetAttributes(int entryNumber);
2019-11-03 01:41:48 +00:00
/// <summary>Lists all extended attributes, alternate data streams and forks of the given file.</summary>
2019-08-15 22:35:57 +02:00
/// <param name="entryNumber">The entry in the archive for which to retreive the list of attributes.</param>
/// <returns>List of extended attributes, alternate data streams and forks.</returns>
List<string> GetXAttrs(int entryNumber);
2019-11-03 01:41:48 +00:00
/// <summary>Reads an extended attribute, alternate data stream or fork from the given file.</summary>
2019-08-15 22:35:57 +02:00
/// <returns>Error number.</returns>
/// <param name="entryNumber">The entry in the archive for which to retreive the XAttr.</param>
/// <param name="xattr">Extended attribute, alternate data stream or fork name.</param>
/// <returns>Buffer with the XAttr data.</returns>
byte[] GetXattr(int entryNumber, string xattr);
2019-11-03 01:41:48 +00:00
/// <summary>Gets information about an entry in the archive.</summary>
/// <remarks>Note that some of the data might be incomplete or not available at all, depending on the type of archive.</remarks>
/// <seealso cref="GetAttributes(int)" />
/// <seealso cref="GetFilename(int)" />
2019-08-15 22:35:57 +02:00
/// <param name="entryNumber">The entry int he archive for which to get the information</param>
/// <returns>The available information about the entry in the archive</returns>
FileSystemInfo Stat(int entryNumber);
/// <summary>
2019-11-03 01:41:48 +00:00
/// Returns the Filter for the given entry. It will return <c>null</c> if the entry in question is not a regular
/// file (i.e. directory, volume label, etc.)
2019-08-15 22:35:57 +02:00
/// </summary>
/// <param name="entryNumber">The entry for which the Filter should be returned.</param>
/// <returns>The Filter for the given entry.</returns>
IFilter GetEntry(int entryNumber);
}
2019-11-03 01:41:48 +00:00
}