44namespace GamesLauncher . Platforms . SyncEngines
55{
66 public class ShortcutsSyncEngine : ISyncEngine
7-
87 {
98 public string PlatformName => "Shortcut" ;
9+ public IEnumerable < Game > SynchronizedGames { get ; private set ; } = Array . Empty < Game > ( ) ;
1010
1111 private readonly IPublicAPI publicApi ;
1212 private readonly DirectoryInfo shortcutsDirectory ;
@@ -17,23 +17,30 @@ public ShortcutsSyncEngine(IPublicAPI publicApi)
1717 shortcutsDirectory = Directory . CreateDirectory ( Paths . CustomShortcutsDirectory ) ;
1818 }
1919
20- public async IAsyncEnumerable < Game > GetGames ( )
20+ public async Task SynchronizeGames ( )
2121 {
2222 string [ ] shortcutExtensions = { "*.url" , "*.lnk" } ;
23+ var syncedGames = new List < Game > ( ) ;
2324
2425 foreach ( var shortcutExtension in shortcutExtensions )
2526 {
2627 foreach ( var shortcut in shortcutsDirectory . EnumerateFiles ( shortcutExtension , SearchOption . AllDirectories ) )
2728 {
28- yield return new Game (
29- Title : Path . GetFileNameWithoutExtension ( shortcut . FullName ) ,
30- RunTask : GetGameRunTask ( shortcut . FullName ) ,
31- IconPath : await GetIconPath ( shortcut ) ,
32- IconDelegate : null ,
33- Platform : PlatformName
34- ) ;
29+ syncedGames . Add ( new Game (
30+ title : Path . GetFileNameWithoutExtension ( shortcut . FullName ) ,
31+ runTask : GetGameRunTask ( shortcut . FullName ) ,
32+ iconPath : await GetIconPath ( shortcut ) ,
33+ iconDelegate : null ,
34+ platform : PlatformName ,
35+ uninstallAction : new (
36+ GetShortcutDeleteTask ( shortcut . FullName ) ,
37+ "Delete Shortcut"
38+ )
39+ ) ) ;
3540 }
3641 }
42+
43+ SynchronizedGames = syncedGames ;
3744 }
3845
3946 private Func < ActionContext , ValueTask < bool > > GetGameRunTask ( string fullPath )
@@ -46,6 +53,15 @@ private Func<ActionContext, ValueTask<bool>> GetGameRunTask(string fullPath)
4653 } ;
4754 }
4855
56+ private Func < Task > GetShortcutDeleteTask ( string fullPath )
57+ {
58+ return async ( ) =>
59+ {
60+ File . Delete ( fullPath ) ;
61+ await SynchronizeGames ( ) ;
62+ } ;
63+ }
64+
4965 private static async Task < string ? > GetIconPath ( FileInfo fileInfo )
5066 {
5167 if ( fileInfo . Extension == ".url" )
0 commit comments