Skip to content

Commit

Permalink
Make VPKs lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
cooolbros committed Jan 2, 2024
1 parent 67b2656 commit 10f0026
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/HUDMerger/Services/HUDFileReaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<VPK> TF2MiscDirVPK = new(() => new(Path.Join(Properties.Settings.Default.Team_Fortress_2_Folder, "tf\\tf2_misc_dir.vpk")));
private readonly Lazy<VPK> PlatformMiscDirVPK = new(() => new(Path.Join(Properties.Settings.Default.Team_Fortress_2_Folder, "platform\\platform_misc_dir.vpk")));

private readonly Dictionary<string, dynamic?> Files = [];

public void Require(IEnumerable<(HUD hud, string relativePath, FileType type)> filePaths)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 10f0026

Please sign in to comment.