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

Improve provides prompt usability, with bugfixes #3934

Merged
merged 6 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion Core/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ Please remove manually before trying to install it.</value></data>
<data name="KrakenDependencyModuleNotFound" xml:space="preserve"><value>Module not found: {0} {1}</value></data>
<data name="KrakenParentDependencyNotSatisfied" xml:space="preserve"><value>{0} dependency on {1} version {2} not satisfied</value></data>
<data name="KrakenAny" xml:space="preserve"><value>(any)</value></data>
<data name="KrakenProvidedByMoreThanOne" xml:space="preserve"><value>Module {0} is provided by more than one available module. Please choose one of the following:</value></data>
<data name="KrakenProvidedByMoreThanOne" xml:space="preserve"><value>{1} requires {0}, which can be provided by multiple mods.

Which {0} provider would you like to install?</value></data>
<data name="KrakenInconsistenciesHeader" xml:space="preserve"><value>Inconsistencies were found:</value></data>
<data name="KrakenMissingDependency" xml:space="preserve"><value>{0} missing dependency {1}</value></data>
<data name="KrakenConflictsWith" xml:space="preserve"><value>{0} conflicts with {1}</value></data>
Expand Down
19 changes: 10 additions & 9 deletions Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,13 @@ private void ResolveStanza(List<RelationshipDescriptor> stanza,
// Oh no, too many to pick from!
if (options.without_toomanyprovides_kraken)
{
if (options.get_recommenders)
if (options.get_recommenders && !(reason is SelectionReason.Depends))
{
for (int i = 0; i < candidates.Count; ++i)
{
var cand = candidates[i];
Add(cand, reason is SelectionReason.Recommended rec
? rec.WithIndex(i)
: reason);
Add(candidates[i], reason is SelectionReason.Recommended rec
? rec.WithIndex(i)
: reason);
}
}
continue;
Expand All @@ -348,15 +347,17 @@ private void ResolveStanza(List<RelationshipDescriptor> stanza,
.ToList();
if (provide.Count != 1)
{
//We still have either nothing, or too many to pick from
//Just throw the TMP now
throw new TooManyModsProvideKraken(descriptor.ToString(), candidates, descriptor.choice_help_text);
// We still have either nothing, or too many to pick from
// Just throw the TMP now
throw new TooManyModsProvideKraken(reason.Parent, descriptor.ToString(),
candidates, descriptor.choice_help_text);
}
candidates[0] = provide.First();
}
else
{
throw new TooManyModsProvideKraken(descriptor.ToString(), candidates, descriptor.choice_help_text);
throw new TooManyModsProvideKraken(reason.Parent, descriptor.ToString(),
candidates, descriptor.choice_help_text);
}
}

Expand Down
6 changes: 3 additions & 3 deletions Core/Repositories/AvailableModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private static bool DependsAndConflictsOK(CkanModule module, ICollection<CkanMod
// If 'others' matches an identifier, it must also match the versions, else fail
if (rel.ContainsAny(others.Select(m => m.identifier)) && !rel.MatchesAny(others, null, null))
{
log.DebugFormat("Unsatisfied dependency {0}, rejecting", rel);
log.DebugFormat("Unsatisfied dependency {0}, rejecting {1}", rel, module);
return false;
}
}
Expand All @@ -151,7 +151,7 @@ private static bool DependsAndConflictsOK(CkanModule module, ICollection<CkanMod
// If any of the conflicts are present, fail
if (rel.MatchesAny(othersMinusSelf, null, null, out CkanModule matched))
{
log.DebugFormat("Found conflict with {0}, rejecting", matched);
log.DebugFormat("Found conflict with {0}, rejecting {1}", matched, module);
return false;
}
}
Expand All @@ -166,7 +166,7 @@ private static bool DependsAndConflictsOK(CkanModule module, ICollection<CkanMod
{
if (rel.MatchesAny(selfArray, null, null))
{
log.DebugFormat("Found reverse conflict with {0}, rejecting", other);
log.DebugFormat("Found reverse conflict with {0}, rejecting {1}", other, module);
return false;
}
}
Expand Down
7 changes: 5 additions & 2 deletions Core/Types/Kraken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,21 @@ public RegistryVersionNotSupportedKraken(int v, string reason = null, Exception

public class TooManyModsProvideKraken : Kraken
{
public readonly CkanModule requester;
public readonly List<CkanModule> modules;
public readonly string requested;
public readonly string choice_help_text;

public TooManyModsProvideKraken(string requested,
public TooManyModsProvideKraken(CkanModule requester,
string requested,
List<CkanModule> modules,
string choice_help_text = null,
Exception innerException = null)
: base(choice_help_text ?? string.Format(Properties.Resources.KrakenProvidedByMoreThanOne,
requested),
requested, requester.name),
innerException)
{
this.requester = requester;
this.requested = requested;
this.modules = modules;
this.choice_help_text = choice_help_text;
Expand Down
1 change: 1 addition & 0 deletions GUI/Controls/ChooseProvidedMods.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions GUI/Controls/ChooseProvidedMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,33 @@ public void LoadProviders(string message, List<CkanModule> modules, NetModuleCac
Util.Invoke(this, () =>
{
ChooseProvidedModsLabel.Text = message;
ChooseProvidedModsLabel.Height =
Util.LabelStringHeight(CreateGraphics(), ChooseProvidedModsLabel);

ChooseProvidedModsListView.Items.Clear();
ChooseProvidedModsListView.Items.AddRange(modules
.Select(module => new ListViewItem(new string[]
.Select((module, index) => new ListViewItem(new string[]
{
cache.DescribeAvailability(module),
module.@abstract
})
{
Tag = module,
Checked = false
Checked = index == 0,
})
.ToArray());
ChooseProvidedModsListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
ChooseProvidedModsContinueButton.Enabled = false;
ChooseProvidedModsContinueButton.Enabled =
(ChooseProvidedModsListView.CheckedItems.Count > 0);
});
}

protected override void OnResize(EventArgs e)
{
base.OnResize(e);
ChooseProvidedModsLabel.Height = Util.LabelStringHeight(CreateGraphics(), ChooseProvidedModsLabel);
}

[ForbidGUICalls]
public CkanModule Wait()
{
Expand Down
5 changes: 5 additions & 0 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,9 @@ private bool _UpdateModsList(Dictionary<string, bool> old_modules = null)
Main.Instance.Wait.AddLogMessage(Properties.Resources.MainModListLoadingInstalled);
var versionCriteria = Main.Instance.CurrentInstance.VersionCriteria();

var installed = registry.InstalledModules
.Select(im => im.Module)
.ToHashSet();
var gui_mods = registry.InstalledModules
.AsParallel()
.Where(instMod => !instMod.Module.IsDLC)
Expand All @@ -1201,13 +1204,15 @@ private bool _UpdateModsList(Dictionary<string, bool> old_modules = null)
Main.Instance.configuration.HideEpochs,
Main.Instance.configuration.HideV))
.Concat(registry.CompatibleModules(versionCriteria)
.Except(installed)
.AsParallel()
.Where(m => !m.IsDLC)
.Select(m => new GUIMod(
m, repoData, registry, versionCriteria, null,
Main.Instance.configuration.HideEpochs,
Main.Instance.configuration.HideV)))
.Concat(registry.IncompatibleModules(versionCriteria)
.Except(installed)
.AsParallel()
.Where(m => !m.IsDLC)
.Select(m => new GUIMod(
Expand Down
15 changes: 14 additions & 1 deletion GUI/Main/MainInstall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Linq;
using System.Transactions;

using Autofac;

using CKAN.Extensions;
using CKAN.GUI.Attributes;
#if NET5_0_OR_GREATER
Expand Down Expand Up @@ -271,7 +273,17 @@ private void InstallMods(object sender, DoWorkEventArgs e)
{
// Prompt user to choose which mod to use
tabController.ShowTab("ChooseProvidedModsTabPage", 3);
ChooseProvidedMods.LoadProviders(k.Message, k.modules, Manager.Cache);
Util.Invoke(this, () => StatusProgress.Visible = false);
var repoData = ServiceLocator.Container.Resolve<RepositoryDataManager>();
ChooseProvidedMods.LoadProviders(
k.Message,
k.modules.OrderByDescending(m => repoData.GetDownloadCount(registry.Repositories.Values,
m.identifier)
?? 0)
.ThenByDescending(m => m.identifier == k.requested)
.ThenBy(m => m.name)
.ToList(),
Manager.Cache);
tabController.SetTabLock(true);
CkanModule chosen = ChooseProvidedMods.Wait();
// Close the selection prompt
Expand All @@ -283,6 +295,7 @@ private void InstallMods(object sender, DoWorkEventArgs e)
toInstall.Add(chosen);
// DON'T return so we can loop around and try the above InstallList call again
tabController.ShowTab("WaitTabPage");
Util.Invoke(this, () => StatusProgress.Visible = true);
}
else
{
Expand Down