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

Modpack usability fixes #3243

Merged
merged 2 commits into from
Feb 6, 2021
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
2 changes: 1 addition & 1 deletion Core/DLC/StandardDlcDetectorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class StandardDlcDetectorBase : IDlcDetector
private IGame game;

private static readonly Regex VersionPattern = new Regex(
@"^Version\s+(?<version>\S+)$",
@"^Version\s+(?<version>\S+)",
RegexOptions.Compiled | RegexOptions.IgnoreCase
);

Expand Down
7 changes: 3 additions & 4 deletions Core/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,17 +1315,16 @@ HashSet<CkanModule> toExclude
/// Determine whether there is any way to install the given set of mods.
/// Handles virtual dependencies, including recursively.
/// </summary>
/// <param name="registry">Registry of instance into which we want to install</param>
/// <param name="versionCriteria">Compatible versions of instance</param>
/// <param name="opts">Installer options</param>
/// <param name="toInstall">Mods we want to install</param>
/// <param name="registry">Registry of instance into which we want to install</param>
/// <returns>
/// True if it's possible to install these mods, false otherwise
/// </returns>
private bool CanInstall(
public bool CanInstall(
RelationshipResolverOptions opts,
List<CkanModule> toInstall,
Registry registry
IRegistryQuerier registry
)
{
string request = toInstall.Select(m => m.identifier).Aggregate((a, b) => $"{a}, {b}");
Expand Down
2 changes: 2 additions & 0 deletions Core/Registry/RegistryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,13 @@ public CkanModule GenerateModpack(bool recommends = false, bool with_versions =
spec_version = new ModuleVersion("v1.18"),
identifier = Identifier.Sanitize(name),
name = name,
author = new List<string>() { System.Environment.UserName },
@abstract = $"A list of modules installed on the {kspInstanceName} KSP instance",
kind = "metapackage",
version = new ModuleVersion(DateTime.UtcNow.ToString("yyyy.MM.dd.hh.mm.ss")),
license = new List<License>() { new License("unknown") },
download_content_type = "application/zip",
release_date = DateTime.Now,
};

List<RelationshipDescriptor> mods = registry.Installed(false, false)
Expand Down
72 changes: 34 additions & 38 deletions GUI/Controls/AllModVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,25 @@ private void VersionsListView_ItemCheck(object sender, ItemCheckEventArgs e)
}
}

private bool installable(CkanModule module)
private bool installable(ModuleInstaller installer, CkanModule module, IRegistryQuerier registry)
{
var currentInstance = Main.Instance.Manager.CurrentInstance;
var version = currentInstance.VersionCriteria();
if (!module.IsCompatibleKSP(version))
{
return false;
}
try
{
RelationshipResolver resolver = new RelationshipResolver(
new CkanModule[] { module },
null,
new RelationshipResolverOptions()
{
with_recommends = false,
without_toomanyprovides_kraken = true,
},
RegistryManager.Instance(currentInstance).registry,
version
);
}
catch (Exception)
{
return false;
}
return true;
return module.IsCompatibleKSP(Main.Instance.CurrentInstance.VersionCriteria())
&& installer.CanInstall(
RelationshipResolver.DependsOnlyOpts(),
new List<CkanModule>() { module },
registry);
}

private bool allowInstall(CkanModule module)
{
return installable(module)
GameInstance currentInstance = Main.Instance.Manager.CurrentInstance;
IRegistryQuerier registry = RegistryManager.Instance(currentInstance).registry;
var installer = ModuleInstaller.GetInstance(
currentInstance,
Main.Instance.Manager.Cache,
Main.Instance.currentUser);

return installable(installer, module, registry)
|| Main.Instance.YesNoDialog(
string.Format(Properties.Resources.AllModVersionsInstallPrompt, module.ToString()),
Properties.Resources.AllModVersionsInstallYes,
Expand Down Expand Up @@ -122,7 +109,6 @@ public GUIMod SelectedModule
{
set
{
ignoreItemCheck = true;
if (!(visibleGuiModule?.Equals(value) ?? value?.Equals(visibleGuiModule) ?? true))
{
// Listen for property changes (we only care about GUIMod.SelectedMod)
Expand All @@ -136,31 +122,41 @@ public GUIMod SelectedModule
visibleGuiModule.PropertyChanged += visibleGuiModule_PropertyChanged;
}
}
VersionsListView.Items.Clear();
// Only show checkboxes for non-DLC modules
VersionsListView.CheckBoxes = !value.ToModule().IsDLC;

// Get all the data; can put this in bg if slow
GameInstance currentInstance = Main.Instance.Manager.CurrentInstance;
IRegistryQuerier registry = RegistryManager.Instance(currentInstance).registry;

List<CkanModule> allAvailableVersions;
var installer = ModuleInstaller.GetInstance(
currentInstance,
Main.Instance.Manager.Cache,
Main.Instance.currentUser);
Dictionary<CkanModule, bool> allAvailableVersions = null;
try
{
allAvailableVersions = registry.AvailableByIdentifier(value.Identifier)
.OrderByDescending(m => m.version)
.ToList();
.ToDictionary(m => m,
m => installable(installer, m, registry));
}
catch (ModuleNotFoundKraken)
{
// No versions to be shown, abort and hope an auto refresh happens
return;
}

ModuleVersion installedVersion = registry.InstalledVersion(value.Identifier);

// Update UI; must be in fg
ignoreItemCheck = true;
bool latestCompatibleVersionAlreadyFound = false;
VersionsListView.Items.AddRange(allAvailableVersions.Select(module =>

VersionsListView.Items.Clear();
// Only show checkboxes for non-DLC modules
VersionsListView.CheckBoxes = !value.ToModule().IsDLC;

VersionsListView.Items.AddRange(allAvailableVersions
.OrderByDescending(kvp => kvp.Key.version)
.Select(kvp =>
{
CkanModule module = kvp.Key;
ModuleVersion minMod = null, maxMod = null;
GameVersion minKsp = null, maxKsp = null;
Registry.GetMinMaxVersions(new List<CkanModule>() {module}, out minMod, out maxMod, out minKsp, out maxKsp);
Expand All @@ -173,7 +169,7 @@ public GUIMod SelectedModule
Tag = module
};

if (installable(module))
if (kvp.Value)
{
if (!latestCompatibleVersionAlreadyFound)
{
Expand Down
15 changes: 15 additions & 0 deletions GUI/Controls/Changeset.Designer.cs

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

22 changes: 20 additions & 2 deletions GUI/Controls/Changeset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public void LoadChangeset(List<ModChange> changes, List<ModuleLabel> AlertLabels
}
}

protected override void OnVisibleChanged(EventArgs e)
{
base.OnVisibleChanged(e);
if (Visible && Platform.IsMono)
{
// Workaround: make sure the ListView headers are drawn
Util.Invoke(ChangesListView, () => ChangesListView.EndUpdate());
}
}

public ListView.SelectedListViewItemCollection SelectedItems
{
get
Expand All @@ -53,7 +63,7 @@ public ListView.SelectedListViewItemCollection SelectedItems
public event Action<ListView.SelectedListViewItemCollection> OnSelectedItemsChanged;

public event Action OnConfirmChanges;
public event Action OnCancelChanges;
public event Action<bool> OnCancelChanges;

private void ChangesListView_SelectedIndexChanged(object sender, EventArgs e)
{
Expand All @@ -75,7 +85,15 @@ private void CancelChangesButton_Click(object sender, EventArgs e)
{
if (OnCancelChanges != null)
{
OnCancelChanges();
OnCancelChanges(true);
}
}

private void BackButton_Click(object sender, EventArgs e)
{
if (OnCancelChanges != null)
{
OnCancelChanges(false);
}
}

Expand Down
1 change: 1 addition & 0 deletions GUI/Controls/Changeset.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<data name="Mod.Text" xml:space="preserve"><value>Mod</value></data>
<data name="ChangeType.Text" xml:space="preserve"><value>Change</value></data>
<data name="Reason.Text" xml:space="preserve"><value>Reason for action</value></data>
<data name="BackButton.Text" xml:space="preserve"><value>Back</value></data>
<data name="CancelChangesButton.Text" xml:space="preserve"><value>Clear</value></data>
<data name="ConfirmChangesButton.Text" xml:space="preserve"><value>Apply</value></data>
</root>
27 changes: 26 additions & 1 deletion GUI/Controls/EditModpack.Designer.cs

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

3 changes: 3 additions & 0 deletions GUI/Controls/EditModpack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void LoadModule(CkanModule module, IRegistryQuerier registry)
IdentifierTextBox.Text = module.identifier;
NameTextBox.Text = module.name;
AbstractTextBox.Text = module.@abstract;
AuthorTextBox.Text = string.Join(", ", module.author);
VersionTextBox.Text = module.version.ToString();
var options = new string[] { "" }.Concat(Main.Instance.CurrentInstance.game.KnownVersions
.SelectMany(v => new GameVersion[] {
Expand Down Expand Up @@ -175,6 +176,8 @@ private bool TryFieldsToModule(out string error, out Control badField)
module.identifier = IdentifierTextBox.Text;
module.name = NameTextBox.Text;
module.@abstract = AbstractTextBox.Text;
module.author = AuthorTextBox.Text
.Split(',').Select(a => a.Trim()).ToList();
module.version = new ModuleVersion(VersionTextBox.Text);
module.license = new List<License>() { new License(LicenseComboBox.Text) };
module.ksp_version_min = string.IsNullOrEmpty(GameVersionMinComboBox.Text)
Expand Down
1 change: 1 addition & 0 deletions GUI/Controls/EditModpack.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<data name="IdentifierLabel.Text" xml:space="preserve"><value>Identifier:</value></data>
<data name="NameLabel.Text" xml:space="preserve"><value>Name:</value></data>
<data name="AbstractLabel.Text" xml:space="preserve"><value>Abstract:</value></data>
<data name="AuthorLabel.Text" xml:space="preserve"><value>Author:</value></data>
<data name="VersionLabel.Text" xml:space="preserve"><value>Version:</value></data>
<data name="GameVersionLabel.Text" xml:space="preserve"><value>Game versions:</value></data>
<data name="LicenseLabel.Text" xml:space="preserve"><value>Licence:</value></data>
Expand Down
2 changes: 1 addition & 1 deletion GUI/Controls/ManageMods.Designer.cs

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

Loading