Example #1
0
        private bool installable(CkanModule module)
        {
            var currentInstance = Main.Instance.Manager.CurrentInstance;
            var version         = currentInstance.VersionCriteria();

            if (!module.IsCompatibleKSP(version))
            {
                return(false);
            }
            try
            {
                RelationshipResolver resolver = new RelationshipResolver(
                    new CkanModule[] { module },
                    null,
                    new RelationshipResolverOptions()
                {
                    with_recommends = false,
                    without_toomanyprovides_kraken = true,
                },
                    RegistryManager.Instance(currentInstance).registry,
                    version
                    );
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Example #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_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 = false)
            : this(mod.identifier, registry, current_ksp_version, incompatible)
        {
            Mod    = mod;
            IsCKAN = mod is CkanModule;

            Name        = mod.name.Trim();
            Abstract    = [email protected]();
            Abbrevation = new string(Name.Split(' ').Where(s => s.Length > 0).Select(s => s[0]).ToArray());
            Authors     = mod.author == null ? "N/A" : String.Join(",", mod.author);

            HasUpdate      = registry.HasUpdate(mod.identifier, current_ksp_version);
            DownloadSize   = mod.download_size == 0 ? "N/A" : CkanModule.FmtSize(mod.download_size);
            IsIncompatible = IsIncompatible || !mod.IsCompatibleKSP(current_ksp_version);

            if (mod.resources != null)
            {
                Homepage = mod.resources.homepage?.ToString()
                           ?? mod.resources.spacedock?.ToString()
                           ?? mod.resources.curse?.ToString()
                           ?? mod.resources.repository?.ToString()
                           ?? "N/A";
            }

            UpdateIsCached();
        }
Example #3
0
File: GUIMod.cs Project: pjf/CKAN
        public GUIMod(CkanModule mod, Registry registry, KSPVersion ksp_version)
        {
            //Currently anything which could alter these causes a full reload of the modlist
            // If this is ever changed these could be moved into the properties
            Mod              = mod;
            IsInstalled      = registry.IsInstalled(mod.identifier);
            IsInstallChecked = IsInstalled;
            HasUpdate        = registry.HasUpdate(mod.identifier);
            IsIncompatible   = !mod.IsCompatibleKSP(ksp_version);
            IsAutodetected   = registry.IsAutodetected(mod.identifier);
            Authors          = mod.author == null ? "N/A" : String.Join(",", mod.author);

            var installedVersion = registry.InstalledVersion(mod.identifier);
            var latestVersion    = mod.version;
            var kspVersion       = mod.ksp_version;

            InstalledVersion = installedVersion != null?installedVersion.ToString() : "-";

            LatestVersion = latestVersion != null?latestVersion.ToString() : "-";

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

            Abstract = mod.@abstract;
            Homepage = mod.resources != null && mod.resources.homepage != null
                ? (object)mod.resources.homepage
                : "N/A";

            Identifier = mod.identifier;
        }
Example #4
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_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 = false)
            : 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);
            IsIncompatible = IsIncompatible || !mod.IsCompatibleKSP(current_ksp_version);

            if (mod.resources != null)
            {
                Homepage = mod.resources.homepage?.ToString()
                           ?? mod.resources.spacedock?.ToString()
                           ?? mod.resources.curse?.ToString()
                           ?? mod.resources.repository?.ToString()
                           ?? Properties.Resources.GUIModNSlashA;
            }

            // Get the Searchables.
            SearchableName        = mod.SearchableName;
            SearchableAbstract    = mod.SearchableAbstract;
            SearchableDescription = mod.SearchableDescription;
            SearchableAuthors     = mod.SearchableAuthors;

            UpdateIsCached();
        }
Example #5
0
 private bool allowInstall(CkanModule module)
 {
     return(module.IsCompatibleKSP(Main.Instance.Manager.CurrentInstance.VersionCriteria()) ||
            Main.Instance.YesNoDialog(
                string.Format(Properties.Resources.AllModVersionsInstallPrompt, module.ToString()),
                Properties.Resources.AllModVersionsInstallYes,
                Properties.Resources.AllModVersionsInstallNo));
 }
Example #6
0
 private bool installable(ModuleInstaller installer, CkanModule module, IRegistryQuerier registry)
 {
     return(module.IsCompatibleKSP(Main.Instance.CurrentInstance.VersionCriteria()) &&
            installer.CanInstall(
                RelationshipResolver.DependsOnlyOpts(),
                new List <CkanModule>()
     {
         module
     },
                registry));
 }
Example #7
0
        /// <summary>
        /// React to double click of a version by prompting to install
        /// </summary>
        /// <param name="sender">The version list view</param>
        /// <param name="e">The mouse click event</param>
        public void VersionsListView_DoubleClick(object sender, MouseEventArgs e)
        {
            ListViewHitTestInfo info   = ((ListView)sender).HitTest(e.X, e.Y);
            ListViewItem        item   = info.Item;
            CkanModule          module = item.Tag as CkanModule;

            if (module.IsCompatibleKSP(Main.Instance.Manager.CurrentInstance.VersionCriteria()) &&
                Main.Instance.YesNoDialog($"Install {module}?"))
            {
                Main.Instance.InstallModuleDriver(
                    RegistryManager.Instance(Main.Instance.Manager.CurrentInstance).registry,
                    module
                    );
            }
        }
Example #8
0
        /// <summary>
        /// React to double click of a version by prompting to install
        /// </summary>
        /// <param name="sender">The version list view</param>
        /// <param name="e">The mouse click event</param>
        public void VersionsListView_DoubleClick(object sender, MouseEventArgs e)
        {
            ListViewHitTestInfo info   = ((ListView)sender).HitTest(e.X, e.Y);
            ListViewItem        item   = info.Item;
            CkanModule          module = item.Tag as CkanModule;

            if (module.IsCompatibleKSP(Main.Instance.Manager.CurrentInstance.VersionCriteria()) &&
                Main.Instance.YesNoDialog(
                    string.Format(Properties.Resources.MainAllModVersionsInstallPrompt, module.ToString()),
                    Properties.Resources.MainAllModVersionsInstallYes,
                    Properties.Resources.MainAllModVersionsInstallNo))
            {
                Main.Instance.InstallModuleDriver(
                    RegistryManager.Instance(Main.Instance.Manager.CurrentInstance).registry,
                    module
                    );
            }
        }
Example #9
0
        public GUIMod(CkanModule mod, IRegistryQuerier registry, KspVersionCriteria current_ksp_version)
        {
            IsCKAN = mod is CkanModule;
            //Currently anything which could alter these causes a full reload of the modlist
            // If this is ever changed these could be moved into the properties
            Mod              = mod;
            IsInstalled      = registry.IsInstalled(mod.identifier, false);
            IsInstallChecked = IsInstalled;
            HasUpdate        = registry.HasUpdate(mod.identifier, current_ksp_version);
            IsIncompatible   = !mod.IsCompatibleKSP(current_ksp_version);
            IsAutodetected   = registry.IsAutodetected(mod.identifier);
            Authors          = mod.author == null ? "N/A" : String.Join(",", mod.author);

            var     installed_version = registry.InstalledVersion(mod.identifier);
            Version latest_version    = null;
            var     ksp_version       = mod.ksp_version;

            try
            {
                var latest_available = registry.LatestAvailable(mod.identifier, current_ksp_version);
                if (latest_available != null)
                {
                    latest_version = latest_available.version;
                }
            }
            catch (ModuleNotFoundKraken)
            {
                latest_version = installed_version;
            }

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

            // 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(mod.identifier, null);
            }
            catch
            {
                // 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;
                }
            }

            // If there's known information for this mod in any form, calculate the highest compatible
            // KSP.
            if (latest_available_for_any_ksp != null)
            {
                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
            {
                // No idea what this mod is, sorry!
                KSPCompatibility = KSPCompatibilityLong = "unknown";
            }

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

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

            Abstract = mod.@abstract;

            // 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 = "N/A";
            if (mod.resources != null)
            {
                if (mod.resources.homepage != null)
                {
                    Homepage = mod.resources.homepage.ToString();
                }
                else if (mod.resources.spacedock != null)
                {
                    Homepage = mod.resources.spacedock.ToString();
                }
                else if (mod.resources.curse != null)
                {
                    Homepage = mod.resources.curse.ToString();
                }
                else if (mod.resources.repository != null)
                {
                    Homepage = mod.resources.repository.ToString();
                }
            }

            Identifier = mod.identifier;

            if (mod.download_size == 0)
            {
                DownloadSize = "N/A";
            }
            else if (mod.download_size / 1024.0 < 1)
            {
                DownloadSize = "1<KB";
            }
            else
            {
                DownloadSize = mod.download_size / 1024 + "";
            }

            Abbrevation = new string(mod.name.Split(' ').
                                     Where(s => s.Length > 0).Select(s => s[0]).ToArray());

            UpdateIsCached();
        }
Example #10
0
        private void UpdateModInfo(GUIMod gui_module)
        {
            CkanModule module = gui_module.ToModule();

            Util.Invoke(MetadataModuleNameTextBox, () => MetadataModuleNameTextBox.Text = module.name);
            UpdateTagsAndLabels(module);
            Util.Invoke(MetadataModuleAbstractLabel, () => MetadataModuleAbstractLabel.Text = module.@abstract);
            Util.Invoke(MetadataModuleDescriptionTextBox, () =>
            {
                MetadataModuleDescriptionTextBox.Text = module.description
                                                        ?.Replace("\r\n", "\n").Replace("\n", Environment.NewLine);
                MetadataModuleDescriptionTextBox.ScrollBars =
                    string.IsNullOrWhiteSpace(module.description)
                        ? ScrollBars.None
                        : ScrollBars.Vertical;
            });

            Util.Invoke(MetadataModuleVersionTextBox, () => MetadataModuleVersionTextBox.Text = gui_module.LatestVersion.ToString());
            Util.Invoke(MetadataModuleLicenseTextBox, () => MetadataModuleLicenseTextBox.Text = string.Join(", ", module.license));
            Util.Invoke(MetadataModuleAuthorTextBox, () => MetadataModuleAuthorTextBox.Text   = gui_module.Authors);
            Util.Invoke(MetadataIdentifierTextBox, () => MetadataIdentifierTextBox.Text       = module.identifier);

            Util.Invoke(MetadataModuleReleaseStatusTextBox, () =>
            {
                if (module.release_status == null)
                {
                    ReleaseLabel.Visible = false;
                    MetadataModuleReleaseStatusTextBox.Visible = false;
                    MetaDataLowerLayoutPanel.LayoutSettings.RowStyles[3].Height = 0;
                }
                else
                {
                    ReleaseLabel.Visible = true;
                    MetadataModuleReleaseStatusTextBox.Visible = true;
                    MetaDataLowerLayoutPanel.LayoutSettings.RowStyles[3].Height = 30;
                    MetadataModuleReleaseStatusTextBox.Text = module.release_status.ToString();
                }
            });
            Util.Invoke(MetadataModuleGameCompatibilityTextBox, () => MetadataModuleGameCompatibilityTextBox.Text = gui_module.GameCompatibilityLong);

            Util.Invoke(ModInfoTabControl, () =>
            {
                // Mono doesn't draw TabPage.ImageIndex, so fake it
                const string fakeStopSign          = "<!> ";
                ComponentResourceManager resources = new SingleAssemblyComponentResourceManager(typeof(ModInfo));
                resources.ApplyResources(RelationshipTabPage, "RelationshipTabPage");
                resources.ApplyResources(AllModVersionsTabPage, "AllModVersionsTabPage");
                if (gui_module.IsIncompatible)
                {
                    if (!module.IsCompatibleKSP(manager.CurrentInstance.VersionCriteria()))
                    {
                        AllModVersionsTabPage.Text = fakeStopSign + AllModVersionsTabPage.Text;
                    }
                    else
                    {
                        RelationshipTabPage.Text = fakeStopSign + RelationshipTabPage.Text;
                    }
                }
            });
            Util.Invoke(ReplacementTextBox, () =>
            {
                if (module.replaced_by == null)
                {
                    ReplacementLabel.Visible   = false;
                    ReplacementTextBox.Visible = false;
                    MetaDataLowerLayoutPanel.LayoutSettings.RowStyles[6].Height = 0;
                }
                else
                {
                    ReplacementLabel.Visible   = true;
                    ReplacementTextBox.Visible = true;
                    MetaDataLowerLayoutPanel.LayoutSettings.RowStyles[6].Height = 30;
                    ReplacementTextBox.Text = module.replaced_by.ToString();
                }
            });

            Util.Invoke(MetaDataLowerLayoutPanel, () =>
            {
                ClearResourceLinks();
                var res = module.resources;
                if (res != null)
                {
                    AddResourceLink(Properties.Resources.ModInfoHomepageLabel, res.homepage);
                    AddResourceLink(Properties.Resources.ModInfoSpaceDockLabel, res.spacedock);
                    AddResourceLink(Properties.Resources.ModInfoCurseLabel, res.curse);
                    AddResourceLink(Properties.Resources.ModInfoRepositoryLabel, res.repository);
                    AddResourceLink(Properties.Resources.ModInfoBugTrackerLabel, res.bugtracker);
                    AddResourceLink(Properties.Resources.ModInfoContinuousIntegrationLabel, res.ci);
                    AddResourceLink(Properties.Resources.ModInfoLicenseLabel, res.license);
                    AddResourceLink(Properties.Resources.ModInfoManualLabel, res.manual);
                    AddResourceLink(Properties.Resources.ModInfoMetanetkanLabel, res.metanetkan);
                    AddResourceLink(Properties.Resources.ModInfoRemoteAvcLabel, res.remoteAvc);
                    AddResourceLink(Properties.Resources.ModInfoStoreLabel, res.store);
                    AddResourceLink(Properties.Resources.ModInfoSteamStoreLabel, res.steamstore);
                }
            });
        }
Example #11
0
File: GUIMod.cs Project: yalov/CKAN
        public GUIMod(CkanModule mod, IRegistryQuerier registry, KspVersionCriteria current_ksp_version, bool incompatible = false)
        {
            IsCKAN = mod is CkanModule;
            //Currently anything which could alter these causes a full reload of the modlist
            // If this is ever changed these could be moved into the properties
            Mod              = mod;
            IsInstalled      = registry.IsInstalled(mod.identifier, false);
            IsInstallChecked = IsInstalled;
            HasUpdate        = registry.HasUpdate(mod.identifier, current_ksp_version);
            IsIncompatible   = incompatible || !mod.IsCompatibleKSP(current_ksp_version);
            IsAutodetected   = registry.IsAutodetected(mod.identifier);
            Authors          = mod.author == null ? "N/A" : String.Join(",", mod.author);

            var           installed_version = registry.InstalledVersion(mod.identifier);
            ModuleVersion latest_version    = null;
            var           ksp_version       = mod.ksp_version;

            try
            {
                var latest_available = registry.LatestAvailable(mod.identifier, current_ksp_version);
                if (latest_available != null)
                {
                    latest_version = latest_available.version;
                }
            }
            catch (ModuleNotFoundKraken)
            {
                latest_version = installed_version;
            }

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

            // 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(mod.identifier, null);
            }
            catch
            {
                // 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;
                }
            }

            // If there's known information for this mod in any form, calculate the highest compatible
            // KSP.
            if (latest_available_for_any_ksp != null)
            {
                if (!VersionMaxWasGenerated)
                {
                    VersionMaxWasGenerated = true;
                    List <KspVersion> versions = new KspBuildMap(new Win32Registry()).KnownVersions;  // should be sorted

                    VersionsMax     = new Dictionary <string, KspVersion>();
                    VersionsMax[""] = versions.Last();

                    foreach (var v in versions)
                    {
                        VersionsMax[v.Major.ToString()]      = v;   // add or replace
                        VersionsMax[v.Major + "." + v.Minor] = v;
                    }
                }

                const int Undefined = -1;

                KspVersion ksp_ver = registry.LatestCompatibleKSP(mod.identifier);
                string     ver = ksp_ver?.ToString();
                int        major = ksp_ver.Major, minor = ksp_ver.Minor, patch = ksp_ver.Patch;
                KspVersion value;

                if (major == Undefined
                    //|| (major >= UptoNines(VersionsMax[""].Major))       // 9.99.99
                    || (major > VersionsMax[""].Major) ||                                                                                       // 2.0.0
                    (major == VersionsMax[""].Major && VersionsMax.TryGetValue(major.ToString(), out value) && minor >= UptoNines(value.Minor)) // 1.99.99 ?
                    )
                {
                    KSPCompatibility = "any";
                }

                else if (minor != Undefined &&
                         VersionsMax.TryGetValue(major + "." + minor, out value) &&
                         (patch == Undefined || patch >= UptoNines(value.Patch))
                         )
                {
                    KSPCompatibility = major + "." + minor + "." + UptoNines(value.Patch);
                }

                else
                {
                    KSPCompatibility = ver;
                }

                // KSPCompatibility += " | " + major + "." + minor + "." + patch;   // for testing

                // 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);
                    //    ver, latest_available_for_any_ksp.version);   //  true values in the right tab
                }
                else
                {
                    KSPCompatibilityLong = KSPCompatibility;
                    // KSPCompatibilityLong = ver;   //  true values in the right tab
                }
            }
            else
            {
                // No idea what this mod is, sorry!
                KSPCompatibility = KSPCompatibilityLong = "unknown";
            }

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

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

            Abstract = mod.@abstract;

            // 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 = "N/A";
            if (mod.resources != null)
            {
                if (mod.resources.homepage != null)
                {
                    Homepage = mod.resources.homepage.ToString();
                }
                else if (mod.resources.spacedock != null)
                {
                    Homepage = mod.resources.spacedock.ToString();
                }
                else if (mod.resources.curse != null)
                {
                    Homepage = mod.resources.curse.ToString();
                }
                else if (mod.resources.repository != null)
                {
                    Homepage = mod.resources.repository.ToString();
                }
            }

            Identifier = mod.identifier;

            DownloadSize = (mod.download_size == 0)
                ? "N/A"
                : CkanModule.FmtSize(mod.download_size);

            Abbrevation = new string(mod.name.Split(' ').
                                     Where(s => s.Length > 0).Select(s => s[0]).ToArray());

            UpdateIsCached();
        }