Skip to content

Commit

Permalink
Merge #4193 Per-file progress for uninstall and upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Sep 24, 2024
2 parents bcdf2b7 + c18ac77 commit 219f799
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ All notable changes to this project will be documented in this file.
- [Core] Support Windows KSP1 instances on Linux (#4044 by: HebaruSan)
- [GUI] I18n updates from Crowdin (#4050 by: HebaruSan)
- [Multiple] Better version specific relationships at install and upgrade (#4023, #4152 by: HebaruSan)
- [GUI] Proportional, granular progress updates for installing (#4055 by: HebaruSan)
- [GUI] Proportional, granular progress updates (#4055, #4193 by: HebaruSan)
- [GUI] Modpack compatibility prompt, GameComparator clean-up (#4056 by: HebaruSan)
- [ConsoleUI] Add downloads column for ConsoleUI (#4063 by: HebaruSan)
- [ConsoleUI] Play game option for ConsoleUI (#4064 by: HebaruSan)
Expand Down
60 changes: 34 additions & 26 deletions Core/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -761,16 +761,19 @@ public void UninstallList(IEnumerable<string> mods,

using (var transaction = CkanTransaction.CreateTransactionScope())
{
int step = 0;
foreach (string mod in goners)
var registry = registry_manager.registry;
var progDescr = "";
var progress = new ProgressScalePercentsByFileSizes(
new Progress<int>(percent => User.RaiseProgress(progDescr, percent)),
goners.Select(id => (long?)registry.InstalledModule(id)?.Files.Count()
?? 0));
foreach (string ident in goners)
{
int percent_complete = (step++ * 100) / goners.Count;
var registry = registry_manager.registry;
User.RaiseProgress(string.Format(Properties.Resources.ModuleInstallerRemovingMod,
registry.InstalledModule(mod)?.Module.ToString()
?? mod),
percent_complete);
Uninstall(mod, ref possibleConfigOnlyDirs, registry);
progDescr = string.Format(Properties.Resources.ModuleInstallerRemovingMod,
registry.InstalledModule(ident)?.Module.ToString()
?? ident);
Uninstall(ident, ref possibleConfigOnlyDirs, registry, progress);
progress.NextFile();
}

// Enforce consistency if we're not installing anything,
Expand All @@ -792,7 +795,8 @@ public void UninstallList(IEnumerable<string> mods,
/// <param name="possibleConfigOnlyDirs">Directories that the user might want to remove after uninstall</param>
private void Uninstall(string identifier,
ref HashSet<string>? possibleConfigOnlyDirs,
Registry registry)
Registry registry,
IProgress<int> progress)
{
var file_transaction = new TxFileManager();

Expand All @@ -815,9 +819,11 @@ private void Uninstall(string identifier,
// Files that Windows refused to delete due to locking (probably)
var undeletableFiles = new List<string>();

int i = 0;
foreach (string relPath in modFiles)
{
string absPath = instance.ToAbsoluteGameDir(relPath);
progress?.Report(100 * i++ / modFiles.Length);

try
{
Expand Down Expand Up @@ -1077,39 +1083,41 @@ private void AddRemove(ref HashSet<string>? possibleConfigOnlyDirs,
using (var tx = CkanTransaction.CreateTransactionScope())
{
int totSteps = remove.Count + add.Count;
int step = 0;

string progDescr = "";
var rmProgress = new ProgressScalePercentsByFileSizes(
new Progress<int>(percent =>
User.RaiseProgress(progDescr,
percent * add.Count / totSteps)),
remove.Select(instMod => (long)instMod.Files.Count()));
foreach (InstalledModule instMod in remove)
{
// The post-install steps start at 80%, so count up to 70% for installation
int percent_complete = (step++ * 70) / totSteps;
User.RaiseProgress(
string.Format(Properties.Resources.ModuleInstallerRemovingMod, instMod.Module),
percent_complete);
Uninstall(instMod.Module.identifier, ref possibleConfigOnlyDirs, registry_manager.registry);
progDescr = string.Format(Properties.Resources.ModuleInstallerRemovingMod, instMod.Module);
Uninstall(instMod.Module.identifier, ref possibleConfigOnlyDirs, registry_manager.registry, rmProgress);
rmProgress.NextFile();
}

var addProgress = new ProgressScalePercentsByFileSizes(
new Progress<int>(percent =>
User.RaiseProgress(progDescr,
((100 * add.Count) + (percent * remove.Count)) / totSteps)),
add.Select(m => m.install_size));
foreach ((CkanModule module, bool autoInst) in add.Zip(autoInstalled))
{
progDescr = string.Format(Properties.Resources.ModuleInstallerInstallingMod, module);
var previous = remove?.FirstOrDefault(im => im.Module.identifier == module.identifier);
int percent_complete = (step++ * 70) / totSteps;
User.RaiseProgress(
string.Format(Properties.Resources.ModuleInstallerInstallingMod, module),
percent_complete);
// For upgrading, new modules are dependencies and should be marked auto-installed,
// for replacing, new modules are the replacements and should not be marked auto-installed
Install(module,
previous?.AutoInstalled ?? autoInst,
registry_manager.registry,
ref possibleConfigOnlyDirs,
null);
addProgress);
addProgress.NextFile();
}

User.RaiseProgress(Properties.Resources.ModuleInstallerUpdatingRegistry, 80);
registry_manager.Save(enforceConsistency);

User.RaiseProgress(Properties.Resources.ModuleInstallerCommitting, 90);
tx.Complete();

EnforceCacheSizeLimit(registry_manager.registry, Cache);
}
}
Expand Down

0 comments on commit 219f799

Please sign in to comment.