mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-09-23 07:14:57 +00:00
Add PKZIP shell wrapper
This commit is contained in:
79
SabreTools.Serialization/Wrappers/PKZIP.cs
Normal file
79
SabreTools.Serialization/Wrappers/PKZIP.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System.IO;
|
||||
using SabreTools.Models.PKZIP;
|
||||
|
||||
namespace SabreTools.Serialization.Wrappers
|
||||
{
|
||||
public class PKZIP : WrapperBase<Archive>
|
||||
{
|
||||
#region Descriptive Properties
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string DescriptionString => "PKZIP Archive (or Derived Format)";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PKZIP(Archive? model, byte[]? data, int offset)
|
||||
: base(model, data, offset)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PKZIP(Archive? model, Stream? data)
|
||||
: base(model, data)
|
||||
{
|
||||
// All logic is handled by the base class
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a PKZIP archive (or derived format) from a byte array and offset
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array representing the archive</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>A PKZIP wrapper on success, null on failure</returns>
|
||||
public static PKZIP? Create(byte[]? data, int offset)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and use that
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return Create(dataStream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a PKZIP archive (or derived format) from a Stream
|
||||
/// </summary>
|
||||
/// <param name="data">Stream representing the archive</param>
|
||||
/// <returns>A PKZIP wrapper on success, null on failure</returns>
|
||||
public static PKZIP? Create(Stream? data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
return null;
|
||||
|
||||
var archive = Deserializers.PKZIP.DeserializeStream(data);
|
||||
if (archive == null)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
return new PKZIP(archive, data);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
case WrapperType.PAK: return PAK.Create(data);
|
||||
case WrapperType.PFF: return PFF.Create(data);
|
||||
case WrapperType.PIC: return PIC.Create(data);
|
||||
case WrapperType.PKZIP: return null; // TODO: Implement wrapper
|
||||
case WrapperType.PKZIP: return PKZIP.Create(data);
|
||||
case WrapperType.PlayJAudioFile: return PlayJAudioFile.Create(data);
|
||||
case WrapperType.PlayJPlaylist: return PlayJPlaylist.Create(data);
|
||||
case WrapperType.Quantum: return Quantum.Create(data);
|
||||
|
||||
@@ -136,7 +136,6 @@ namespace SabreTools.Serialization.Wrappers
|
||||
/// <summary>
|
||||
/// PKWARE ZIP archive and derivatives
|
||||
/// </summary>
|
||||
/// <remarks>Currently has no IWrapper implementation</remarks>
|
||||
PKZIP,
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user