using System.Collections.Generic; using SabreTools.Library.Data; using SabreTools.Library.DatItems; #if MONO using System.IO; #else using MemoryStream = System.IO.MemoryStream; using Stream = System.IO.Stream; #endif using SharpCompress.Common; namespace SabreTools.Library.FileTypes { public abstract class BaseArchive { #region Protected instance variables // Buffer size used by archives protected const int _bufferSize = 4096 * 128; protected ArchiveType _archiveType; protected string _filename; #endregion #region Construtors /// /// Create a new Archive with no base file /// public BaseArchive() { } /// /// Create a new Archive from the given file /// /// Name of the file to use as an archive public BaseArchive(string filename) { _filename = filename; } #endregion #region Extraction /// /// Attempt to extract a file as an archive /// /// Output directory for archive extraction /// True if the extraction was a success, false otherwise public abstract bool ExtractAll(string outDir); /// /// Attempt to extract an entry from an archive /// /// Name of the entry to be extracted /// Output directory for archive extraction /// Name of the extracted file, null on error public abstract string ExtractEntry(string entryName, string outDir); /// /// Attempt to extract a stream from an archive /// /// Name of the entry to be extracted /// Output representing the entry name that was found /// MemoryStream representing the entry, null on error public abstract (MemoryStream, string) ExtractEntryStream(string entryName); #endregion #region Information /// /// Generate a list of DatItem objects from the header values in an archive /// /// Hash representing the hashes that should be skipped /// True if entry dates should be included, false otherwise (default) /// List of DatItem objects representing the found data /// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually public abstract List GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false); /// /// Generate a list of empty folders in an archive /// /// Input file to get data from /// List of empty folders in the archive public abstract List GetEmptyFolders(); /// /// Check whether the input file is a standardized format /// public abstract bool IsTorrent(); #endregion #region Writing /// /// Write an input file to an archive /// /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information /// True if the date from the DAT should be used if available, false otherwise (default) /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise public abstract bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool romba = false); /// /// Write an input stream to an archive /// /// Input stream to be moved /// Output directory to build to /// DatItem representing the new information /// True if the date from the DAT should be used if available, false otherwise (default) /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise public abstract bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool romba = false); /// /// Write a set of input files to an archive (assuming the same output archive name) /// /// Input files to be moved /// Output directory to build to /// DatItem representing the new information /// True if the date from the DAT should be used if available, false otherwise (default) /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise public abstract bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false); #endregion } }