Allow forward slashes in queries sometimes

This commit is contained in:
Matt Nadareski
2024-10-04 01:41:05 -04:00
parent 652270c8c7
commit fe8686a2bb
2 changed files with 17 additions and 8 deletions

View File

@@ -51,6 +51,11 @@ namespace SabreTools.RedumpLib
/// </summary>
public bool OnlyList { get; set; }
/// <summary>
/// Don't replace forward slashes with `-` in queries
/// </summary>
public bool NoSlash { get; set; }
/// <summary>
/// Force continuing downloads until user cancels or pages run out
/// </summary>
@@ -131,9 +136,9 @@ namespace SabreTools.RedumpLib
break;
case Feature.Quicksearch:
if (OnlyList)
await Search.ListSearchResults(_client, QueryString);
await Search.ListSearchResults(_client, QueryString, NoSlash);
else
await Search.DownloadSearchResults(_client, QueryString, OutDir);
await Search.DownloadSearchResults(_client, QueryString, OutDir, NoSlash);
break;
default:
return false;

View File

@@ -15,8 +15,9 @@ namespace SabreTools.RedumpLib.Web
/// </summary>
/// <param name="rc">RedumpClient for connectivity</param>
/// <param name="query">Query string to attempt to search for</param>
/// <param name="noSlash">Don't replace slashes with `-` in queries</param>
/// <returns>All disc IDs for the given query, null on error</returns>
public static async Task<List<int>?> ListSearchResults(RedumpClient rc, string? query)
public static async Task<List<int>?> ListSearchResults(RedumpClient rc, string? query, bool noSlash)
{
// If the query is invalid
if (string.IsNullOrEmpty(query))
@@ -29,8 +30,9 @@ namespace SabreTools.RedumpLib.Web
// Special characters become dashes
query = query.Replace(' ', '-');
query = query.Replace('/', '-');
query = query.Replace('\\', '/');
query = query.Replace('\\', '-');
if (!noSlash)
query = query.Replace('/', '-');
// Lowercase is defined per language
query = query.ToLowerInvariant();
@@ -62,7 +64,8 @@ namespace SabreTools.RedumpLib.Web
/// <param name="rc">RedumpClient for connectivity</param>
/// <param name="query">Query string to attempt to search for</param>
/// <param name="outDir">Output directory to save data to</param>
public static async Task<bool> DownloadSearchResults(RedumpClient rc, string? query, string? outDir)
/// <param name="noSlash">Don't replace slashes with `-` in queries</param>
public static async Task<bool> DownloadSearchResults(RedumpClient rc, string? query, string? outDir, bool noSlash)
{
// If the query is invalid
if (string.IsNullOrEmpty(query))
@@ -73,8 +76,9 @@ namespace SabreTools.RedumpLib.Web
// Special characters become dashes
query = query.Replace(' ', '-');
query = query.Replace('/', '-');
query = query.Replace('\\', '/');
query = query.Replace('\\', '-');
if (!noSlash)
query = query.Replace('/', '-');
// Lowercase is defined per language
query = query.ToLowerInvariant();