Beispiel #1
0
        /// <summary>
        /// This method creates the Install part of the changeset
        /// It arranges the changeset in a human-friendly order
        /// The requested mod is listed first, it's dependencies right after it
        /// So we get for example "ModuleRCSFX" directly after "USI Exploration Pack"
        /// 
        /// It is very likely that this is forward-compatible with new ChangeTypes's,
        /// like a a "reconfigure" changetype, but only the future will tell
        /// </summary>
        /// <param name="changes">Every leftover ModChange that should be sorted</param>
        /// <param name="parent"></param>
        private void CreateSortedModList(IEnumerable<ModChange> changes, ModChange parent=null)
        {
            foreach (ModChange change in changes)
            {
                bool goDeeper = parent == null || change.Reason.Parent.identifier == parent.Mod.Identifier;

                if (goDeeper)
                {
                    if (!m_Changeset.Any(c => c.Mod.Identifier == change.Mod.Identifier))
                        m_Changeset.Add(change);
                    CreateSortedModList(changes.Where(c => !(c.Reason is SelectionReason.UserRequested)), change);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method creates the Install part of the changeset
        /// It arranges the changeset in a human-friendly order
        /// The requested mod is listed first, it's dependencies right after it
        /// So we get for example "ModuleRCSFX" directly after "USI Exploration Pack"
        ///
        /// It is very likely that this is forward-compatible with new ChangeTypes's,
        /// like a a "reconfigure" changetype, but only the future will tell
        /// </summary>
        /// <param name="changes">Every leftover ModChange that should be sorted</param>
        /// <param name="parent"></param>
        private void CreateSortedModList(IEnumerable <ModChange> changes, ModChange parent = null)
        {
            foreach (ModChange change in changes)
            {
                bool goDeeper = parent == null || change.Reason.Parent.identifier == parent.Mod.Identifier;

                if (goDeeper)
                {
                    if (!changeSet.Any(c => c.Mod.Identifier == change.Mod.Identifier))
                    {
                        changeSet.Add(change);
                    }
                    CreateSortedModList(changes.Where(c => !(c.Reason is SelectionReason.UserRequested)), change);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// This method creates the Install part of the changeset
        /// It arranges the changeset in a human-friendly order
        /// The requested mod is listed first, its dependencies right after it
        /// So we get for example "ModuleRCSFX" directly after "USI Exploration Pack"
        ///
        /// It is very likely that this is forward-compatible with new ChangeTypes's,
        /// like a "reconfigure" changetype, but only the future will tell
        /// </summary>
        /// <param name="changes">Every leftover ModChange that should be sorted</param>
        /// <param name="parent"></param>
        private void CreateSortedModList(IEnumerable <ModChange> changes, ModChange parent = null)
        {
            var notUserReq = changes
                             .Where(c => !(c.Reason is SelectionReason.UserRequested))
                             .Memoize();

            foreach (ModChange change in changes)
            {
                bool goDeeper = parent == null || change.Reason.Parent.identifier == parent.Mod.identifier;

                if (goDeeper)
                {
                    if (!sortedChangeSet.Any(c => c.Mod.identifier == change.Mod.identifier && c.ChangeType != GUIModChangeType.Remove))
                    {
                        sortedChangeSet.Add(change);
                    }
                    CreateSortedModList(notUserReq, change);
                }
            }
        }
Beispiel #4
0
        private ListViewItem makeItem(ModChange change)
        {
            CkanModule  m       = change.Mod;
            ModuleLabel warnLbl = alertLabels?.FirstOrDefault(l => l.ModuleIdentifiers.Contains(m.identifier));

            return(new ListViewItem(new string[]
            {
                change.NameAndStatus,
                change.ChangeType.ToString(),
                warnLbl != null
                    ? string.Format(
                    Properties.Resources.MainChangesetWarningInstallingModuleWithLabel,
                    warnLbl.Name,
                    change.Description
                    )
                    : change.Description
            })
            {
                Tag = m,
                ForeColor = warnLbl != null ? Color.Red : SystemColors.WindowText
            });
        }
Beispiel #5
0
        private DataGridViewRow MakeRow(GUIMod mod, List <ModChange> changes, string instanceName, bool hideEpochs = false, bool hideV = false)
        {
            DataGridViewRow item = new DataGridViewRow()
            {
                Tag = mod
            };

            Color?myColor = ModuleLabels.LabelsFor(instanceName)
                            .FirstOrDefault(l => l.ModuleIdentifiers.Contains(mod.Identifier))
                            ?.Color;

            if (myColor.HasValue)
            {
                item.DefaultCellStyle.BackColor = myColor.Value;
            }

            ModChange myChange = changes?.FindLast((ModChange ch) => ch.Mod.Equals(mod));

            var selecting = mod.IsAutodetected
                ? new DataGridViewTextBoxCell()
            {
                Value = Properties.Resources.MainModListAutoDetected
            }
                : mod.IsInstallable()
                ? (DataGridViewCell) new DataGridViewCheckBoxCell()
            {
                Value = myChange == null ? mod.IsInstalled
                        : myChange.ChangeType == GUIModChangeType.Install ? true
                        : myChange.ChangeType == GUIModChangeType.Remove  ? false
                        : mod.IsInstalled
            }
                : new DataGridViewTextBoxCell()
            {
                Value = "-"
            };

            var autoInstalled = mod.IsInstalled && !mod.IsAutodetected
                ? (DataGridViewCell) new DataGridViewCheckBoxCell()
            {
                Value = mod.IsAutoInstalled
            }
                : new DataGridViewTextBoxCell()
            {
                Value = "-"
            };

            var updating = mod.IsInstallable() && mod.HasUpdate
                ? (DataGridViewCell) new DataGridViewCheckBoxCell()
            {
                Value = myChange == null ? false
                        : myChange.ChangeType == GUIModChangeType.Update ? true
                        : false
            }
                : new DataGridViewTextBoxCell()
            {
                Value = "-"
            };

            var replacing = IsModInFilter(GUIModFilter.Replaceable, null, null, mod)
                ? (DataGridViewCell) new DataGridViewCheckBoxCell()
            {
                Value = myChange == null ? false
                        : myChange.ChangeType == GUIModChangeType.Replace ? true
                        : false
            }
                : new DataGridViewTextBoxCell()
            {
                Value = "-"
            };

            var name = new DataGridViewTextBoxCell {
                Value = mod.Name.Replace("&", "&&")
            };
            var author = new DataGridViewTextBoxCell {
                Value = mod.Authors.Replace("&", "&&")
            };

            var installVersion = new DataGridViewTextBoxCell()
            {
                Value = hideEpochs
                    ? (hideV
                        ? ModuleInstaller.StripEpoch(ModuleInstaller.StripV(mod.InstalledVersion ?? ""))
                        : ModuleInstaller.StripEpoch(mod.InstalledVersion ?? ""))
                    : (hideV
                        ? ModuleInstaller.StripV(mod.InstalledVersion ?? "")
                        : mod.InstalledVersion ?? "")
            };

            var latestVersion = new DataGridViewTextBoxCell()
            {
                Value =
                    hideEpochs ?
                    (hideV ? ModuleInstaller.StripEpoch(ModuleInstaller.StripV(mod.LatestVersion))
                        : ModuleInstaller.StripEpoch(mod.LatestVersion))
                    : (hideV ? ModuleInstaller.StripV(mod.LatestVersion)
                        : mod.LatestVersion)
            };

            var downloadCount = new DataGridViewTextBoxCell {
                Value = $"{mod.DownloadCount:N0}"
            };
            var compat = new DataGridViewTextBoxCell {
                Value = mod.GameCompatibility
            };
            var size = new DataGridViewTextBoxCell {
                Value = mod.DownloadSize
            };
            var releaseDate = new DataGridViewTextBoxCell {
                Value = mod.ToModule().release_date
            };
            var installDate = new DataGridViewTextBoxCell {
                Value = mod.InstallDate
            };
            var desc = new DataGridViewTextBoxCell {
                Value = mod.Abstract.Replace("&", "&&")
            };

            item.Cells.AddRange(selecting, autoInstalled, updating, replacing, name, author, installVersion, latestVersion, compat, size, releaseDate, installDate, downloadCount, desc);

            selecting.ReadOnly     = selecting     is DataGridViewTextBoxCell;
            autoInstalled.ReadOnly = autoInstalled is DataGridViewTextBoxCell;
            updating.ReadOnly      = updating      is DataGridViewTextBoxCell;

            return(item);
        }
Beispiel #6
0
        private DataGridViewRow MakeRow(GUIMod mod, List <ModChange> changes, bool hideEpochs = false, bool hideV = false)
        {
            DataGridViewRow item = new DataGridViewRow()
            {
                Tag = mod
            };

            ModChange myChange = changes?.FindLast((ModChange ch) => ch.Mod.Identifier == mod.Identifier);

            var selecting = mod.IsInstallable()
                ? (DataGridViewCell) new DataGridViewCheckBoxCell()
            {
                Value = myChange == null ? mod.IsInstalled
                        : myChange.ChangeType == GUIModChangeType.Install ? true
                        : myChange.ChangeType == GUIModChangeType.Remove  ? false
                        : mod.IsInstalled
            }
                : new DataGridViewTextBoxCell()
            {
                Value = mod.IsAutodetected ? Properties.Resources.MainModListAutoDetected : "-"
            };

            var autoInstalled = mod.IsInstalled && !mod.IsAutodetected
                ? (DataGridViewCell) new DataGridViewCheckBoxCell()
            {
                Value = mod.IsAutoInstalled
            }
                : new DataGridViewTextBoxCell()
            {
                Value = "-"
            };

            var updating = mod.IsInstallable() && mod.HasUpdate
                ? (DataGridViewCell) new DataGridViewCheckBoxCell()
            {
                Value = myChange == null ? false
                        : myChange.ChangeType == GUIModChangeType.Update ? true
                        : false
            }
                : new DataGridViewTextBoxCell()
            {
                Value = "-"
            };

            var replacing = IsModInFilter(GUIModFilter.Replaceable, mod)
                ? (DataGridViewCell) new DataGridViewCheckBoxCell()
            {
                Value = myChange == null ? false
                        : myChange.ChangeType == GUIModChangeType.Replace ? true
                        : false
            }
                : new DataGridViewTextBoxCell()
            {
                Value = "-"
            };

            var name = new DataGridViewTextBoxCell()
            {
                Value = mod.Name
            };
            var author = new DataGridViewTextBoxCell()
            {
                Value = mod.Authors
            };

            var installVersion = new DataGridViewTextBoxCell()
            {
                Value = hideEpochs
                    ? (hideV
                        ? ModuleInstaller.StripEpoch(ModuleInstaller.StripV(mod.InstalledVersion ?? ""))
                        : ModuleInstaller.StripEpoch(mod.InstalledVersion ?? ""))
                    : (hideV
                        ? ModuleInstaller.StripV(mod.InstalledVersion ?? "")
                        : mod.InstalledVersion ?? "")
            };

            var latestVersion = new DataGridViewTextBoxCell()
            {
                Value =
                    hideEpochs ?
                    (hideV ? ModuleInstaller.StripEpoch(ModuleInstaller.StripV(mod.LatestVersion))
                        : ModuleInstaller.StripEpoch(mod.LatestVersion))
                    : (hideV ? ModuleInstaller.StripV(mod.LatestVersion)
                        : mod.LatestVersion)
            };

            var downloadCount = new DataGridViewTextBoxCell()
            {
                Value = String.Format("{0:N0}", mod.DownloadCount)
            };
            var compat = new DataGridViewTextBoxCell()
            {
                Value = mod.KSPCompatibility
            };
            var size = new DataGridViewTextBoxCell()
            {
                Value = mod.DownloadSize
            };
            var installDate = new DataGridViewTextBoxCell()
            {
                Value = mod.InstallDate
            };
            var desc = new DataGridViewTextBoxCell()
            {
                Value = mod.Abstract
            };

            item.Cells.AddRange(selecting, autoInstalled, updating, replacing, name, author, installVersion, latestVersion, compat, size, installDate, downloadCount, desc);

            selecting.ReadOnly     = selecting     is DataGridViewTextBoxCell;
            autoInstalled.ReadOnly = autoInstalled is DataGridViewTextBoxCell;
            updating.ReadOnly      = updating      is DataGridViewTextBoxCell;

            return(item);
        }
Beispiel #7
0
        /// <summary>
        /// Constructs the mod list suitable for display to the user.
        /// This manipulates <c>full_list_of_mod_rows</c> as it runs, and by default
        /// will only update entries which have changed or were previously missing.
        /// (Set <c>refreshAll</c> to force update everything.)
        /// </summary>
        /// <returns>The mod list.</returns>
        /// <param name="modules">A list of modules that may require updating</param>
        /// <param name="refreshAll">If set to <c>true</c> then always rebuild the list from scratch</param>
        /// <param name="hideEpochs">If true, remove epochs from the displayed versions</param>
        public IEnumerable <DataGridViewRow> ConstructModList(IEnumerable <GUIMod> modules, List <ModChange> mc = null, bool refreshAll = false, bool hideEpochs = false, bool hideV = false)
        {
            if (refreshAll || full_list_of_mod_rows == null)
            {
                full_list_of_mod_rows = new Dictionary <string, DataGridViewRow>();
            }

            // We're only going to update the status of rows that either don't already exist,
            // or which exist but have changed their latest version
            // or whose installation status has changed
            //
            // TODO: Will this catch a mod where the latest version number remains the same, but
            // another part of the metadata (eg: dependencies or description) has changed?
            IEnumerable <GUIMod> rowsToUpdate = modules.Where(
                mod => !full_list_of_mod_rows.ContainsKey(mod.Identifier) ||
                mod.LatestVersion != (full_list_of_mod_rows[mod.Identifier].Tag as GUIMod)?.LatestVersion ||
                mod.IsInstalled != (full_list_of_mod_rows[mod.Identifier].Tag as GUIMod)?.IsInstalled);

            // Let's update our list!
            foreach (var mod in rowsToUpdate)
            {
                full_list_of_mod_rows.Remove(mod.Identifier);
                var item = new DataGridViewRow {
                    Tag = mod
                };

                ModChange myChange = mc?.FindLast((ModChange ch) => ch.Mod.Identifier == mod.Identifier);

                var selecting = mod.IsInstallable()
                    ? (DataGridViewCell) new DataGridViewCheckBoxCell()
                {
                    Value = myChange == null ? mod.IsInstalled
                            : myChange.ChangeType == GUIModChangeType.Install ? true
                            : myChange.ChangeType == GUIModChangeType.Remove  ? false
                            : mod.IsInstalled
                } : new DataGridViewTextBoxCell()
                {
                    Value = mod.IsAutodetected ? "AD" : "-"
                };

                var updating = mod.IsInstallable() && mod.HasUpdate
                    ? (DataGridViewCell) new DataGridViewCheckBoxCell()
                {
                    Value = myChange == null ? false
                            : myChange.ChangeType == GUIModChangeType.Update ? true
                            : false
                } : new DataGridViewTextBoxCell()
                {
                    Value = "-"
                };

                var name = new DataGridViewTextBoxCell {
                    Value = mod.Name
                };
                var author = new DataGridViewTextBoxCell {
                    Value = mod.Authors
                };

                var installVersion = new DataGridViewTextBoxCell {
                    Value =
                        hideEpochs ?
                        (hideV ? ModuleInstaller.StripEpoch(ModuleInstaller.StripV(mod.InstalledVersion))
                            : ModuleInstaller.StripEpoch(mod.InstalledVersion))
                        :   (hideV ? ModuleInstaller.StripV(mod.InstalledVersion)
                            : mod.InstalledVersion)
                };

                var latestVersion = new DataGridViewTextBoxCell
                {
                    Value =
                        hideEpochs ?
                        (hideV ? ModuleInstaller.StripEpoch(ModuleInstaller.StripV(mod.LatestVersion))
                            : ModuleInstaller.StripEpoch(mod.LatestVersion))
                        : (hideV ? ModuleInstaller.StripV(mod.LatestVersion)
                            : mod.LatestVersion)
                };

                var desc = new DataGridViewTextBoxCell {
                    Value = mod.Abstract
                };
                var compat = new DataGridViewTextBoxCell {
                    Value = mod.KSPCompatibility
                };
                var size = new DataGridViewTextBoxCell {
                    Value = mod.DownloadSize
                };

                item.Cells.AddRange(selecting, updating, name, author, installVersion, latestVersion, compat, size, desc);

                selecting.ReadOnly = selecting is DataGridViewTextBoxCell;
                updating.ReadOnly  = updating is  DataGridViewTextBoxCell;

                full_list_of_mod_rows.Add(mod.Identifier, item);
            }
            return(full_list_of_mod_rows.Values);
        }