/// <summary>
 /// Registers a SiteHandler to the Manager.
 /// </summary>
 /// <param name="handler">The SiteHandler to register.</param>
 public static void RegisterSiteHandler(ISiteHandler handler)
 {
     if (!mSiteHandlers.ContainsKey(handler.Name))
     {
         mSiteHandlers.Add(handler.Name, handler);
     }
 }
Beispiel #2
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);
        }
Beispiel #3
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();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Downloads the mod from ModURL.
        /// </summary>
        /// <param name="importInfo">The ImportInfo of the mod to download.</param>
        /// <returns>True if download was successful, otherwise false.</returns>
        private static bool DownloadMod(ref ImportInfo importInfo)
        {
            ISiteHandler siteHandler = importInfo.SiteHandler;

            if (siteHandler != null)
            {
                ModInfo modInfo = siteHandler.GetModInfo(importInfo.ModURL);
                importInfo.DownloadSuccessfull = siteHandler.DownloadMod(ref modInfo);
                importInfo.ModInfo             = modInfo;
            }

            return(importInfo.DownloadSuccessfull);
        }
Beispiel #5
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);
                }
            }
        }
 /// <summary>
 /// Removes a SiteHandler from the Manager.
 /// </summary>
 /// <param name="handler">The SiteHandler to remove.</param>
 public static void RemoveSiteHandler(ISiteHandler handler)
 {
     RemoveSiteHandler(handler.Name);
 }
 /// <summary>
 /// Registers a SiteHandler to the Manager.
 /// </summary>
 /// <param name="handler">The SiteHandler to register.</param>
 public static void RegisterSiteHandler(ISiteHandler handler)
 {
     if (!mSiteHandlers.ContainsKey(handler.Name))
         mSiteHandlers.Add(handler.Name, handler);
 }
        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();
        }
Beispiel #9
0
        /// <summary>
        /// Gets the content of the site of the passed URL and parses it for ModInfos.
        /// </summary>
        /// <param name="url">The URL of the site to parse the ModInfos from.</param>
        /// <returns>The ModInfos parsed from the site of the passed URL.</returns>
        public ModInfo GetModInfo(string url)
        {
            ISiteHandler curseForge = SiteHandlerManager.GetSiteHandlerByName("CurseForge");

            return(curseForge.GetModInfo(GetDownloadURL(url)));
        }
Beispiel #10
0
        /// <summary>
        /// Returns the plain url to the mod, where the ModInfos would be get from.
        /// </summary>
        /// <param name="url">The url to reduce.</param>
        /// <returns>The plain url to the mod, where the ModInfos would be get from.</returns>
        public string ReduceToPlainUrl(string url)
        {
            ISiteHandler curseForge = SiteHandlerManager.GetSiteHandlerByName("CurseForge");

            return(curseForge.ReduceToPlainUrl(GetDownloadURL(url)));
        }
Beispiel #11
0
        /// <summary>
        /// Downloads the mod.
        /// </summary>
        /// <param name="modInfo">The infos of the mod. Must have at least ModURL and LocalPath</param>
        /// <param name="downloadProgressCallback">Callback function for download progress.</param>
        /// <returns>True if the mod was downloaded.</returns>
        public bool DownloadMod(ref ModInfo modInfo, DownloadProgressCallback downloadProgressCallback = null)
        {
            ISiteHandler curseForge = SiteHandlerManager.GetSiteHandlerByName("CurseForge");

            return(curseForge.DownloadMod(ref modInfo, downloadProgressCallback));
        }
        /// <summary>
        /// Copies Infos to the ModInfo.
        /// Try to find a compatible SiteHandler for the provided urls (like Download, URL, ChangeLogUrl, GitHub)
        /// </summary>
        private static void ImportAvcInfo(AVCInfo avcInfo, ref ModInfo modInfo)
        {
            Messenger.AddDebug(string.Format(Messages.MSG_IMPORTING_AVC_VERSIONFILE_INFO_0, modInfo.Name));

            string fileName = Path.GetFileNameWithoutExtension(modInfo.LocalPath);

            if (!OptionsController.AVCIgnoreName && !string.IsNullOrEmpty(avcInfo.Name) && (string.IsNullOrEmpty(modInfo.Name) || modInfo.Name == fileName))
            {
                modInfo.Name = avcInfo.Name;
            }
            if (!string.IsNullOrEmpty(avcInfo.Version) && (string.IsNullOrEmpty(modInfo.Version)))
            {
                modInfo.Version = avcInfo.Version;
            }
            if (!string.IsNullOrEmpty(avcInfo.KspVersion) && (string.IsNullOrEmpty(modInfo.KSPVersion)))
            {
                modInfo.KSPVersion = avcInfo.KspVersion;
            }

            if (!OptionsController.AVCIgnoreURL && !string.IsNullOrEmpty(avcInfo.Url) && (string.IsNullOrEmpty(modInfo.AvcURL)))
            {
                AVCInfo newAvcInfo = null;
                try
                {
                    // Get newest AVC informations for this mod.
                    newAvcInfo = AVCParser.ReadFromWeb(avcInfo.Url);
                }
                catch (Exception ex)
                {
                    Messenger.AddError(string.Format(Messages.MSG_ERROR_DOWNLOADING_NEW_AVC_VERION_FILE_FAILED), ex);
                }

                if (newAvcInfo != null)
                {
                    modInfo.AvcURL                = avcInfo.Url;
                    avcInfo.Download              = newAvcInfo.Download;
                    avcInfo.ChangeLog             = newAvcInfo.ChangeLog;
                    avcInfo.ChangeLogUrl          = newAvcInfo.ChangeLogUrl;
                    avcInfo.GitHubUsername        = newAvcInfo.GitHubUsername;
                    avcInfo.GitHubRepository      = newAvcInfo.GitHubRepository;
                    avcInfo.GitHubAllowPreRelease = newAvcInfo.GitHubAllowPreRelease;
                }
            }

            if (string.IsNullOrEmpty(modInfo.ModURL) && !modInfo.HasSiteHandler)
            {
                ISiteHandler siteHandler = null;
                string       downloadUrl = string.Empty;
                string[]     urls        = new[] { GitHubHandler.GetProjectUrl(avcInfo.GitHubUsername, avcInfo.GitHubRepository), avcInfo.Download, avcInfo.Url, avcInfo.ChangeLogUrl };
                foreach (string url in urls)
                {
                    downloadUrl = url;
                    siteHandler = SiteHandlerManager.GetSiteHandlerByURL(downloadUrl);

                    if (siteHandler != null)
                    {
                        break;
                    }
                }

                if (siteHandler != null)
                {
                    modInfo.ModURL          = downloadUrl;
                    modInfo.SiteHandlerName = siteHandler.Name;
                    Messenger.AddDebug(string.Format(Messages.MSG_COMPATIBLE_SITEHANDLER_0_FOUND_1, siteHandler.Name, modInfo.Name));
                }
                else
                {
                    Messenger.AddDebug(string.Format(Messages.MSG_NO_COMPATIBLE_SITEHANDLER_FOUND_0, modInfo.Name));
                }
            }
        }
 /// <summary>
 /// Removes a SiteHandler from the Manager.
 /// </summary>
 /// <param name="handler">The SiteHandler to remove.</param>
 public static void RemoveSiteHandler(ISiteHandler handler)
 {
     RemoveSiteHandler(handler.Name);
 }