2017-11-02 00:29:20 -07:00
|
|
|
|
using System.Collections.Generic;
|
2020-06-11 11:44:46 -07:00
|
|
|
|
using System.IO;
|
2025-01-04 22:09:53 -05:00
|
|
|
|
using SabreTools.Hashing;
|
|
|
|
|
|
using SabreTools.IO.Logging;
|
2020-12-10 22:31:23 -08:00
|
|
|
|
|
2020-12-08 14:53:49 -08:00
|
|
|
|
namespace SabreTools.FileTypes
|
2017-11-02 00:29:20 -07:00
|
|
|
|
{
|
2025-01-04 22:10:52 -05:00
|
|
|
|
public abstract class BaseArchive : BaseFile, IParent
|
2019-02-08 20:51:44 -08:00
|
|
|
|
{
|
2020-09-18 15:01:03 -07:00
|
|
|
|
#region Protected instance variables
|
2020-09-18 01:50:44 -07:00
|
|
|
|
|
2025-01-04 22:09:53 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Hashes that are available for children
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected HashType[] _hashTypes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Set of children file objects
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected List<BaseFile>? _children;
|
|
|
|
|
|
|
2025-01-04 21:40:45 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Determines if real dates are written
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected bool _realDates = false;
|
|
|
|
|
|
|
2020-09-18 15:01:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Buffer size used by archives
|
|
|
|
|
|
/// </summary>
|
2019-02-08 20:51:44 -08:00
|
|
|
|
protected const int _bufferSize = 4096 * 128;
|
|
|
|
|
|
|
2025-01-04 22:09:53 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Logging object
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected Logger _logger;
|
|
|
|
|
|
|
2019-02-08 20:51:44 -08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Construtors
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create a new Archive with no base file
|
|
|
|
|
|
/// </summary>
|
2025-01-04 22:09:53 -05:00
|
|
|
|
public BaseArchive()
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger = new Logger(this);
|
|
|
|
|
|
}
|
2019-02-08 20:51:44 -08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-04 20:24:56 -05:00
|
|
|
|
/// Create a new BaseArchive from the given file
|
2019-02-08 20:51:44 -08:00
|
|
|
|
/// </summary>
|
2025-01-04 20:24:56 -05:00
|
|
|
|
/// <param name="filename">Name of the file to use</param>
|
2025-01-04 22:09:53 -05:00
|
|
|
|
public BaseArchive(string filename) : base(filename)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger = new Logger(this);
|
|
|
|
|
|
}
|
2020-07-15 09:41:59 -07:00
|
|
|
|
|
2019-02-08 20:51:44 -08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Extraction
|
|
|
|
|
|
|
2020-12-08 11:09:05 -08:00
|
|
|
|
/// <inheritdoc/>
|
2025-01-04 22:09:53 -05:00
|
|
|
|
public abstract bool CopyAll(string outDir);
|
2019-02-08 20:51:44 -08:00
|
|
|
|
|
2020-12-08 11:09:05 -08:00
|
|
|
|
/// <inheritdoc/>
|
2025-01-04 22:09:53 -05:00
|
|
|
|
public abstract string? CopyToFile(string entryName, string outDir);
|
2019-02-08 20:51:44 -08:00
|
|
|
|
|
2020-12-08 11:09:05 -08:00
|
|
|
|
/// <inheritdoc/>
|
2025-01-04 22:09:53 -05:00
|
|
|
|
public abstract (Stream?, string?) GetEntryStream(string entryName);
|
2019-02-08 20:51:44 -08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Information
|
|
|
|
|
|
|
2025-01-04 22:09:53 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Set the hash type that can be included in children
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void SetHashType(HashType hashType)
|
|
|
|
|
|
=> SetHashTypes([hashType]);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Set the hash types that can be included in children
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void SetHashTypes(HashType[] hashTypes)
|
|
|
|
|
|
=> _hashTypes = hashTypes;
|
|
|
|
|
|
|
2020-12-08 11:09:05 -08:00
|
|
|
|
/// <inheritdoc/>
|
2025-01-04 22:09:53 -05:00
|
|
|
|
public abstract List<BaseFile>? GetChildren();
|
2019-02-08 20:51:44 -08:00
|
|
|
|
|
2020-12-08 11:09:05 -08:00
|
|
|
|
/// <inheritdoc/>
|
2025-01-04 22:09:53 -05:00
|
|
|
|
public abstract List<string> GetEmptyFolders();
|
2019-02-08 20:51:44 -08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Check whether the input file is a standardized format
|
|
|
|
|
|
/// </summary>
|
2025-01-04 21:42:46 -05:00
|
|
|
|
public abstract bool IsStandardized();
|
2019-02-08 20:51:44 -08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Writing
|
|
|
|
|
|
|
2025-01-04 21:40:45 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Set if real dates are written
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void SetRealDates(bool realDates)
|
|
|
|
|
|
{
|
|
|
|
|
|
_realDates = realDates;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-08 11:09:05 -08:00
|
|
|
|
/// <inheritdoc/>
|
2025-01-04 22:09:53 -05:00
|
|
|
|
public abstract bool Write(string inputFile, string outDir, BaseFile? baseFile);
|
2019-02-08 20:51:44 -08:00
|
|
|
|
|
2020-12-08 11:09:05 -08:00
|
|
|
|
/// <inheritdoc/>
|
2025-01-04 22:09:53 -05:00
|
|
|
|
public abstract bool Write(Stream? inputStream, string outDir, BaseFile? baseFile);
|
2019-02-08 20:51:44 -08:00
|
|
|
|
|
2020-12-08 11:09:05 -08:00
|
|
|
|
/// <inheritdoc/>
|
2025-01-04 22:09:53 -05:00
|
|
|
|
public abstract bool Write(List<string> inputFiles, string outDir, List<BaseFile>? baseFiles);
|
2019-02-08 20:51:44 -08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
2017-11-02 00:29:20 -07:00
|
|
|
|
}
|