From a4383412ed7bf49a3117181bc664c07abf2331aa Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 7 Apr 2021 11:34:54 +0100 Subject: [PATCH 1/7] auto refresh games list on load --- UWPHook/GamesWindow.xaml.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/UWPHook/GamesWindow.xaml.cs b/UWPHook/GamesWindow.xaml.cs index 8ea2751..1a1df85 100644 --- a/UWPHook/GamesWindow.xaml.cs +++ b/UWPHook/GamesWindow.xaml.cs @@ -35,13 +35,15 @@ namespace UWPHook var args = Environment.GetCommandLineArgs(); //If null or 1, the app was launched normally - if (args != null) + if (args != null && Environment.GetCommandLineArgs().Length > 1) { //When length is 1, the only argument is the path where the app is installed - if (Environment.GetCommandLineArgs().Length > 1) - { - _ = LauncherAsync(args); - } + _ = LauncherAsync(args); + } + else + { + //auto refresh on load + LoadButton_Click(null, null); } } From b8fb532fa968758eedd789b58f6baa0485a9578e Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 12 Sep 2021 11:24:11 +0100 Subject: [PATCH 2/7] removed bonus import --- UWPHook/GamesWindow.xaml.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/UWPHook/GamesWindow.xaml.cs b/UWPHook/GamesWindow.xaml.cs index 42c4d84..7cb211c 100644 --- a/UWPHook/GamesWindow.xaml.cs +++ b/UWPHook/GamesWindow.xaml.cs @@ -1,4 +1,4 @@ -using Force.Crc32; +using Force.Crc32; using SharpSteam; using System; using System.Collections.Generic; @@ -18,7 +18,6 @@ using UWPHook.Properties; using UWPHook.SteamGridDb; using VDFParser; using VDFParser.Models; -using System.Diagnostics; namespace UWPHook { From d8c527e3c8e55961e82ac4334f97a9f5357d4f3e Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 12 Sep 2021 11:46:41 +0100 Subject: [PATCH 3/7] typo --- UWPHook/GamesWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UWPHook/GamesWindow.xaml.cs b/UWPHook/GamesWindow.xaml.cs index 7cb211c..295b90f 100644 --- a/UWPHook/GamesWindow.xaml.cs +++ b/UWPHook/GamesWindow.xaml.cs @@ -428,7 +428,7 @@ namespace UWPHook } catch (Exception ex) { - MessageBox.Show("Error: Program failed while trying to clear your Steam shurtcuts:" + Environment.NewLine + ex.Message + ex.StackTrace); + MessageBox.Show("Error: Program failed while trying to clear your Steam shortcuts:" + Environment.NewLine + ex.Message + ex.StackTrace); } } MessageBox.Show("All non-Steam shortcuts has been cleared."); From a5ea0db936f0e00ecd6e13bc866e02d2b2599143 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 12 Sep 2021 12:03:44 +0100 Subject: [PATCH 4/7] automatically restart steam after exporting apps --- README.md | 2 +- UWPHook/GamesWindow.xaml.cs | 64 +++++++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 968e892..6c935aa 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Select every app you want to add to Steam, you can change the name by double cli ![](https://i.imgur.com/on46CMQ.png) -Close UWPHook, restart Steam, click play on your UWP game, and Steam will show your current game on your status as long as you are playing it! +Close UWPHook, restart Steam if prompted, click play on your UWP game, and Steam will show your current game on your status as long as you are playing it! ---------- diff --git a/UWPHook/GamesWindow.xaml.cs b/UWPHook/GamesWindow.xaml.cs index 295b90f..ab2d65f 100644 --- a/UWPHook/GamesWindow.xaml.cs +++ b/UWPHook/GamesWindow.xaml.cs @@ -130,11 +130,23 @@ namespace UWPHook grid.IsEnabled = false; progressBar.Visibility = Visibility.Visible; - await ExportGames(); + bool restartSteam = true; + var result = await ExportGames(restartSteam); grid.IsEnabled = true; progressBar.Visibility = Visibility.Collapsed; - MessageBox.Show("Your apps were successfuly exported, please restart Steam in order to see your apps.", "UWPHook", MessageBoxButton.OK, MessageBoxImage.Information); + + string msg = "Your apps were successfuly exported!"; + if(!restartSteam) + { + msg += " Please restart Steam in order to see them."; + } + else if(result) + { + msg += " Steam has been restarted."; + } + + MessageBox.Show(msg, "UWPHook", MessageBoxButton.OK, MessageBoxImage.Information); } private async Task SaveImage(string imageUrl, string destinationFilename, ImageFormat format) @@ -265,7 +277,7 @@ namespace UWPHook } } - private async Task ExportGames() + private async Task ExportGames(bool restartSteam) { string[] tags = Settings.Default.Tags.Split(','); string steam_folder = SteamManager.GetSteamFolder(); @@ -392,6 +404,52 @@ namespace UWPHook }); } } + + if(restartSteam) + { + Func getSteam = () => Process.GetProcessesByName("steam").SingleOrDefault(); + + Process steam = getSteam(); + if (steam != null) + { + string steamExe = steam.MainModule.FileName; + + //we always ask politely + Debug.WriteLine("Requesting Steam shutdown"); + Process.Start(steamExe, "-exitsteam"); + + bool restarted = false; + Stopwatch watch = new Stopwatch(); + watch.Start(); + + //give it N seconds to sort itself out + int waitSeconds = 8; + while (watch.Elapsed.TotalSeconds < waitSeconds) + { + Thread.Sleep(TimeSpan.FromSeconds(0.5f)); + if (getSteam() == null) + { + Debug.WriteLine("Restarting Steam"); + Process.Start(steamExe); + restarted = true; + break; + } + } + + if (!restarted) + { + Debug.WriteLine("Steam instance not restarted"); + MessageBox.Show("Failed to restart Steam, please launch it manually", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); + return false; + } + } + else + { + Debug.WriteLine("Steam instance not found to be restarted"); + } + } + + return true; } public static void ClearAllShortcuts() From 16522024cfafd5a2dd05ff58ec7aac849249469c Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 12 Sep 2021 14:40:05 +0100 Subject: [PATCH 5/7] 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 + From b3ec7375efe1910078288baa3c178693471f0897 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 12 Sep 2021 14:44:22 +0100 Subject: [PATCH 6/7] removed duplicate call --- UWPHook/GamesWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UWPHook/GamesWindow.xaml.cs b/UWPHook/GamesWindow.xaml.cs index da15a33..c05ecf7 100644 --- a/UWPHook/GamesWindow.xaml.cs +++ b/UWPHook/GamesWindow.xaml.cs @@ -37,7 +37,7 @@ namespace UWPHook var args = Environment.GetCommandLineArgs(); //If null or 1, the app was launched normally - if (args != null && Environment.GetCommandLineArgs().Length > 1) + if (args?.Length > 1) { //When length is 1, the only argument is the path where the app is installed _ = LauncherAsync(args); From fdb004040813f9368abb2a296a0f5d6ce8385a62 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 1 Nov 2021 10:40:23 +0000 Subject: [PATCH 7/7] search by name + aumid (for Age of Empires IV) --- UWPHook/GamesWindow.xaml | 4 ++-- UWPHook/GamesWindow.xaml.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/UWPHook/GamesWindow.xaml b/UWPHook/GamesWindow.xaml index 3850702..09d0464 100644 --- a/UWPHook/GamesWindow.xaml +++ b/UWPHook/GamesWindow.xaml @@ -39,7 +39,7 @@