/// <summary> /// Initialize a GUIMod based on just an identifier /// </summary> /// <param name="identifier">The id of the module to represent</param> /// <param name="registry">CKAN registry object for current game instance</param> /// <param name="current_ksp_version">Current game version</param> /// <param name="incompatible">If true, mark this module as incompatible</param> public GUIMod(string identifier, IRegistryQuerier registry, KspVersionCriteria current_ksp_version, bool?incompatible = null) { Identifier = identifier; IsAutodetected = registry.IsAutodetected(identifier); DownloadCount = registry.DownloadCount(identifier); if (IsAutodetected) { IsInstalled = true; } ModuleVersion latest_version = null; try { LatestCompatibleMod = registry.LatestAvailable(identifier, current_ksp_version); latest_version = LatestCompatibleMod?.version; } catch (ModuleNotFoundKraken) { } IsIncompatible = incompatible ?? LatestCompatibleMod == null; // 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. CkanModule latest_available_for_any_ksp = null; try { latest_available_for_any_ksp = registry.LatestAvailable(identifier, null); } catch { } // If there's known information for this mod in any form, calculate the highest compatible // KSP. if (latest_available_for_any_ksp != null) { KSPCompatibilityVersion = registry.LatestCompatibleKSP(identifier); KSPCompatibility = KSPCompatibilityVersion?.ToYalovString() ?? Properties.Resources.GUIModUnknown; KSPCompatibilityLong = string.Format(Properties.Resources.GUIModKSPCompatibilityLong, KSPCompatibility, latest_available_for_any_ksp.version); } if (latest_version != null) { LatestVersion = latest_version.ToString(); } else if (latest_available_for_any_ksp != null) { LatestVersion = latest_available_for_any_ksp.version.ToString(); } else { LatestVersion = "-"; } SearchableIdentifier = CkanModule.nonAlphaNums.Replace(Identifier, ""); }
/// <summary> /// Initialize a GUIMod based on a CkanModule /// </summary> /// <param name="mod">The module to represent</param> /// <param name="registry">CKAN registry object for current game instance</param> /// <param name="current_ksp_version">Current game version</param> /// <param name="incompatible">If true, mark this module as incompatible</param> public GUIMod(CkanModule mod, IRegistryQuerier registry, KspVersionCriteria current_ksp_version, bool?incompatible = null) : this(mod.identifier, registry, current_ksp_version, incompatible) { Mod = mod; IsCKAN = mod is CkanModule; Name = mod.name.Trim(); Abstract = [email protected](); Description = mod.description?.Trim() ?? string.Empty; Abbrevation = new string(Name.Split(' ').Where(s => s.Length > 0).Select(s => s[0]).ToArray()); Authors = mod.author == null ? Properties.Resources.GUIModNSlashA : String.Join(",", mod.author); HasUpdate = registry.HasUpdate(mod.identifier, current_ksp_version); HasReplacement = registry.GetReplacement(mod, current_ksp_version) != null; DownloadSize = mod.download_size == 0 ? Properties.Resources.GUIModNSlashA : CkanModule.FmtSize(mod.download_size); // Get the Searchables. SearchableName = mod.SearchableName; SearchableAbstract = mod.SearchableAbstract; SearchableDescription = mod.SearchableDescription; SearchableAuthors = mod.SearchableAuthors; // If not set in GUIMod(identifier, ...) (because the mod is not known to the registry), // set based on the the data we have from the CkanModule. if (KSPCompatibilityVersion == null) { KSPCompatibilityVersion = mod.LatestCompatibleKSP(); KSPCompatibility = KSPCompatibilityVersion?.ToYalovString() ?? Properties.Resources.GUIModUnknown; KSPCompatibilityLong = string.Format( Properties.Resources.GUIModKSPCompatibilityLong, KSPCompatibility, mod.version ); } UpdateIsCached(); }