From 939c85bc7cae493173b2a108e93bc6d6c2e95696 Mon Sep 17 00:00:00 2001 From: Archangel Date: Sun, 18 Aug 2024 15:49:22 +0000 Subject: [PATCH] Rename ShouldReaquire & check if bundle exists (!160) I didn't keep in mind that 'ShouldReaquire' handles both the initial check for acquiring of a file and also the re-acquiring of it, I've renamed the method here to be more accurate in this behavior so that hopefully it prevents this from happening again in the future. Also fixes the issue of an exception being thrown when checking if the bundle exists or not. Thanks to MadByte for finding this issue Reviewed-on: https://dev.sp-tarkov.com/SPT/Modules/pulls/160 Co-authored-by: Archangel Co-committed-by: Archangel --- project/SPT.Custom/Patches/EasyAssetsPatch.cs | 7 +++++-- project/SPT.Custom/Utils/BundleManager.cs | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/project/SPT.Custom/Patches/EasyAssetsPatch.cs b/project/SPT.Custom/Patches/EasyAssetsPatch.cs index 06590ab..280d27a 100644 --- a/project/SPT.Custom/Patches/EasyAssetsPatch.cs +++ b/project/SPT.Custom/Patches/EasyAssetsPatch.cs @@ -95,9 +95,12 @@ namespace SPT.Custom.Patches path = BundleManager.GetBundlePath(bundleInfo); // only download when connected externally - if (await BundleManager.ShouldReaquire(bundleInfo)) + if (await BundleManager.ShouldAcquire(bundleInfo)) { - VFS.DeleteFile(BundleManager.GetBundleFilePath(bundleInfo)); + if (VFS.Exists(BundleManager.GetBundleFilePath(bundleInfo))) + { + VFS.DeleteFile(BundleManager.GetBundleFilePath(bundleInfo)); + } await BundleManager.DownloadBundle(bundleInfo); } diff --git a/project/SPT.Custom/Utils/BundleManager.cs b/project/SPT.Custom/Utils/BundleManager.cs index 93f443b..ba0f749 100644 --- a/project/SPT.Custom/Utils/BundleManager.cs +++ b/project/SPT.Custom/Utils/BundleManager.cs @@ -51,7 +51,8 @@ namespace SPT.Custom.Utils await VFS.WriteFileAsync(filepath, data); } - public static async Task ShouldReaquire(BundleItem bundle) + // Handles both the check for initially acquiring and also re-acquiring a file. + public static async Task ShouldAcquire(BundleItem bundle) { // read cache var filepath = GetBundleFilePath(bundle);