@@ -28,26 +28,19 @@ public static partial class Win32Helper
2828 {
2929 public static async Task < string ? > GetFileAssociationAsync ( string filename , bool checkDesktopFirst = false )
3030 {
31- // Find UWP apps
32- async Task < string ? > GetUwpAssoc ( )
33- {
34- var uwpApps = await Launcher . FindFileHandlersAsync ( Path . GetExtension ( filename ) ) ;
35- return uwpApps . Any ( ) ? uwpApps [ 0 ] . PackageFamilyName : null ;
36- }
37-
38- // Find desktop apps
39- string ? GetDesktopAssoc ( )
40- {
41- var lpResult = new StringBuilder ( 2048 ) ;
42- var hResult = Shell32 . FindExecutable ( filename , null , lpResult ) ;
43-
44- return hResult . ToInt64 ( ) > 32 ? lpResult . ToString ( ) : null ;
45- }
46-
4731 if ( checkDesktopFirst )
48- return GetDesktopAssoc ( ) ?? await GetUwpAssoc ( ) ;
32+ return GetDesktopFileAssociation ( filename ) ?? ( await GetUwpFileAssociations ( filename ) ) . FirstOrDefault ( ) ;
4933
50- return await GetUwpAssoc ( ) ?? GetDesktopAssoc ( ) ;
34+ return ( await GetUwpFileAssociations ( filename ) ) . FirstOrDefault ( ) ?? GetDesktopFileAssociation ( filename ) ;
35+ }
36+
37+ public static async Task < IEnumerable < string > > GetAllFileAssociationsAsync ( string filename )
38+ {
39+ var uwpApps = await GetUwpFileAssociations ( filename ) ;
40+ var desktopApp = GetDesktopFileAssociation ( filename ) ;
41+ return desktopApp is not null
42+ ? uwpApps . Append ( desktopApp )
43+ : uwpApps ;
5144 }
5245
5346 public static string ExtractStringFromDLL ( string file , int number )
@@ -1073,5 +1066,17 @@ public static bool GetWin32FindDataForPath(string targetPath, out Win32PInvoke.W
10731066
10741067 return false ;
10751068 }
1069+ private static async Task < IEnumerable < string > > GetUwpFileAssociations ( string filename )
1070+ {
1071+ var uwpApps = await Launcher . FindFileHandlersAsync ( Path . GetExtension ( filename ) ) ;
1072+ return uwpApps . Select ( x => x . PackageFamilyName ) ;
1073+ }
1074+
1075+ private static string ? GetDesktopFileAssociation ( string filename )
1076+ {
1077+ var lpResult = new StringBuilder ( 2048 ) ;
1078+ var hResult = Shell32 . FindExecutable ( filename , null , lpResult ) ;
1079+ return hResult . ToInt64 ( ) > 32 ? lpResult . ToString ( ) : null ;
1080+ }
10761081 }
10771082}
0 commit comments