diff --git a/ConsoleUI/ModListScreen.cs b/ConsoleUI/ModListScreen.cs index 1143429d26..38c1209232 100644 --- a/ConsoleUI/ModListScreen.cs +++ b/ConsoleUI/ModListScreen.cs @@ -477,16 +477,34 @@ private bool ScanForMods() private bool SelectInstall(ConsoleTheme theme) { GameInstance prevInst = manager.CurrentInstance; + var prevRepos = new SortedDictionary(registry.Repositories); + var prevVerCrit = prevInst.VersionCriteria(); LaunchSubScreen(theme, new GameInstanceListScreen(manager)); - // Abort if same instance as before if (!prevInst.Equals(manager.CurrentInstance)) { + // Game instance changed, reset everything plan.Reset(); registry = RegistryManager.Instance(manager.CurrentInstance).registry; RefreshList(theme); + } else if (!SortedDictionaryEquals(registry.Repositories, prevRepos)) { + // Repos changed, need to fetch them + UpdateRegistry(theme, false); + RefreshList(theme); + } else if (!manager.CurrentInstance.VersionCriteria().Equals(prevVerCrit)) { + // VersionCriteria changed, need to re-check what is compatible + RefreshList(theme); } return true; } + private bool SortedDictionaryEquals(SortedDictionary a, SortedDictionary b) + { + return a == null ? b == null + : b == null ? false + : a.Count == b.Count + && a.Keys.All(k => b.ContainsKey(k)) + && b.Keys.All(k => a.ContainsKey(k) && a[k].Equals(b[k])); + } + private bool EditAuthTokens(ConsoleTheme theme) { LaunchSubScreen(theme, new AuthTokenScreen()); @@ -497,7 +515,7 @@ private void RefreshList(ConsoleTheme theme) { // In the constructor this is called while moduleList is being populated, just do nothing in this case. // ModListScreen -> moduleList = (GetAllMods ...) -> UpdateRegistry -> RefreshList - moduleList?.SetData(GetAllMods(theme,true)); + moduleList?.SetData(GetAllMods(theme, true)); } private List allMods = null; diff --git a/Core/Types/Repository.cs b/Core/Types/Repository.cs index b0ebb6e661..66d3772bf6 100644 --- a/Core/Types/Repository.cs +++ b/Core/Types/Repository.cs @@ -5,7 +5,7 @@ namespace CKAN { - public class Repository + public class Repository : IEquatable { [JsonIgnore] public static readonly string default_ckan_repo_name = "default"; @@ -13,7 +13,6 @@ public class Repository public Uri uri; public string last_server_etag; public int priority = 0; - public Boolean ckan_mirror = false; public Repository() { @@ -38,6 +37,19 @@ public Repository(string name, Uri uri) this.uri = uri; } + public override bool Equals(Object other) + { + return Equals(other as Repository); + } + + public bool Equals(Repository other) + { + return other != null + && name == other.name + && uri == other.uri + && priority == other.priority; + } + public override string ToString() { return String.Format("{0} ({1}, {2})", name, priority, uri);