/// <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.ModURL); modInfo.LocalPath = Www.DownloadFile2(downloadURL, OptionsController.DownloadPath, downloadProgressCallback); return(!string.IsNullOrEmpty(modInfo.LocalPath) && 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); } HtmlWeb web = new HtmlWeb(); HtmlDocument htmlDoc = web.Load(modInfo.ModURL); htmlDoc.OptionFixNestedTags = true; // get filename from hover text HtmlNode fileNode = htmlDoc.DocumentNode.SelectSingleNode("//*[@id='content']/section[2]/div[4]/div[2]/ul/li[1]/div[2]/p/a"); HtmlNode fileNode2 = htmlDoc.DocumentNode.SelectSingleNode("//*[@id='content']/section[2]/div[4]/div[2]/ul/li/div[2]/p/a/span"); string downloadURL = GetDownloadURL(modInfo.ModURL); if (fileNode == null || (fileNode.InnerHtml.Contains("...") && fileNode2 == null)) { modInfo.LocalPath = Www.DownloadFile2(downloadURL, OptionsController.DownloadPath, downloadProgressCallback); return(!string.IsNullOrEmpty(modInfo.LocalPath) && File.Exists(modInfo.LocalPath)); } string filename = string.Empty; if (fileNode.InnerHtml.Contains("...")) { filename = fileNode2.Attributes["title"].Value; // Long filename was truncated } else { filename = fileNode.InnerHtml; } modInfo.LocalPath = Path.Combine(OptionsController.DownloadPath, filename); Www.DownloadFile(downloadURL, modInfo.LocalPath, downloadProgressCallback); return(File.Exists(modInfo.LocalPath)); }