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

Fix Newly Compatible filter with repo autoupdate #2734

Merged
merged 1 commit into from
Apr 23, 2019
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: 2 additions & 2 deletions GUI/MainInstall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ private void PostInstallMods(object sender, RunWorkerCompletedEventArgs e)
if (result.Key && !installCanceled)
{
// Rebuilds the list of GUIMods
UpdateModsList(false, null);
UpdateModsList(null);

if (modChangedCallback != null)
{
Expand All @@ -385,7 +385,7 @@ private void PostInstallMods(object sender, RunWorkerCompletedEventArgs e)
{
// User cancelled the installation
// Rebuilds the list of GUIMods
UpdateModsList(false, ChangeSet);
UpdateModsList(ChangeSet);
UpdateChangesDialog(null, installWorker);
if (result.Key) {
FailWaitDialog("Cancellation to late, process complete!", "User canceled the process manually, but all mods already (un)installed/upgraded.", "Process complete!", result.Key);
Expand Down
16 changes: 8 additions & 8 deletions GUI/MainModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ private void _UpdateFilters()
}
}

public void UpdateModsList(Boolean repo_updated = false, IEnumerable<ModChange> mc = null)
public void UpdateModsList(IEnumerable<ModChange> mc = null, Dictionary<string, bool> old_modules = null)
{
// Run the update in the background so the UI thread can appear alive
Task.Factory.StartNew(() =>
_UpdateModsList(repo_updated, mc ?? new List<ModChange>())
_UpdateModsList(mc ?? new List<ModChange>(), old_modules)
);
}

private void _UpdateModsList(bool repo_updated, IEnumerable<ModChange> mc)
private void _UpdateModsList(IEnumerable<ModChange> mc, Dictionary<string, bool> old_modules = null)
{
log.Info("Updating the mod list");

Expand Down Expand Up @@ -209,13 +209,12 @@ private void _UpdateModsList(bool repo_updated, IEnumerable<ModChange> mc)
}

AddLogMessage("Preserving new flags...");
var old_modules = mainModList.Modules.ToDictionary(m => m, m => m.IsIncompatible);
if (repo_updated)
if (old_modules != null)
{
foreach (GUIMod gm in gui_mods)
{
bool oldIncompat;
if (old_modules.TryGetValue(gm, out oldIncompat))
if (old_modules.TryGetValue(gm.Identifier, out oldIncompat))
{
// Found it; check if newly compatible
if (!gm.IsIncompatible && oldIncompat)
Expand All @@ -232,8 +231,9 @@ private void _UpdateModsList(bool repo_updated, IEnumerable<ModChange> mc)
}
else
{
//Copy the new mod flag from the old list.
var old_new_mods = new HashSet<GUIMod>(old_modules.Keys.Where(m => m.IsNew));
// Copy the new mod flag from the old list.
var old_new_mods = new HashSet<GUIMod>(
mainModList.Modules.Where(m => m.IsNew));
foreach (var gui_mod in gui_mods.Where(m => old_new_mods.Contains(m)))
{
gui_mod.IsNew = true;
Expand Down
29 changes: 25 additions & 4 deletions GUI/MainRepo.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net;
using System.Timers;
using System.Linq;
using Newtonsoft.Json;
using CKAN.Versioning;

namespace CKAN
{
Expand Down Expand Up @@ -64,7 +66,22 @@ private void UpdateRepo(object sender, DoWorkEventArgs e)
try
{
AddStatusMessage("Updating repositories...");
e.Result = Repo.UpdateAllRepositories(RegistryManager.Instance(CurrentInstance), CurrentInstance, Manager.Cache, GUI.user);

// Note the current mods' compatibility for the NewlyCompatible filter
KspVersionCriteria versionCriteria = CurrentInstance.VersionCriteria();
IRegistryQuerier registry = RegistryManager.Instance(CurrentInstance).registry;
Dictionary<string, bool> oldModules = registry.Available(versionCriteria)
.ToDictionary(m => m.identifier, m => false);
registry.Incompatible(versionCriteria)
.Where(m => !oldModules.ContainsKey(m.identifier))
.ToList()
.ForEach(m => oldModules.Add(m.identifier, true));

RepoUpdateResult result = Repo.UpdateAllRepositories(
RegistryManager.Instance(CurrentInstance),
CurrentInstance, Manager.Cache, GUI.user);
e.Result = new KeyValuePair<RepoUpdateResult, Dictionary<string, bool>>(
result, oldModules);
}
catch (UriFormatException ex)
{
Expand All @@ -82,15 +99,19 @@ private void UpdateRepo(object sender, DoWorkEventArgs e)

private void PostUpdateRepo(object sender, RunWorkerCompletedEventArgs e)
{
switch (e.Result as RepoUpdateResult?)
var resultPair = e.Result as KeyValuePair<RepoUpdateResult, Dictionary<string, bool>>?;
RepoUpdateResult? result = resultPair?.Key;
Dictionary<string, bool> oldModules = resultPair?.Value;

switch (result)
{
case RepoUpdateResult.NoChanges:
AddStatusMessage("Repositories already up to date.");
HideWaitDialog(true);
// Load rows if grid empty, otherwise keep current
if (ModList.Rows.Count < 1)
{
UpdateModsList(true, ChangeSet);
UpdateModsList(ChangeSet);
}
break;

Expand All @@ -100,7 +121,7 @@ private void PostUpdateRepo(object sender, RunWorkerCompletedEventArgs e)

case RepoUpdateResult.Updated:
default:
UpdateModsList(true, ChangeSet);
UpdateModsList(ChangeSet, oldModules);
AddStatusMessage("Repositories successfully updated.");
ShowRefreshQuestion();
HideWaitDialog(true);
Expand Down