From 16522024cfafd5a2dd05ff58ec7aac849249469c Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 12 Sep 2021 14:40:05 +0100 Subject: [PATCH] added AppEntry.ToString() moved "known apps" (name overrides) to a json file, now it's data driven --- UWPHook/AppEntry.cs | 14 ++++++++------ UWPHook/AppManager.cs | 24 ++++++++++++++++++++++++ UWPHook/GamesWindow.xaml.cs | 17 ++++++----------- UWPHook/Resources/KnownApps.json | 4 ++++ UWPHook/UWPHook.csproj | 5 ++++- 5 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 UWPHook/Resources/KnownApps.json diff --git a/UWPHook/AppEntry.cs b/UWPHook/AppEntry.cs index c8dce92..8df6091 100644 --- a/UWPHook/AppEntry.cs +++ b/UWPHook/AppEntry.cs @@ -118,14 +118,11 @@ namespace UWPHook public string isKnownApp() { - if (_aumid.Contains("Microsoft.SeaofThieves")) + if(AppManager.IsKnownApp(_aumid, out string name)) { - return "Sea of Thieves"; - } - else if (_aumid.Contains("Microsoft.DeltaPC")) - { - return "Gears of War: Ultimate Edition"; + return name; } + return "Name not found, double click here to edit"; } @@ -135,5 +132,10 @@ namespace UWPHook { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + + public override string ToString() + { + return $"{Name} ({Aumid})"; + } } } diff --git a/UWPHook/AppManager.cs b/UWPHook/AppManager.cs index 7b22e5d..ffd5856 100644 --- a/UWPHook/AppManager.cs +++ b/UWPHook/AppManager.cs @@ -101,6 +101,30 @@ namespace UWPHook return result; } + /// + /// Try to convert an aumid into a human-readable app name + /// + /// Application user model ID (aumid) + /// User-friendly app name + /// Whether this is a known app + public static bool IsKnownApp(string appName, out string readableName) + { + string appsJson = File.ReadAllText(@"Resources\KnownApps.json"); + var apps = Newtonsoft.Json.JsonConvert.DeserializeObject>(appsJson); + + foreach (var kvp in apps) + { + if (appName.StartsWith(kvp.Key + "_")) + { + readableName = kvp.Value; + return true; + } + } + + readableName = null; + return false; + } + [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); diff --git a/UWPHook/GamesWindow.xaml.cs b/UWPHook/GamesWindow.xaml.cs index ab2d65f..da15a33 100644 --- a/UWPHook/GamesWindow.xaml.cs +++ b/UWPHook/GamesWindow.xaml.cs @@ -542,6 +542,12 @@ namespace UWPHook //Remove end lines from the String and split both values, I split the appname and the AUMID using | //I hope no apps have that in their name. Ever. var values = app.Replace("\r\n", "").Split('|'); + + if (values.Length >= 3 && AppManager.IsKnownApp(values[2], out string readableName)) + { + values[0] = readableName; + } + if (!String.IsNullOrWhiteSpace(values[0])) { //We get the default square tile to find where the app stores it's icons, then we resolve which one is the widest @@ -551,17 +557,6 @@ namespace UWPHook Apps.Entries.Add(new AppEntry() { Name = values[0], IconPath = logosPath, Aumid = values[2], Selected = false }); }); } - if (values.Length > 2) - { - if (values[2].Contains("Microsoft.SeaofThieves")) - { - values[0] = "Sea of Thieves"; - } - else if (values[2].Contains("Microsoft.DeltaPC")) - { - values[0] = "Gears of War: Ultimate Edition"; - } - } } } catch (Exception ex) diff --git a/UWPHook/Resources/KnownApps.json b/UWPHook/Resources/KnownApps.json new file mode 100644 index 0000000..d7d263e --- /dev/null +++ b/UWPHook/Resources/KnownApps.json @@ -0,0 +1,4 @@ +{ + "Microsoft.SeaofThieves": "Sea of Thieves", + "Microsoft.DeltaPC": "Gears of War: Ultimate Edition" +} \ No newline at end of file diff --git a/UWPHook/UWPHook.csproj b/UWPHook/UWPHook.csproj index 8d641f2..a380e08 100644 --- a/UWPHook/UWPHook.csproj +++ b/UWPHook/UWPHook.csproj @@ -1,4 +1,4 @@ - + @@ -162,6 +162,9 @@ Settings.Designer.cs + + Always +