Add more extension properties

This commit is contained in:
Matt Nadareski
2024-11-28 20:50:43 -05:00
parent ab0e68110c
commit 884746a5a1
3 changed files with 47 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
using System.IO;
using SabreTools.Models.PAK;
namespace SabreTools.Serialization.Wrappers
{
@@ -11,6 +12,13 @@ namespace SabreTools.Serialization.Wrappers
#endregion
#region Extension Properties
/// <inheritdoc cref="Models.PAK.File.DirectoryItems"/>
public DirectoryItem?[] DirectoryItems => Model.DirectoryItems ?? [];
#endregion
#region Constructors
/// <inheritdoc/>
@@ -85,12 +93,12 @@ namespace SabreTools.Serialization.Wrappers
public bool ExtractAll(string outputDirectory)
{
// If we have no directory items
if (Model.DirectoryItems == null || Model.DirectoryItems.Length == 0)
if (DirectoryItems == null || DirectoryItems.Length == 0)
return false;
// Loop through and extract all files to the output
bool allExtracted = true;
for (int i = 0; i < Model.DirectoryItems.Length; i++)
for (int i = 0; i < DirectoryItems.Length; i++)
{
allExtracted &= ExtractFile(i, outputDirectory);
}
@@ -107,15 +115,15 @@ namespace SabreTools.Serialization.Wrappers
public bool ExtractFile(int index, string outputDirectory)
{
// If we have no directory items
if (Model.DirectoryItems == null || Model.DirectoryItems.Length == 0)
if (DirectoryItems == null || DirectoryItems.Length == 0)
return false;
// If the directory item index is invalid
if (index < 0 || index >= Model.DirectoryItems.Length)
if (index < 0 || index >= DirectoryItems.Length)
return false;
// Get the directory item
var directoryItem = Model.DirectoryItems[index];
var directoryItem = DirectoryItems[index];
if (directoryItem == null)
return false;
@@ -143,7 +151,7 @@ namespace SabreTools.Serialization.Wrappers
try
{
// Open the output file for writing
using Stream fs = File.OpenWrite(filename);
using Stream fs = System.IO.File.OpenWrite(filename);
fs.Write(data, 0, data.Length);
}
catch

View File

@@ -1,8 +1,9 @@
using System.IO;
using SabreTools.Models.PFF;
namespace SabreTools.Serialization.Wrappers
{
public class PFF : WrapperBase<Models.PFF.Archive>
public class PFF : WrapperBase<Archive>
{
#region Descriptive Properties
@@ -11,17 +12,29 @@ namespace SabreTools.Serialization.Wrappers
#endregion
#region Extension Properties
/// <summary>
/// Number of files in the archive
/// </summary>
public long FileCount => Model.Header?.NumberOfFiles ?? 0;
/// <inheritdoc cref="Archive.Segments"/>
public Segment?[] Segments => Model.Segments ?? [];
#endregion
#region Constructors
/// <inheritdoc/>
public PFF(Models.PFF.Archive? model, byte[]? data, int offset)
public PFF(Archive? model, byte[]? data, int offset)
: base(model, data, offset)
{
// All logic is handled by the base class
}
/// <inheritdoc/>
public PFF(Models.PFF.Archive? model, Stream? data)
public PFF(Archive? model, Stream? data)
: base(model, data)
{
// All logic is handled by the base class
@@ -85,12 +98,12 @@ namespace SabreTools.Serialization.Wrappers
public bool ExtractAll(string outputDirectory)
{
// If we have no segments
if (Model.Segments == null || Model.Segments.Length == 0)
if (Segments == null || Segments.Length == 0)
return false;
// Loop through and extract all files to the output
bool allExtracted = true;
for (int i = 0; i < Model.Segments.Length; i++)
for (int i = 0; i < Segments.Length; i++)
{
allExtracted &= ExtractSegment(i, outputDirectory);
}
@@ -107,19 +120,19 @@ namespace SabreTools.Serialization.Wrappers
public bool ExtractSegment(int index, string outputDirectory)
{
// If we have no files
if (Model.Header?.NumberOfFiles == null || Model.Header.NumberOfFiles == 0)
if (FileCount == 0)
return false;
// If we have no segments
if (Model.Segments == null || Model.Segments.Length == 0)
if (Segments == null || Segments.Length == 0)
return false;
// If we have an invalid index
if (index < 0 || index >= Model.Segments.Length)
if (index < 0 || index >= Segments.Length)
return false;
// Get the segment information
var file = Model.Segments[index];
var file = Segments[index];
if (file == null)
return false;

View File

@@ -1,8 +1,9 @@
using System.IO;
using SabreTools.Models.PIC;
namespace SabreTools.Serialization.Wrappers
{
public class PIC : WrapperBase<Models.PIC.DiscInformation>
public class PIC : WrapperBase<DiscInformation>
{
#region Descriptive Properties
@@ -11,17 +12,24 @@ namespace SabreTools.Serialization.Wrappers
#endregion
#region Extension Properties
/// <inheritdoc cref="DiscInformation.Units"/>
public DiscInformationUnit?[] Units => Model.Units ?? [];
#endregion
#region Constructors
/// <inheritdoc/>
public PIC(Models.PIC.DiscInformation? model, byte[]? data, int offset)
public PIC(DiscInformation? model, byte[]? data, int offset)
: base(model, data, offset)
{
// All logic is handled by the base class
}
/// <inheritdoc/>
public PIC(Models.PIC.DiscInformation? model, Stream? data)
public PIC(DiscInformation? model, Stream? data)
: base(model, data)
{
// All logic is handled by the base class