- 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)
This commit is contained in:
pointfeev 2022-03-03 19:01:01 -05:00
parent a679a683be
commit 6012c7c74f
7 changed files with 39 additions and 77 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.0.1</Version> <Version>3.0.1.0</Version>
<PackageIcon>Resources\ini.ico</PackageIcon> <PackageIcon>Resources\ini.ico</PackageIcon>
<PackageIconUrl /> <PackageIconUrl />
<Description /> <Description />

View file

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -16,13 +17,12 @@ internal static class EpicStore
{ {
internal static async Task<List<(string id, string name, string product, string icon, string developer)>> ParseDlcIds(string categoryNamespace) internal static async Task<List<(string id, string name, string product, string icon, string developer)>> ParseDlcIds(string categoryNamespace)
{ {
// this method does not yet find ALL dlcs
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(categoryNamespace); Response response = await QueryGraphQL(categoryNamespace);
if (response is null) if (response is null) return dlcIds;
return dlcIds;
try { File.WriteAllText(ProgramData.AppInfoPath + @$"\{categoryNamespace}.json", JsonConvert.SerializeObject(response, Formatting.Indented)); } catch { } try { File.WriteAllText(ProgramData.AppInfoPath + @$"\{categoryNamespace}.json", JsonConvert.SerializeObject(response, Formatting.Indented)); } catch { }
List<Element> elements = new(response.Data.Catalog.CatalogOffers.Elements); List<Element> elements = new(response.Data.Catalog.CatalogOffers.Elements);
elements.AddRange(response.Data.Catalog.SearchStore.Elements);
foreach (Element element in elements) foreach (Element element in elements)
{ {
string product = null; string product = null;
@ -37,9 +37,12 @@ internal static class EpicStore
break; break;
} }
} }
(string id, string name, string product, string icon, string developer) app = (element.Items[0].Id, element.Title, product, icon, element.Developer); foreach (Item item in element.Items)
if (!dlcIds.Contains(app)) {
dlcIds.Add(app); (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; return dlcIds;
} }

View file

@ -20,40 +20,20 @@ internal class Request
} }
) { ) {
elements { elements {
id
title title
items {
id
}
keyImages { keyImages {
type type
url url
} }
items {
id
developer
}
catalogNs { catalogNs {
mappings(pageType: ""productHome"") { mappings(pageType: ""productHome"") {
pageSlug pageSlug
} }
} }
developer
}
}
searchStore(category: ""games/edition/base"", namespace: $namespace) {
elements {
id
title
items {
id
}
keyImages {
type
url
}
catalogNs {
mappings(pageType: ""productHome"") {
pageSlug
}
}
developer
} }
} }
} }

View file

@ -18,28 +18,10 @@ public class Data
public class Catalog public class Catalog
{ {
[JsonProperty(PropertyName = "catalogOffers")] [JsonProperty(PropertyName = "catalogOffers")]
public SearchStore CatalogOffers { get; protected set; } public CatalogOffers CatalogOffers { get; protected set; }
[JsonProperty(PropertyName = "searchStore")]
public SearchStore SearchStore { get; protected set; }
} }
public class CatalogOffers 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")] [JsonProperty(PropertyName = "elements")]
public Element[] Elements { get; protected set; } public Element[] Elements { get; protected set; }
@ -47,29 +29,26 @@ public class SearchStore
public class Element public class Element
{ {
[JsonProperty(PropertyName = "id")]
public string Id { get; protected set; }
[JsonProperty(PropertyName = "title")] [JsonProperty(PropertyName = "title")]
public string Title { get; protected set; } public string Title { get; protected set; }
[JsonProperty(PropertyName = "items")]
public Item[] Items { get; protected set; }
[JsonProperty(PropertyName = "keyImages")] [JsonProperty(PropertyName = "keyImages")]
public KeyImage[] KeyImages { get; protected set; } public KeyImage[] KeyImages { get; protected set; }
[JsonProperty(PropertyName = "items")]
public Item[] Items { get; protected set; }
[JsonProperty(PropertyName = "catalogNs")] [JsonProperty(PropertyName = "catalogNs")]
public CatalogNs CatalogNs { get; protected set; } public CatalogNs CatalogNs { get; protected set; }
[JsonProperty(PropertyName = "developer")]
public string Developer { get; protected set; }
} }
public class Item public class Item
{ {
[JsonProperty(PropertyName = "id")] [JsonProperty(PropertyName = "id")]
public string Id { get; protected set; } public string Id { get; protected set; }
[JsonProperty(PropertyName = "developer")]
public string Developer { get; protected set; }
} }
public class KeyImage public class KeyImage

View file

@ -154,9 +154,9 @@ internal partial class InstallForm : CustomForm
writer.WriteLine(" \"eos_logging\": false,"); writer.WriteLine(" \"eos_logging\": false,");
writer.WriteLine(" \"block_metrics\": false,"); writer.WriteLine(" \"block_metrics\": false,");
writer.WriteLine(" \"catalog_items\": {"); writer.WriteLine(" \"catalog_items\": {");
writer.WriteLine(" \"unlock_all\": false,"); writer.WriteLine(" \"unlock_all\": true,"); //writer.WriteLine(" \"unlock_all\": false,");
writer.WriteLine(" \"override\": ["); writer.WriteLine(" \"override\": []"); //writer.WriteLine(" \"override\": [");
KeyValuePair<string, (string name, string icon)> last = dlcApps.Last(); /*KeyValuePair<string, (string name, string icon)> last = dlcApps.Last();
foreach (KeyValuePair<string, (string name, string icon)> pair in dlcApps) foreach (KeyValuePair<string, (string name, string icon)> pair in dlcApps)
{ {
string id = pair.Key; string id = pair.Key;
@ -165,23 +165,23 @@ internal partial class InstallForm : CustomForm
if (installForm is not null) if (installForm is not null)
installForm.UpdateUser($"Added DLC to ScreamAPI.json with id {id} ({name})", InstallationLog.Resource, info: false); installForm.UpdateUser($"Added DLC to ScreamAPI.json with id {id} ({name})", InstallationLog.Resource, info: false);
} }
writer.WriteLine(" ]"); writer.WriteLine(" ]");*/
writer.WriteLine(" },"); writer.WriteLine(" },");
writer.WriteLine(" \"entitlements\": {"); writer.WriteLine(" \"entitlements\": {");
writer.WriteLine(" \"unlock_all\": false,"); writer.WriteLine(" \"unlock_all\": true,"); //writer.WriteLine(" \"unlock_all\": false,");
writer.WriteLine(" \"auto_inject\": false,"); writer.WriteLine(" \"auto_inject\": true,"); //writer.WriteLine(" \"auto_inject\": false,");
writer.WriteLine(" \"inject\": ["); writer.WriteLine(" \"inject\": []"); //writer.WriteLine(" \"inject\": [");
foreach (KeyValuePair<string, (string name, string icon)> pair in dlcApps) /*foreach (KeyValuePair<string, (string name, string icon)> pair in dlcApps)
{ {
string id = pair.Key; string id = pair.Key;
(string name, _) = pair.Value; (string name, _) = pair.Value;
writer.WriteLine($" \"{id}\"{(pair.Equals(last) ? "" : ",")}"); 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(" }");
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(() => internal static async Task UninstallScreamAPI(string directory, InstallForm installForm = null) => await Task.Run(() =>

View file

@ -260,7 +260,7 @@ internal partial class SelectForm : CustomForm
return; return;
} }
if (Program.Canceled) return; if (Program.Canceled) return;
ConcurrentDictionary<string, (string name, string product, string icon, string developer)> dlc = new(); /*ConcurrentDictionary<string, (string name, string product, string icon, string developer)> dlc = new();
List<Task> dlcTasks = new(); List<Task> dlcTasks = new();
List<(string id, string name, string product, string icon, string developer)> dlcIds = await EpicStore.ParseDlcIds(@namespace); List<(string id, string name, string product, string icon, string developer)> dlcIds = await EpicStore.ParseDlcIds(@namespace);
if (dlcIds.Count > 0) if (dlcIds.Count > 0)
@ -292,7 +292,7 @@ internal partial class SelectForm : CustomForm
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
await task; await task;
} }*/
selection ??= new(); selection ??= new();
if (allCheckBox.Checked) selection.Enabled = true; if (allCheckBox.Checked) selection.Enabled = true;
@ -301,13 +301,13 @@ internal partial class SelectForm : CustomForm
selection.Name = name; selection.Name = name;
selection.RootDirectory = directory; selection.RootDirectory = directory;
selection.DllDirectories = dllDirectories; selection.DllDirectories = dllDirectories;
foreach (KeyValuePair<string, (string name, string product, string icon, string developer)> pair in dlc) /*foreach (KeyValuePair<string, (string name, string product, string icon, string developer)> pair in dlc)
if (pair.Value.name == selection.Name) if (pair.Value.name == selection.Name)
{ {
selection.ProductUrl = "https://www.epicgames.com/store/product/" + pair.Value.product; selection.ProductUrl = "https://www.epicgames.com/store/product/" + pair.Value.product;
selection.IconUrl = pair.Value.icon; selection.IconUrl = pair.Value.icon;
selection.Publisher = pair.Value.developer; selection.Publisher = pair.Value.developer;
} }*/
if (Program.Canceled) return; if (Program.Canceled) return;
Program.Invoke(selectionTreeView, delegate Program.Invoke(selectionTreeView, delegate
@ -319,7 +319,7 @@ internal partial class SelectForm : CustomForm
programNode.Checked = selection.Enabled; programNode.Checked = selection.Enabled;
programNode.Remove(); programNode.Remove();
selectionTreeView.Nodes.Add(programNode); selectionTreeView.Nodes.Add(programNode);
foreach (KeyValuePair<string, (string name, string product, string icon, string developer)> pair in dlc) /*foreach (KeyValuePair<string, (string name, string product, string icon, string developer)> pair in dlc)
{ {
if (Program.Canceled || programNode is null) return; if (Program.Canceled || programNode is null) return;
string dlcId = pair.Key; string dlcId = pair.Key;
@ -332,7 +332,7 @@ internal partial class SelectForm : CustomForm
dlcNode.Checked = selection.SelectedDlc.ContainsKey(dlcId); dlcNode.Checked = selection.SelectedDlc.ContainsKey(dlcId);
dlcNode.Remove(); dlcNode.Remove();
programNode.Nodes.Add(dlcNode); programNode.Nodes.Add(dlcNode);
} }*/
}); });
if (Program.Canceled) return; if (Program.Canceled) return;
RemoveFromRemainingGames(name); RemoveFromRemainingGames(name);

View file

@ -15,7 +15,7 @@ internal static class HttpClientManager
internal static void Setup() internal static void Setup()
{ {
HttpClient = new(); 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<HtmlDocument> Get(string url) internal static async Task<HtmlDocument> Get(string url)