Skip to content

Commit

Permalink
Merge #3934 Improve provides prompt usability, with bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 1, 2023
2 parents d6ecc87 + 919a596 commit 5684cd6
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ All notable changes to this project will be documented in this file.
- [Build] Clean up Linux .desktop files (#3927 by: irasponsible; reviewed: HebaruSan)
- [GUI] Don't change language setting with scroll wheel (#3928 by: HebaruSan; reviewed: techman83)
- [Core] Make where-CKAN-would-install logic consistent (#3931 by: HebaruSan; reviewed: techman83)
- [Multiple] Improve provides prompt usability, with bugfixes (#3934 by: HebaruSan; reviewed: JonnyOThan)

### Internal

Expand Down
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

0 comments on commit 5684cd6

Please sign in to comment.