From 10f0026ad6382bf366c958d69eaeffe3e6c8c197 Mon Sep 17 00:00:00 2001 From: cooolbros Date: Tue, 2 Jan 2024 14:20:36 +1100 Subject: [PATCH] Make VPKs lazy --- src/HUDMerger/Services/HUDFileReaderService.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/HUDMerger/Services/HUDFileReaderService.cs b/src/HUDMerger/Services/HUDFileReaderService.cs index f9dd9b3..ba8c418 100644 --- a/src/HUDMerger/Services/HUDFileReaderService.cs +++ b/src/HUDMerger/Services/HUDFileReaderService.cs @@ -22,8 +22,9 @@ public enum FileType : byte public partial class HUDFileReaderService { - private readonly VPK TF2MiscDirVPK = new(Path.Join(Properties.Settings.Default.Team_Fortress_2_Folder, "tf\\tf2_misc_dir.vpk")); - private readonly VPK PlatformMiscDirVPK = new(Path.Join(Properties.Settings.Default.Team_Fortress_2_Folder, "platform\\platform_misc_dir.vpk")); + private readonly Lazy TF2MiscDirVPK = new(() => new(Path.Join(Properties.Settings.Default.Team_Fortress_2_Folder, "tf\\tf2_misc_dir.vpk"))); + private readonly Lazy PlatformMiscDirVPK = new(() => new(Path.Join(Properties.Settings.Default.Team_Fortress_2_Folder, "platform\\platform_misc_dir.vpk"))); + private readonly Dictionary Files = []; public void Require(IEnumerable<(HUD hud, string relativePath, FileType type)> filePaths) @@ -52,15 +53,15 @@ void Add(HUD hud, string relativePath, FileType type) return File.ReadAllText(absolutePath); } - if (TF2MiscDirVPK.Exists(relativePath)) + if (TF2MiscDirVPK.Value.Exists(relativePath)) { - return Encoding.UTF8.GetString(TF2MiscDirVPK.Read(relativePath)); + return Encoding.UTF8.GetString(TF2MiscDirVPK.Value.Read(relativePath)); } // resource/sourceschemebase.res - if (PlatformMiscDirVPK.Exists(relativePath)) + if (PlatformMiscDirVPK.Value.Exists(relativePath)) { - return Encoding.UTF8.GetString(PlatformMiscDirVPK.Read(relativePath)); + return Encoding.UTF8.GetString(PlatformMiscDirVPK.Value.Read(relativePath)); } string tfPath = Path.Join(Properties.Settings.Default.Team_Fortress_2_Folder, "tf", relativePath);