Skip to content

Commit

Permalink
Merge pull request #1295 from KSP-CKAN/1270_adjust
Browse files Browse the repository at this point in the history
GUI: When showing Latest KSP info, do it for the latest mod (for any KSP ver)
  • Loading branch information
Matthew committed Jul 16, 2015
2 parents c259443 + c33fd78 commit bf0e4cf
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 29 deletions.
27 changes: 27 additions & 0 deletions Core/Types/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,33 @@ public bool IsCompatibleKSP(KSPVersion version)
return ksp_version.Targets(version);
}

/// <summary>
/// Returns a human readable string indicating the highest compatible
/// version of KSP this module will run with. (Eg: 1.0.2, 1.0.2+,
/// "All version", etc).
///
/// This is for *human consumption only*, as the strings may change in the
/// future as we support additional locales.
/// </summary>
public string HighestCompatibleKSP()
{
// Find the highest compatible KSP version
if (!String.IsNullOrEmpty(ksp_version_max.ToString()))
{
return ksp_version_max.ToLongMax().ToString();
}
else if (!String.IsNullOrEmpty(ksp_version.ToString()))
{
return ksp_version.ToLongMax().ToString();
}
else if (!String.IsNullOrEmpty(ksp_version_min.ToString()))
{
return ksp_version_min.ToLongMin().ToString() + "+";
}

return "All versions";
}

/// <summary>
/// Returns true if this module provides the functionality requested.
/// </summary>
Expand Down
47 changes: 36 additions & 11 deletions GUI/GUIMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ public string Name
public string Authors { get; private set; }
public string InstalledVersion { get; private set; }
public string LatestVersion { get; private set; }

// These indicate the maximum KSP version that the maximum available
// version of this mod can handle. The "Long" version also indicates
// to the user if a mod upgrade would be required. (#1270)
public string KSPCompatibility { get; private set; }
public string KSPCompatibilityLong { get; private set; }

public string KSPversion { get; private set; }
public string Abstract { get; private set; }
public object Homepage { get; private set; }
Expand Down Expand Up @@ -51,6 +57,10 @@ public GUIMod(Module mod, IRegistryQuerier registry, KSPVersion current_ksp_vers
var installed_version = registry.InstalledVersion(mod.identifier);
Version latest_version = null;
var ksp_version = mod.ksp_version;

InstalledVersion = installed_version != null ? installed_version.ToString() : "-";
LatestVersion = latest_version != null ? latest_version.ToString() : "-";

try
{
var latest_available = registry.LatestAvailable(mod.identifier, current_ksp_version);
Expand All @@ -62,29 +72,44 @@ public GUIMod(Module mod, IRegistryQuerier registry, KSPVersion current_ksp_vers
latest_version = installed_version;
}

// Let's try to find the compatibility for this mod. If it's not in the registry at
// all (because it's a DarkKAN mod) then this might fail.

InstalledVersion = installed_version != null ? installed_version.ToString() : "-";
LatestVersion = latest_version != null ? latest_version.ToString() : "-";
CkanModule latest_available_for_any_ksp = null;

// Find the highest compatible KSP version
if (!String.IsNullOrEmpty(mod.ksp_version_max.ToString()))
try
{
KSPCompatibility = mod.ksp_version_max.ToLongMax().ToString();
latest_available_for_any_ksp = registry.LatestAvailable(mod.identifier, null);
}
else if (!String.IsNullOrEmpty(mod.ksp_version.ToString()))
catch
{
KSPCompatibility = mod.ksp_version.ToLongMax().ToString();
// If we can't find the mod in the CKAN, but we've a CkanModule installed, then
// use that.
if (IsCKAN)
latest_available_for_any_ksp = (CkanModule) mod;

}
else if (!String.IsNullOrEmpty(mod.ksp_version_min.ToString()))

// If there's known information for this mod in any form, calculate the highest compatible
// KSP.
if (latest_available_for_any_ksp != null)
{
KSPCompatibility = mod.ksp_version_min.ToLongMin().ToString() + " and up";
KSPCompatibility = KSPCompatibilityLong = latest_available_for_any_ksp.HighestCompatibleKSP();

// If the mod we have installed is *not* the mod we have installed, or we don't know
// what we have installed, indicate that an upgrade would be needed.
if (installed_version == null || !latest_available_for_any_ksp.version.IsEqualTo(installed_version))
{
KSPCompatibilityLong = string.Format("{0} (using mod version {1})",
KSPCompatibility, latest_available_for_any_ksp.version);
}
}
else
{
KSPCompatibility = "All versions";
// No idea what this mod is, sorry!
KSPCompatibility = KSPCompatibilityLong = "unknown";
}


KSPversion = ksp_version != null ? ksp_version.ToString() : "-";

Abstract = mod.@abstract;
Expand Down
22 changes: 4 additions & 18 deletions GUI/MainModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public enum RelationshipType

public partial class Main : Form
{
private void UpdateModInfo(Module module)
private void UpdateModInfo(GUIMod gui_module)
{
Module module = gui_module.ToModule();

Util.Invoke(MetadataModuleNameLabel, () => MetadataModuleNameLabel.Text = module.name);
Util.Invoke(MetadataModuleVersionLabel, () => MetadataModuleVersionLabel.Text = module.version.ToString());
Util.Invoke(MetadataModuleLicenseLabel, () => MetadataModuleLicenseLabel.Text = string.Join(", ",module.license));
Expand Down Expand Up @@ -71,23 +73,7 @@ private void UpdateModInfo(Module module)
Util.Invoke(MetadataModuleReleaseStatusLabel, () => MetadataModuleReleaseStatusLabel.Text = module.release_status.ToString());
}

// Show mod highest compatible KSP version
if (!String.IsNullOrEmpty(module.ksp_version_max.ToString()))
{
Util.Invoke(MetadataModuleKSPCompatibilityLabel, () => MetadataModuleKSPCompatibilityLabel.Text = module.ksp_version_max.ToLongMax().ToString());
}
else if (!String.IsNullOrEmpty(module.ksp_version.ToString()))
{
Util.Invoke(MetadataModuleKSPCompatibilityLabel, () => MetadataModuleKSPCompatibilityLabel.Text = module.ksp_version.ToLongMax().ToString());
}
else if (!String.IsNullOrEmpty(module.ksp_version_min.ToString()))
{
Util.Invoke(MetadataModuleKSPCompatibilityLabel, () => MetadataModuleKSPCompatibilityLabel.Text = module.ksp_version_min.ToLongMin().ToString() + " and up");
}
else
{
Util.Invoke(MetadataModuleKSPCompatibilityLabel, () => MetadataModuleKSPCompatibilityLabel.Text = "All versions");
}
Util.Invoke(MetadataModuleKSPCompatibilityLabel, () => MetadataModuleKSPCompatibilityLabel.Text = gui_module.KSPCompatibilityLong);
}

private void UpdateModInfoAuthor(Module module)
Expand Down

0 comments on commit bf0e4cf

Please sign in to comment.