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 compatible popup messing with max game version column #3976

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
25 changes: 17 additions & 8 deletions Core/Games/KerbalSpaceProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,29 @@ public void RefreshVersions()

private List<GameVersion> versions;

private readonly object versionMutex = new object();

public List<GameVersion> KnownVersions
{
get
{
// There's a lot of duplicate real versions with different build IDs,
// skip all those extra checks when we use these
if (versions == null)
{
versions = ServiceLocator.Container
.Resolve<IKspBuildMap>()
.KnownVersions
.Select(v => v.WithoutBuild)
.Distinct()
.ToList();
lock (versionMutex)
{
if (versions == null)
{
// There's a lot of duplicate real versions with different build IDs,
// skip all those extra checks when we use these
versions = ServiceLocator.Container
.Resolve<IKspBuildMap>()
.KnownVersions
.Select(v => v.WithoutBuild)
.Distinct()
.OrderBy(v => v)
.ToList();
}
}
}
return versions;
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Repositories/AvailableModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public GameVersion LatestCompatibleGameVersion(List<GameVersion> realVersions)
{
// Cheat slightly for performance:
// Find the CkanModule with the highest ksp_version_max,
// then get the real lastest compatible of just that one mod
// then get the real latest compatible of just that one mod
GameVersion best = null;
CkanModule bestMod = null;
foreach (var mod in module_version.Values)
Expand Down
67 changes: 25 additions & 42 deletions GUI/Dialogs/CompatibleGameVersionsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ public CompatibleGameVersionsDialog(GameInstance inst, bool centerScreen)
StartPosition = FormStartPosition.CenterScreen;
}

List<GameVersion> compatibleVersions = inst.GetCompatibleVersions();
var compatibleVersions = inst.GetCompatibleVersions();

GameVersionLabel.Text = inst.Version()?.ToString() ?? Properties.Resources.CompatibleGameVersionsDialogNone;
GameLocationLabel.Text = inst.GameDir().Replace('/', Path.DirectorySeparatorChar);
List<GameVersion> knownVersions = inst.game.KnownVersions;
List<GameVersion> majorVersionsList = CreateMajorVersionsList(knownVersions);
List<GameVersion> compatibleVersionsLeftOthers = new List<GameVersion>(compatibleVersions);
compatibleVersionsLeftOthers.RemoveAll((el)=>knownVersions.Contains(el) || majorVersionsList.Contains(el));
var knownVersions = inst.game.KnownVersions;
var majorVersionsList = CreateMajorVersionsList(knownVersions);
var compatibleVersionsLeftOthers = compatibleVersions.Except(knownVersions)
.Except(majorVersionsList)
.ToList();

SortAndAddVersionsToList(compatibleVersionsLeftOthers, compatibleVersions);
SortAndAddVersionsToList(majorVersionsList, compatibleVersions);
Expand Down Expand Up @@ -74,37 +75,23 @@ private void CompatibleGameVersionsDialog_Shown(object sender, EventArgs e)
GameVersionLabel.Text = string.Format(
Properties.Resources.CompatibleGameVersionsDialogVersionDetails,
_inst.Version(),
_inst.GameVersionWhenCompatibleVersionsWereStored
);
_inst.GameVersionWhenCompatibleVersionsWereStored);
GameVersionLabel.ForeColor = Color.Red;
}
}

private static List<GameVersion> CreateMajorVersionsList(List<GameVersion> knownVersions)
{
Dictionary<GameVersion, bool> majorVersions = new Dictionary<GameVersion, bool>();
foreach (var version in knownVersions)
{
GameVersion fullKnownVersion = version.ToVersionRange().Lower.Value;
GameVersion toAdd = new GameVersion(fullKnownVersion.Major, fullKnownVersion.Minor);
if (!majorVersions.ContainsKey(toAdd))
{
majorVersions.Add(toAdd, true);
}
}
return new List<GameVersion>(majorVersions.Keys);
}
=> knownVersions.Select(v => v.ToVersionRange().Lower.Value)
.Select(v => new GameVersion(v.Major, v.Minor))
.Distinct()
.ToList();

private void SortAndAddVersionsToList(List<GameVersion> versions, List<GameVersion> compatibleVersions)
{
versions.Sort();
versions.Reverse();
foreach (GameVersion version in versions)
foreach (var version in versions.Where(v => v != _inst.Version())
.Reverse())
{
if (!version.Equals(_inst.Version()))
{
SelectedVersionsCheckedListBox.Items.Add(version, compatibleVersions.Contains(version));
}
SelectedVersionsCheckedListBox.Items.Add(version, compatibleVersions.Contains(version));
}
}

Expand All @@ -116,12 +103,10 @@ private void AddVersionToListButton_Click(object sender, EventArgs e)
}
if (AddVersionToListTextBox.Text.ToLower() == "any")
{
MessageBox.Show(
Properties.Resources.CompatibleGameVersionsDialogInvalidFormat,
Properties.Resources.CompatibleGameVersionsDialogErrorTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
MessageBox.Show(Properties.Resources.CompatibleGameVersionsDialogInvalidFormat,
Properties.Resources.CompatibleGameVersionsDialogErrorTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
try
Expand All @@ -131,12 +116,10 @@ private void AddVersionToListButton_Click(object sender, EventArgs e)
}
catch (FormatException)
{
MessageBox.Show(
Properties.Resources.CompatibleGameVersionsDialogInvalidFormat,
Properties.Resources.CompatibleGameVersionsDialogErrorTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
MessageBox.Show(Properties.Resources.CompatibleGameVersionsDialogInvalidFormat,
Properties.Resources.CompatibleGameVersionsDialogErrorTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}

Expand All @@ -156,9 +139,9 @@ private void CancelButton_Click(object sender, EventArgs e)

private void SaveButton_Click(object sender, EventArgs e)
{
_inst.SetCompatibleVersions(
SelectedVersionsCheckedListBox.CheckedItems.Cast<GameVersion>().ToList()
);
_inst.SetCompatibleVersions(SelectedVersionsCheckedListBox.CheckedItems
.Cast<GameVersion>()
.ToList());

DialogResult = DialogResult.OK;
Close();
Expand Down
6 changes: 6 additions & 0 deletions GUI/Model/GUIMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ public GUIMod(CkanModule mod,
if (GameCompatibilityVersion == null)
{
GameCompatibilityVersion = mod.LatestCompatibleGameVersion();
if (GameCompatibilityVersion.IsAny)
{
GameCompatibilityVersion = mod.LatestCompatibleRealGameVersion(
Main.Instance?.Manager.CurrentInstance?.game.KnownVersions
?? new List<GameVersion>() {});
}
}

UpdateIsCached();
Expand Down
Loading