- 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>
<ApplicationIcon>Resources\ini.ico</ApplicationIcon>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<Version>3.0.0.1</Version>
<Version>3.0.1.0</Version>
<PackageIcon>Resources\ini.ico</PackageIcon>
<PackageIconUrl />
<Description />

View file

@ -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<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();
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<Element> 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;
}

View file

@ -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
}
}
}

View file

@ -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

View file

@ -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<string, (string name, string icon)> last = dlcApps.Last();
writer.WriteLine(" \"unlock_all\": true,"); //writer.WriteLine(" \"unlock_all\": false,");
writer.WriteLine(" \"override\": []"); //writer.WriteLine(" \"override\": [");
/*KeyValuePair<string, (string name, string icon)> last = dlcApps.Last();
foreach (KeyValuePair<string, (string name, string icon)> 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<string, (string name, string icon)> 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<string, (string name, string icon)> 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(() =>

View file

@ -260,7 +260,7 @@ internal partial class SelectForm : CustomForm
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<(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<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)
{
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<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;
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);

View file

@ -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<HtmlDocument> Get(string url)