Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            // check for one valid url or users permission.
            ISiteHandler siteHandler = SiteHandlerManager.GetSiteHandlerByName(cbVersionControl.SelectedItem as string);

            if (siteHandler == null || siteHandler.IsValidURL(ModURL) || (MessageBox.Show(this, Messages.MSG_INVALID_URL_SAVE_ANYWAY, Messages.MSG_TITLE_ATTENTION, MessageBoxButtons.YesNo) == DialogResult.Yes))
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads and registers all SiteHandler.
        /// </summary>
        protected static void LoadSiteHandler()
        {
            // Add default SiteHandler
            var siteHandlers = PluginLoader.GetPlugins <ISiteHandler>(new[] { Assembly.GetExecutingAssembly() });

            foreach (ISiteHandler handler in siteHandlers)
            {
                SiteHandlerManager.RegisterSiteHandler(handler);
            }

            // Add additional SiteHandlers
            siteHandlers = PluginLoader.LoadPlugins <ISiteHandler>(KSPPathHelper.GetPath(KSPPaths.KSPMA_Plugins));
            foreach (ISiteHandler handler in siteHandlers)
            {
                SiteHandlerManager.RegisterSiteHandler(handler);
            }
        }
Exemplo n.º 3
0
        private void btnGotoSpaceport_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(ModURL))
            {
                MessageBox.Show(this, Messages.MSG_ENTER_VALID_URL_FIRST);
            }
            else
            {
                try
                {
                    ISiteHandler siteHandler = SiteHandlerManager.GetSiteHandlerByURL(ModURL); ////ByName(cbVersionControl.SelectedItem as string);
                    if (siteHandler == null)
                    {
                        // set selected sitehandler to none.
                        cbVersionControl.SelectedItem = cbVersionControl.Items[0];
                        string msg = string.Format(Messages.MSG_NO_SITEHANDLER_FOUND_FOR_URL_0, ModURL);
                        MessageBox.Show(this, msg, Messages.MSG_TITLE_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    ModInfo newModInfo = null;
                    if (siteHandler.IsValidURL(ModURL))
                    {
                        newModInfo = siteHandler.GetModInfo(ModURL);
                    }

                    if (newModInfo != null)
                    {
                        newModInfo.AdditionalURL = ModInfo.AdditionalURL;
                        ModInfo = newModInfo;
                    }
                }
                catch (Exception ex)
                {
                    string msg = string.Format(Messages.MSG_ERROR_DURING_MODINFO_UPDATE, ModURL, Environment.NewLine, ex.Message);
                    MessageBox.Show(this, msg, Messages.MSG_TITLE_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Log.AddErrorS(msg, ex);
                }
            }
        }
Exemplo n.º 4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            tbModName.Enabled                    = false;
            tbModPath.Enabled                    = false;
            btnAdd.Enabled                       = false;
            btnAddAndClose.Enabled               = false;
            btnClose.Enabled                     = false;
            btnFolderSearch.Enabled              = false;
            cbInstallAfterAdd.Enabled            = false;
            picLoading.Visible                   = true;
            progressBar1.Visible                 = true;
            ModSelectionController.View.ShowBusy = true;

            string modPath = tbModPath.Text;

            new AsyncTask <bool>(() =>
            {
                ModNode newMod       = null;
                ISiteHandler handler = SiteHandlerManager.GetSiteHandlerByURL(modPath);

                if (handler != null)
                {
                    InvokeIfRequired(() =>
                    {
                        if (!OptionsController.HasValidDownloadPath)
                        {
                            Messenger.AddInfo(Messages.MSG_DOWNLOAD_PATH_MISSING_PLEASE_SELECT_ONE);
                            OptionsController.SelectNewDownloadPath();
                        }
                    });

                    if (!OptionsController.HasValidDownloadPath)
                    {
                        return(false);
                    }

                    Messenger.AddInfo(Messages.MSG_URL_DETECTED_STARTING_DOWNLOAD);
                    newMod = handler.HandleAdd(modPath, tbModName.Text, cbInstallAfterAdd.Checked, UpdateProgressBar);
                }

                else if (ValidModPath(modPath))
                {
                    newMod = ModSelectionController.HandleModAddViaPath(modPath, tbModName.Text, cbInstallAfterAdd.Checked);
                }

                else
                {
                    Messenger.AddError(string.Format(Messages.MSG_ERROR_MOD_PATH_URL_0_INVALID, modPath));
                    InvokeIfRequired(() => MessageBox.Show(this, Messages.MSG_PLS_ENTER_VALID_ARCHIVE_URL, Messages.MSG_TITLE_ATTENTION));
                }

                return(newMod != null);
            }, (success, ex) =>
            {
                if (ex != null)
                {
                    Messenger.AddError(ex.Message, ex);
                    MessageBox.Show(this, ex.Message, Messages.MSG_TITLE_ERROR);
                }

                tbModName.Enabled                    = true;
                tbModPath.Enabled                    = true;
                btnAdd.Enabled                       = true;
                btnAddAndClose.Enabled               = true;
                btnClose.Enabled                     = true;
                btnFolderSearch.Enabled              = true;
                cbInstallAfterAdd.Enabled            = true;
                picLoading.Visible                   = false;
                progressBar1.Visible                 = false;
                ModSelectionController.View.ShowBusy = false;

                if (success && sender == btnAddAndClose)
                {
                    Close();
                }
                else
                {
                    tbModName.Text = string.Empty;
                    tbModPath.Text = string.Empty;
                }
            }).Run();
        }