/// <exception cref="NotImplementedException">When the given url doesn't have any driver</exception> /// <exception cref="ArgumentException">When can't parse the url to obtain the download link</exception> public static IDownloadLink GetHostType(string urlBase, string modName, MyWebView wb) { foreach (var driver in Drivers.Value) { if (urlBase.Contains(driver.Key)) { IDownloadLink obj = (IDownloadLink)Activator.CreateInstance(driver.Value); obj.Initialize(urlBase, modName, wb); return(obj); } } throw new NotImplementedException("The link " + urlBase + "comes from an unknown host"); }
/// <exception cref="NotImplementedException">To document</exception> protected override void GetZipURL() { var homePage = Utils.DownloadHtmlDocument(UrlBase); var posts = homePage.DocumentNode.Descendants("div").SingleOrDefault(x => x.Id == "elPostFeed"); var firstPost = posts?.SelectSingleNode(posts.XPath + "/form[1]/article[1]"); var aTags = firstPost?.Descendants("a").ToList(); foreach (var driver in DownloadLinkHelper.Drivers.Value) { var driverAttributes = driver.Value.GetCustomAttribute <DriverDetailsAttribute>(); // Prevent from infinite recursivity if (driverAttributes.UrlPattern == UrlPattern) { continue; } var links = aTags?.Where(x => x.GetAttributeValue("href", "").Contains(driverAttributes.UrlPattern)).Select(x => x.GetAttributeValue("href", "")).ToList(); links = driverAttributes.RemoveDuplicateEntries(links); links = driverAttributes.RemoveNotLinkedEntries(links, this.ModName); if (links.Count == 1) { SubDownloadLink = DownloadLinkHelper.GetHostType(links[0], this.ModName, _wb); this.ZipLink = SubDownloadLink.ZipLink; if (!string.IsNullOrEmpty(ZipLink)) { return; } } } throw new NotImplementedException("Unable to get the ZIP link of this Ksp forum Mod"); }
public static void LaunchUpdate(object paramObj) { Task.Run(async() => { var param = (UpdateOrchestraMasterParams)paramObj; var modPathList = GetModPathList(param.GameDataPath); //var modPathList = new List<string>(); //modPathList.Add("C:\\Program Files (x86)\\Steam\\steamapps\\common\\Kerbal Space Program\\GameData\\AirplanePlus"); // Forum KSP URL //modPathList.Add("C:\\Program Files (x86)\\Steam\\steamapps\\common\\Kerbal Space Program\\GameData\\B9PartSwitch"); // Github URL //modPathList.Add("C:\\Program Files (x86)\\Steam\\steamapps\\common\\Kerbal Space Program\\GameData\\EasyVesselSwitch"); // Curseforge URL //modPathList.Add("C:\\Program Files (x86)\\Steam\\steamapps\\common\\Kerbal Space Program\\GameData\\FuelTanksPlus"); // Spacedock URL //Todo : Parallel.ForEach() foreach (var modpath in modPathList) { var toLog = new List <UpdateDetails>(); try { var modName = new DirectoryInfo(modpath).Name; var dotVersionFile = new DotVersion(modpath); if (string.IsNullOrEmpty(dotVersionFile.DownloadLink)) { toLog.Add(new UpdateDetails() { ModName = modName, Status = UpdateStatus.FailedToUpdate, Tooltip = "! No Download link inside " + modName + " mod" }); continue; } IDownloadLink hostLink = DownloadLinkHelper.GetHostType(dotVersionFile.DownloadLink, dotVersionFile.ModName, param.Webview); var zipExtractor = new ZipExtractor(hostLink.ZipLink); zipExtractor.DownloadAndExtract(); var updateMod = new PushUpdatedMod(zipExtractor.UnzippedDirectory, param.GameDataPath, modName); toLog.AddRange(await updateMod.AutomaticPush()); } catch (Exception e) { toLog.Add(new UpdateDetails() { ModName = new DirectoryInfo(modpath).Name, Status = UpdateStatus.FailedToUpdate, Tooltip = "! " + e.Message, }); } finally { Application.Current.Dispatcher.Invoke(() => { foreach (UpdateDetails log in toLog) { if (param.Logs.ContainsKey(log.ModName)) { // ModAdded < SuccessfullyUpdated < AlreadyUpdated < FailedToUpdate // So if my log is inferior has the saved one, it should be updated. Else, it shouldn't if (log.Status < param.Logs[log.ModName].Status) { param.Logs[log.ModName] = log; } } else { param.Logs.Add(log.ModName, log); } Trace.WriteLine(log.Tooltip); } }); } } }).Wait(); }