From 4eb4316d6b0054056163f0f3b36faad6b5ba233c Mon Sep 17 00:00:00 2001 From: EnumC Date: Wed, 25 Aug 2021 17:32:22 -0700 Subject: [PATCH 1/2] Prevent duplicate entries --- README.md | 10 ++ UWPHook/GamesWindow.xaml.cs | 66 +++++++++- UWPHook/SettingsWindow.xaml | 233 +++++++++++++++++---------------- UWPHook/SettingsWindow.xaml.cs | 4 +- 4 files changed, 192 insertions(+), 121 deletions(-) diff --git a/README.md b/README.md index dc7f13b..968e892 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,16 @@ Special thanks to @FusRoDah061 for implementing the base feature! ---------- +# Building # + +- Clone project or forked project. +- Install Visual Studio 2019 with .NET Framework 4.6.2. +- Install [SharpSteam by BrianLima](https://github.com/BrianLima/SharpSteam/releases/) and [VDFParser by heyvito](https://github.com/heyvito/VDFParser). +- Add the above two dll to the project in Visual Studio Reference Manager. +- Press run! + +---------- + # About # This software is open-source under the MIT License. diff --git a/UWPHook/GamesWindow.xaml.cs b/UWPHook/GamesWindow.xaml.cs index 439f414..e0ca503 100644 --- a/UWPHook/GamesWindow.xaml.cs +++ b/UWPHook/GamesWindow.xaml.cs @@ -17,6 +17,7 @@ using UWPHook.Properties; using UWPHook.SteamGridDb; using VDFParser; using VDFParser.Models; +using System.Diagnostics; namespace UWPHook { @@ -31,6 +32,7 @@ namespace UWPHook public GamesWindow() { InitializeComponent(); + Debug.WriteLine("Init GamesWindow"); Apps = new AppEntryModel(); var args = Environment.GetCommandLineArgs(); @@ -324,10 +326,27 @@ namespace UWPHook DevkitGameID = "", LastPlayTime = (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds(), }; + Boolean isFound = false; + for (int i = 0; i < shortcuts.Length; i++) + { + Debug.WriteLine(shortcuts[i].ToString()); + + + if (shortcuts[i].AppName == app.Name) + { + isFound = true; + Debug.WriteLine(app.Name + " already added to Steam. Updating existing shortcut."); + shortcuts[i] = newApp; + } + } - //Resize this array so it fits the new entries - Array.Resize(ref shortcuts, shortcuts.Length + 1); - shortcuts[shortcuts.Length - 1] = newApp; + if (!isFound) + { + //Resize this array so it fits the new entries + Array.Resize(ref shortcuts, shortcuts.Length + 1); + shortcuts[shortcuts.Length - 1] = newApp; + } + } try @@ -368,6 +387,47 @@ namespace UWPHook } } + public static void ClearAllShortcuts() + { + Debug.WriteLine("DBG: Clearing all elements in shortcuts.vdf"); + string[] tags = Settings.Default.Tags.Split(','); + string steam_folder = SteamManager.GetSteamFolder(); + + if (Directory.Exists(steam_folder)) + { + var users = SteamManager.GetUsers(steam_folder); + var exePath = @"""" + System.Reflection.Assembly.GetExecutingAssembly().Location + @""""; + var exeDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); + + foreach (var user in users) + { + try + { + VDFEntry[] shortcuts = new VDFEntry[0]; + + try + { + if (!Directory.Exists(user + @"\\config\\")) + { + Directory.CreateDirectory(user + @"\\config\\"); + } + //Write the file with all the shortcuts + File.WriteAllBytes(user + @"\\config\\shortcuts.vdf", VDFSerializer.Serialize(shortcuts)); + } + catch (Exception ex) + { + throw new Exception("Error: Program failed while trying to write your Steam shortcuts" + Environment.NewLine + ex.Message); + } + } + catch (Exception ex) + { + MessageBox.Show("Error: Program failed while trying to clear your Steam shurtcuts:" + Environment.NewLine + ex.Message + ex.StackTrace); + } + } + MessageBox.Show("All non-Steam shortcuts has been cleared."); + } + } + private void LoadButton_Click(object sender, RoutedEventArgs e) { bwrLoad = new BackgroundWorker(); diff --git a/UWPHook/SettingsWindow.xaml b/UWPHook/SettingsWindow.xaml index 5ee8bea..f975df4 100644 --- a/UWPHook/SettingsWindow.xaml +++ b/UWPHook/SettingsWindow.xaml @@ -12,130 +12,131 @@ TextElement.FontSize="14" FontFamily="Segoe UI Light" Title="Settings" Height="638" Width="800" Icon="Resources/hook2.ico"> - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - -