diff --git a/RiotGamesLibrary.cs b/RiotGamesLibrary.cs index bc3de72..fe9a90e 100644 --- a/RiotGamesLibrary.cs +++ b/RiotGamesLibrary.cs @@ -14,6 +14,8 @@ using System.Windows; using System.Windows.Controls; using System.Management; +using System.Drawing; +using System.Drawing.Imaging; namespace RiotGamesLibrary { @@ -70,6 +72,14 @@ public override IEnumerable GetGames(LibraryGetGamesArgs args) { foreach (var game in rgGames.Keys) { + // pass icon as bytes so it doesn't get deleted on game removal + byte[] iconData = null; + using (var ms = new MemoryStream()) + { + Bitmap bmp = new Icon(RiotGame.Icons[game]).ToBitmap(); + bmp.Save(ms, ImageFormat.Png); + iconData = ms.ToArray(); + } yield return new GameMetadata() { Name = rgGames[game].Item1, @@ -78,7 +88,7 @@ public override IEnumerable GetGames(LibraryGetGamesArgs args) Platforms = new HashSet { new MetadataNameProperty("PC (Windows)") }, IsInstalled = RiotGame.IsInstalled(game), InstallDirectory = RiotGame.InstallPath(game), - Icon = new MetadataFile(RiotGame.Icons[game]) + Icon = new MetadataFile($"{game}_icon.png", iconData) }; } } @@ -157,6 +167,11 @@ public override void OnApplicationStarted(OnApplicationStartedEventArgs args) } } + /// + /// Creates a game action for the given companion app + /// + /// A CompanionApp + /// A new game action to launch the companion app private GameAction GenAction (CompanionApp comp) { return new GameAction() @@ -171,6 +186,9 @@ private GameAction GenAction (CompanionApp comp) }; } + /// + /// Creates or removes game actions for each companion app based on settings + /// public void UpdateCompanionActions() { PlayniteApi.Database.Games.BeginBufferUpdate(); @@ -238,7 +256,11 @@ public void UpdateCompanionActions() } PlayniteApi.Database.Games.EndBufferUpdate(); } - + + /// + /// Launch relevant companion apps on game start + /// + /// public override void OnGameStarted(OnGameStartedEventArgs args) { //logger.Debug($"launching game with id {args.Game.Id}"); @@ -266,6 +288,24 @@ public override void OnGameStopped(OnGameStoppedEventArgs args) { return; } + OnGameStoppedAsync(args); + } + + /// + /// Asynchronously close companion apps and client + /// + /// OnGameStoppedEventArgs + private async void OnGameStoppedAsync(OnGameStoppedEventArgs args) + { + await Task.Run(() => OGS(args)); + } + + /// + /// Close companion apps and client + /// + /// OnGameStoppedEventArgs + private void OGS(OnGameStoppedEventArgs args) + { if (args.Game.GameId != "rg-legendsofruneterra") { ObservableCollection companionsList = (args.Game.GameId == "rg-leagueoflegends") ? settings.Settings.LeagueCompanions : settings.Settings.ValorantCompanions; @@ -275,7 +315,7 @@ public override void OnGameStopped(OnGameStoppedEventArgs args) if (comp.CloseWithGame) { logger.Info($"Trying to stop {gameName} companion app: {comp.ExeName}"); - var wmiQueryString = "SELECT ProcessId, ExecutablePath, CommandLine FROM Win32_Process"; + var wmiQueryString = "SELECT ProcessId, ExecutablePath, CommandLine FROM Win32_Process"; using (var searcher = new ManagementObjectSearcher(wmiQueryString)) using (var results = searcher.Get()) { diff --git a/RiotGamesLibrary.csproj b/RiotGamesLibrary.csproj index d55604e..ab2b50a 100644 --- a/RiotGamesLibrary.csproj +++ b/RiotGamesLibrary.csproj @@ -38,6 +38,7 @@ +