mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-09 02:16:55 +00:00
VPK model cleanup
This commit is contained in:
@@ -18,4 +18,4 @@ namespace SabreTools.Data.Models.VPK
|
||||
/// </summary>
|
||||
public const int HL_VPK_CHECKSUM_LENGTH = 0x00008000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@ namespace SabreTools.Data.Models.VPK
|
||||
/// <see href="https://developer.valvesoftware.com/wiki/VPK_(file_format)"/>
|
||||
public sealed class DirectoryItem
|
||||
{
|
||||
public string? Extension { get; set; }
|
||||
public string Extension { get; set; }
|
||||
|
||||
public string? Path { get; set; }
|
||||
public string Path { get; set; }
|
||||
|
||||
public string? Name { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public DirectoryEntry? DirectoryEntry { get; set; }
|
||||
public DirectoryEntry DirectoryEntry { get; set; }
|
||||
|
||||
public byte[] PreloadData { get; set; }
|
||||
}
|
||||
|
||||
@@ -9,21 +9,23 @@ namespace SabreTools.Data.Models.VPK
|
||||
/// <summary>
|
||||
/// Header data
|
||||
/// </summary>
|
||||
public Header? Header { get; set; }
|
||||
public Header Header { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Extended header data
|
||||
/// </summary>
|
||||
/// <remarks>Version 2 only</remarks>
|
||||
public ExtendedHeader? ExtendedHeader { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Archive hashes data
|
||||
/// </summary>
|
||||
/// <remarks>Version 2 only</remarks>
|
||||
public ArchiveHash[]? ArchiveHashes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Directory items data
|
||||
/// </summary>
|
||||
public DirectoryItem[]? DirectoryItems { get; set; }
|
||||
public DirectoryItem[] DirectoryItems { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
public bool Extract(string outputDirectory, bool includeDebug)
|
||||
{
|
||||
// If we have no directory items
|
||||
if (DirectoryItems == null || DirectoryItems.Length == 0)
|
||||
if (DirectoryItems.Length == 0)
|
||||
return false;
|
||||
|
||||
// Loop through and extract all files to the output
|
||||
@@ -34,7 +34,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
public bool ExtractFile(int index, string outputDirectory, bool includeDebug)
|
||||
{
|
||||
// If we have no directory items
|
||||
if (DirectoryItems == null || DirectoryItems.Length == 0)
|
||||
if (DirectoryItems.Length == 0)
|
||||
return false;
|
||||
|
||||
// If the directory item index is invalid
|
||||
@@ -43,8 +43,6 @@ namespace SabreTools.Serialization.Wrappers
|
||||
|
||||
// Get the directory item
|
||||
var directoryItem = DirectoryItems[index];
|
||||
if (directoryItem.DirectoryEntry == null)
|
||||
return false;
|
||||
|
||||
// If we have an item with no archive
|
||||
byte[] data = [];
|
||||
|
||||
@@ -24,17 +24,10 @@ namespace SabreTools.Serialization.Wrappers
|
||||
Print(builder, Model.DirectoryItems);
|
||||
}
|
||||
|
||||
private static void Print(StringBuilder builder, Header? header)
|
||||
private static void Print(StringBuilder builder, Header header)
|
||||
{
|
||||
builder.AppendLine(" Header Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (header == null)
|
||||
{
|
||||
builder.AppendLine(" No header");
|
||||
builder.AppendLine();
|
||||
return;
|
||||
}
|
||||
|
||||
builder.AppendLine(header.Signature, " Signature");
|
||||
builder.AppendLine(header.Version, " Version");
|
||||
builder.AppendLine(header.TreeSize, " Tree size");
|
||||
@@ -84,11 +77,11 @@ namespace SabreTools.Serialization.Wrappers
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
private static void Print(StringBuilder builder, DirectoryItem[]? entries)
|
||||
private static void Print(StringBuilder builder, DirectoryItem[] entries)
|
||||
{
|
||||
builder.AppendLine(" Directory Items Information:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (entries == null || entries.Length == 0)
|
||||
if (entries.Length == 0)
|
||||
{
|
||||
builder.AppendLine(" No directory items");
|
||||
builder.AppendLine();
|
||||
@@ -112,16 +105,10 @@ namespace SabreTools.Serialization.Wrappers
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
private static void Print(StringBuilder builder, DirectoryEntry? entry)
|
||||
private static void Print(StringBuilder builder, DirectoryEntry entry)
|
||||
{
|
||||
builder.AppendLine(" Directory Entry:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (entry == null)
|
||||
{
|
||||
builder.AppendLine(" [NULL]");
|
||||
return;
|
||||
}
|
||||
|
||||
builder.AppendLine(entry.CRC, " CRC");
|
||||
builder.AppendLine(entry.PreloadBytes, " Preload bytes");
|
||||
builder.AppendLine(entry.ArchiveIndex, " Archive index");
|
||||
|
||||
@@ -44,10 +44,8 @@ namespace SabreTools.Serialization.Wrappers
|
||||
|
||||
// Get the archive count
|
||||
ushort archiveCount = 0;
|
||||
foreach (var di in DirectoryItems ?? [])
|
||||
foreach (var di in DirectoryItems)
|
||||
{
|
||||
if (di.DirectoryEntry == null)
|
||||
continue;
|
||||
if (di.DirectoryEntry.ArchiveIndex == HL_VPK_NO_ARCHIVE)
|
||||
continue;
|
||||
|
||||
@@ -71,7 +69,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Models.VPK.File.DirectoryItems"/>
|
||||
public Data.Models.VPK.DirectoryItem[]? DirectoryItems => Model.DirectoryItems;
|
||||
public Data.Models.VPK.DirectoryItem[] DirectoryItems => Model.DirectoryItems;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user