Bundle loader refactor (#502)

* Bundle loader refactor

- Made async
- Validate if bundle actually exists, if not throw warning into the console
- Updated mod example

* Cleanup unused var
This commit is contained in:
Jesse
2025-07-22 13:54:06 +02:00
committed by GitHub
parent 7d8c3d041e
commit c852debf2b
4 changed files with 81 additions and 70 deletions
@@ -14,7 +14,7 @@ public class BundleHashCacheService(
{
protected const string _bundleHashCachePath = "./user/cache/";
protected const string _cacheName = "bundleHashCache.json";
protected readonly Dictionary<string, uint> _bundleHashes = new();
protected readonly Dictionary<string, uint> _bundleHashes = [];
public uint GetStoredValue(string key)
{
@@ -26,7 +26,7 @@ public class BundleHashCacheService(
return value;
}
public void StoreValue(string bundlePath, uint hash)
public async Task StoreValue(string bundlePath, uint hash)
{
_bundleHashes.Add(bundlePath, hash);
@@ -35,7 +35,7 @@ public class BundleHashCacheService(
Directory.CreateDirectory(_bundleHashCachePath);
}
fileUtil.WriteFile(
await fileUtil.WriteFileAsync(
Path.Join(_bundleHashCachePath, _cacheName),
jsonUtil.Serialize(_bundleHashes)
);
@@ -48,9 +48,9 @@ public class BundleHashCacheService(
return MatchWithStoredHash(BundlePath, CalculateHash(BundlePath));
}
public void CalculateAndStoreHash(string BundlePath)
public async Task CalculateAndStoreHash(string BundlePath)
{
StoreValue(BundlePath, CalculateHash(BundlePath));
await StoreValue(BundlePath, CalculateHash(BundlePath));
}
public uint CalculateHash(string BundlePath)