22// Licensed under the MIT License.
33
44using System ;
5+ using System . Collections . Frozen ;
6+ using System . Collections . Generic ;
57using System . IO ;
68using System . Linq ;
79
@@ -12,6 +14,18 @@ namespace Files.Shared.Helpers
1214 /// </summary>
1315 public static class FileExtensionHelpers
1416 {
17+ private static readonly FrozenSet < string > _signableTypes = new HashSet < string > ( )
18+ {
19+ ".aab" , ".apk" , ".application" , ".appx" , ".appxbundle" , ".arx" , ".cab" , ".cat" , ".cbx" ,
20+ ".cpl" , ".crx" , ".dbx" , ".deploy" , ".dll" , ".doc" , ".docm" , ".dot" , ".dotm" , ".drx" ,
21+ ".ear" , ".efi" , ".exe" , ".jar" , ".js" , ".manifest" , ".mpp" , ".mpt" , ".msi" , ".msix" ,
22+ ".msixbundle" , ".msm" , ".msp" , ".nupkg" , ".ocx" , ".pot" , ".potm" , ".ppa" , ".ppam" , ".pps" ,
23+ ".ppsm" , ".ppt" , ".pptm" , ".ps1" , ".psm1" , ".psi" , ".pub" , ".sar" , ".stl" , ".sys" , ".vbs" ,
24+ ".vdw" , ".vdx" , ".vsd" , ".vsdm" , ".vss" , ".vssm" , ".vst" , ".vstm" , ".vsto" , ".vsix" , ".vsx" , ".vtx" ,
25+ ".vxd" , ".war" , ".wiz" , ".wsf" , ".xap" , ".xla" , ".xlam" , ".xls" , ".xlsb" , ".xlsm" , ".xlt" ,
26+ ".xltm" , ".xlsm" , ".xsn"
27+ } . ToFrozenSet ( ) ;
28+
1529 /// <summary>
1630 /// Check if the file extension matches one of the specified extensions.
1731 /// </summary>
@@ -273,5 +287,20 @@ public static bool IsSystemFile(string? filePathToCheck)
273287 return HasExtension ( filePathToCheck , ".dll" , ".exe" , ".sys" , ".inf" ) ;
274288 }
275289
290+ /// <summary>
291+ /// Check if the file is signable.
292+ /// </summary>
293+ /// <param name="filePathToCheck"></param>
294+ /// <returns><c>true</c> if the filePathToCheck is a signable file; otherwise, <c>false</c>.</returns>
295+ public static bool IsSignableFile ( string ? filePathToCheck , bool isExtension = false )
296+ {
297+ if ( string . IsNullOrWhiteSpace ( filePathToCheck ) )
298+ return false ;
299+
300+ if ( ! isExtension )
301+ filePathToCheck = Path . GetExtension ( filePathToCheck ) ;
302+
303+ return _signableTypes . Contains ( filePathToCheck ) ;
304+ }
276305 }
277306}
0 commit comments