From e52eee1e2074c079f7c2bf6b5c3f1c778fb540eb Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Fri, 17 May 2024 18:16:28 +0200 Subject: [PATCH] Skip loading unneeded plugins via cli --- BottlesPlugin/Bottles.cs | 2 ++ GogIntegration/GogIntegration.cs | 2 ++ HideGamesMiddleware/HideGames.cs | 3 +++ ItchIoIntegration/ItchGameSource.cs | 1 + Launcher/Loader/App.cs | 14 ++++++++++---- Launcher/Loader/PluginLoader.cs | 2 +- Launcher/Middleware/MiddlewareBridge.cs | 2 ++ Launcher/Program.cs | 4 +++- Launcher/Views/GameViewSmall.axaml.cs | 2 +- LauncherGamePlugin/Enums/PluginType.cs | 9 +++++++++ LauncherGamePlugin/Interfaces/IGameSource.cs | 2 ++ LegendaryIntegration/LegendaryGameSource.cs | 2 ++ LocalGames/LocalGameSource.cs | 1 + SteamExporterPlugin/Exporter.cs | 2 ++ SteamGridDbMiddleware/SteamGridDb.cs | 2 ++ 15 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 LauncherGamePlugin/Enums/PluginType.cs diff --git a/BottlesPlugin/Bottles.cs b/BottlesPlugin/Bottles.cs index 9d73466..a8e9164 100644 --- a/BottlesPlugin/Bottles.cs +++ b/BottlesPlugin/Bottles.cs @@ -15,6 +15,8 @@ public class Bottles : IGameSource public string Version => "v1.0.8"; public string SlugServiceName => "bottles"; public string ShortServiceName => "bottles"; + public PluginType Type => PluginType.BootProfile; + private string _message = ""; private List _wrappers = new(); private List _games = new(); diff --git a/GogIntegration/GogIntegration.cs b/GogIntegration/GogIntegration.cs index ff2b1f6..6dea23f 100644 --- a/GogIntegration/GogIntegration.cs +++ b/GogIntegration/GogIntegration.cs @@ -6,6 +6,7 @@ using LauncherGamePlugin.Enums; using LauncherGamePlugin.Forms; using LauncherGamePlugin.Interfaces; +using LauncherGamePlugin.Launcher; using Newtonsoft.Json; namespace GogIntegration; @@ -16,6 +17,7 @@ public class GogIntegration : IGameSource public string Version => "v1.1.4"; public string SlugServiceName => "gog-integration"; public string ShortServiceName => "GOG"; + public PluginType Type => PluginType.GameSource; public IApp App { get; private set; } public Config Config => _storage.Data; diff --git a/HideGamesMiddleware/HideGames.cs b/HideGamesMiddleware/HideGames.cs index 4285814..e40074c 100644 --- a/HideGamesMiddleware/HideGames.cs +++ b/HideGamesMiddleware/HideGames.cs @@ -1,5 +1,6 @@ using LauncherGamePlugin; using LauncherGamePlugin.Commands; +using LauncherGamePlugin.Enums; using LauncherGamePlugin.Interfaces; namespace HideGamesMiddleware; @@ -12,6 +13,8 @@ public class HideGames : IGameSource public string ShortServiceName => SlugServiceName; public Storage Storage { get; set; } public IApp App { get; set; } + public PluginType Type => PluginType.Middleware; + public async Task Initialize(IApp app) { Storage = new(app, "hidegames.json"); diff --git a/ItchIoIntegration/ItchGameSource.cs b/ItchIoIntegration/ItchGameSource.cs index cef605e..268cc30 100644 --- a/ItchIoIntegration/ItchGameSource.cs +++ b/ItchIoIntegration/ItchGameSource.cs @@ -16,6 +16,7 @@ public class ItchGameSource : IGameSource public string Version => "v1.1.6"; public string SlugServiceName => "itch-io"; public string ShortServiceName => "Itch.io"; + public PluginType Type => PluginType.GameSource; private Config Config => _storage.Data; private Storage _storage; diff --git a/Launcher/Loader/App.cs b/Launcher/Loader/App.cs index e72a7c6..c611146 100644 --- a/Launcher/Loader/App.cs +++ b/Launcher/Loader/App.cs @@ -99,7 +99,7 @@ public LogType LogLevel public event Action OnPluginInitialised; - private async Task InitialiseService(IGameSource source) + private async Task InitializeService(IGameSource source) { Stopwatch stopwatch = new(); stopwatch.Start(); @@ -113,7 +113,7 @@ private async Task InitialiseService(IGameSource source) return source; } - public async Task InitializeGameSources() + public async Task InitializeGameSources(Func? loadPlugin = null) { if (_initialised) return; @@ -122,8 +122,14 @@ public async Task InitializeGameSources() List> tasks = new(); sources.ForEach(x => { - Logger.Log($"Initialising {x.ServiceName}..."); - tasks.Add(InitialiseService(x)); + if (loadPlugin != null && !loadPlugin(x)) + { + Logger.Log($"Skipping load for service {x.ServiceName}..."); + return; + } + + Logger.Log($"Initialising service {x.ServiceName}..."); + tasks.Add(InitializeService(x)); }); while (true) diff --git a/Launcher/Loader/PluginLoader.cs b/Launcher/Loader/PluginLoader.cs index b0e3e81..4774a1b 100644 --- a/Launcher/Loader/PluginLoader.cs +++ b/Launcher/Loader/PluginLoader.cs @@ -19,7 +19,7 @@ public static List AvailablePlugins() File.ReadAllLines(Path.GetFullPath(Path.Join(path, "..", "..", "..", "..", "..", "Plugins.txt"))) .Select(x => x.Trim()) .Where(x => !string.IsNullOrWhiteSpace(x)) - .Select(x => Path.GetFullPath(Path.Join(path, "..", "..", "..", "..", "..", x, "bin", "Debug", "net7.0", $"{x}.dll")))); + .Select(x => Path.GetFullPath(Path.Join(path, "..", "..", "..", "..", "..", x, "bin", "Debug", "net8.0", $"{x}.dll")))); #endif if (!Directory.Exists(path)) diff --git a/Launcher/Middleware/MiddlewareBridge.cs b/Launcher/Middleware/MiddlewareBridge.cs index 20294f4..931e6fe 100644 --- a/Launcher/Middleware/MiddlewareBridge.cs +++ b/Launcher/Middleware/MiddlewareBridge.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using LauncherGamePlugin; using LauncherGamePlugin.Commands; +using LauncherGamePlugin.Enums; using LauncherGamePlugin.Interfaces; using LauncherGamePlugin.Launcher; @@ -12,6 +13,7 @@ public class MiddlewareBridge : IGameSource public IGameSource Service { get; set; } public IServiceMiddleware? NextMiddleware { get; set; } public MiddlewareBridge? NextBridge { get; set; } + public PluginType Type => PluginType.Middleware; public MiddlewareBridge(IGameSource service, IServiceMiddleware? nextMiddleware, MiddlewareBridge? nextBridge) { diff --git a/Launcher/Program.cs b/Launcher/Program.cs index 22e852e..b298577 100644 --- a/Launcher/Program.cs +++ b/Launcher/Program.cs @@ -6,6 +6,7 @@ using Avalonia; using LauncherGamePlugin; using LauncherGamePlugin.Commands; +using LauncherGamePlugin.Enums; using LauncherGamePlugin.Extensions; using LauncherGamePlugin.Forms; using LauncherGamePlugin.Interfaces; @@ -20,6 +21,7 @@ internal class Program [STAThread] public static void Main(string[] args) { + args = new[] { "epic-games", "Salt", "Launch" }; AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; if (args.Length <= 2) @@ -32,7 +34,7 @@ public static void Start(string[] args) { Loader.App app = Loader.App.GetInstance(); app.HeadlessMode = true; - app.InitializeGameSources().GetAwaiter().GetResult(); + app.InitializeGameSources(gameSource => gameSource.Type != PluginType.GameSource || gameSource.SlugServiceName == args[0]).GetAwaiter().GetResult(); List allGames = app.GetGames().GetAwaiter().GetResult(); IGame? target = allGames.Find(x => x.Source.SlugServiceName == args[0] && x.InternalName == args[1]); if (target == null) diff --git a/Launcher/Views/GameViewSmall.axaml.cs b/Launcher/Views/GameViewSmall.axaml.cs index 0d2c928..bf5ead9 100644 --- a/Launcher/Views/GameViewSmall.axaml.cs +++ b/Launcher/Views/GameViewSmall.axaml.cs @@ -197,7 +197,7 @@ public List GetCommands() GameSession total = config.GetTotalTime(); if (total.TimeSpent.TotalSeconds > 0) { - string time = total.TimeSpent.ToString(@"hh\:mm"); + string time = total.TimeSpent.ToString(@"hh\hmm\m"); commands.Add(new($"Played for {time}")); } } diff --git a/LauncherGamePlugin/Enums/PluginType.cs b/LauncherGamePlugin/Enums/PluginType.cs new file mode 100644 index 0000000..e22c702 --- /dev/null +++ b/LauncherGamePlugin/Enums/PluginType.cs @@ -0,0 +1,9 @@ +namespace LauncherGamePlugin.Enums; + +public enum PluginType +{ + GameSource, + BootProfile, + Middleware, + Other +} \ No newline at end of file diff --git a/LauncherGamePlugin/Interfaces/IGameSource.cs b/LauncherGamePlugin/Interfaces/IGameSource.cs index 8959f73..fced1b9 100644 --- a/LauncherGamePlugin/Interfaces/IGameSource.cs +++ b/LauncherGamePlugin/Interfaces/IGameSource.cs @@ -1,4 +1,5 @@ using LauncherGamePlugin.Commands; +using LauncherGamePlugin.Enums; using LauncherGamePlugin.Launcher; namespace LauncherGamePlugin.Interfaces; @@ -9,6 +10,7 @@ public interface IGameSource string Version { get; } string SlugServiceName { get; } string ShortServiceName { get; } + PluginType Type { get; } public Task Initialize(IApp app); public async Task> GetBootProfiles() => new(); diff --git a/LegendaryIntegration/LegendaryGameSource.cs b/LegendaryIntegration/LegendaryGameSource.cs index 660e063..acdfdee 100644 --- a/LegendaryIntegration/LegendaryGameSource.cs +++ b/LegendaryIntegration/LegendaryGameSource.cs @@ -1,5 +1,6 @@ using LauncherGamePlugin; using LauncherGamePlugin.Commands; +using LauncherGamePlugin.Enums; using LauncherGamePlugin.Forms; using LauncherGamePlugin.Interfaces; using LauncherGamePlugin.Launcher; @@ -18,6 +19,7 @@ public class LegendaryGameSource : IGameSource public string Version => "v1.2.4"; public string SlugServiceName => "epic-games"; public string ShortServiceName => "EpicGames"; + public PluginType Type => PluginType.GameSource; public LegendaryAuth? auth; public LegendaryGameManager? manager; public static LegendaryGameSource Source { get; private set; } diff --git a/LocalGames/LocalGameSource.cs b/LocalGames/LocalGameSource.cs index 9705ee5..9109029 100644 --- a/LocalGames/LocalGameSource.cs +++ b/LocalGames/LocalGameSource.cs @@ -17,6 +17,7 @@ public class LocalGameSource : IGameSource public string ShortServiceName => "Local"; public string Version => "v2.0.1"; public string SlugServiceName => "local-games"; + public PluginType Type => PluginType.GameSource; private IApp _app; public List Games => _storage.Data.LocalGames; diff --git a/SteamExporterPlugin/Exporter.cs b/SteamExporterPlugin/Exporter.cs index da6c886..f4b0b0c 100644 --- a/SteamExporterPlugin/Exporter.cs +++ b/SteamExporterPlugin/Exporter.cs @@ -16,6 +16,8 @@ public class Exporter : IGameSource public string Version => "v1.2.7"; public string SlugServiceName => "steam-exporter"; public string ShortServiceName => "Steam"; + public PluginType Type => PluginType.BootProfile; + public IApp? App { get; private set; } private bool _initialised = false; private ProtonManager? _protonManager; diff --git a/SteamGridDbMiddleware/SteamGridDb.cs b/SteamGridDbMiddleware/SteamGridDb.cs index bc55519..07378cf 100644 --- a/SteamGridDbMiddleware/SteamGridDb.cs +++ b/SteamGridDbMiddleware/SteamGridDb.cs @@ -15,6 +15,8 @@ public class SteamGridDb : IGameSource public string Version => "v1.2.2"; public string SlugServiceName => "steam-grid-db"; public string ShortServiceName => "steamgriddb"; + public PluginType Type => PluginType.Middleware; + public IApp App { get; set; } public craftersmine.SteamGridDBNet.SteamGridDb? Api { get; set; } public Storage Storage { get; set; }