示例#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);
        }
示例#2
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)));
        }
示例#3
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));
        }
示例#4
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)));
        }
        /// <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));
                }
            }
        }