override public void Dispose() { if (Www != null) { Www.Dispose(); Www = null; } //Url = string.Empty; }
/// <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) { if (modInfo == null) { return(false); } string downloadUrl = GetDownloadPath(GetPathToDownloads(modInfo.ModURL)); modInfo.LocalPath = Path.Combine(OptionsController.DownloadPath, downloadUrl.Split("/").Last()); Www.DownloadFile(downloadUrl, modInfo.LocalPath, downloadProgressCallback); return(File.Exists(modInfo.LocalPath)); }
/// <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) { if (modInfo == null) { return(false); } string downloadUrl = GetDownloadURL(modInfo); ////string siteContent = www.Load(GetFilesURL(modInfo.ModURL)); ////string filename = GetFileName(siteContent); modInfo.LocalPath = Path.Combine(OptionsController.DownloadPath, GetDownloadName(modInfo)); Www.DownloadFile(downloadUrl, modInfo.LocalPath, downloadProgressCallback); return(File.Exists(modInfo.LocalPath)); }
/// <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) { if (modInfo == null) { return(false); } var downloadInfos = GetDownloadInfo(modInfo); DownloadInfo selected = null; if (downloadInfos.Count > 1) { // create new selection form if more than one download option found var dlg = new frmSelectDownload(downloadInfos); if (dlg.ShowDialog() == DialogResult.OK) { selected = dlg.SelectedLink; } } else if (downloadInfos.Count == 1) { selected = downloadInfos.First(); } else { string msg = string.Format(Messages.MSG_NO_BINARY_DOWNLOAD_FOUND_AT_0, modInfo.SiteHandlerName); MessageBox.Show(msg, Messages.MSG_TITLE_ERROR); Messenger.AddDebug(msg); return(false); } if (selected != null) { string downloadUrl = selected.DownloadURL; modInfo.LocalPath = Path.Combine(OptionsController.DownloadPath, selected.Filename); Www.DownloadFile(downloadUrl, modInfo.LocalPath, downloadProgressCallback); } return(File.Exists(modInfo.LocalPath)); }
/// <summary> /// Downloads the list of Ckan Repositories from the passed URL. /// </summary> /// <param name="repoListURL">The URL to get the Ckan Repositories from.</param> /// <returns>The list of Ckan Repositories from the passed URL.</returns> public static CkanRepositories GetRepositoryList(Uri repoListURL = null) { CkanRepositories repos; if (repoListURL != null) { // load repositories from repoListURL Messenger.AddInfo($"Downloading repository list from \"{repoListURL.AbsoluteUri}\"..."); var content = Www.Load(repoListURL.AbsoluteUri); repos = JsonConvert.DeserializeObject <CkanRepositories>(content); Messenger.AddInfo($"Downloading repository list done. {repos.repositories.Length} repositories found."); } else { // create default repository repos = new CkanRepositories { repositories = new [] { CkanRepository.GitHubRepository } }; } return(repos); }
/// <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) { string modInfoUrl = MODINFO_URL + (url.Split(new string[] { "/" }, StringSplitOptions.None).ToList())[4]; if (string.IsNullOrEmpty(modInfoUrl)) { return(null); } string content = Www.Load(modInfoUrl); if (string.IsNullOrEmpty(content)) { return(null); } JObject jObject = JObject.Parse(content); var modInfo = new ModInfo { SiteHandlerName = Name, ModURL = url, AdditionalURL = GetString(jObject["website"]), ProductID = GetString(jObject["id"]), Name = GetString(jObject["name"]), Downloads = GetString(jObject["downloads"]), Author = GetString(jObject["author"]), Version = GetVersion(jObject["versions"] as JToken), KSPVersion = GetKSPVersion(jObject["versions"] as JToken), Note = GetString(jObject["description"]) }; ////modInfo.CreationDate = kerbalMod.Versions.Last().Date; // TODO when KS API supports dates from versions return(modInfo); }