Skip to content

Commit

Permalink
Start installing mods while downloads are still in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Nov 6, 2024
1 parent a58dfff commit 987df51
Show file tree
Hide file tree
Showing 36 changed files with 980 additions and 600 deletions.
22 changes: 11 additions & 11 deletions Cmdline/Action/Upgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,18 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
/// <param name="user">IUser object for output</param>
/// <param name="instance">Game instance to use</param>
/// <param name="modules">List of modules to upgrade</param>
private void UpgradeModules(NetModuleCache cache,
string? userAgent,
IUser user,
CKAN.GameInstance instance,
List<CkanModule> modules)
private void UpgradeModules(NetModuleCache cache,
string? userAgent,
IUser user,
CKAN.GameInstance instance,
List<CkanModule> modules)
{
UpgradeModules(
cache, userAgent, user, instance, repoData,
(ModuleInstaller installer, NetAsyncModulesDownloader downloader, RegistryManager regMgr, ref HashSet<string>? possibleConfigOnlyDirs) =>
installer.Upgrade(modules, downloader,
ref possibleConfigOnlyDirs,
regMgr, true, true, true),
regMgr, true, true),
modules.Add);
}

Expand All @@ -206,11 +206,11 @@ private void UpgradeModules(NetModuleCache cache,
/// <param name="user">IUser object for output</param>
/// <param name="instance">Game instance to use</param>
/// <param name="identsAndVersions">List of identifier[=version] to upgrade</param>
private void UpgradeModules(NetModuleCache cache,
string? userAgent,
IUser user,
CKAN.GameInstance instance,
List<string> identsAndVersions)
private void UpgradeModules(NetModuleCache cache,
string? userAgent,
IUser user,
CKAN.GameInstance instance,
List<string> identsAndVersions)
{
UpgradeModules(
cache, userAgent, user, instance, repoData,
Expand Down
22 changes: 7 additions & 15 deletions Cmdline/ConsoleUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,29 +258,21 @@ public void RaiseProgress(string message, int percent)
{
if (message != lastProgressMessage)
{
// The percent looks weird on non-download messages.
// The leading newline makes sure we don't end up with a mess from previous
// download messages.
GoToStartOfLine();
Console.Write("{0}", message);
// The percent looks weird on non-download messages
Console.WriteLine("{0}", message);
lastProgressMessage = message;
}

// This message leaves the cursor at the end of a line of text
atStartOfLine = false;
atStartOfLine = true;
}

public void RaiseProgress(int percent, long bytesPerSecond, long bytesLeft)
public void RaiseProgress(ByteRateCounter rateCounter)
{
if (!Headless || percent != previousPercent)
if (!Headless || rateCounter.Percent != previousPercent)
{
GoToStartOfLine();
var fullMsg = string.Format(CKAN.Properties.Resources.NetAsyncDownloaderProgress,
CkanModule.FmtSize(bytesPerSecond),
CkanModule.FmtSize(bytesLeft));
// The \r at the front here causes download messages to *overwrite* each other.
Console.Write("\r{0} - {1}% ", fullMsg, percent);
previousPercent = percent;
Console.Write("\r{0} ", rateCounter.Summary);
previousPercent = rateCounter.Percent;

// This message leaves the cursor at the end of a line of text
atStartOfLine = false;
Expand Down
4 changes: 2 additions & 2 deletions ConsoleUI/InstallScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public override void Run(Action? process = null)
HashSet<string>? possibleConfigOnlyDirs = null;

ModuleInstaller inst = new ModuleInstaller(manager.CurrentInstance, manager.Cache, this, userAgent);
inst.onReportModInstalled += OnModInstalled;
inst.OneComplete += OnModInstalled;
if (plan.Remove.Count > 0) {
inst.UninstallList(plan.Remove, ref possibleConfigOnlyDirs, regMgr, true, new List<CkanModule>(plan.Install));
plan.Remove.Clear();
Expand Down Expand Up @@ -113,7 +113,7 @@ public override void Run(Action? process = null)
}

trans.Complete();
inst.onReportModInstalled -= OnModInstalled;
inst.OneComplete -= OnModInstalled;
// Don't let the installer re-use old screen references
inst.User = new NullUser();

Expand Down
11 changes: 3 additions & 8 deletions ConsoleUI/Toolkit/ConsoleScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,10 @@ public void RaiseProgress(string message, int percent)
/// <summary>
/// Update a user visible progress bar
/// </summary>
/// <param name="percent">Value 0-100 representing the progress</param>
/// <param name="bytesPerSecond">Current download rate</param>
/// <param name="bytesLeft">Bytes remaining in the downloads</param>
public void RaiseProgress(int percent, long bytesPerSecond, long bytesLeft)
/// <param name="rateCounter">Object with the progress info</param>
public void RaiseProgress(ByteRateCounter rateCounter)
{
var fullMsg = string.Format(CKAN.Properties.Resources.NetAsyncDownloaderProgress,
CkanModule.FmtSize(bytesPerSecond),
CkanModule.FmtSize(bytesLeft));
Progress(fullMsg, percent);
Progress(rateCounter.Summary, rateCounter.Percent);
Draw();
}

Expand Down
9 changes: 9 additions & 0 deletions Core/Extensions/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Collections.Generic;

Expand All @@ -23,5 +24,13 @@ public static bool DictionaryEquals<K, V>(this IDictionary<K, V>? a,
return val;
}

public static IEnumerable<Tuple<K, V1, V2>> KeyZip<K, V1, V2>(this IDictionary<K, V1> source,
IDictionary<K, V2> other)
where K : notnull
=> source.Select(kvp => other.TryGetValue(kvp.Key, out V2? val2)
? Tuple.Create(kvp.Key, kvp.Value, val2)
: null)
.OfType<Tuple<K, V1, V2>>();

}
}
Loading

0 comments on commit 987df51

Please sign in to comment.