- Fixed an exception from temporarily unavailable Epic GraphQL
This commit is contained in:
pointfeev 2022-03-04 18:57:11 -05:00
parent c410cbdfd8
commit aaffd43168
3 changed files with 23 additions and 17 deletions

View file

@ -5,7 +5,7 @@
<UseWindowsForms>True</UseWindowsForms> <UseWindowsForms>True</UseWindowsForms>
<ApplicationIcon>Resources\ini.ico</ApplicationIcon> <ApplicationIcon>Resources\ini.ico</ApplicationIcon>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract> <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<Version>3.0.2.0</Version> <Version>3.0.2.1</Version>
<PackageIcon>Resources\ini.ico</PackageIcon> <PackageIcon>Resources\ini.ico</PackageIcon>
<PackageIconUrl /> <PackageIconUrl />
<Description /> <Description />

View file

@ -20,13 +20,12 @@ internal static class EpicStore
{ {
}*/ }*/
internal static async Task<List<(string id, string name, string product, string icon, string developer)>> QueryEntitlements(Manifest manifest) internal static async Task<List<(string id, string name, string product, string icon, string developer)>> QueryEntitlements(string categoryNamespace)
{ {
string @namespace = manifest.CatalogNamespace;
List<(string id, string name, string product, string icon, string developer)> dlcIds = new(); List<(string id, string name, string product, string icon, string developer)> dlcIds = new();
Response response = await QueryGraphQL(@namespace); Response response = await QueryGraphQL(categoryNamespace);
if (response is null) return dlcIds; if (response is null) return dlcIds;
try { File.WriteAllText(ProgramData.AppInfoPath + @$"\{@namespace}.json", JsonConvert.SerializeObject(response, Formatting.Indented)); } catch { } try { File.WriteAllText(ProgramData.AppInfoPath + @$"\{categoryNamespace}.json", JsonConvert.SerializeObject(response, Formatting.Indented)); } catch { }
List<Element> searchStore = new(response.Data.Catalog.SearchStore.Elements); List<Element> searchStore = new(response.Data.Catalog.SearchStore.Elements);
foreach (Element element in searchStore) foreach (Element element in searchStore)
{ {
@ -89,16 +88,23 @@ internal static class EpicStore
private static async Task<Response> QueryGraphQL(string categoryNamespace) private static async Task<Response> QueryGraphQL(string categoryNamespace)
{ {
string encoded = HttpUtility.UrlEncode(categoryNamespace); try
Request request = new(encoded); {
string payload = JsonConvert.SerializeObject(request); string encoded = HttpUtility.UrlEncode(categoryNamespace);
HttpContent content = new StringContent(payload); Request request = new(encoded);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); string payload = JsonConvert.SerializeObject(request);
HttpClient client = HttpClientManager.HttpClient; HttpContent content = new StringContent(payload);
if (client is null) return null; content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpResponseMessage httpResponse = await client.PostAsync("https://graphql.epicgames.com/graphql", content); HttpClient client = HttpClientManager.HttpClient;
httpResponse.EnsureSuccessStatusCode(); if (client is null) return null;
string response = await httpResponse.Content.ReadAsStringAsync(); HttpResponseMessage httpResponse = await client.PostAsync("https://graphql.epicgames.com/graphql", content);
return JsonConvert.DeserializeObject<Response>(response); httpResponse.EnsureSuccessStatusCode();
string response = await httpResponse.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<Response>(response);
}
catch
{
return null;
}
} }
} }

View file

@ -261,7 +261,7 @@ internal partial class SelectForm : CustomForm
if (Program.Canceled) return; if (Program.Canceled) return;
ConcurrentDictionary<string, (string name, string product, string icon, string developer)> entitlements = new(); ConcurrentDictionary<string, (string name, string product, string icon, string developer)> entitlements = new();
List<Task> dlcTasks = new(); List<Task> dlcTasks = new();
List<(string id, string name, string product, string icon, string developer)> entitlementIds = await EpicStore.QueryEntitlements(manifest); List<(string id, string name, string product, string icon, string developer)> entitlementIds = await EpicStore.QueryEntitlements(@namespace);
if (entitlementIds.Any()) if (entitlementIds.Any())
{ {
foreach ((string id, string name, string product, string icon, string developer) in entitlementIds) foreach ((string id, string name, string product, string icon, string developer) in entitlementIds)