From 6012c7c74f1e1fb15e337947702c255026e56ddd Mon Sep 17 00:00:00 2001 From: pointfeev Date: Thu, 3 Mar 2022 19:01:01 -0500 Subject: [PATCH] v3.0.1.0 - More code refactoring and simplifications - Converted ScreamAPI config creation into unlock_all for now until I can figure out how to properly get ALL dlc ids (some games worked, some didn't) --- CreamInstaller/CreamInstaller.csproj | 2 +- CreamInstaller/Epic/EpicStore.cs | 15 +++++---- CreamInstaller/Epic/GraphQL/Request.cs | 28 +++-------------- CreamInstaller/Epic/GraphQL/Response.cs | 35 +++++---------------- CreamInstaller/InstallForm.cs | 22 ++++++------- CreamInstaller/SelectForm.cs | 12 +++---- CreamInstaller/Utility/HttpClientManager.cs | 2 +- 7 files changed, 39 insertions(+), 77 deletions(-) diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index 41d462a..679292c 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -5,7 +5,7 @@ True Resources\ini.ico true - 3.0.0.1 + 3.0.1.0 Resources\ini.ico diff --git a/CreamInstaller/Epic/EpicStore.cs b/CreamInstaller/Epic/EpicStore.cs index a3a1b02..c23ee5a 100644 --- a/CreamInstaller/Epic/EpicStore.cs +++ b/CreamInstaller/Epic/EpicStore.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; @@ -16,13 +17,12 @@ internal static class EpicStore { internal static async Task> ParseDlcIds(string categoryNamespace) { + // this method does not yet find ALL dlcs List<(string id, string name, string product, string icon, string developer)> dlcIds = new(); Response response = await QueryGraphQL(categoryNamespace); - if (response is null) - return dlcIds; + if (response is null) return dlcIds; try { File.WriteAllText(ProgramData.AppInfoPath + @$"\{categoryNamespace}.json", JsonConvert.SerializeObject(response, Formatting.Indented)); } catch { } List elements = new(response.Data.Catalog.CatalogOffers.Elements); - elements.AddRange(response.Data.Catalog.SearchStore.Elements); foreach (Element element in elements) { string product = null; @@ -37,9 +37,12 @@ internal static class EpicStore break; } } - (string id, string name, string product, string icon, string developer) app = (element.Items[0].Id, element.Title, product, icon, element.Developer); - if (!dlcIds.Contains(app)) - dlcIds.Add(app); + foreach (Item item in element.Items) + { + (string id, string name, string product, string icon, string developer) app = (item.Id, element.Title, product, icon, item.Developer); + if (!dlcIds.Any(a => a.id == app.id)) + dlcIds.Add(app); + } } return dlcIds; } diff --git a/CreamInstaller/Epic/GraphQL/Request.cs b/CreamInstaller/Epic/GraphQL/Request.cs index 09f03e3..ff937b9 100644 --- a/CreamInstaller/Epic/GraphQL/Request.cs +++ b/CreamInstaller/Epic/GraphQL/Request.cs @@ -20,40 +20,20 @@ internal class Request } ) { elements { - id title - items { - id - } keyImages { type url } + items { + id + developer + } catalogNs { mappings(pageType: ""productHome"") { pageSlug } } - developer - } - } - searchStore(category: ""games/edition/base"", namespace: $namespace) { - elements { - id - title - items { - id - } - keyImages { - type - url - } - catalogNs { - mappings(pageType: ""productHome"") { - pageSlug - } - } - developer } } } diff --git a/CreamInstaller/Epic/GraphQL/Response.cs b/CreamInstaller/Epic/GraphQL/Response.cs index ec82135..53f01ce 100644 --- a/CreamInstaller/Epic/GraphQL/Response.cs +++ b/CreamInstaller/Epic/GraphQL/Response.cs @@ -18,28 +18,10 @@ public class Data public class Catalog { [JsonProperty(PropertyName = "catalogOffers")] - public SearchStore CatalogOffers { get; protected set; } - - [JsonProperty(PropertyName = "searchStore")] - public SearchStore SearchStore { get; protected set; } + public CatalogOffers CatalogOffers { get; protected set; } } public class CatalogOffers -{ - [JsonProperty(PropertyName = "namespace")] - public string Namespace { get; protected set; } - - [JsonProperty(PropertyName = "params")] - public Parameters Parameters { get; protected set; } -} - -public class Parameters -{ - [JsonProperty(PropertyName = "count")] - public int Count { get; protected set; } -} - -public class SearchStore { [JsonProperty(PropertyName = "elements")] public Element[] Elements { get; protected set; } @@ -47,29 +29,26 @@ public class SearchStore public class Element { - [JsonProperty(PropertyName = "id")] - public string Id { get; protected set; } - [JsonProperty(PropertyName = "title")] public string Title { get; protected set; } - [JsonProperty(PropertyName = "items")] - public Item[] Items { get; protected set; } - [JsonProperty(PropertyName = "keyImages")] public KeyImage[] KeyImages { get; protected set; } + [JsonProperty(PropertyName = "items")] + public Item[] Items { get; protected set; } + [JsonProperty(PropertyName = "catalogNs")] public CatalogNs CatalogNs { get; protected set; } - - [JsonProperty(PropertyName = "developer")] - public string Developer { get; protected set; } } public class Item { [JsonProperty(PropertyName = "id")] public string Id { get; protected set; } + + [JsonProperty(PropertyName = "developer")] + public string Developer { get; protected set; } } public class KeyImage diff --git a/CreamInstaller/InstallForm.cs b/CreamInstaller/InstallForm.cs index da36e95..6587bcc 100644 --- a/CreamInstaller/InstallForm.cs +++ b/CreamInstaller/InstallForm.cs @@ -154,9 +154,9 @@ internal partial class InstallForm : CustomForm writer.WriteLine(" \"eos_logging\": false,"); writer.WriteLine(" \"block_metrics\": false,"); writer.WriteLine(" \"catalog_items\": {"); - writer.WriteLine(" \"unlock_all\": false,"); - writer.WriteLine(" \"override\": ["); - KeyValuePair last = dlcApps.Last(); + writer.WriteLine(" \"unlock_all\": true,"); //writer.WriteLine(" \"unlock_all\": false,"); + writer.WriteLine(" \"override\": []"); //writer.WriteLine(" \"override\": ["); + /*KeyValuePair last = dlcApps.Last(); foreach (KeyValuePair pair in dlcApps) { string id = pair.Key; @@ -165,23 +165,23 @@ internal partial class InstallForm : CustomForm if (installForm is not null) installForm.UpdateUser($"Added DLC to ScreamAPI.json with id {id} ({name})", InstallationLog.Resource, info: false); } - writer.WriteLine(" ]"); + writer.WriteLine(" ]");*/ writer.WriteLine(" },"); writer.WriteLine(" \"entitlements\": {"); - writer.WriteLine(" \"unlock_all\": false,"); - writer.WriteLine(" \"auto_inject\": false,"); - writer.WriteLine(" \"inject\": ["); - foreach (KeyValuePair pair in dlcApps) + writer.WriteLine(" \"unlock_all\": true,"); //writer.WriteLine(" \"unlock_all\": false,"); + writer.WriteLine(" \"auto_inject\": true,"); //writer.WriteLine(" \"auto_inject\": false,"); + writer.WriteLine(" \"inject\": []"); //writer.WriteLine(" \"inject\": ["); + /*foreach (KeyValuePair pair in dlcApps) { string id = pair.Key; (string name, _) = pair.Value; writer.WriteLine($" \"{id}\"{(pair.Equals(last) ? "" : ",")}"); - if (installForm is not null) - installForm.UpdateUser($"Added DLC to ScreamAPI.json with id {id} ({name})", InstallationLog.Resource, info: false); } - writer.WriteLine(" ]"); + writer.WriteLine(" ]");*/ writer.WriteLine(" }"); writer.WriteLine("}"); + if (installForm is not null) + installForm.UpdateUser($"Created 'unlock_all: true' ScreamAPI.json configuration (temporary until I figure out how to properly get all DLC ids)", InstallationLog.Resource, info: false); } internal static async Task UninstallScreamAPI(string directory, InstallForm installForm = null) => await Task.Run(() => diff --git a/CreamInstaller/SelectForm.cs b/CreamInstaller/SelectForm.cs index 32d4eb3..61f24fc 100644 --- a/CreamInstaller/SelectForm.cs +++ b/CreamInstaller/SelectForm.cs @@ -260,7 +260,7 @@ internal partial class SelectForm : CustomForm return; } if (Program.Canceled) return; - ConcurrentDictionary dlc = new(); + /*ConcurrentDictionary dlc = new(); List dlcTasks = new(); List<(string id, string name, string product, string icon, string developer)> dlcIds = await EpicStore.ParseDlcIds(@namespace); if (dlcIds.Count > 0) @@ -292,7 +292,7 @@ internal partial class SelectForm : CustomForm { if (Program.Canceled) return; await task; - } + }*/ selection ??= new(); if (allCheckBox.Checked) selection.Enabled = true; @@ -301,13 +301,13 @@ internal partial class SelectForm : CustomForm selection.Name = name; selection.RootDirectory = directory; selection.DllDirectories = dllDirectories; - foreach (KeyValuePair pair in dlc) + /*foreach (KeyValuePair pair in dlc) if (pair.Value.name == selection.Name) { selection.ProductUrl = "https://www.epicgames.com/store/product/" + pair.Value.product; selection.IconUrl = pair.Value.icon; selection.Publisher = pair.Value.developer; - } + }*/ if (Program.Canceled) return; Program.Invoke(selectionTreeView, delegate @@ -319,7 +319,7 @@ internal partial class SelectForm : CustomForm programNode.Checked = selection.Enabled; programNode.Remove(); selectionTreeView.Nodes.Add(programNode); - foreach (KeyValuePair pair in dlc) + /*foreach (KeyValuePair pair in dlc) { if (Program.Canceled || programNode is null) return; string dlcId = pair.Key; @@ -332,7 +332,7 @@ internal partial class SelectForm : CustomForm dlcNode.Checked = selection.SelectedDlc.ContainsKey(dlcId); dlcNode.Remove(); programNode.Nodes.Add(dlcNode); - } + }*/ }); if (Program.Canceled) return; RemoveFromRemainingGames(name); diff --git a/CreamInstaller/Utility/HttpClientManager.cs b/CreamInstaller/Utility/HttpClientManager.cs index 1f4e3f8..587c830 100644 --- a/CreamInstaller/Utility/HttpClientManager.cs +++ b/CreamInstaller/Utility/HttpClientManager.cs @@ -15,7 +15,7 @@ internal static class HttpClientManager internal static void Setup() { HttpClient = new(); - HttpClient.DefaultRequestHeaders.Add("user-agent", $"CreamInstaller-{Environment.MachineName}_{Environment.UserDomainName}_{Environment.UserName}"); + HttpClient.DefaultRequestHeaders.Add("User-Agent", $"CreamInstaller-{Environment.MachineName}_{Environment.UserDomainName}_{Environment.UserName}"); } internal static async Task Get(string url)