using System.Collections.Generic;
using System.IO;
using SabreTools.Hashing;
using SabreTools.IO.Logging;
namespace SabreTools.FileTypes
{
public abstract class BaseArchive : BaseFile, IParent
{
#region Protected instance variables
///
/// Hashes that are available for children
///
protected HashType[] _hashTypes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
///
/// Set of children file objects
///
protected List? _children;
///
/// Determines if real dates are written
///
protected bool _realDates = false;
///
/// Buffer size used by archives
///
protected const int _bufferSize = 4096 * 128;
///
/// Logging object
///
protected Logger _logger;
#endregion
#region Construtors
///
/// Create a new Archive with no base file
///
public BaseArchive()
{
_logger = new Logger(this);
}
///
/// Create a new BaseArchive from the given file
///
/// Name of the file to use
public BaseArchive(string filename) : base(filename)
{
_logger = new Logger(this);
}
#endregion
#region Extraction
///
public abstract bool CopyAll(string outDir);
///
public abstract string? CopyToFile(string entryName, string outDir);
///
public abstract (Stream?, string?) GetEntryStream(string entryName);
#endregion
#region Information
///
/// Set the hash type that can be included in children
///
public void SetHashType(HashType hashType)
=> SetHashTypes([hashType]);
///
/// Set the hash types that can be included in children
///
public void SetHashTypes(HashType[] hashTypes)
=> _hashTypes = hashTypes;
///
public abstract List? GetChildren();
///
public abstract List GetEmptyFolders();
///
/// Check whether the input file is a standardized format
///
public abstract bool IsStandardized();
#endregion
#region Writing
///
/// Set if real dates are written
///
public void SetRealDates(bool realDates)
{
_realDates = realDates;
}
///
public abstract bool Write(string file, string outDir, BaseFile? baseFile);
///
public abstract bool Write(Stream? stream, string outDir, BaseFile? baseFile);
///
public abstract bool Write(List files, string outDir, List? baseFiles);
#endregion
}
}