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

Update or refresh ConsoleUI mod list after repo or compat changes #3353

Merged
merged 1 commit into from
Apr 24, 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
22 changes: 20 additions & 2 deletions ConsoleUI/ModListScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,34 @@ private bool ScanForMods()
private bool SelectInstall(ConsoleTheme theme)
{
GameInstance prevInst = manager.CurrentInstance;
var prevRepos = new SortedDictionary<string, Repository>(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<K, V>(SortedDictionary<K, V> a, SortedDictionary<K, V> 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());
Expand All @@ -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<CkanModule> allMods = null;
Expand Down
21 changes: 19 additions & 2 deletions Core/Types/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

namespace CKAN
{
public class Repository
public class Repository : IEquatable<Repository>
{
[JsonIgnore] public static readonly string default_ckan_repo_name = "default";

public string name;
public Uri uri;
public string last_server_etag;
public int priority = 0;
public Boolean ckan_mirror = false;

public Repository()
{
Expand All @@ -38,6 +37,24 @@ 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 int GetHashCode()
{
return name.GetHashCode();
}

public override string ToString()
{
return String.Format("{0} ({1}, {2})", name, priority, uri);
Expand Down