@@ -165,26 +165,19 @@ public static Task StartSTATask(Action action)
165
165
166
166
public static async Task < string ? > GetFileAssociationAsync ( string filename , bool checkDesktopFirst = false )
167
167
{
168
- // Find UWP apps
169
- async Task < string ? > GetUwpAssoc ( )
170
- {
171
- var uwpApps = await Launcher . FindFileHandlersAsync ( Path . GetExtension ( filename ) ) ;
172
- return uwpApps . Any ( ) ? uwpApps [ 0 ] . PackageFamilyName : null ;
173
- }
174
-
175
- // Find desktop apps
176
- string ? GetDesktopAssoc ( )
177
- {
178
- var lpResult = new StringBuilder ( 2048 ) ;
179
- var hResult = Shell32 . FindExecutable ( filename , null , lpResult ) ;
180
-
181
- return hResult . ToInt64 ( ) > 32 ? lpResult . ToString ( ) : null ;
182
- }
183
-
184
168
if ( checkDesktopFirst )
185
- return GetDesktopAssoc ( ) ?? await GetUwpAssoc ( ) ;
169
+ return GetDesktopFileAssociation ( filename ) ?? ( await GetUwpFileAssociations ( filename ) ) . FirstOrDefault ( ) ;
186
170
187
- return await GetUwpAssoc ( ) ?? GetDesktopAssoc ( ) ;
171
+ return ( await GetUwpFileAssociations ( filename ) ) . FirstOrDefault ( ) ?? GetDesktopFileAssociation ( filename ) ;
172
+ }
173
+
174
+ public static async Task < IEnumerable < string > > GetAllFileAssociationsAsync ( string filename )
175
+ {
176
+ var uwpApps = await GetUwpFileAssociations ( filename ) ;
177
+ var desktopApp = GetDesktopFileAssociation ( filename ) ;
178
+ return desktopApp is not null
179
+ ? uwpApps . Append ( desktopApp )
180
+ : uwpApps ;
188
181
}
189
182
190
183
public static string ExtractStringFromDLL ( string file , int number )
@@ -1210,5 +1203,17 @@ public static bool GetWin32FindDataForPath(string targetPath, out Win32PInvoke.W
1210
1203
1211
1204
return false ;
1212
1205
}
1206
+ private static async Task < IEnumerable < string > > GetUwpFileAssociations ( string filename )
1207
+ {
1208
+ var uwpApps = await Launcher . FindFileHandlersAsync ( Path . GetExtension ( filename ) ) ;
1209
+ return uwpApps . Select ( x => x . PackageFamilyName ) ;
1210
+ }
1211
+
1212
+ private static string ? GetDesktopFileAssociation ( string filename )
1213
+ {
1214
+ var lpResult = new StringBuilder ( 2048 ) ;
1215
+ var hResult = Shell32 . FindExecutable ( filename , null , lpResult ) ;
1216
+ return hResult . ToInt64 ( ) > 32 ? lpResult . ToString ( ) : null ;
1217
+ }
1213
1218
}
1214
1219
}
0 commit comments