示例#1
0
        /// <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)
        {
            ISiteHandler curseForge = SiteHandlerManager.GetSiteHandlerByName("CurseForge");
            ModNode      modNode    = curseForge.HandleAdd(GetDownloadURL(url), modName, install, downloadProgressCallback);

            ////modNode.VersionControllerName = Name;

            return(modNode);
        }
        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();
        }