Skip to content

Commit

Permalink
Merge #3944 Protect upgradeable mods from being displayed as uninstalled
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 14, 2023
2 parents 8120d3f + 4cb4ca6 commit a79f1c9
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ All notable changes to this project will be documented in this file.

## v1.34.1

### Bugfixes

- [GUI] Protect upgradeable mods from being displayed as uninstalled (#3944 by: HebaruSan)

## v1.34.0 (Minkowski)

Expand Down
2 changes: 1 addition & 1 deletion Core/Configuration/Win32RegistryConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public bool TryGetAuthToken(string host, out string token)
public IEnumerable<string> GetAuthTokenHosts()
{
RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(authTokenKeyNoPrefix);
return key?.GetValueNames() ?? new string[0];
return key?.GetValueNames() ?? Array.Empty<string>();
}

public void SetAuthToken(string host, string token)
Expand Down
4 changes: 2 additions & 2 deletions Core/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public void UninstallList(
registry_manager.registry.FindRemovableAutoInstalled(
registry_manager.registry.InstalledModules
.Where(im => !revdep.Contains(im.identifier))
.Concat(installing?.Select(m => new InstalledModule(null, m, new string[0], false)) ?? new InstalledModule[0])
.Concat(installing?.Select(m => new InstalledModule(null, m, Array.Empty<string>(), false)) ?? Array.Empty<InstalledModule>())
.ToList(),
ksp.VersionCriteria())
.Select(im => im.identifier))
Expand Down Expand Up @@ -1160,7 +1160,7 @@ public void Upgrade(IEnumerable<CkanModule> modules,
// Conjure the future state of the installed modules list after upgrading
registry.InstalledModules
.Where(im => !removingIdents.Contains(im.identifier))
.Concat(modules.Select(m => new InstalledModule(null, m, new string[0], false)))
.Concat(modules.Select(m => new InstalledModule(null, m, Array.Empty<string>(), false)))
.ToList(),
ksp.VersionCriteria())
.ToList();
Expand Down
2 changes: 1 addition & 1 deletion Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private void ResolveStanza(List<RelationshipDescriptor> stanza,
// Nothing found, try again while simulating an empty mod list
// Necessary for e.g. proceed_with_inconsistencies, conflicts will still be caught below
candidates = descriptor
.LatestAvailableWithProvides(registry, versionCrit, new CkanModule[0])
.LatestAvailableWithProvides(registry, versionCrit, Array.Empty<CkanModule>())
.Where(mod => !modlist.ContainsKey(mod.identifier)
&& descriptor1.WithinBounds(mod)
&& MightBeInstallable(mod))
Expand Down
18 changes: 9 additions & 9 deletions GUI/Controls/EditModSearchDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ public ModSearch CurrentSearch()
private ModSearch CurrentSearch(List<ModuleLabel> knownLabels)
=> new ModSearch(
FilterByNameTextBox.Text,
FilterByAuthorTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterByAuthorTextBox.Text.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterByDescriptionTextBox.Text,
FilterByLanguageTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterByDependsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterByRecommendsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterBySuggestsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterByConflictsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterBySupportsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterByTagsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterByLabelsTextBox.Text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries)
FilterByLanguageTextBox.Text.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterByDependsTextBox.Text.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterByRecommendsTextBox.Text.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterBySuggestsTextBox.Text.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterByConflictsTextBox.Text.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterBySupportsTextBox.Text.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterByTagsTextBox.Text.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries).ToList(),
FilterByLabelsTextBox.Text.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries)
.Select(ln => knownLabels.FirstOrDefault(lb => lb.Name == ln))
.Where(lb => lb != null)
.ToList(),
Expand Down
10 changes: 5 additions & 5 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,9 +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 installedIdents = registry.InstalledModules
.Select(im => im.identifier)
.ToHashSet();
var gui_mods = registry.InstalledModules
.AsParallel()
.Where(instMod => !instMod.Module.IsDLC)
Expand All @@ -1204,15 +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)
.Where(m => !installedIdents.Contains(m.identifier))
.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)
.Where(m => !installedIdents.Contains(m.identifier))
.AsParallel()
.Where(m => !m.IsDLC)
.Select(m => new GUIMod(
Expand Down
2 changes: 1 addition & 1 deletion GUI/Model/ModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private IEnumerable<InstalledModule> InstalledAfterChanges(
ch.ChangeType == GUIModChangeType.Replace
? registry.GetReplacement(ch.Mod, crit)?.ReplaceWith
: (ch as ModUpgrade)?.targetMod ?? ch.Mod,
new string[0],
Enumerable.Empty<string>(),
false)));
}

Expand Down
5 changes: 3 additions & 2 deletions Tests/Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Transactions;
using System.Collections.Generic;
Expand Down Expand Up @@ -315,8 +316,8 @@ public void HasUpdate_OtherModDependsOnCurrent_ReturnsFalse()
CkanModule dependingMod = registry.GetModuleByVersion("DependingMod", "1.0");

GameInstance gameInst = gameInstWrapper.KSP;
registry.RegisterModule(olderDepMod, new string[0], gameInst, false);
registry.RegisterModule(dependingMod, new string[0], gameInst, false);
registry.RegisterModule(olderDepMod, Array.Empty<string>(), gameInst, false);
registry.RegisterModule(dependingMod, Array.Empty<string>(), gameInst, false);
GameVersionCriteria crit = new GameVersionCriteria(olderDepMod.ksp_version);

// Act
Expand Down
4 changes: 2 additions & 2 deletions Tests/Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,8 @@ public void UninstallingConflictingModule_InstallingRecursiveDependencies_Resolv
var registry = new CKAN.Registry(repoData.Manager, repo.repo);

// Start with eve and eveDefaultConfig installed
registry.RegisterModule(eve, new string[0], ksp.KSP, false);
registry.RegisterModule(eveDefaultConfig, new string[0], ksp.KSP, false);
registry.RegisterModule(eve, Array.Empty<string>(), ksp.KSP, false);
registry.RegisterModule(eveDefaultConfig, Array.Empty<string>(), ksp.KSP, false);

Assert.DoesNotThrow(() => registry.CheckSanity());

Expand Down

0 comments on commit a79f1c9

Please sign in to comment.