();
- if (this.DumpersAndStatus.Dumpers.Length > 0)
- {
- foreach (string dumper in this.DumpersAndStatus.Dumpers)
- tempDumpers.Add(dumper);
- }
-
- foreach (Match submatch in matches)
- tempDumpers.Add(WebUtility.HtmlDecode(submatch.Groups[1].Value));
-
- this.DumpersAndStatus.Dumpers = tempDumpers.ToArray();
- }
-
- // Barcode
- match = barcodeRegex.Match(discData);
- if (match.Success)
- this.CommonDiscInfo.Barcode = WebUtility.HtmlDecode(match.Groups[1].Value);
-
- // Comments
- match = commentsRegex.Match(discData);
- if (match.Success)
- {
- this.CommonDiscInfo.Comments = WebUtility.HtmlDecode(match.Groups[1].Value)
- .Replace("
", "\n")
- .Replace("ISBN", "[T:ISBN]") + "\n";
- }
-
- // Contents
- match = contentsRegex.Match(discData);
- if (match.Success)
- {
- this.CommonDiscInfo.Contents = WebUtility.HtmlDecode(match.Groups[1].Value)
- .Replace("
", "\n")
- .Replace("", "");
- this.CommonDiscInfo.Contents = Regex.Replace(this.CommonDiscInfo.Contents, @"", "");
- }
-
- // Added
- match = addedRegex.Match(discData);
- if (match.Success)
- this.Added = DateTime.Parse(match.Groups[1].Value);
-
- // Last Modified
- match = lastModifiedRegex.Match(discData);
- if (match.Success)
- this.LastModified = DateTime.Parse(match.Groups[1].Value);
- }
}
///
diff --git a/DICUI.Library/Utilities/DumpEnvironment.cs b/DICUI.Library/Utilities/DumpEnvironment.cs
index 401289f4..20ef817d 100644
--- a/DICUI.Library/Utilities/DumpEnvironment.cs
+++ b/DICUI.Library/Utilities/DumpEnvironment.cs
@@ -714,8 +714,7 @@ namespace DICUI.Utilities
if (info.MatchedIDs.Count == 1)
{
progress?.Report(Result.Success($"Filling fields from existing ID {info.MatchedIDs[0]}..."));
- string discData = wc.DownloadSingleSiteID(info.MatchedIDs[0]);
- info.FillFromDiscPage(discData);
+ wc.FillFromId(info, info.MatchedIDs[0]);
progress?.Report(Result.Success("Information filling complete!"));
}
}
diff --git a/DICUI.Library/Web/RedumpWebClient.cs b/DICUI.Library/Web/RedumpWebClient.cs
index cc81c015..bebcbc93 100644
--- a/DICUI.Library/Web/RedumpWebClient.cs
+++ b/DICUI.Library/Web/RedumpWebClient.cs
@@ -6,6 +6,8 @@ using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
+using DICUI.Data;
+using DICUI.Utilities;
namespace DICUI.Web
{
@@ -354,6 +356,217 @@ namespace DICUI.Web
return true;
}
+ ///
+ /// Create a new SubmissionInfo object based on a disc page
+ ///
+ /// Redump disc ID to retrieve
+ /// Filled SubmissionInfo object on success, null on error
+ public SubmissionInfo CreateFromId(int id)
+ {
+ string discData = DownloadSingleSiteID(id);
+ if (string.IsNullOrEmpty(discData))
+ return null;
+
+ // Create the new object
+ SubmissionInfo info = new SubmissionInfo();
+
+ // Added
+ var match = addedRegex.Match(discData);
+ if (match.Success)
+ {
+ if (DateTime.TryParse(match.Groups[1].Value, out DateTime added))
+ info.Added = added;
+ else
+ info.Added = null;
+ }
+
+ // Barcode
+ match = barcodeRegex.Match(discData);
+ if (match.Success)
+ info.CommonDiscInfo.Barcode = WebUtility.HtmlDecode(match.Groups[1].Value);
+
+ // BCA
+ match = bcaRegex.Match(discData);
+ if (match.Success)
+ {
+ info.Extras.BCA = WebUtility.HtmlDecode(match.Groups[1].Value)
+ .Replace("
", "\n")
+ .Replace(" ", "");
+ info.Extras.BCA = Regex.Replace(info.Extras.BCA, @"", "");
+ }
+
+ // Category
+ match = categoryRegex.Match(discData);
+ if (match.Success)
+ info.CommonDiscInfo.Category = Extensions.ToCategory(match.Groups[1].Value);
+ else
+ info.CommonDiscInfo.Category = DiscCategory.Games;
+
+ // Comments
+ match = commentsRegex.Match(discData);
+ if (match.Success)
+ {
+ info.CommonDiscInfo.Comments = WebUtility.HtmlDecode(match.Groups[1].Value)
+ .Replace("
", "\n")
+ .Replace("ISBN", "[T:ISBN]") + "\n";
+ }
+
+ // Contents
+ match = contentsRegex.Match(discData);
+ if (match.Success)
+ {
+ info.CommonDiscInfo.Contents = WebUtility.HtmlDecode(match.Groups[1].Value)
+ .Replace("
", "\n")
+ .Replace("
", "");
+ info.CommonDiscInfo.Contents = Regex.Replace(info.CommonDiscInfo.Contents, @"", "");
+ }
+
+ // Dumpers
+ var matches = dumpersRegex.Matches(discData);
+ if (matches.Count > 0)
+ {
+ List tempDumpers = new List();
+ foreach (Match submatch in matches)
+ {
+ tempDumpers.Add(WebUtility.HtmlDecode(submatch.Groups[1].Value));
+ }
+
+ info.DumpersAndStatus.Dumpers = tempDumpers.ToArray();
+ }
+
+ // Edition
+ match = editionRegex.Match(discData);
+ if (match.Success)
+ info.VersionAndEditions.OtherEditions = WebUtility.HtmlDecode(match.Groups[1].Value);
+
+ // Error Count
+ match = errorCountRegex.Match(discData);
+ if (match.Success)
+ info.CommonDiscInfo.ErrorsCount = match.Groups[1].Value;
+
+ // Foreign Title
+ match = foreignTitleRegex.Match(discData);
+ if (match.Success)
+ info.CommonDiscInfo.ForeignTitleNonLatin = WebUtility.HtmlDecode(match.Groups[1].Value);
+ else
+ info.CommonDiscInfo.ForeignTitleNonLatin = null;
+
+ // Languages
+ matches = languagesRegex.Matches(discData);
+ if (matches.Count > 0)
+ {
+ List tempLanguages = new List();
+ foreach (Match submatch in matches)
+ {
+ tempLanguages.Add(Extensions.ToLanguage(submatch.Groups[1].Value));
+ }
+
+ info.CommonDiscInfo.Languages = tempLanguages.Where(l => l != null).ToArray();
+ }
+
+ // Last Modified
+ match = lastModifiedRegex.Match(discData);
+ if (match.Success)
+ {
+ if (DateTime.TryParse(match.Groups[1].Value, out DateTime lastModified))
+ info.LastModified = lastModified;
+ else
+ info.LastModified = null;
+ }
+
+ // Media
+ match = mediaRegex.Match(discData);
+ if (match.Success)
+ info.CommonDiscInfo.Media = Converters.ToMediaType(match.Groups[1].Value);
+
+ // PVD
+ match = pvdRegex.Match(discData);
+ if (match.Success)
+ {
+ info.Extras.PVD = WebUtility.HtmlDecode(match.Groups[1].Value)
+ .Replace("
", "\n")
+ .Replace("
", "");
+ info.Extras.PVD = Regex.Replace(info.Extras.PVD, @"", "");
+ }
+
+ // Region
+ match = regionRegex.Match(discData);
+ if (match.Success)
+ info.CommonDiscInfo.Region = Extensions.ToRegion(match.Groups[1].Value);
+
+ // Serial
+ match = serialRegex.Match(discData);
+ if (match.Success)
+ info.CommonDiscInfo.Serial = WebUtility.HtmlDecode(match.Groups[1].Value);
+
+ // System
+ match = systemRegex.Match(discData);
+ if (match.Success)
+ info.CommonDiscInfo.System = Converters.ToKnownSystem(match.Groups[1].Value);
+
+ // Title, Disc Number/Letter, Disc Title
+ match = titleRegex.Match(discData);
+ if (match.Success)
+ {
+ string title = WebUtility.HtmlDecode(match.Groups[1].Value);
+
+ // If we have parenthesis, title is everything before the first one
+ int firstParenLocation = title.IndexOf(" (");
+ if (firstParenLocation >= 0)
+ {
+ info.CommonDiscInfo.Title = title.Substring(0, firstParenLocation);
+ var subMatches = discNumberLetterRegex.Match(title);
+ for (int i = 1; i < subMatches.Groups.Count; i++)
+ {
+ string subMatch = subMatches.Groups[i].Value;
+
+ // Disc number or letter
+ if (subMatch.StartsWith("Disc"))
+ info.CommonDiscInfo.DiscNumberLetter = subMatch.Remove(0, "Disc ".Length);
+
+ // Disc title
+ else
+ info.CommonDiscInfo.DiscTitle = subMatch;
+ }
+ }
+ // Otherwise, leave the title as-is
+ else
+ {
+ info.CommonDiscInfo.Title = title;
+ }
+ }
+
+ // Tracks
+ matches = trackRegex.Matches(discData);
+ if (matches.Count > 0)
+ {
+ List
tempTracks = new List();
+ foreach (Match submatch in matches)
+ {
+ tempTracks.Add(submatch.Groups[1].Value);
+ }
+
+ info.TracksAndWriteOffsets.ClrMameProData = string.Join("\n", tempTracks);
+ }
+
+ // Track Count
+ match = trackCountRegex.Match(discData);
+ if (match.Success)
+ info.TracksAndWriteOffsets.Cuesheet = match.Groups[1].Value;
+
+ // Version
+ match = versionRegex.Match(discData);
+ if (match.Success)
+ info.VersionAndEditions.Version = WebUtility.HtmlDecode(match.Groups[1].Value);
+
+ // Write Offset
+ match = writeOffsetRegex.Match(discData);
+ if (match.Success)
+ info.TracksAndWriteOffsets.OtherWriteOffsets = WebUtility.HtmlDecode(match.Groups[1].Value);
+
+ return info;
+ }
+
///
/// Download the last modified disc pages, until first failure
///
@@ -554,6 +767,166 @@ namespace DICUI.Web
}
}
+ ///
+ /// Fill out an existing SubmissionInfo object based on a disc page
+ ///
+ /// Existing SubmissionInfo object to fill
+ /// Redump disc ID to retrieve
+ public void FillFromId(SubmissionInfo info, int id)
+ {
+ string discData = DownloadSingleSiteID(id);
+ if (string.IsNullOrEmpty(discData))
+ return;
+
+ // Title, Disc Number/Letter, Disc Title
+ var match = titleRegex.Match(discData);
+ if (match.Success)
+ {
+ string title = WebUtility.HtmlDecode(match.Groups[1].Value);
+
+ // If we have parenthesis, title is everything before the first one
+ int firstParenLocation = title.IndexOf(" (");
+ if (firstParenLocation >= 0)
+ {
+ info.CommonDiscInfo.Title = title.Substring(0, firstParenLocation);
+ var subMatches = discNumberLetterRegex.Match(title);
+ for (int i = 1; i < subMatches.Groups.Count; i++)
+ {
+ string subMatch = subMatches.Groups[i].Value;
+
+ // Disc number or letter
+ if (subMatch.StartsWith("Disc"))
+ info.CommonDiscInfo.DiscNumberLetter = subMatch.Remove(0, "Disc ".Length);
+
+ // Disc title
+ else
+ info.CommonDiscInfo.DiscTitle = subMatch;
+ }
+ }
+ // Otherwise, leave the title as-is
+ else
+ {
+ info.CommonDiscInfo.Title = title;
+ }
+ }
+
+ // Foreign Title
+ match = foreignTitleRegex.Match(discData);
+ if (match.Success)
+ info.CommonDiscInfo.ForeignTitleNonLatin = WebUtility.HtmlDecode(match.Groups[1].Value);
+ else
+ info.CommonDiscInfo.ForeignTitleNonLatin = null;
+
+ // Category
+ match = categoryRegex.Match(discData);
+ if (match.Success)
+ info.CommonDiscInfo.Category = Extensions.ToCategory(match.Groups[1].Value);
+ else
+ info.CommonDiscInfo.Category = DiscCategory.Games;
+
+ // Region
+ match = regionRegex.Match(discData);
+ if (match.Success)
+ info.CommonDiscInfo.Region = Extensions.ToRegion(match.Groups[1].Value);
+
+ // Languages
+ var matches = languagesRegex.Matches(discData);
+ if (matches.Count > 0)
+ {
+ List tempLanguages = new List();
+ foreach (Match submatch in matches)
+ tempLanguages.Add(Extensions.ToLanguage(submatch.Groups[1].Value));
+
+ info.CommonDiscInfo.Languages = tempLanguages.Where(l => l != null).ToArray();
+ }
+
+ // Serial
+ match = serialRegex.Match(discData);
+ if (match.Success)
+ info.CommonDiscInfo.Serial = WebUtility.HtmlDecode(match.Groups[1].Value);
+
+ // Error count
+ match = errorCountRegex.Match(discData);
+ if (match.Success)
+ {
+ // If the error counts don't match, then use the one from the disc page
+ if (!string.IsNullOrEmpty(info.CommonDiscInfo.ErrorsCount) && match.Groups[1].Value != info.CommonDiscInfo.ErrorsCount)
+ info.CommonDiscInfo.ErrorsCount = match.Groups[1].Value;
+ }
+
+ // Version
+ match = versionRegex.Match(discData);
+ if (match.Success)
+ info.VersionAndEditions.Version = WebUtility.HtmlDecode(match.Groups[1].Value);
+
+ // Edition
+ match = editionRegex.Match(discData);
+ if (match.Success)
+ info.VersionAndEditions.OtherEditions = WebUtility.HtmlDecode(match.Groups[1].Value);
+
+ // Dumpers
+ matches = dumpersRegex.Matches(discData);
+ if (matches.Count > 0)
+ {
+ // Start with any currently listed dumpers
+ List tempDumpers = new List();
+ if (info.DumpersAndStatus.Dumpers.Length > 0)
+ {
+ foreach (string dumper in info.DumpersAndStatus.Dumpers)
+ tempDumpers.Add(dumper);
+ }
+
+ foreach (Match submatch in matches)
+ tempDumpers.Add(WebUtility.HtmlDecode(submatch.Groups[1].Value));
+
+ info.DumpersAndStatus.Dumpers = tempDumpers.ToArray();
+ }
+
+ // Barcode
+ match = barcodeRegex.Match(discData);
+ if (match.Success)
+ info.CommonDiscInfo.Barcode = WebUtility.HtmlDecode(match.Groups[1].Value);
+
+ // Comments
+ match = commentsRegex.Match(discData);
+ if (match.Success)
+ {
+ info.CommonDiscInfo.Comments = WebUtility.HtmlDecode(match.Groups[1].Value)
+ .Replace("
", "\n")
+ .Replace("ISBN", "[T:ISBN]") + "\n";
+ }
+
+ // Contents
+ match = contentsRegex.Match(discData);
+ if (match.Success)
+ {
+ info.CommonDiscInfo.Contents = WebUtility.HtmlDecode(match.Groups[1].Value)
+ .Replace("
", "\n")
+ .Replace(" ", "");
+ info.CommonDiscInfo.Contents = Regex.Replace(info.CommonDiscInfo.Contents, @"", "");
+ }
+
+ // Added
+ match = addedRegex.Match(discData);
+ if (match.Success)
+ {
+ if (DateTime.TryParse(match.Groups[1].Value, out DateTime added))
+ info.Added = added;
+ else
+ info.Added = null;
+ }
+
+ // Last Modified
+ match = lastModifiedRegex.Match(discData);
+ if (match.Success)
+ {
+ if (DateTime.TryParse(match.Groups[1].Value, out DateTime lastModified))
+ info.LastModified = lastModified;
+ else
+ info.LastModified = null;
+ }
+ }
+
///
/// List the disc IDs associated with a given quicksearch query
///
@@ -592,11 +965,11 @@ namespace DICUI.Web
///
///
Username to check discs for
///
All disc IDs for the given user, empty on error
- public List
ListUser(RedumpWebClient wc, string username)
+ public List ListUser(string username)
{
List ids = new List();
- if (!wc.LoggedIn)
+ if (!LoggedIn)
{
Console.WriteLine("User download functionality is only available to Redump members");
return ids;
@@ -606,7 +979,7 @@ namespace DICUI.Web
int pageNumber = 1;
while (true)
{
- List pageIds = wc.CheckSingleSitePage(string.Format(userDumpsUrl, username, pageNumber++));
+ List pageIds = CheckSingleSitePage(string.Format(userDumpsUrl, username, pageNumber++));
ids.AddRange(pageIds);
if (pageIds.Count <= 1)
break;
@@ -624,7 +997,7 @@ namespace DICUI.Web
///
/// Base URL to download using
/// List of IDs from the page, empty on error
- internal List CheckSingleSitePage(string url)
+ private List CheckSingleSitePage(string url)
{
List ids = new List();
var dumpsPage = DownloadString(url);
@@ -669,7 +1042,7 @@ namespace DICUI.Web
/// Output directory to save data to
/// True to return on first error, false otherwise
/// True if the page could be downloaded, false otherwise
- internal bool CheckSingleSitePage(string url, string outDir, bool failOnSingle)
+ private bool CheckSingleSitePage(string url, string outDir, bool failOnSingle)
{
var dumpsPage = DownloadString(url);
@@ -719,7 +1092,7 @@ namespace DICUI.Web
///
/// RedumpWebClient to access the packs
/// List of IDs from the page, empty on error
- internal List CheckSingleWIPPage(string url)
+ private List CheckSingleWIPPage(string url)
{
List ids = new List();
var dumpsPage = DownloadString(url);
@@ -754,7 +1127,7 @@ namespace DICUI.Web
/// Output directory to save data to
/// True to return on first error, false otherwise
/// True if the page could be downloaded, false otherwise
- internal bool CheckSingleWIPPage(string url, string outDir, bool failOnSingle)
+ private bool CheckSingleWIPPage(string url, string outDir, bool failOnSingle)
{
var dumpsPage = DownloadString(url);
@@ -795,7 +1168,7 @@ namespace DICUI.Web
/// Base URL to download using
/// System to download packs for
/// Byte array containing the downloaded pack, null on error
- internal byte[] DownloadSinglePack(string url, RedumpSystem? system)
+ private byte[] DownloadSinglePack(string url, RedumpSystem? system)
{
try
{
@@ -815,7 +1188,7 @@ namespace DICUI.Web
/// System to download packs for
/// Output directory to save data to
/// Named subfolder for the pack, used optionally
- internal void DownloadSinglePack(string url, RedumpSystem? system, string outDir, string subfolder)
+ private void DownloadSinglePack(string url, RedumpSystem? system, string outDir, string subfolder)
{
try
{
@@ -834,7 +1207,7 @@ namespace DICUI.Web
///
/// Redump disc ID to retrieve
/// String containing the page contents if successful, null on error
- internal string DownloadSingleSiteID(int id)
+ private string DownloadSingleSiteID(int id)
{
string paddedId = id.ToString().PadLeft(5, '0');
Console.WriteLine($"Processing ID: {paddedId}");
@@ -864,7 +1237,7 @@ namespace DICUI.Web
/// Output directory to save data to
/// True to rename deleted entries, false otherwise
/// True if all data was downloaded, false otherwise
- internal bool DownloadSingleSiteID(int id, string outDir, bool rename)
+ private bool DownloadSingleSiteID(int id, string outDir, bool rename)
{
string paddedId = id.ToString().PadLeft(5, '0');
string paddedIdDir = Path.Combine(outDir, paddedId);
@@ -973,7 +1346,7 @@ namespace DICUI.Web
///
/// Redump WIP disc ID to retrieve
/// String containing the page contents if successful, null on error
- internal string DownloadSingleWIPID(int id)
+ private string DownloadSingleWIPID(int id)
{
string paddedId = id.ToString().PadLeft(5, '0');
Console.WriteLine($"Processing ID: {paddedId}");
@@ -1003,7 +1376,7 @@ namespace DICUI.Web
/// Output directory to save data to
/// True to rename deleted entries, false otherwise
/// True if all data was downloaded, false otherwise
- internal bool DownloadSingleWIPID(int id, string outDir, bool rename)
+ private bool DownloadSingleWIPID(int id, string outDir, bool rename)
{
string paddedId = id.ToString().PadLeft(5, '0');
string paddedIdDir = Path.Combine(outDir, paddedId);
@@ -1083,7 +1456,7 @@ namespace DICUI.Web
/// Base URL to download using
/// Systems to download packs for
/// Name of the pack that is downloading
- internal Dictionary DownloadPacks(string url, RedumpSystem?[] systems, string title)
+ private Dictionary DownloadPacks(string url, RedumpSystem?[] systems, string title)
{
var packsDictionary = new Dictionary();
@@ -1114,7 +1487,7 @@ namespace DICUI.Web
/// Name of the pack that is downloading
/// Output directory to save data to
/// Named subfolder for the pack, used optionally
- internal void DownloadPacks(string url, RedumpSystem?[] systems, string title, string outDir, string subfolder)
+ private void DownloadPacks(string url, RedumpSystem?[] systems, string title, string outDir, string subfolder)
{
// If we didn't have credentials
if (!LoggedIn)