Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per-file progress for uninstall and upgrade #4193

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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