private void tsbCreateZip_Click(object sender, EventArgs e)
 {
     if (HasSelectedNode)
     {
         ModSelectionController.CreateZip(new ModNode[] { SelectedMod }.ToList());
     }
 }
Beispiel #2
0
        /// <summary>
        /// Solves the destination collision for a Mod.
        /// Removes the destination of all mod files registered to the destination of
        /// </summary>
        /// <param name="modRoot">The mod to keep the destination.</param>
        public static void SolveCollisions(ModNode modRoot)
        {
            var collidingNodes = GetAllCollisionNodes(modRoot);

            foreach (ModNode collidingNode in collidingNodes)
            {
                if (string.IsNullOrEmpty(collidingNode.Destination) || !mRegisterdModFiles.ContainsKey(collidingNode.Destination.ToLower()))
                {
                    collidingNode.HasCollision = false;
                    continue;
                }

                List <ModNode> removeDestinationNodes = mRegisterdModFiles[collidingNode.Destination.ToLower()].Where(node => node != collidingNode).ToList();
                foreach (ModNode delNode in removeDestinationNodes)
                {
                    RemoveRegisteredModFile(delNode);

                    // TODO:
                    ////TreeViewEx.ChangeCheckedState(delNode, false, true, true);

                    if (!delNode.IsFile && delNode.IsInstalled)
                    {
                        ModSelectionController.ProcessMods(new ModNode[] { delNode }, true);
                    }

                    delNode.SetDestinationPaths(string.Empty);
                }
            }
        }
 private void tsbCopyModInfos_Click(object sender, EventArgs e)
 {
     if (HasSelectedNode)
     {
         ModSelectionController.CopyModInfos(SelectedMod);
     }
 }
 private void tsbChangeDestination_Click(object sender, EventArgs e)
 {
     if (HasSelectedNode)
     {
         ModSelectionController.ChangeDestination(SelectedNode);
     }
 }
 private void tsbRemoveMod_Click(object sender, EventArgs e)
 {
     if (HasSelectedNode)
     {
         ModSelectionController.RemoveMod(new[] { SelectedMod });
     }
 }
 private void tsmiCmsRemoveHighlightedMods_Click(object sender, EventArgs e)
 {
     if (HasSelectedNode)
     {
         ModSelectionController.RemoveMod(SelectedMods.ToArray());
     }
 }
 private void OpenFile(ModNode node)
 {
     if (node != null && node.IsFile)
     {
         ModSelectionController.OpenTextDisplayer(node);
     }
 }
Beispiel #8
0
        /// <summary>
        /// Imports a mod to the current selected KSP install path.
        /// </summary>
        /// <param name="importInfo">The ImportInfo </param>
        /// <param name="copyDest">Flag to determine if the destination should be copied or if the auto destination detection should be used.</param>
        /// <param name="addOnly">Flag to determine if the mod should be installed or only added to the ModSelection.</param>
        private static void ImportMod(ImportInfo importInfo, bool copyDest, bool addOnly)
        {
            ModInfo modInfo  = importInfo.ModInfo;
            ModNode addedMod = ModSelectionController.AddMods(new ModInfo[] { modInfo }, false).FirstOrDefault();

            if (addedMod != null)
            {
                if (copyDest)
                {
                    // remove all destinations and uncheck all nodes.
                    ModNodeHandler.SetDestinationPaths(addedMod, string.Empty);
                    addedMod._Checked = false;

                    // copy destination
                    UpdateMessage(string.Format(Messages.MSG_COPY_MOD_DESTINATION_0, addedMod.Name));
                    if (!ModNodeHandler.TryCopyDestToMatchingNodes(importInfo, addedMod))
                    {
                        UpdateMessage(string.Format(Messages.MSG_COPY_MOD_0_DESTINATION_FAILED, addedMod.Name));
                        UpdateMessage(string.Format(Messages.MSG_IMPORT_0_FAILED, importInfo.Name), importInfo);
                        return;
                    }
                }

                // install the mod.
                if (!addOnly)
                {
                    UpdateMessage(string.Format(Messages.MSG_INSTALLING_MOD_0, addedMod.Name));
                    ModSelectionController.ProcessMods(new ModNode[] { addedMod });
                }
            }
            else
            {
                UpdateMessage(string.Format(Messages.MSG_IMPORT_0_FAILED, importInfo.Name), importInfo);
            }
        }
        /// <summary>
        /// Handles a mod add via URL.
        /// Validates the URL, gets ModInfos, downloads mod archive, adds it to the ModSelection and installs the mod if selected.
        /// </summary>
        /// <param name="url">The URL to the mod.</param>
        /// <param name="modName">The name for the mod.</param>
        /// <param name="install">Flag to determine if the mod should be installed after adding.</param>
        /// <param name="downloadProgressCallback">Callback function for download progress.</param>
        /// <returns>The root node of the added mod, or null.</returns>
        public ModNode HandleAdd(string url, string modName, bool install, DownloadProgressCallback downloadProgressCallback = null)
        {
            url = ReduceToPlainUrl(url);

            ModInfo modInfo = GetModInfo(url);

            if (modInfo == null)
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(modName))
            {
                modInfo.Name = modName;
            }

            ModNode newMod = null;

            if (DownloadMod(ref modInfo, downloadProgressCallback))
            {
                newMod = ModSelectionController.HandleModAddViaModInfo(modInfo, install);
            }

            return(newMod);
        }
        private void btnProceedAll_Click(object sender, EventArgs e)
        {
            ModSelectionController.ProcessAllModsAsync();

            tvModSelection.Select();
            tvModSelection.Focus();
            tvModSelection.Invalidate();
        }
 private void tsbAddMod_Click(object sender, EventArgs e)
 {
     //Check for a downloads folder (configured and exists)
     while (!OptionsController.HasValidDownloadPath)
     {
         OptionsController.SelectNewDownloadPath();
     }
     ModSelectionController.OpenAddModDialog();
 }
        /// <summary>
        /// Handles the Click event of the color change buttons.
        /// </summary>
        private void ColorChangeButton_Click(object sender, EventArgs e)
        {
            ColorDialog dlg = new ColorDialog();

            if (((Button)sender).Name.Contains(DEST_DETECTED))
            {
                dlg.Color = pDestinationDetected.BackColor;
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    pDestinationDetected.BackColor = dlg.Color;
                }
            }
            else if (((Button)sender).Name.Contains(DEST_MISSING))
            {
                dlg.Color = pDestinationMissing.BackColor;
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    pDestinationMissing.BackColor = dlg.Color;
                }
            }
            else if (((Button)sender).Name.Contains(DEST_CONFLICT))
            {
                dlg.Color = pDestinationConflict.BackColor;
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    pDestinationConflict.BackColor = dlg.Color;
                }
            }
            else if (((Button)sender).Name.Contains(MOD_INSTALLED))
            {
                dlg.Color = pModInstalled.BackColor;
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    pModInstalled.BackColor = dlg.Color;
                }
            }
            else if (((Button)sender).Name.Contains(MOD_ARCHIVE_MISSING))
            {
                dlg.Color = pModArchiveMissing.BackColor;
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    pModArchiveMissing.BackColor = dlg.Color;
                }
            }
            else if (((Button)sender).Name.Contains(MOD_OUTDATED))
            {
                dlg.Color = pModOutdated.BackColor;
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    pModOutdated.BackColor = dlg.Color;
                }
            }

            ModSelectionController.InvalidateView();
        }
        private void tsmiResetDestination_Click(object sender, EventArgs e)
        {
            ////if (HasSelectedNode)
            ////    ModSelectionController.ResetDestination(SelectedNode);

            if (tvModSelection.SelectedNodes.Count > 0)
            {
                foreach (var node in tvModSelection.SelectedNodes)
                {
                    ModSelectionController.ResetDestination(node.Tag as ModNode);
                }
            }
        }
Beispiel #14
0
        private void Import()
        {
            AddMessage(Messages.MSG_IMPORT_STARTED);
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.InitialDirectory = OptionsController.DownloadPath;
            dlg.Filter           = Constants.MODPACK_FILTER;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                pbImport.Visible = true;
                new AsyncTask <bool>(() =>
                {
                    if (cbClearModSelection.Checked)
                    {
                        AddMessage(Messages.MSG_CLEARING_MODSELECTION);
                        InvokeIfRequired(() => ModSelectionController.RemoveAllMods());
                    }

                    AddMessage(string.Format(Messages.MSG_IMPORTING_FROM_0, dlg.FileName));
                    ModPackHandler.MessageCallbackFunction = AddMessage;
                    ModPackHandler.Import(dlg.FileName, OptionsController.DownloadPath, cbExtract.Checked, cbDownloadIfNeeded.Checked, rbCopyDestination.Checked, rbAddOnly.Checked);
                    ModPackHandler.MessageCallbackFunction = null;
                    return(true);
                },
                                     (b, ex) =>
                {
                    pbImport.Visible = false;
                    if (ex != null)
                    {
                        AddMessage(Messages.MSG_IMPORTING_FAILED, true, ex);
                        MessageBox.Show(this, ex.Message, Messages.MSG_TITLE_ERROR);
                    }
                    else
                    {
                        AddMessage(Messages.MSG_IMPORTING_DONE);
                        Close();
                    }
                }).Run();
            }
            else
            {
                AddMessage(Messages.MSG_IMPORTING_ABORTED);
            }
        }
        private void ColorTextBoxes_TextChanged(object sender, EventArgs e)
        {
            TextBox tb = (TextBox)sender;

            if (string.IsNullOrEmpty(((TextBox)sender).Text))
            {
                tb.Text = ZERO;
            }

            if (tb.Name.Contains(DEST_DETECTED))
            {
                pDestinationDetected.BackColor = Color.FromArgb(255, int.Parse(tbDestinationDetectedRed.Text),
                                                                int.Parse(tbDestinationDetectedGreen.Text), int.Parse(tbDestinationDetectedBlue.Text));
            }
            else if (tb.Name.Contains(DEST_MISSING))
            {
                pDestinationMissing.BackColor = Color.FromArgb(255, int.Parse(tbDestinationMissingRed.Text),
                                                               int.Parse(tbDestinationMissingGreen.Text), int.Parse(tbDestinationMissingBlue.Text));
            }
            else if (tb.Name.Contains(DEST_CONFLICT))
            {
                pDestinationConflict.BackColor = Color.FromArgb(255, int.Parse(tbDestinationConflictRed.Text),
                                                                int.Parse(tbDestinationConflictGreen.Text), int.Parse(tbDestinationConflictBlue.Text));
            }
            else if (tb.Name.Contains(MOD_INSTALLED))
            {
                pModInstalled.BackColor = Color.FromArgb(255, int.Parse(tbModInstalledRed.Text),
                                                         int.Parse(tbModInstalledGreen.Text), int.Parse(tbModInstalledBlue.Text));
            }
            else if (tb.Name.Contains(MOD_ARCHIVE_MISSING))
            {
                pModArchiveMissing.BackColor = Color.FromArgb(255, int.Parse(tbModArchiveMissingRed.Text),
                                                              int.Parse(tbModArchiveMissingGreen.Text), int.Parse(tbModArchiveMissingBlue.Text));
            }
            else if (tb.Name.Contains(MOD_OUTDATED))
            {
                pModOutdated.BackColor = Color.FromArgb(255, int.Parse(tbModOutdatedRed.Text),
                                                        int.Parse(tbModOutdatedGreen.Text), int.Parse(tbModOutdatedBlue.Text));
            }

            ModSelectionController.InvalidateView();
        }
        /// <summary>
        /// Creates a new instance of the ucModSelection class.
        /// </summary>
        public ucModSelection()
        {
            InitializeComponent();

            // Create TreeViewAdv columns
            new ModSelectionColumnsInfo().ToTreeViewAdv(tvModSelection);

            if (LicenseManager.UsageMode == LicenseUsageMode.Designtime || DesignMode)
            {
                return;
            }

            ModSelectionController.Initialize(this);
            tvModSelection.Model = ModSelectionController.Model;

            // TODO: Fix display error of icons & CheckBoxes when Columns are used!
            if (PlatformHelper.GetPlatform() == Platform.Linux)
            {
                tvModSelection.UseColumns = false;
            }
        }
Beispiel #17
0
        /// <summary>
        /// Loads the KSPConfig from the selected KSP folder.
        /// </summary>
        protected static void LoadKSPConfig()
        {
            ModSelectionController.ClearMods();

            string configPath = KSPPathHelper.GetPath(KSPPaths.KSPConfig);

            if (File.Exists(configPath))
            {
                Messenger.AddInfo(Messages.MSG_LOADING_KSP_MOD_CONFIGURATION);
                List <ModNode> mods = new List <ModNode>();
                KSPConfig.Load(configPath, ref mods);
                ModSelectionController.AddMods(mods.ToArray());
                ModSelectionController.SortModSelection();
            }
            else
            {
                Messenger.AddInfo(Messages.MSG_KSP_MOD_CONFIGURATION_NOT_FOUND);
            }

            ModSelectionController.RefreshCheckedStateAllMods();
            Messenger.AddInfo(Messages.MSG_DONE);
        }