Skip to content

Commit

Permalink
Fix bug in cached package handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Sep 7, 2024
1 parent 99ff002 commit 1bdf761
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public class Bootstrapper

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;
Expand Down Expand Up @@ -559,10 +559,14 @@ private async Task UpgradeRoblox()
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)
{
Expand Down Expand Up @@ -682,27 +686,27 @@ private async Task UpgradeRoblox()
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);
}
}
}

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;

Expand Down

0 comments on commit 1bdf761

Please sign in to comment.