Beispiel #1
0
        private void _UpdateModsList()
        {
            Registry registry = RegistryManager.Instance(CurrentInstance).registry;

            var ckanModules = registry.Available(CurrentInstance.Version()).Concat(
                registry.Incompatible(CurrentInstance.Version())).ToList();
            var gui_mods = ckanModules.Select(m => new GUIMod(m, registry, CurrentInstance.Version())).ToList();

            mainModList.Modules = new ReadOnlyCollection <GUIMod>(gui_mods);
            var rows = MainModList.ConstructModList(mainModList.Modules);

            ModList.Rows.Clear();
            ModList.Rows.AddRange(rows.ToArray());
            ModList.Sort(ModList.Columns[2], ListSortDirection.Ascending);

            //TODO Consider using smart enum patten so stuff like this is easier
            FilterToolButton.DropDownItems[0].Text = String.Format("All ({0})",
                                                                   mainModList.CountModsByFilter(GUIModFilter.All));
            FilterToolButton.DropDownItems[1].Text = String.Format("Installed ({0})",
                                                                   mainModList.CountModsByFilter(GUIModFilter.Installed));
            FilterToolButton.DropDownItems[2].Text = String.Format("Updated ({0})",
                                                                   mainModList.CountModsByFilter(GUIModFilter.InstalledUpdateAvailable));
            FilterToolButton.DropDownItems[3].Text = String.Format("New in repository ({0})",
                                                                   mainModList.CountModsByFilter(GUIModFilter.NewInRepository));
            FilterToolButton.DropDownItems[4].Text = String.Format("Not installed ({0})",
                                                                   mainModList.CountModsByFilter(GUIModFilter.NotInstalled));
            FilterToolButton.DropDownItems[5].Text = String.Format("Incompatible ({0})",
                                                                   mainModList.CountModsByFilter(GUIModFilter.Incompatible));

            var has_any_updates = gui_mods.Any(mod => mod.HasUpdate);

            UpdateAllToolButton.Enabled = has_any_updates;
            UpdateFilters(this);
        }
Beispiel #2
0
        private void _UpdateModsList(bool repo_updated)
        {
            log.Debug("Updating the mod list");
            Registry registry = RegistryManager.Instance(CurrentInstance).registry;

            var ckanModules = registry.Available(CurrentInstance.Version()).Concat(
                registry.Incompatible(CurrentInstance.Version())).ToList();
            var gui_mods =
                new HashSet <GUIMod>(ckanModules.Select(m => new GUIMod(m, registry, CurrentInstance.Version())));
            var old_modules = new HashSet <GUIMod>(mainModList.Modules);

            if (repo_updated)
            {
                foreach (var gui_mod in gui_mods.Where(m => !old_modules.Contains(m)))
                {
                    gui_mod.IsNew = true;
                }
            }
            else
            {
                //Copy the new mod flag from the old list.
                var old_new_mods = new HashSet <GUIMod>(old_modules.Where(m => m.IsNew));
                foreach (var gui_mod in gui_mods.Where(m => old_new_mods.Contains(m)))
                {
                    gui_mod.IsNew = true;
                }
            }
            mainModList.Modules = new ReadOnlyCollection <GUIMod>(gui_mods.ToList());
            var rows = mainModList.ConstructModList(mainModList.Modules);

            ModList.Rows.Clear();
            ModList.Rows.AddRange(rows.ToArray());
            ModList.Sort(ModList.Columns[2], ListSortDirection.Ascending);

            //TODO Consider using smart enum patten so stuff like this is easier
            FilterToolButton.DropDownItems[0].Text = String.Format("Compatible ({0})",
                                                                   mainModList.CountModsByFilter(GUIModFilter.Compatible));
            FilterToolButton.DropDownItems[1].Text = String.Format("Installed ({0})",
                                                                   mainModList.CountModsByFilter(GUIModFilter.Installed));
            FilterToolButton.DropDownItems[2].Text = String.Format("Upgradeable ({0})",
                                                                   mainModList.CountModsByFilter(GUIModFilter.InstalledUpdateAvailable));
            FilterToolButton.DropDownItems[3].Text = String.Format("New in repository ({0})",
                                                                   mainModList.CountModsByFilter(GUIModFilter.NewInRepository));
            FilterToolButton.DropDownItems[4].Text = String.Format("Not installed ({0})",
                                                                   mainModList.CountModsByFilter(GUIModFilter.NotInstalled));
            FilterToolButton.DropDownItems[5].Text = String.Format("Incompatible ({0})",
                                                                   mainModList.CountModsByFilter(GUIModFilter.Incompatible));
            FilterToolButton.DropDownItems[6].Text = String.Format("All ({0})",
                                                                   mainModList.CountModsByFilter(GUIModFilter.All));

            var has_any_updates = gui_mods.Any(mod => mod.HasUpdate);

            UpdateAllToolButton.Enabled = has_any_updates;
            UpdateFilters(this);
        }
Beispiel #3
0
        private void _UpdateModsList(bool markUpdates)
        {
            Registry registry = RegistryManager.Instance(KSPManager.CurrentInstance).registry;

            ModList.Rows.Clear();

            List <CkanModule> modules = GetModsByFilter(m_ModFilter);

            // filter by left menu selection
            switch (m_ModFilter)
            {
            case GUIModFilter.All:
                break;

            case GUIModFilter.Installed:
                modules.RemoveAll(m => !registry.IsInstalled(m.identifier));
                break;

            case GUIModFilter.InstalledUpdateAvailable:
                modules.RemoveAll
                (
                    m => !(registry.IsInstalled(m.identifier) &&
                           m.version.IsGreaterThan(
                               registry.InstalledVersion(m.identifier)))
                );
                break;

            case GUIModFilter.NewInRepository:
                break;

            case GUIModFilter.NotInstalled:
                modules.RemoveAll(m => registry.IsInstalled(m.identifier));
                break;

            case GUIModFilter.Incompatible:
                break;
            }

            // filter by name
            modules.RemoveAll(m => !m.name.ToLowerInvariant().Contains(m_ModNameFilter.ToLowerInvariant()));

            foreach (CkanModule mod in modules)
            {
                var item = new DataGridViewRow();
                item.Tag = mod;

                bool isInstalled = registry.IsInstalled(mod.identifier);

                // installed
                if (m_ModFilter != GUIModFilter.Incompatible)
                {
                    var installedCell = new DataGridViewCheckBoxCell();
                    installedCell.Value = isInstalled;
                    item.Cells.Add(installedCell);
                }
                else
                {
                    var installedCell = new DataGridViewTextBoxCell();
                    installedCell.Value = "-";
                    item.Cells.Add(installedCell);
                }

                // want update
                if (!isInstalled)
                {
                    var updateCell = new DataGridViewTextBoxCell();
                    item.Cells.Add(updateCell);
                    updateCell.ReadOnly = true;
                    updateCell.Value    = "-";
                }
                else
                {
                    bool isUpToDate =
                        !registry.InstalledVersion(mod.identifier).IsLessThan(mod.version);
                    if (!isUpToDate)
                    {
                        var updateCell = new DataGridViewCheckBoxCell();
                        item.Cells.Add(updateCell);
                        updateCell.ReadOnly = false;
                    }
                    else
                    {
                        var updateCell = new DataGridViewTextBoxCell();
                        item.Cells.Add(updateCell);
                        updateCell.ReadOnly = true;
                        updateCell.Value    = "-";
                    }
                }

                // name
                var nameCell = new DataGridViewTextBoxCell();
                nameCell.Value = mod.name;
                item.Cells.Add(nameCell);

                // author
                var authorCell = new DataGridViewTextBoxCell();
                if (mod.author != null)
                {
                    string authors = "";
                    for (int i = 0; i < mod.author.Count(); i++)
                    {
                        authors += mod.author[i];
                        if (i != mod.author.Count() - 1)
                        {
                            authors += ", ";
                        }
                    }

                    authorCell.Value = authors;
                }
                else
                {
                    authorCell.Value = "N/A";
                }

                item.Cells.Add(authorCell);

                // installed version
                Version installedVersion     = registry.InstalledVersion(mod.identifier);
                var     installedVersionCell = new DataGridViewTextBoxCell();

                if (installedVersion != null)
                {
                    installedVersionCell.Value = installedVersion.ToString();
                }
                else
                {
                    installedVersionCell.Value = "-";
                }

                item.Cells.Add(installedVersionCell);

                // latest version
                Version latestVersion     = mod.version;
                var     latestVersionCell = new DataGridViewTextBoxCell();

                if (latestVersion != null)
                {
                    latestVersionCell.Value = latestVersion.ToString();
                }
                else
                {
                    latestVersionCell.Value = "-";
                }

                item.Cells.Add(latestVersionCell);

                // KSP version
                KSPVersion kspVersion     = mod.ksp_version;
                var        kspVersionCell = new DataGridViewTextBoxCell();

                if (kspVersion != null)
                {
                    kspVersionCell.Value = kspVersion.ToString();
                }
                else
                {
                    kspVersionCell.Value = "-";
                }

                item.Cells.Add(kspVersionCell);

                // description
                var descriptionCell = new DataGridViewTextBoxCell();
                descriptionCell.Value = mod.@abstract;
                item.Cells.Add(descriptionCell);

                // homepage
                var homepageCell = new DataGridViewLinkCell();

                if (mod.resources != null && mod.resources.homepage != null)
                {
                    homepageCell.Value = mod.resources.homepage;
                }
                else
                {
                    homepageCell.Value = "N/A";
                }

                item.Cells.Add(homepageCell);

                ModList.Rows.Add(item);

                // sort by name
                ModList.Sort(ModList.Columns[2], ListSortDirection.Ascending);
                ModList.Refresh();
            }
        }