Extract package immediately after download

This commit is contained in:
pizzaboxer 2023-01-09 18:40:33 +00:00
parent af9b130ac1
commit 62ba5c83aa

View File

@ -85,6 +85,7 @@ namespace Bloxstrap
private double ProgressIncrement; private double ProgressIncrement;
private long TotalBytes = 0; private long TotalBytes = 0;
private long TotalDownloadedBytes = 0; private long TotalDownloadedBytes = 0;
private int PackagesExtracted = 0;
private bool CancelFired = false; private bool CancelFired = false;
public IBootstrapperDialog Dialog = null!; public IBootstrapperDialog Dialog = null!;
@ -467,17 +468,22 @@ namespace Bloxstrap
Dialog.ProgressStyle = ProgressBarStyle.Continuous; Dialog.ProgressStyle = ProgressBarStyle.Continuous;
// compute total bytes to download // compute total bytes to download
foreach (Package package in VersionPackageManifest) foreach (Package package in VersionPackageManifest)
TotalBytes += package.PackedSize; TotalBytes += package.PackedSize;
ProgressIncrement = (double)1 / TotalBytes * 100; ProgressIncrement = (double)1 / TotalBytes * 100;
Directory.CreateDirectory(Directories.Downloads); Directory.CreateDirectory(Directories.Downloads);
Directory.CreateDirectory(Directories.Versions);
foreach (Package package in VersionPackageManifest) foreach (Package package in VersionPackageManifest)
{ {
// download all the packages at once // download all the packages synchronously
await DownloadPackage(package); await DownloadPackage(package);
// extract the package immediately after download amogus balls
ExtractPackage(package);
} }
// allow progress bar to 100% before continuing (purely ux reasons lol) // allow progress bar to 100% before continuing (purely ux reasons lol)
@ -485,20 +491,14 @@ namespace Bloxstrap
Dialog.ProgressStyle = ProgressBarStyle.Marquee; Dialog.ProgressStyle = ProgressBarStyle.Marquee;
Debug.WriteLine("Finished downloading");
Dialog.Message = "Configuring Roblox..."; Dialog.Message = "Configuring Roblox...";
Directory.CreateDirectory(Directories.Versions); // wait for all packages to finish extracting
while (PackagesExtracted < VersionPackageManifest.Count)
foreach (Package package in VersionPackageManifest)
{ {
// extract all the packages at once (shouldn't be too heavy on cpu?) await Task.Delay(100);
ExtractPackage(package);
} }
Debug.WriteLine("Finished extracting packages");
string appSettingsLocation = Path.Combine(VersionFolder, "AppSettings.xml"); string appSettingsLocation = Path.Combine(VersionFolder, "AppSettings.xml");
await File.WriteAllTextAsync(appSettingsLocation, AppSettings); await File.WriteAllTextAsync(appSettingsLocation, AppSettings);
@ -708,7 +708,7 @@ namespace Bloxstrap
} }
} }
private void ExtractPackage(Package package) private async Task ExtractPackage(Package package)
{ {
if (CancelFired) if (CancelFired)
return; return;
@ -720,7 +720,7 @@ namespace Bloxstrap
Debug.WriteLine($"Extracting {package.Name} to {packageFolder}..."); Debug.WriteLine($"Extracting {package.Name} to {packageFolder}...");
using (ZipArchive archive = ZipFile.OpenRead(packageLocation)) using (ZipArchive archive = await Task.Run(() => ZipFile.OpenRead(packageLocation)))
{ {
foreach (ZipArchiveEntry entry in archive.Entries) foreach (ZipArchiveEntry entry in archive.Entries)
{ {
@ -732,7 +732,7 @@ namespace Bloxstrap
extractPath = Path.Combine(packageFolder, entry.FullName); extractPath = Path.Combine(packageFolder, entry.FullName);
Debug.WriteLine($"[{package.Name}] Writing {extractPath}..."); //Debug.WriteLine($"[{package.Name}] Writing {extractPath}...");
directory = Path.GetDirectoryName(extractPath); directory = Path.GetDirectoryName(extractPath);
@ -744,9 +744,13 @@ namespace Bloxstrap
if (File.Exists(extractPath)) if (File.Exists(extractPath))
File.Delete(extractPath); File.Delete(extractPath);
entry.ExtractToFile(extractPath); await Task.Run(() => entry.ExtractToFile(extractPath));
} }
} }
Debug.WriteLine($"Finished extracting {package.Name}");
PackagesExtracted += 1;
} }
private void ExtractFileFromPackage(string packageName, string fileName) private void ExtractFileFromPackage(string packageName, string fileName)