Ejemplo n.º 1
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_game_version">Current game version</param>
        /// <param name="incompatible">If true, mark this module as incompatible</param>
        public GUIMod(string identifier, IRegistryQuerier registry, GameVersionCriteria current_game_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_game_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)
            {
                GameCompatibilityVersion = registry.LatestCompatibleKSP(identifier);
                GameCompatibility        = GameCompatibilityVersion?.ToYalovString()
                                           ?? Properties.Resources.GUIModUnknown;
                GameCompatibilityLong = string.Format(Properties.Resources.GUIModGameCompatibilityLong, GameCompatibility, 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, "");
        }
Ejemplo n.º 2
0
        /// <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_game_version">Current game version</param>
        /// <param name="incompatible">If true, mark this module as incompatible</param>
        public GUIMod(CkanModule mod, IRegistryQuerier registry, GameVersionCriteria current_game_version, bool?incompatible = null)
            : this(mod.identifier, registry, current_game_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_game_version);
            HasReplacement = registry.GetReplacement(mod, current_game_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 (GameCompatibilityVersion == null)
            {
                GameCompatibilityVersion = mod.LatestCompatibleKSP();
                GameCompatibility        = GameCompatibilityVersion?.ToYalovString() ?? Properties.Resources.GUIModUnknown;
                GameCompatibilityLong    = string.Format(
                    Properties.Resources.GUIModGameCompatibilityLong,
                    GameCompatibility,
                    mod.version
                    );
            }

            UpdateIsCached();
        }