From 34606a4f04ef6d1440c3690292a6abfb9764452c Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 12 Nov 2024 17:05:10 -0500 Subject: [PATCH] Easier to read archive count in VPK --- SabreTools.Serialization/Wrappers/VPK.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/SabreTools.Serialization/Wrappers/VPK.cs b/SabreTools.Serialization/Wrappers/VPK.cs index a08295d3..456cfed2 100644 --- a/SabreTools.Serialization/Wrappers/VPK.cs +++ b/SabreTools.Serialization/Wrappers/VPK.cs @@ -1,5 +1,5 @@ +using System; using System.IO; -using System.Linq; using static SabreTools.Models.VPK.Constants; namespace SabreTools.Serialization.Wrappers @@ -43,13 +43,16 @@ namespace SabreTools.Serialization.Wrappers return null; // Get the archive count - int archiveCount = Model.DirectoryItems == null - ? 0 - : Model.DirectoryItems - .Select(di => di?.DirectoryEntry) - .Select(de => de?.ArchiveIndex ?? 0) - .Where(ai => ai != HL_VPK_NO_ARCHIVE) - .Max(); + ushort archiveCount = 0; + foreach (var di in Model.DirectoryItems ?? []) + { + if (di?.DirectoryEntry == null) + continue; + if (di.DirectoryEntry.ArchiveIndex == HL_VPK_NO_ARCHIVE) + continue; + + archiveCount = Math.Max(archiveCount, di.DirectoryEntry.ArchiveIndex); + } // Build the list of archive filenames to populate _archiveFilenames = new string[archiveCount];