Reorder methods to match other extension classes

This commit is contained in:
Matt Nadareski
2026-03-02 21:56:14 -05:00
parent 8cdf894cbb
commit 4e19eb2c68

View File

@@ -9,54 +9,6 @@ namespace SabreTools.RedumpLib.Web
/// </summary>
public static class Search
{
/// <summary>
/// List the disc IDs associated with a given quicksearch query
/// </summary>
/// <param name="client">RedumpClient for connectivity</param>
/// <param name="query">Query string to attempt to search for</param>
/// <param name="convertForwardSlashes">Replace forward slashes with `-` in queries</param>
/// <param name="limit">Limit number of retrieved result pages, non-positive for unlimited</param>
/// <returns>All disc IDs for the given query, empty on error</returns>
public static async Task<List<int>> ListSearchResults(this RedumpClient client,
string? query,
bool convertForwardSlashes,
int limit = -1)
{
// If the query is invalid
if (string.IsNullOrEmpty(query))
return [];
// Keep getting quicksearch pages until there are none left
List<int> ids = [];
try
{
int pageNumber = 1;
while (true)
{
if (limit > 0 && pageNumber >= limit)
break;
// Convert forward slashes implies a strict query
var pageIds = convertForwardSlashes
? await client.CheckSingleDiscsPage(quicksearch: query, page: pageNumber++)
: await client.CheckSingleQuicksearchPage(query!, pageNumber++);
if (pageIds is null)
return [];
ids.AddRange(pageIds);
if (pageIds.Count <= 1)
break;
}
}
catch (Exception ex)
{
Console.WriteLine($"An exception occurred while trying to log in: {ex}");
return [];
}
return ids;
}
/// <summary>
/// Download the disc pages associated with a given quicksearch query
/// </summary>
@@ -106,5 +58,53 @@ namespace SabreTools.RedumpLib.Web
return ids;
}
/// <summary>
/// List the disc IDs associated with a given quicksearch query
/// </summary>
/// <param name="client">RedumpClient for connectivity</param>
/// <param name="query">Query string to attempt to search for</param>
/// <param name="convertForwardSlashes">Replace forward slashes with `-` in queries</param>
/// <param name="limit">Limit number of retrieved result pages, non-positive for unlimited</param>
/// <returns>All disc IDs for the given query, empty on error</returns>
public static async Task<List<int>> ListSearchResults(this RedumpClient client,
string? query,
bool convertForwardSlashes,
int limit = -1)
{
// If the query is invalid
if (string.IsNullOrEmpty(query))
return [];
// Keep getting quicksearch pages until there are none left
List<int> ids = [];
try
{
int pageNumber = 1;
while (true)
{
if (limit > 0 && pageNumber >= limit)
break;
// Convert forward slashes implies a strict query
var pageIds = convertForwardSlashes
? await client.CheckSingleDiscsPage(quicksearch: query, page: pageNumber++)
: await client.CheckSingleQuicksearchPage(query!, pageNumber++);
if (pageIds is null)
return [];
ids.AddRange(pageIds);
if (pageIds.Count <= 1)
break;
}
}
catch (Exception ex)
{
Console.WriteLine($"An exception occurred while trying to log in: {ex}");
return [];
}
return ids;
}
}
}