From 1bdf761d075088e4b4862d30d4ba51dc54ca0fae Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sat, 7 Sep 2024 23:11:39 +0100 Subject: [PATCH] Fix bug in cached package handling --- Bloxstrap/Bootstrapper.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 8c4b725..8b2c332 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -34,9 +34,9 @@ namespace Bloxstrap private readonly CancellationTokenSource _cancelTokenSource = new(); - private IAppData AppData; + private readonly IAppData AppData; - private bool FreshInstall => String.IsNullOrEmpty(AppData.State.VersionGuid); + private bool FreshInstall => !File.Exists(AppData.ExecutablePath) || String.IsNullOrEmpty(AppData.State.VersionGuid); private string _launchCommandLine = App.LaunchSettings.RobloxLaunchArgs; private LaunchMode _launchMode = App.LaunchSettings.RobloxLaunchMode; @@ -559,10 +559,14 @@ namespace Bloxstrap var lockFile = new FileInfo(AppData.LockFilePath); lockFile.Create().Dispose(); + var cachedPackageHashes = Directory.GetFiles(Paths.Downloads).Select(x => Path.GetFileName(x)); + // package manifest states packed size and uncompressed size in exact bytes + int totalSizeRequired = 0; + // packed size only matters if we don't already have the package cached on disk - var cachedPackages = Directory.GetFiles(Paths.Downloads); - int totalSizeRequired = _versionPackageManifest.Where(x => !cachedPackages.Contains(x.Signature)).Sum(x => x.PackedSize) + _versionPackageManifest.Sum(x => x.Size); + totalSizeRequired += _versionPackageManifest.Where(x => !cachedPackageHashes.Contains(x.Signature)).Sum(x => x.PackedSize); + totalSizeRequired += _versionPackageManifest.Sum(x => x.Size); if (Filesystem.GetFreeDiskSpace(Paths.Base) < totalSizeRequired) { @@ -682,19 +686,19 @@ namespace Bloxstrap allPackageHashes.AddRange(App.State.Prop.Player.PackageHashes.Values); allPackageHashes.AddRange(App.State.Prop.Studio.PackageHashes.Values); - foreach (string filename in cachedPackages) + foreach (string hash in cachedPackageHashes) { - if (!allPackageHashes.Contains(filename)) + if (!allPackageHashes.Contains(hash)) { - App.Logger.WriteLine(LOG_IDENT, $"Deleting unused package {filename}"); + App.Logger.WriteLine(LOG_IDENT, $"Deleting unused package {hash}"); try { - File.Delete(filename); + File.Delete(Path.Combine(Paths.Downloads, hash)); } catch (Exception ex) { - App.Logger.WriteLine(LOG_IDENT, $"Failed to delete {filename}!"); + App.Logger.WriteLine(LOG_IDENT, $"Failed to delete {hash}!"); App.Logger.WriteException(LOG_IDENT, ex); } } @@ -702,7 +706,7 @@ namespace Bloxstrap App.Logger.WriteLine(LOG_IDENT, "Registering approximate program size..."); - int distributionSize = _versionPackageManifest.Sum(x => x.Size + x.PackedSize) / 1000; + int distributionSize = _versionPackageManifest.Sum(x => x.Size + x.PackedSize) / 1024; AppData.State.Size = distributionSize;