context menu

This commit is contained in:
pointfeev 2022-03-03 07:20:19 -05:00
parent 26bb1269dc
commit da61c74e95
6 changed files with 78 additions and 61 deletions

View file

@ -13,24 +13,28 @@ namespace CreamInstaller.Epic;
internal static class EpicStore internal static class EpicStore
{ {
internal static async Task<List<(string id, string name)>> ParseDlcAppIds(string categoryNamespace) internal static async Task<List<(string id, string name, string product, string icon)>> ParseDlcAppIds(string categoryNamespace)
{ {
List<(string id, string name)> dlcIds = new(); List<(string id, string name, string product, string icon)> dlcIds = new();
Response response = await QueryEpicGraphQL(categoryNamespace); Response response = await QueryGraphQL(categoryNamespace);
if (response is null) if (response is null)
return dlcIds; return dlcIds;
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); elements.AddRange(response.Data.Catalog.SearchStore.Elements);
foreach (Element element in elements) foreach (Element element in elements)
{ {
(string id, string name) app = (element.Items[0].Id, element.Title); string product = null;
try { product = element.CatalogNs.Mappings[0].PageSlug; } catch { }
string icon = null;
try { icon = element.KeyImages[0].Url; } catch { }
(string id, string name, string product, string icon) app = (element.Items[0].Id, element.Title, product, icon);
if (!dlcIds.Contains(app)) if (!dlcIds.Contains(app))
dlcIds.Add(app); dlcIds.Add(app);
} }
return dlcIds; return dlcIds;
} }
internal static async Task<Response> QueryEpicGraphQL(string categoryNamespace) internal static async Task<Response> QueryGraphQL(string categoryNamespace)
{ {
string encoded = HttpUtility.UrlEncode(categoryNamespace); string encoded = HttpUtility.UrlEncode(categoryNamespace);
Request request = new(encoded); Request request = new(encoded);

View file

@ -1,5 +1,4 @@
using System; 
using Newtonsoft.Json; using Newtonsoft.Json;
namespace CreamInstaller.Epic.GraphQL; namespace CreamInstaller.Epic.GraphQL;

View file

@ -53,7 +53,7 @@ internal partial class InstallForm : CustomForm
} }
} }
internal static void WriteCreamConfiguration(StreamWriter writer, string steamAppId, string name, SortedList<string, (string name, string iconStaticId)> steamDlcApps, InstallForm installForm = null) internal static void WriteCreamConfiguration(StreamWriter writer, string steamAppId, string name, SortedList<string, (string name, string icon)> steamDlcApps, InstallForm installForm = null)
{ {
writer.WriteLine($"; {name}"); writer.WriteLine($"; {name}");
writer.WriteLine("[steam]"); writer.WriteLine("[steam]");
@ -62,7 +62,7 @@ internal partial class InstallForm : CustomForm
writer.WriteLine("[dlc]"); writer.WriteLine("[dlc]");
if (installForm is not null) if (installForm is not null)
installForm.UpdateUser($"Added game to cream_api.ini with appid {steamAppId} ({name})", InstallationLog.Resource, info: false); installForm.UpdateUser($"Added game to cream_api.ini with appid {steamAppId} ({name})", InstallationLog.Resource, info: false);
foreach (KeyValuePair<string, (string name, string iconStaticId)> pair in steamDlcApps) foreach (KeyValuePair<string, (string name, string icon)> pair in steamDlcApps)
{ {
string appId = pair.Key; string appId = pair.Key;
(string dlcName, _) = pair.Value; (string dlcName, _) = pair.Value;
@ -140,13 +140,13 @@ internal partial class InstallForm : CustomForm
StreamWriter writer = new(cApi, true, Encoding.UTF8); StreamWriter writer = new(cApi, true, Encoding.UTF8);
if (selection.Id != "ParadoxLauncher") if (selection.Id != "ParadoxLauncher")
WriteCreamConfiguration(writer, selection.Id, selection.Name, selection.SelectedDlc, installForm); WriteCreamConfiguration(writer, selection.Id, selection.Name, selection.SelectedDlc, installForm);
foreach (Tuple<string, string, SortedList<string, (string name, string iconStaticId)>> extraAppDlc in selection.ExtraDlc) foreach (Tuple<string, string, SortedList<string, (string name, string icon)>> extraAppDlc in selection.ExtraDlc)
WriteCreamConfiguration(writer, extraAppDlc.Item1, extraAppDlc.Item2, extraAppDlc.Item3, installForm); WriteCreamConfiguration(writer, extraAppDlc.Item1, extraAppDlc.Item2, extraAppDlc.Item3, installForm);
writer.Flush(); writer.Flush();
writer.Close(); writer.Close();
}); });
internal static void WriteScreamConfiguration(StreamWriter writer, SortedList<string, (string name, string iconStaticId)> steamDlcApps, InstallForm installForm = null) internal static void WriteScreamConfiguration(StreamWriter writer, SortedList<string, (string name, string icon)> dlcApps, InstallForm installForm = null)
{ {
writer.WriteLine("{"); writer.WriteLine("{");
writer.WriteLine(" \"version\": 2,"); writer.WriteLine(" \"version\": 2,");
@ -156,8 +156,8 @@ internal partial class InstallForm : CustomForm
writer.WriteLine(" \"catalog_items\": {"); writer.WriteLine(" \"catalog_items\": {");
writer.WriteLine(" \"unlock_all\": false,"); writer.WriteLine(" \"unlock_all\": false,");
writer.WriteLine(" \"override\": ["); writer.WriteLine(" \"override\": [");
KeyValuePair<string, (string name, string iconStaticId)> last = steamDlcApps.Last(); KeyValuePair<string, (string name, string icon)> last = dlcApps.Last();
foreach (KeyValuePair<string, (string name, string iconStaticId)> pair in steamDlcApps) 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;
@ -171,7 +171,7 @@ internal partial class InstallForm : CustomForm
writer.WriteLine(" \"unlock_all\": false,"); writer.WriteLine(" \"unlock_all\": false,");
writer.WriteLine(" \"auto_inject\": false,"); writer.WriteLine(" \"auto_inject\": false,");
writer.WriteLine(" \"inject\": ["); writer.WriteLine(" \"inject\": [");
foreach (KeyValuePair<string, (string name, string iconStaticId)> pair in steamDlcApps) 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;
@ -252,7 +252,7 @@ internal partial class InstallForm : CustomForm
StreamWriter writer = new(sApi, true, Encoding.UTF8); StreamWriter writer = new(sApi, true, Encoding.UTF8);
if (selection.Id != "ParadoxLauncher") if (selection.Id != "ParadoxLauncher")
WriteScreamConfiguration(writer, selection.SelectedDlc, installForm); WriteScreamConfiguration(writer, selection.SelectedDlc, installForm);
foreach (Tuple<string, string, SortedList<string, (string name, string iconStaticId)>> extraAppDlc in selection.ExtraDlc) foreach (Tuple<string, string, SortedList<string, (string name, string icon)>> extraAppDlc in selection.ExtraDlc)
WriteScreamConfiguration(writer, extraAppDlc.Item3, installForm); WriteScreamConfiguration(writer, extraAppDlc.Item3, installForm);
writer.Flush(); writer.Flush();
writer.Close(); writer.Close();

View file

@ -140,7 +140,7 @@ internal partial class SelectForm : CustomForm
return; return;
} }
if (Program.Canceled) return; if (Program.Canceled) return;
ConcurrentDictionary<string, (string name, string iconStaticId)> dlc = new(); ConcurrentDictionary<string, (string name, string icon)> dlc = new();
List<Task> dlcTasks = new(); List<Task> dlcTasks = new();
List<string> dlcIds = await SteamCMD.ParseDlcAppIds(appInfo); List<string> dlcIds = await SteamCMD.ParseDlcAppIds(appInfo);
await SteamStore.ParseDlcAppIds(appId, dlcIds); await SteamStore.ParseDlcAppIds(appId, dlcIds);
@ -162,6 +162,8 @@ internal partial class SelectForm : CustomForm
dlcIconStaticId = dlcAppInfo.Value?.GetChild("common")?.GetChild("icon")?.ToString(); dlcIconStaticId = dlcAppInfo.Value?.GetChild("common")?.GetChild("icon")?.ToString();
dlcIconStaticId ??= dlcAppInfo.Value?.GetChild("common")?.GetChild("logo_small")?.ToString(); dlcIconStaticId ??= dlcAppInfo.Value?.GetChild("common")?.GetChild("logo_small")?.ToString();
dlcIconStaticId ??= dlcAppInfo.Value?.GetChild("common")?.GetChild("logo")?.ToString(); dlcIconStaticId ??= dlcAppInfo.Value?.GetChild("common")?.GetChild("logo")?.ToString();
if (dlcIconStaticId is not null)
dlcIconStaticId = IconGrabber.SteamAppImagesPath + @$"\{dlcAppId}\{dlcIconStaticId}.jpg";
} }
if (Program.Canceled) return; if (Program.Canceled) return;
if (!string.IsNullOrWhiteSpace(dlcName)) if (!string.IsNullOrWhiteSpace(dlcName))
@ -196,8 +198,9 @@ internal partial class SelectForm : CustomForm
selection.DllDirectories = dllDirectories; selection.DllDirectories = dllDirectories;
selection.IsSteam = true; selection.IsSteam = true;
selection.AppInfo = appInfo; selection.AppInfo = appInfo;
selection.IconStaticID = appInfo?.Value?.GetChild("common")?.GetChild("icon")?.ToString(); selection.ProductUrl = "https://store.steampowered.com/app/" + appId;
selection.ClientIconStaticID = appInfo?.Value?.GetChild("common")?.GetChild("clienticon")?.ToString(); selection.IconUrl = IconGrabber.SteamAppImagesPath + @$"\{appId}\{appInfo?.Value?.GetChild("common")?.GetChild("icon")?.ToString()}.jpg";
selection.ClientIconUrl = IconGrabber.SteamAppImagesPath + @$"\{appId}\{appInfo?.Value?.GetChild("common")?.GetChild("clienticon")?.ToString()}.ico";
if (Program.Canceled) return; if (Program.Canceled) return;
Program.Invoke(selectionTreeView, delegate Program.Invoke(selectionTreeView, delegate
@ -209,11 +212,11 @@ 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 iconStaticId)> pair in dlc) foreach (KeyValuePair<string, (string name, string icon)> pair in dlc)
{ {
if (Program.Canceled || programNode is null) return; if (Program.Canceled || programNode is null) return;
string appId = pair.Key; string appId = pair.Key;
(string name, string iconStaticId) dlcApp = pair.Value; (string name, string icon) dlcApp = pair.Value;
selection.AllDlc[appId] = dlcApp; selection.AllDlc[appId] = dlcApp;
if (allCheckBox.Checked) selection.SelectedDlc[appId] = dlcApp; if (allCheckBox.Checked) selection.SelectedDlc[appId] = dlcApp;
TreeNode dlcNode = TreeNodes.Find(s => s.Name == appId) ?? new(); TreeNode dlcNode = TreeNodes.Find(s => s.Name == appId) ?? new();
@ -239,10 +242,11 @@ internal partial class SelectForm : CustomForm
Dictionary<string, List<string>> games = new(); Dictionary<string, List<string>> games = new();
foreach (Manifest manifest in epicGames) foreach (Manifest manifest in epicGames)
{ {
string id = manifest.CatalogNamespace; string @namespace = manifest.CatalogNamespace;
string mainId = manifest.MainGameCatalogItemId;
string name = manifest.DisplayName; string name = manifest.DisplayName;
string directory = manifest.InstallLocation; string directory = manifest.InstallLocation;
ProgramSelection selection = ProgramSelection.FromId(id); ProgramSelection selection = ProgramSelection.FromId(@namespace);
if (Program.Canceled) return; if (Program.Canceled) return;
if (Program.IsGameBlocked(name, directory)) continue; if (Program.IsGameBlocked(name, directory)) continue;
AddToRemainingGames(name); AddToRemainingGames(name);
@ -256,19 +260,19 @@ internal partial class SelectForm : CustomForm
return; return;
} }
if (Program.Canceled) return; if (Program.Canceled) return;
ConcurrentDictionary<string, string> dlc = new(); ConcurrentDictionary<string, (string name, string product, string icon)> dlc = new();
List<Task> dlcTasks = new(); List<Task> dlcTasks = new();
List<(string id, string name)> dlcIds = await EpicStore.ParseDlcAppIds(id); List<(string id, string name, string product, string icon)> dlcIds = await EpicStore.ParseDlcAppIds(@namespace);
if (dlcIds.Count > 0) if (dlcIds.Count > 0)
{ {
foreach ((string id, string name) in dlcIds) foreach ((string id, string name, string product, string icon) in dlcIds)
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
AddToRemainingDLCs(id); AddToRemainingDLCs(id);
Task task = Task.Run(() => Task task = Task.Run(() =>
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
dlc[id] = name; dlc[id] = (name, product, icon);
RemoveFromRemainingDLCs(id); RemoveFromRemainingDLCs(id);
progress.Report(++CompleteTasks); progress.Report(++CompleteTasks);
}); });
@ -293,32 +297,37 @@ internal partial class SelectForm : CustomForm
selection ??= new(); selection ??= new();
if (allCheckBox.Checked) selection.Enabled = true; if (allCheckBox.Checked) selection.Enabled = true;
selection.Usable = true; selection.Usable = true;
selection.Id = id; selection.Id = @namespace;
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)> 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;
}
if (Program.Canceled) return; if (Program.Canceled) return;
Program.Invoke(selectionTreeView, delegate Program.Invoke(selectionTreeView, delegate
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
TreeNode programNode = TreeNodes.Find(s => s.Name == id) ?? new(); TreeNode programNode = TreeNodes.Find(s => s.Name == @namespace) ?? new();
programNode.Name = id; programNode.Name = @namespace;
programNode.Text = name; programNode.Text = name;
programNode.Checked = selection.Enabled; programNode.Checked = selection.Enabled;
programNode.Remove(); programNode.Remove();
selectionTreeView.Nodes.Add(programNode); selectionTreeView.Nodes.Add(programNode);
foreach (KeyValuePair<string, string> pair in dlc) foreach (KeyValuePair<string, (string name, string product, string icon)> 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;
string dlcName = pair.Value; (string name, string icon) dlcApp = (pair.Value.name, pair.Value.icon);
(string name, string iconStaticId) dlcApp = (dlcName, null); // temporary?
selection.AllDlc[dlcId] = dlcApp; selection.AllDlc[dlcId] = dlcApp;
if (allCheckBox.Checked) selection.SelectedDlc[dlcId] = dlcApp; if (allCheckBox.Checked) selection.SelectedDlc[dlcId] = dlcApp;
TreeNode dlcNode = TreeNodes.Find(s => s.Name == dlcId) ?? new(); TreeNode dlcNode = TreeNodes.Find(s => s.Name == dlcId) ?? new();
dlcNode.Name = dlcId; dlcNode.Name = dlcId;
dlcNode.Text = dlcName; dlcNode.Text = dlcApp.name;
dlcNode.Checked = selection.SelectedDlc.ContainsKey(dlcId); dlcNode.Checked = selection.SelectedDlc.ContainsKey(dlcId);
dlcNode.Remove(); dlcNode.Remove();
programNode.Nodes.Add(dlcNode); programNode.Nodes.Add(dlcNode);
@ -523,12 +532,14 @@ internal partial class SelectForm : CustomForm
images["SteamDB"] = await HttpClientManager.GetImageFromUrl("https://steamdb.info/favicon.ico"); images["SteamDB"] = await HttpClientManager.GetImageFromUrl("https://steamdb.info/favicon.ico");
images["Steam Store"] = await HttpClientManager.GetImageFromUrl("https://store.steampowered.com/favicon.ico"); images["Steam Store"] = await HttpClientManager.GetImageFromUrl("https://store.steampowered.com/favicon.ico");
images["Steam Community"] = await HttpClientManager.GetImageFromUrl("https://steamcommunity.com/favicon.ico"); images["Steam Community"] = await HttpClientManager.GetImageFromUrl("https://steamcommunity.com/favicon.ico");
images["ScreamDB"] = await HttpClientManager.GetImageFromUrl("https://scream-db.web.app/favicon.ico");
images["Epic Games"] = await HttpClientManager.GetImageFromUrl("https://www.epicgames.com/favicon.ico");
}); });
Image Image(string identifier) => images.GetValueOrDefault(identifier, null); Image Image(string identifier) => images.GetValueOrDefault(identifier, null);
void TrySetImageAsync(ToolStripMenuItem menuItem, string appId, string iconStaticId, bool client = false) => void TrySetImageAsync(ToolStripMenuItem menuItem, string appId, string iconUrl, bool client = false) =>
Task.Run(async () => Task.Run(async () =>
{ {
menuItem.Image = client ? await IconGrabber.GetSteamClientIcon(appId, iconStaticId) : await IconGrabber.GetSteamIcon(appId, iconStaticId); menuItem.Image = await HttpClientManager.GetImageFromUrl(iconUrl);
images[client ? "ClientIcon_" + appId : "Icon_" + appId] = menuItem.Image; images[client ? "ClientIcon_" + appId : "Icon_" + appId] = menuItem.Image;
}); });
selectionTreeView.NodeMouseClick += (sender, e) => selectionTreeView.NodeMouseClick += (sender, e) =>
@ -537,7 +548,7 @@ internal partial class SelectForm : CustomForm
TreeNode parentNode = node.Parent; TreeNode parentNode = node.Parent;
string id = node.Name; string id = node.Name;
ProgramSelection selection = ProgramSelection.FromId(id); ProgramSelection selection = ProgramSelection.FromId(id);
(string gameAppId, (string name, string iconStaticId) app)? dlc = null; (string gameAppId, (string name, string icon) app)? dlc = null;
if (selection is null) dlc = ProgramSelection.GetDlcFromId(id); if (selection is null) dlc = ProgramSelection.GetDlcFromId(id);
if (e.Button == MouseButtons.Right && node.Bounds.Contains(e.Location)) if (e.Button == MouseButtons.Right && node.Bounds.Contains(e.Location))
{ {
@ -546,17 +557,17 @@ internal partial class SelectForm : CustomForm
ToolStripMenuItem header = new(selection?.Name ?? node.Text, Image("Icon_" + id)); ToolStripMenuItem header = new(selection?.Name ?? node.Text, Image("Icon_" + id));
if (header.Image is null) if (header.Image is null)
{ {
string iconStaticId = dlc?.app.iconStaticId ?? selection?.IconStaticID; string icon = dlc?.app.icon ?? selection?.IconUrl;
if (iconStaticId is not null) if (icon is not null)
TrySetImageAsync(header, id, iconStaticId); TrySetImageAsync(header, id, icon);
else if (dlc is not null) else if (dlc is not null)
{ {
string gameAppId = dlc.Value.gameAppId; string gameAppId = dlc.Value.gameAppId;
header.Image = Image("Icon_" + gameAppId); header.Image = Image("Icon_" + gameAppId);
ProgramSelection gameSelection = ProgramSelection.FromId(gameAppId); ProgramSelection gameSelection = ProgramSelection.FromId(gameAppId);
iconStaticId = gameSelection?.IconStaticID; icon = gameSelection?.IconUrl;
if (header.Image is null && iconStaticId is not null) if (header.Image is null && icon is not null)
TrySetImageAsync(header, gameAppId, iconStaticId); TrySetImageAsync(header, gameAppId, icon);
} }
} }
nodeContextMenu.Items.Add(header); nodeContextMenu.Items.Add(header);
@ -683,19 +694,23 @@ internal partial class SelectForm : CustomForm
nodeContextMenu.Items.Add(new ToolStripMenuItem("Open SteamDB", Image("SteamDB"), nodeContextMenu.Items.Add(new ToolStripMenuItem("Open SteamDB", Image("SteamDB"),
new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://steamdb.info/app/" + id)))); new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://steamdb.info/app/" + id))));
nodeContextMenu.Items.Add(new ToolStripMenuItem("Open Steam Store", Image("Steam Store"), nodeContextMenu.Items.Add(new ToolStripMenuItem("Open Steam Store", Image("Steam Store"),
new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://store.steampowered.com/app/" + id)))); new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser(selection.ProductUrl))));
ToolStripMenuItem steamCommunity = new("Open Steam Community", Image("ClientIcon_" + id), ToolStripMenuItem steamCommunity = new("Open Steam Community", Image("ClientIcon_" + id),
new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://steamcommunity.com/app/" + id))); new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://steamcommunity.com/app/" + id)));
nodeContextMenu.Items.Add(steamCommunity); nodeContextMenu.Items.Add(steamCommunity);
if (steamCommunity.Image is null) if (steamCommunity.Image is null)
{ {
steamCommunity.Image = Image("Steam Community"); steamCommunity.Image = Image("Steam Community");
TrySetImageAsync(steamCommunity, id, selection.ClientIconStaticID, true); TrySetImageAsync(steamCommunity, id, selection.ClientIconUrl, true);
} }
} }
else else
{ {
// Epic Games links? nodeContextMenu.Items.Add(new ToolStripSeparator());
nodeContextMenu.Items.Add(new ToolStripMenuItem("Open ScreamDB", Image("ScreamDB"),
new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://scream-db.web.app/offers/" + id))));
nodeContextMenu.Items.Add(new ToolStripMenuItem("Open Epic Games Store", Image("Epic Games"),
new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser(selection.ProductUrl))));
} }
} }
nodeContextMenu.Show(selectionTreeView, e.Location); nodeContextMenu.Show(selectionTreeView, e.Location);

View file

@ -15,8 +15,10 @@ internal class ProgramSelection
internal string Id = "0"; internal string Id = "0";
internal string Name = "Program"; internal string Name = "Program";
internal string IconStaticID = null; internal string ProductUrl = null;
internal string ClientIconStaticID = null;
internal string IconUrl = null;
internal string ClientIconUrl = null;
internal string RootDirectory = null; internal string RootDirectory = null;
internal List<string> DllDirectories = null; internal List<string> DllDirectories = null;
@ -24,9 +26,9 @@ internal class ProgramSelection
internal bool IsSteam = false; internal bool IsSteam = false;
internal VProperty AppInfo = null; internal VProperty AppInfo = null;
internal readonly SortedList<string, (string name, string iconStaticId)> AllDlc = new(); internal readonly SortedList<string, (string name, string icon)> AllDlc = new();
internal readonly SortedList<string, (string name, string iconStaticId)> SelectedDlc = new(); internal readonly SortedList<string, (string name, string icon)> SelectedDlc = new();
internal readonly List<Tuple<string, string, SortedList<string, (string name, string iconStaticId)>>> ExtraDlc = new(); internal readonly List<Tuple<string, string, SortedList<string, (string name, string icon)>>> ExtraDlc = new();
internal bool AreDllsLocked internal bool AreDllsLocked
{ {
@ -53,7 +55,7 @@ internal class ProgramSelection
} }
} }
private void Toggle(string dlcAppId, (string name, string iconStaticId) dlcApp, bool enabled) private void Toggle(string dlcAppId, (string name, string icon) dlcApp, bool enabled)
{ {
if (enabled) SelectedDlc[dlcAppId] = dlcApp; if (enabled) SelectedDlc[dlcAppId] = dlcApp;
else SelectedDlc.Remove(dlcAppId); else SelectedDlc.Remove(dlcAppId);
@ -61,10 +63,10 @@ internal class ProgramSelection
internal void ToggleDlc(string dlcAppId, bool enabled) internal void ToggleDlc(string dlcAppId, bool enabled)
{ {
foreach (KeyValuePair<string, (string name, string iconStaticId)> pair in AllDlc) foreach (KeyValuePair<string, (string name, string icon)> pair in AllDlc)
{ {
string appId = pair.Key; string appId = pair.Key;
(string name, string iconStaticId) dlcApp = pair.Value; (string name, string icon) dlcApp = pair.Value;
if (appId == dlcAppId) if (appId == dlcAppId)
{ {
Toggle(appId, dlcApp, enabled); Toggle(appId, dlcApp, enabled);
@ -77,10 +79,10 @@ internal class ProgramSelection
internal void ToggleAllDlc(bool enabled) internal void ToggleAllDlc(bool enabled)
{ {
if (!enabled) SelectedDlc.Clear(); if (!enabled) SelectedDlc.Clear();
else foreach (KeyValuePair<string, (string name, string iconStaticId)> pair in AllDlc) else foreach (KeyValuePair<string, (string name, string icon)> pair in AllDlc)
{ {
string appId = pair.Key; string appId = pair.Key;
(string name, string iconStaticId) dlcApp = pair.Value; (string name, string icon) dlcApp = pair.Value;
Toggle(appId, dlcApp, enabled); Toggle(appId, dlcApp, enabled);
} }
Enabled = SelectedDlc.Any(); Enabled = SelectedDlc.Any();
@ -116,10 +118,10 @@ internal class ProgramSelection
internal static ProgramSelection FromId(string id) => AllUsable.Find(s => s.Id == id); internal static ProgramSelection FromId(string id) => AllUsable.Find(s => s.Id == id);
internal static (string gameAppId, (string name, string iconStaticId) app)? GetDlcFromId(string appId) internal static (string gameAppId, (string name, string icon) app)? GetDlcFromId(string appId)
{ {
foreach (ProgramSelection selection in AllUsable) foreach (ProgramSelection selection in AllUsable)
foreach (KeyValuePair<string, (string name, string iconStaticId)> pair in selection.AllDlc) foreach (KeyValuePair<string, (string name, string icon)> pair in selection.AllDlc)
if (pair.Key == appId) return (selection.Id, pair.Value); if (pair.Key == appId) return (selection.Id, pair.Value);
return null; return null;
} }

View file

@ -1,7 +1,6 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Threading.Tasks;
namespace CreamInstaller.Utility; namespace CreamInstaller.Utility;
@ -13,9 +12,7 @@ internal static class IconGrabber
return Icon.FromHandle(dialogIconBitmap.GetHicon()); return Icon.FromHandle(dialogIconBitmap.GetHicon());
} }
private static readonly string SteamAppImagesPath = "https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/"; internal static readonly string SteamAppImagesPath = "https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/";
internal static async Task<Image> GetSteamIcon(string steamAppId, string iconStaticId) => await HttpClientManager.GetImageFromUrl(SteamAppImagesPath + $"/{steamAppId}/{iconStaticId}.jpg");
internal static async Task<Image> GetSteamClientIcon(string steamAppId, string clientIconStaticId) => await HttpClientManager.GetImageFromUrl(SteamAppImagesPath + $"/{steamAppId}/{clientIconStaticId}.ico");
internal static Image GetFileIconImage(string path) => File.Exists(path) ? Icon.ExtractAssociatedIcon(path).ToBitmap() : null; internal static Image GetFileIconImage(string path) => File.Exists(path) ? Icon.ExtractAssociatedIcon(path).ToBitmap() : null;