Fix cache size and switch to using fileAnalysis for bundle sizes

This commit is contained in:
Natsumi
2025-08-10 22:54:31 +12:00
parent d40d0af21f
commit e182b4f2c2
9 changed files with 102 additions and 150 deletions

View File

@@ -28,16 +28,14 @@ namespace VRCX
public string GetAssetId(string id, string variant = "")
{
using (var sha256 = SHA256.Create())
using var sha256 = SHA256.Create();
var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(id + variant));
var idHex = new StringBuilder(hash.Length * 2);
foreach (var b in hash)
{
byte[] hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(id + variant));
StringBuilder idHex = new StringBuilder(hash.Length * 2);
foreach (byte b in hash)
{
idHex.AppendFormat("{0:x2}", b);
}
return idHex.ToString().ToUpper().Substring(0, 16);
idHex.Append($"{b:x2}");
}
return idHex.ToString().ToUpper().Substring(0, 16);
}
public string GetAssetVersion(int version, int variantVersion = 0)
@@ -136,7 +134,7 @@ namespace VRCX
if (File.Exists(fileLocation))
{
cachePath = fullLocation;
FileInfo data = new FileInfo(fileLocation);
var data = new FileInfo(fileLocation);
fileSize = data.Length;
}
if (File.Exists(Path.Join(fullLocation, "__lock")))
@@ -241,8 +239,8 @@ namespace VRCX
public long DirSize(DirectoryInfo d)
{
long size = 0;
FileInfo[] files = d.GetFiles("*.*", SearchOption.AllDirectories);
foreach (FileInfo file in files)
var files = d.GetFiles("*.*", SearchOption.AllDirectories);
foreach (var file in files)
{
size += file.Length;
}

View File

@@ -217,8 +217,7 @@ namespace VRCX
{
var fileHashBytes = await sha256.ComputeHashAsync(stream, _cancellationToken);
var fileHashString = Convert.ToHexString(fileHashBytes);
if (!string.IsNullOrEmpty(fileHashString) &&
!hashString.Equals(fileHashString, StringComparison.OrdinalIgnoreCase))
if (!hashString.Equals(fileHashString, StringComparison.OrdinalIgnoreCase))
{
logger.Error($"Hash check failed file:{fileHashString} web:{hashString}");
throw new Exception("Hash check failed");