From 92a20f87f447a6deb51b11aca9f85771954d623f Mon Sep 17 00:00:00 2001 From: pointfeev Date: Wed, 22 Jun 2022 21:56:14 -0500 Subject: [PATCH] v3.5.3.1 - Right-click context menu favicons are now grabbed via Google's favicons API - Official program/game websites are now openable via the right-click context menu should the Steam Store provide one --- CreamInstaller/Components/ContextMenuItem.cs | 22 ++++++++++---------- CreamInstaller/CreamInstaller.csproj | 2 +- CreamInstaller/Forms/SelectForm.cs | 12 ++++++++--- CreamInstaller/ProgramSelection.cs | 2 ++ CreamInstaller/Steam/AppDetails.cs | 18 ---------------- CreamInstaller/Utility/IconGrabber.cs | 4 ++++ 6 files changed, 27 insertions(+), 33 deletions(-) diff --git a/CreamInstaller/Components/ContextMenuItem.cs b/CreamInstaller/Components/ContextMenuItem.cs index f22506a..daf74e1 100644 --- a/CreamInstaller/Components/ContextMenuItem.cs +++ b/CreamInstaller/Components/ContextMenuItem.cs @@ -39,19 +39,19 @@ internal class ContextMenuItem : ToolStripMenuItem image = IconGrabber.GetFileExplorerImage(); break; case "SteamDB": - image = await HttpClientManager.GetImageFromUrl("https://steamdb.info/favicon.ico"); + image = await HttpClientManager.GetImageFromUrl(IconGrabber.GetDomainFaviconUrl("steamdb.info")); break; case "Steam Store": - image = await HttpClientManager.GetImageFromUrl("https://store.steampowered.com/favicon.ico"); + image = await HttpClientManager.GetImageFromUrl(IconGrabber.GetDomainFaviconUrl("store.steampowered.com")); break; case "Steam Community": - image = await HttpClientManager.GetImageFromUrl("https://steamcommunity.com/favicon.ico"); + image = await HttpClientManager.GetImageFromUrl(IconGrabber.GetDomainFaviconUrl("steamcommunity.com")); break; case "ScreamDB": - image = await HttpClientManager.GetImageFromUrl("https://scream-db.web.app/favicon.ico"); + image = await HttpClientManager.GetImageFromUrl(IconGrabber.GetDomainFaviconUrl("scream-db.web.app")); break; case "Epic Games": - image = await HttpClientManager.GetImageFromUrl("https://www.epicgames.com/favicon.ico"); + image = await HttpClientManager.GetImageFromUrl(IconGrabber.GetDomainFaviconUrl("epicgames.com")); break; default: return; @@ -64,10 +64,10 @@ internal class ContextMenuItem : ToolStripMenuItem } }).ConfigureAwait(false); - private static async Task TryImageIdentifierInfo(ContextMenuItem item, (string id, string iconUrl, bool sub) imageIdentifierInfo, Action onFail = null) => await Task.Run(async () => + private static async Task TryImageIdentifierInfo(ContextMenuItem item, (string id, string iconUrl) imageIdentifierInfo, Action onFail = null) => await Task.Run(async () => { - (string id, string iconUrl, bool sub) = imageIdentifierInfo; - string imageIdentifier = sub ? "SubIcon_" + id : "Icon_" + id; + (string id, string iconUrl) = imageIdentifierInfo; + string imageIdentifier = "Icon_" + id; if (images.TryGetValue(imageIdentifier, out Image image) && image is not null) item.Image = image; else { @@ -99,12 +99,12 @@ internal class ContextMenuItem : ToolStripMenuItem internal ContextMenuItem(string text, string imageIdentifier, EventHandler onClick = null) : this(text, onClick) => _ = TryImageIdentifier(this, imageIdentifier); - internal ContextMenuItem(string text, (string id, string iconUrl, bool sub) imageIdentifierInfo, EventHandler onClick = null) + internal ContextMenuItem(string text, (string id, string iconUrl) imageIdentifierInfo, EventHandler onClick = null) : this(text, onClick) => _ = TryImageIdentifierInfo(this, imageIdentifierInfo); - internal ContextMenuItem(string text, (string id, string iconUrl, bool sub) imageIdentifierInfo, string imageIdentifierFallback, EventHandler onClick = null) + internal ContextMenuItem(string text, (string id, string iconUrl) imageIdentifierInfo, string imageIdentifierFallback, EventHandler onClick = null) : this(text, onClick) => _ = TryImageIdentifierInfo(this, imageIdentifierInfo, async () => await TryImageIdentifier(this, imageIdentifierFallback)); - internal ContextMenuItem(string text, (string id, string iconUrl, bool sub) imageIdentifierInfo, (string id, string iconUrl, bool sub) imageIdentifierInfoFallback, EventHandler onClick = null) + internal ContextMenuItem(string text, (string id, string iconUrl) imageIdentifierInfo, (string id, string iconUrl) imageIdentifierInfoFallback, EventHandler onClick = null) : this(text, onClick) => _ = TryImageIdentifierInfo(this, imageIdentifierInfo, async () => await TryImageIdentifierInfo(this, imageIdentifierInfoFallback)); } \ No newline at end of file diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index b5745d2..c777c84 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -5,7 +5,7 @@ True Resources\ini.ico true - 3.5.3.0 + 3.5.3.1 Resources\ini.ico LICENSE 2021, pointfeev (https://github.com/pointfeev) diff --git a/CreamInstaller/Forms/SelectForm.cs b/CreamInstaller/Forms/SelectForm.cs index 54c81fb..5d22873 100644 --- a/CreamInstaller/Forms/SelectForm.cs +++ b/CreamInstaller/Forms/SelectForm.cs @@ -231,6 +231,7 @@ internal partial class SelectForm : CustomForm selection.IconUrl = IconGrabber.SteamAppImagesPath + @$"\{appId}\{appInfo?.Value?.GetChild("common")?.GetChild("icon")}.jpg"; selection.SubIconUrl = appData?.header_image ?? IconGrabber.SteamAppImagesPath + @$"\{appId}\{appInfo?.Value?.GetChild("common")?.GetChild("clienticon")}.ico"; selection.Publisher = appData?.publishers[0] ?? appInfo?.Value?.GetChild("extended")?.GetChild("publisher")?.ToString(); + selection.WebsiteUrl = appData?.website; if (Program.Canceled) return; Program.Invoke(selectionTreeView, delegate @@ -607,9 +608,9 @@ internal partial class SelectForm : CustomForm if (id == "ParadoxLauncher") header = new(node.Text, "Paradox Launcher"); else if (selection is not null) - header = new(node.Text, (id, selection.IconUrl, false)); + header = new(node.Text, (id, selection.IconUrl)); else if (dlc is not null && dlcParentSelection is not null) - header = new(node.Text, (id, dlc.Value.app.icon, false), (id, dlcParentSelection.IconUrl, false)); + header = new(node.Text, (id, dlc.Value.app.icon), (id, dlcParentSelection.IconUrl)); contextMenuStrip.Items.Add(header ?? new ContextMenuItem(node.Text)); string appInfoVDF = $@"{SteamCMD.AppInfoPath}\{id}.vdf"; string appInfoJSON = $@"{SteamCMD.AppInfoPath}\{id}.json"; @@ -702,7 +703,7 @@ internal partial class SelectForm : CustomForm { contextMenuStrip.Items.Add(new ContextMenuItem("Open Steam Store", "Steam Store", new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser(selection.ProductUrl)))); - contextMenuStrip.Items.Add(new ContextMenuItem("Open Steam Community", (id, selection.SubIconUrl, true), "Steam Community", + contextMenuStrip.Items.Add(new ContextMenuItem("Open Steam Community", ("Sub_" + id, selection.SubIconUrl), "Steam Community", new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://steamcommunity.com/app/" + id)))); } else if (selection.IsEpic) @@ -715,6 +716,11 @@ internal partial class SelectForm : CustomForm } } } + if (selection is not null && selection.WebsiteUrl is not null) + { + contextMenuStrip.Items.Add(new ContextMenuItem("Open Official Website", ("Web_" + id, IconGrabber.GetDomainFaviconUrl(selection.WebsiteUrl)), + new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser(selection.WebsiteUrl)))); + } contextMenuStrip.Show(selectionTreeView, e.Location); }; OnLoad(forceProvideChoices: true); diff --git a/CreamInstaller/ProgramSelection.cs b/CreamInstaller/ProgramSelection.cs index 6679878..4937eb8 100644 --- a/CreamInstaller/ProgramSelection.cs +++ b/CreamInstaller/ProgramSelection.cs @@ -27,6 +27,8 @@ internal class ProgramSelection internal string Publisher; + internal string WebsiteUrl; + internal string RootDirectory; internal List DllDirectories; diff --git a/CreamInstaller/Steam/AppDetails.cs b/CreamInstaller/Steam/AppDetails.cs index bc09a6f..534295a 100644 --- a/CreamInstaller/Steam/AppDetails.cs +++ b/CreamInstaller/Steam/AppDetails.cs @@ -7,20 +7,6 @@ using System.Collections.Generic; namespace CreamInstaller.Steam; -public class Category -{ - public int id { get; set; } - - public string description { get; set; } -} - -public class Genre -{ - public string id { get; set; } - - public string description { get; set; } -} - public class AppData { public string type { get; set; } @@ -40,10 +26,6 @@ public class AppData public List publishers { get; set; } public List packages { get; set; } - - public List categories { get; set; } - - public List genres { get; set; } } public class AppDetails diff --git a/CreamInstaller/Utility/IconGrabber.cs b/CreamInstaller/Utility/IconGrabber.cs index 2a15de4..ef3fb7d 100644 --- a/CreamInstaller/Utility/IconGrabber.cs +++ b/CreamInstaller/Utility/IconGrabber.cs @@ -14,6 +14,10 @@ internal static class IconGrabber internal const string SteamAppImagesPath = "https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/"; + internal const string GoogleFaviconsApiUrl = "https://www.google.com/s2/favicons"; + + internal static string GetDomainFaviconUrl(string domain, int size = 16) => GoogleFaviconsApiUrl + $"?domain={domain}&sz={size}"; + internal static Image GetFileIconImage(string path) => File.Exists(path) ? Icon.ExtractAssociatedIcon(path).ToBitmap() : null; internal static Image GetNotepadImage() => GetFileIconImage(Diagnostics.GetNotepadPath());