Skip to content

Commit a2f583e

Browse files
Move to helper
1 parent c11b812 commit a2f583e

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

src/Files.App/Data/Factories/PropertiesNavigationViewItemFactory.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,12 @@
33

44
using Files.Shared.Helpers;
55
using Microsoft.UI.Xaml;
6-
using System.Collections.Frozen;
76
using Windows.Storage;
87

98
namespace Files.App.Data.Factories
109
{
1110
public static class PropertiesNavigationViewItemFactory
1211
{
13-
private static readonly FrozenSet<string> _signableTypes = new HashSet<string>()
14-
{
15-
".aab", ".apk", ".application", ".appx", ".appxbundle", ".arx", ".cab", ".cat", ".cbx",
16-
".cpl", ".crx", ".dbx", ".deploy", ".dll", ".doc", ".docm", ".dot", ".dotm", ".drx",
17-
".ear", ".efi", ".exe", ".jar", ".js", ".manifest", ".mpp", ".mpt", ".msi", ".msix",
18-
".msixbundle", ".msm", ".msp", ".nupkg", ".ocx", ".pot", ".potm", ".ppa", ".ppam", ".pps",
19-
".ppsm", ".ppt", ".pptm", ".ps1", ".psm1", ".psi", ".pub", ".sar", ".stl", ".sys", ".vbs",
20-
".vdw", ".vdx", ".vsd", ".vsdm", ".vss", ".vssm", ".vst", ".vstm", ".vsto", ".vsix", ".vsx", ".vtx",
21-
".vxd", ".war", ".wiz", ".wsf", ".xap", ".xla", ".xlam", ".xls", ".xlsb", ".xlsm", ".xlt",
22-
".xltm", ".xlsm", ".xsn"
23-
}.ToFrozenSet();
24-
2512
public static ObservableCollection<NavigationViewItemButtonStyleItem> Initialize(object item)
2613
{
2714
ObservableCollection<NavigationViewItemButtonStyleItem> PropertiesNavigationViewItems = [];
@@ -123,7 +110,11 @@ public static ObservableCollection<NavigationViewItemButtonStyleItem> Initialize
123110
var detailsItemEnabled = !(isFolder && !listedItem.IsArchive) && !isLibrary && !listedItem.IsRecycleBinItem;
124111
var customizationItemEnabled = !isLibrary && (isFolder && !listedItem.IsArchive || isShortcut && !listedItem.IsLinkItem);
125112
var compatibilityItemEnabled = FileExtensionHelpers.IsExecutableFile(listedItem is IShortcutItem sht ? sht.TargetPath : fileExt, true);
126-
var signaturesItemEnabled = !isFolder && !isLibrary && !listedItem.IsRecycleBinItem && _signableTypes.Contains(fileExt);
113+
var signaturesItemEnabled =
114+
!isFolder &&
115+
!isLibrary &&
116+
!listedItem.IsRecycleBinItem &&
117+
FileExtensionHelpers.IsSignableFile(fileExt, true);
127118

128119
if (!securityItemEnabled)
129120
PropertiesNavigationViewItems.Remove(securityItem);

src/Files.Shared/Helpers/FileExtensionHelpers.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Collections.Frozen;
6+
using System.Collections.Generic;
57
using System.IO;
68
using 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

Comments
 (0)