Ejemplo n.º 1
0
        /// <summary>
        /// Generate a string describing the range of game versions
        /// compatible with the given module.
        /// </summary>
        /// <param name="identifier">Mod name to findDependencyShallow</param>
        /// <returns>
        /// String describing range of compatible game versions.
        /// </returns>
        public static string CompatibleGameVersions(this IRegistryQuerier querier, string identifier)
        {
            List <CkanModule> releases = querier.AllAvailable(identifier);

            if (releases != null && releases.Count > 0)
            {
                ModuleVersion minMod = null, maxMod = null;
                KspVersion    minKsp = null, maxKsp = null;
                Registry.GetMinMaxVersions(releases, out minMod, out maxMod, out minKsp, out maxKsp);
                return(KspVersionRange.VersionSpan(minKsp, maxKsp));
            }
            return("");
        }
Ejemplo n.º 2
0
        /// <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;
            IsIncompatible = incompatible
                             ?? registry.AllAvailable(identifier)
                             .All(m => !m.IsCompatibleKSP(current_ksp_version));
            IsAutodetected = registry.IsAutodetected(identifier);
            DownloadCount  = registry.DownloadCount(identifier);
            if (registry.IsAutodetected(identifier))
            {
                IsInstalled = true;
            }

            ModuleVersion latest_version = null;

            try
            {
                LatestCompatibleMod = registry.LatestAvailable(identifier, current_ksp_version);
                latest_version      = LatestCompatibleMod?.version;
            }
            catch (ModuleNotFoundKraken)
            {
            }

            // 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)
            {
                KSPCompatibility = registry.LatestCompatibleKSP(identifier)?.ToYalovString()
                                   ?? Properties.Resources.GUIModUnknown;
                KSPCompatibilityLong = string.Format(Properties.Resources.GUIModKSPCompatibilityLong, KSPCompatibility, latest_available_for_any_ksp.version);
            }
            else
            {
                // No idea what this mod is, sorry!
                KSPCompatibility = KSPCompatibilityLong = Properties.Resources.GUIModUnknown;
            }

            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 = "-";
            }

            // If we have a homepage provided, use that; otherwise use the spacedock page, curse page or the github repo so that users have somewhere to get more info than just the abstract.
            Homepage = Properties.Resources.GUIModNSlashA;

            SearchableIdentifier = CkanModule.nonAlphaNums.Replace(Identifier, "");
        }