diff --git a/README.md b/README.md index 6e0c647..b0683ba 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ GamesLauncher is a plugin for [Flow launcher](https://github.com/Flow-Launcher/F * Epic Games Launcher * Xbox * Amazon Games +* [Custom Shortcuts](#custom-shortcuts) ## Installation In Flow Launcher, use the plugin store to find "GamesLauncher" or type: @@ -39,6 +40,13 @@ You can disable specific platforms via settings menu. +### Custom shortcuts +If you have retail games (or on an unsupported platform) you can add your own shortcuts files (.lnk / .uri) to the plugin games list. + +To do this, go to Settings -> Plugins -> GamesLauncher -> Open Custom Shortcuts Directory + +Place your shortcut in the opened directory and... That's it! You can now `Reload Plugin Data` to update your library. + ### Update library If you have (un)installed a game, you can update the plugin without restarting Flow Launcher by using the `Reload Plugin Data` command. diff --git a/docs/settings.png b/docs/settings.png index d6cc037..d82fc90 100644 Binary files a/docs/settings.png and b/docs/settings.png differ diff --git a/src/GamesLauncher.Common/Paths.cs b/src/GamesLauncher.Common/Paths.cs new file mode 100644 index 0000000..d8a125b --- /dev/null +++ b/src/GamesLauncher.Common/Paths.cs @@ -0,0 +1,9 @@ +namespace GamesLauncher.Common +{ + public static class Paths + { + public static string CustomShortcutsDirectory => Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "FlowLauncher", "Settings", "Plugins", "GamesLauncher Custom Shortcuts"); + } +} diff --git a/src/GamesLauncher.Platforms/GamesLauncher.Platforms.csproj b/src/GamesLauncher.Platforms/GamesLauncher.Platforms.csproj index 97b746f..e7042f3 100644 --- a/src/GamesLauncher.Platforms/GamesLauncher.Platforms.csproj +++ b/src/GamesLauncher.Platforms/GamesLauncher.Platforms.csproj @@ -20,7 +20,7 @@ - + diff --git a/src/GamesLauncher.Platforms/PlatformsManager.cs b/src/GamesLauncher.Platforms/PlatformsManager.cs index 7e61d2f..16027d6 100644 --- a/src/GamesLauncher.Platforms/PlatformsManager.cs +++ b/src/GamesLauncher.Platforms/PlatformsManager.cs @@ -42,9 +42,11 @@ private IEnumerable InitializeEngines(MainSettings settings) if (settings.SynchronizeSteam) engines.Add(new SteamSyncEngine(publicApi)); - if(settings.SynchronizeAmazon) + if (settings.SynchronizeAmazon) engines.Add(new AmazonSyncEngine(publicApi)); + engines.Add(new ShortcutsSyncEngine(publicApi)); + return engines; } diff --git a/src/GamesLauncher.Platforms/SyncEngines/ShortcutsSyncEngine.cs b/src/GamesLauncher.Platforms/SyncEngines/ShortcutsSyncEngine.cs new file mode 100644 index 0000000..3c8a01b --- /dev/null +++ b/src/GamesLauncher.Platforms/SyncEngines/ShortcutsSyncEngine.cs @@ -0,0 +1,71 @@ +using Flow.Launcher.Plugin; +using GamesLauncher.Common; + +namespace GamesLauncher.Platforms.SyncEngines +{ + public class ShortcutsSyncEngine : ISyncEngine + + { + public string PlatformName => "Shortcut"; + + private readonly IPublicAPI publicApi; + private readonly DirectoryInfo shortcutsDirectory; + + public ShortcutsSyncEngine(IPublicAPI publicApi) + { + this.publicApi = publicApi; + shortcutsDirectory = Directory.CreateDirectory(Paths.CustomShortcutsDirectory); + } + + public async IAsyncEnumerable GetGames() + { + string[] shortcutExtensions = { "*.url", "*.lnk" }; + + foreach (var shortcutExtension in shortcutExtensions) + { + foreach (var shortcut in shortcutsDirectory.EnumerateFiles(shortcutExtension, SearchOption.AllDirectories)) + { + yield return new Game( + Title: Path.GetFileNameWithoutExtension(shortcut.FullName), + RunTask: GetGameRunTask(shortcut.FullName), + IconPath: await GetIconPath(shortcut), + IconDelegate: null, + Platform: PlatformName + ); + } + } + } + + private Func> GetGameRunTask(string fullPath) + { + return (context) => + { + publicApi.ShellRun($"start \"\" \"{fullPath}\""); + + return ValueTask.FromResult(true); + }; + } + + private static async Task GetIconPath(FileInfo fileInfo) + { + if (fileInfo.Extension == ".lnk") + { + return fileInfo.FullName; //TODO: Take ico location path directly from lnk like it's done for url below. Flow Launcher weridly handles lnk icons + } + + if (fileInfo.Extension == ".url") + { + await foreach (var line in File.ReadLinesAsync(fileInfo.FullName)) + { + if (line.Trim().StartsWith("IconFile=")) + { + return line.Replace("IconFile=", "").Trim(); + } + } + } + + return null; + } + + } +} diff --git a/src/GamesLauncher/GamesLauncher.csproj b/src/GamesLauncher/GamesLauncher.csproj index d4b4504..6e602df 100644 --- a/src/GamesLauncher/GamesLauncher.csproj +++ b/src/GamesLauncher/GamesLauncher.csproj @@ -8,7 +8,6 @@ https://github.com/KrystianLesniak/Flow.Launcher.Plugin.GamesLauncher flow-launcher flow-plugin true - false true true $(NoWarn);CS1591 @@ -16,6 +15,12 @@ false + + false + false + $([System.Environment]::GetFolderPath(SpecialFolder.ApplicationData))\FlowLauncher\Plugins\$(AssemblyName) + + false None diff --git a/src/GamesLauncher/Main.cs b/src/GamesLauncher/Main.cs index 4514200..21c7281 100644 --- a/src/GamesLauncher/Main.cs +++ b/src/GamesLauncher/Main.cs @@ -50,7 +50,7 @@ public Task> QueryAsync(Query query, CancellationToken token) public Control CreateSettingPanel() { - return new SettingsView(_settings); + return new SettingsView(_settings, _publicApi); } private Result CreateResultFromGame(Game game, string search) diff --git a/src/GamesLauncher/Views/SettingsView.xaml b/src/GamesLauncher/Views/SettingsView.xaml index b9b9bae..8afd320 100644 --- a/src/GamesLauncher/Views/SettingsView.xaml +++ b/src/GamesLauncher/Views/SettingsView.xaml @@ -15,6 +15,7 @@ + + diff --git a/src/GamesLauncher/Views/SettingsView.xaml.cs b/src/GamesLauncher/Views/SettingsView.xaml.cs index 9d222d5..824f990 100644 --- a/src/GamesLauncher/Views/SettingsView.xaml.cs +++ b/src/GamesLauncher/Views/SettingsView.xaml.cs @@ -1,4 +1,6 @@ -using GamesLauncher.Common.Settings; +using Flow.Launcher.Plugin; +using GamesLauncher.Common; +using GamesLauncher.Common.Settings; using System.Windows; using System.Windows.Controls; @@ -7,11 +9,13 @@ namespace GamesLauncher.Views public partial class SettingsView : UserControl { private readonly MainSettings _settings; + private readonly IPublicAPI _publicAPI; - public SettingsView(MainSettings settings) + public SettingsView(MainSettings settings, IPublicAPI publicAPI) { InitializeComponent(); _settings = settings; + _publicAPI = publicAPI; } private void SettingsView_OnLoaded(object sender, RoutedEventArgs re) @@ -57,5 +61,10 @@ private void SettingsView_OnLoaded(object sender, RoutedEventArgs re) _settings.SynchronizeAmazon = false; }; } + + private void BtnOpenCustomShortcutsDirectory_Click(object sender, RoutedEventArgs e) + { + _publicAPI.ShellRun(Paths.CustomShortcutsDirectory, "explorer.exe"); + } } } diff --git a/src/GamesLauncher/plugin.json b/src/GamesLauncher/plugin.json index 55369e2..fe363c9 100644 --- a/src/GamesLauncher/plugin.json +++ b/src/GamesLauncher/plugin.json @@ -4,7 +4,7 @@ "Name": "GamesLauncher", "Description": "Search and launch games from multiple platforms like Steam, Epic Games, Xbox etc.", "Author": "KrystianLesniak", - "Version": "1.3.0", + "Version": "1.4.0", "Language": "csharp", "Website": "https://github.com/KrystianLesniak/Flow.Launcher.Plugin.GamesLauncher", "IcoPath": "icon.png",