Skip to content

Commit

Permalink
Bug fixes and improvements to installer.
Browse files Browse the repository at this point in the history
- Progress bar is now scaled relative to the number of files rather than
file sizes.
- Fixed a bug where files could be written more than once in some
circumstances.
  • Loading branch information
MaximumADHD committed Apr 9, 2020
1 parent 694f4f3 commit 1537e4e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 17 deletions.
3 changes: 3 additions & 0 deletions ProjectSrc/Bootstrapper/FileManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ private FileManifest(string data)
if (path == null || signature == null)
break;

if (path.StartsWith("ExtraContent"))
path = path.Replace("ExtraContent", "content");

Add(path, signature);
}
catch
Expand Down
52 changes: 35 additions & 17 deletions ProjectSrc/Forms/StudioBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public partial class StudioBootstrapper : Form
private FileManifest fileManifest;
private bool forceInstall = false;
private bool exitWhenClosed = true;
private int actualProgressBarSum = 0;

private int actualProgress = 0;
private HashSet<string> writtenFiles;

public SystemEvent StartEvent { get; private set; }
private Task autoExitTask;
Expand Down Expand Up @@ -130,8 +132,8 @@ private void incrementProgressBarMax(int count)
}
else
{
actualProgressBarSum += count;
progressBar.Maximum = Math.Max(progressBar.Maximum, actualProgressBarSum);
actualProgress += count;
progressBar.Maximum = Math.Max(progressBar.Maximum, actualProgress);
}
}

Expand Down Expand Up @@ -497,23 +499,28 @@ private static string fixFilePath(string pkgName, string filePath)
private async Task installPackage(string branch, Package package)
{
string pkgName = package.Name;
var pkgInfo = pkgRegistry.GetSubKey(pkgName);

string studioDir = GetStudioDirectory();
string downloads = getDirectory(studioDir, "downloads");

string oldSig = pkgRegistry.GetString(pkgName);
string oldSig = pkgInfo.GetString("Signature");
string newSig = package.Signature;

if (oldSig == newSig && !forceInstall)
{
int fileCount = pkgInfo.GetInt("NumFiles");
echo($"Package '{pkgName}' hasn't changed between builds, skipping.");

incrementProgressBarMax(fileCount);
incrementProgress(fileCount);

return;
}

string zipFileUrl = $"https://s3.amazonaws.com/setup.{branch}.com/{buildVersion}-{pkgName}";
string zipExtractPath = Path.Combine(downloads, package.Name);

incrementProgressBarMax(package.Size);
echo($"Installing package {zipFileUrl}");

var localHttp = new WebClient();
Expand Down Expand Up @@ -542,9 +549,15 @@ private async Task installPackage(string branch, Package package)
}

ZipArchive archive = ZipFile.OpenRead(zipExtractPath);
string localRootDir = null;
var deferred = new Dictionary<ZipArchiveEntry, string>();

int numFiles = archive.Entries
.Select(entry => entry.FullName)
.Where(name => !name.EndsWith("/"))
.Count();

var reprocess = new Dictionary<ZipArchiveEntry, string>();
string localRootDir = null;
incrementProgressBarMax(numFiles);

foreach (ZipArchiveEntry entry in archive.Entries)
{
Expand Down Expand Up @@ -616,7 +629,7 @@ private async Task installPackage(string branch, Package package)
{
// Check back on this file after we extract the regular files,
// so we can make sure this is extracted to the correct directory.
reprocess.Add(entry, newFileSig);
deferred.Add(entry, newFileSig);
}
else
{
Expand All @@ -629,10 +642,10 @@ private async Task installPackage(string branch, Package package)
}

// Process any files that we deferred from writing immediately.
foreach (ZipArchiveEntry entry in reprocess.Keys)
foreach (ZipArchiveEntry entry in deferred.Keys)
{
string file = entry.FullName;
string newFileSig = reprocess[entry];
string newFileSig = deferred[entry];

if (localRootDir != null)
file = localRootDir + file;
Expand All @@ -642,21 +655,25 @@ private async Task installPackage(string branch, Package package)

// Update the signature in the package registry so we can check
// if this zip file needs to be updated in future versions.
pkgRegistry.SetValue(pkgName, package.Signature);

pkgInfo.SetValue("Signature", package.Signature);
pkgInfo.SetValue("NumFiles", numFiles);
}

private void writePackageFile(string studioDir, string pkgName, string file, string newFileSig, ZipArchiveEntry entry)
{
string filePath = fixFilePath(pkgName, file);
int length = (int)entry.Length;

if (writtenFiles.Contains(filePath))
return;

if (!forceInstall)
{
string oldFileSig = fileRegistry.GetValue(filePath, "") as string;
string oldFileSig = fileRegistry.GetString(filePath);

if (oldFileSig == newFileSig)
{
incrementProgress(length);
incrementProgress();
return;
}
}
Expand All @@ -681,7 +698,8 @@ private void writePackageFile(string studioDir, string pkgName, string file, str
echo($"FILE WRITE FAILED: {filePath} (This build may not run as expected!)");
}

incrementProgress(length);
incrementProgress();
writtenFiles.Add(filePath);
}

public static string GetStudioDirectory()
Expand Down Expand Up @@ -758,14 +776,15 @@ public async Task RunInstaller(string branch, bool setStartEvent = false)
setStatus($"Installing Version {versionId} of Roblox Studio...");

var taskQueue = new List<Task>();
writtenFiles = new HashSet<string>();

echo("Grabbing package manifest...");
var pkgManifest = await PackageManifest.Get(branch, buildVersion);

echo("Grabbing file manifest...");
fileManifest = await FileManifest.Get(branch, buildVersion);

progressBar.Maximum = 1;
progressBar.Maximum = 5000;
progressBar.Value = 0;

progressBar.Style = ProgressBarStyle.Continuous;
Expand All @@ -778,7 +797,6 @@ public async Task RunInstaller(string branch, bool setStartEvent = false)
}

await Task.WhenAll(taskQueue);

echo("Writing AppSettings.xml...");

string appSettings = Path.Combine(studioDir, "AppSettings.xml");
Expand Down
14 changes: 14 additions & 0 deletions ProjectSrc/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public static bool GetBool(this RegistryKey key, string name)
return result;
}

public static int GetInt(this RegistryKey key, string name)
{
string value = key.GetString(name);
int result = 0;

int.TryParse(value, out result);
return result;
}

public static RegistryKey GetSubKey(params string[] path)
{
return MainRegistry.GetSubKey(path);
Expand All @@ -53,6 +62,11 @@ public static bool GetBool(string name)
return MainRegistry.GetBool(name);
}

public static int GetInt(string name)
{
return MainRegistry.GetInt(name);
}

public static void SetValue(string name, object value)
{
MainRegistry.SetValue(name, value);
Expand Down
Binary file modified RobloxStudioModManager.exe
Binary file not shown.

0 comments on commit 1537e4e

Please sign in to comment.