From 913244459e30bb7a37214b285d1a8a86aac5a8a2 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 22 May 2019 21:49:55 -0700 Subject: [PATCH] Oops, forgot a couple --- DICUI.Library/Web/RedumpAccess.cs | 62 ++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/DICUI.Library/Web/RedumpAccess.cs b/DICUI.Library/Web/RedumpAccess.cs index 50d5a165..5e1cd3d5 100644 --- a/DICUI.Library/Web/RedumpAccess.cs +++ b/DICUI.Library/Web/RedumpAccess.cs @@ -223,6 +223,41 @@ namespace DICUI.Web return ids; } + /// + /// Process a Redump WIP page as a list of possible IDs or disc page + /// + /// CookieAwareWebClient to access the pages + /// Page URL to check and parse + /// List of matching IDs + private List CheckSingleWIPPage(CookieAwareWebClient wc, string url) + { + List ids = new List(); + + var wipDumpsPage = wc.DownloadString(url); + + // If we have no WIP dumps left + if (wipDumpsPage.Contains("No WIP discs found.")) + return ids; + + // Otherwise, traverse each dump on the page + var matches = newDiscRegex.Matches(wipDumpsPage); + foreach (Match match in matches) + { + try + { + if (Int32.TryParse(match.Groups[1].Value, out int value)) + ids.Add(value); + } + catch (Exception ex) + { + Console.WriteLine($"An exception has occurred: {ex}"); + continue; + } + } + + return ids; + } + /// /// Download a set of packs /// @@ -252,7 +287,7 @@ namespace DICUI.Web /// /// CookieAwareWebClient to access the pages /// Redump disc ID to retrieve - /// + /// Disc page as a string, null on error public string DownloadSingleSiteID(CookieAwareWebClient wc, int id) { string paddedId = id.ToString().PadLeft(5, '0'); @@ -272,6 +307,31 @@ namespace DICUI.Web } } + /// + /// Download an individual WIP ID page as a string, if possible + /// + /// CookieAwareWebClient to access the pages + /// Redump disc ID to retrieve + /// WIP disc page as a string, null on error + private string DownloadSingleWIPID(CookieAwareWebClient wc, int id) + { + string paddedId = id.ToString().PadLeft(5, '0'); + Console.WriteLine($"Processing WIP ID: {paddedId}"); + try + { + string discPage = wc.DownloadString(string.Format(wipDiscPageUrl, +id)); + if (discPage.Contains($"WIP Disc with ID \"{id}\" doesn't exist")) + return null; + else + return discPage; + } + catch (Exception ex) + { + Console.WriteLine($"An exception has occurred: {ex}"); + return null; + } + } + #endregion } }