Skip to content

Commit 11aca8f

Browse files
authored
Feature: Added "install" toolbar button for certificate files (#12518)
1 parent 5545578 commit 11aca8f

File tree

7 files changed

+68
-1
lines changed

7 files changed

+68
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+

2+
using Files.App.Commands;
3+
using Files.App.Contexts;
4+
using Files.App.Shell;
5+
using Files.Backend.Helpers;
6+
7+
namespace Files.App.Actions;
8+
9+
internal class InstallCertificateAction : ObservableObject, IAction
10+
{
11+
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();
12+
13+
public string Label => "Install".GetLocalizedResource();
14+
15+
public string Description => "InstallCertificateDescription".GetLocalizedResource();
16+
17+
public RichGlyph Glyph { get; } = new("\uEB95");
18+
19+
public bool IsExecutable => context.SelectedItems.Any() &&
20+
context.SelectedItems.All(x => FileExtensionHelpers.IsCertificateFile(x.FileExtension)) &&
21+
context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder;
22+
23+
public InstallCertificateAction()
24+
{
25+
context.PropertyChanged += Context_PropertyChanged;
26+
}
27+
28+
public async Task ExecuteAsync()
29+
{
30+
await ContextMenu.InvokeVerb("add", context.SelectedItems.Select(x => x.ItemPath).ToArray());
31+
}
32+
33+
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
34+
{
35+
if (e.PropertyName == nameof(IContentPageContext.SelectedItems))
36+
{
37+
OnPropertyChanged(nameof(IsExecutable));
38+
}
39+
}
40+
}

src/Files.App/Commands/CommandCodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public enum CommandCodes
7474
// Install
7575
InstallFont,
7676
InstallInfDriver,
77+
InstallCertificate,
7778

7879
// Run
7980
RunAsAdmin,

src/Files.App/Commands/Manager/CommandManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public IRichCommand this[HotKey hotKey]
6969
public IRichCommand DeleteItemPermanently => commands[CommandCodes.DeleteItemPermanently];
7070
public IRichCommand InstallFont => commands[CommandCodes.InstallFont];
7171
public IRichCommand InstallInfDriver => commands[CommandCodes.InstallInfDriver];
72+
public IRichCommand InstallCertificate => commands[CommandCodes.InstallCertificate];
7273
public IRichCommand RunAsAdmin => commands[CommandCodes.RunAsAdmin];
7374
public IRichCommand RunAsAnotherUser => commands[CommandCodes.RunAsAnotherUser];
7475
public IRichCommand RunWithPowershell => commands[CommandCodes.RunWithPowershell];
@@ -219,6 +220,7 @@ public CommandManager()
219220
[CommandCodes.DeleteItemPermanently] = new DeleteItemPermanentlyAction(),
220221
[CommandCodes.InstallFont] = new InstallFontAction(),
221222
[CommandCodes.InstallInfDriver] = new InstallInfDriverAction(),
223+
[CommandCodes.InstallCertificate] = new InstallCertificateAction(),
222224
[CommandCodes.RunAsAdmin] = new RunAsAdminAction(),
223225
[CommandCodes.RunAsAnotherUser] = new RunAsAnotherUserAction(),
224226
[CommandCodes.RunWithPowershell] = new RunWithPowershellAction(),

src/Files.App/Commands/Manager/ICommandManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
6565

6666
IRichCommand InstallFont { get; }
6767
IRichCommand InstallInfDriver { get; }
68+
IRichCommand InstallCertificate { get; }
6869

6970
IRichCommand RunAsAdmin { get; }
7071
IRichCommand RunAsAnotherUser { get; }

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,6 +2724,9 @@
27242724
<data name="InstallInfDriverDescription" xml:space="preserve">
27252725
<value>Install driver(s) using selected inf file(s)</value>
27262726
</data>
2727+
<data name="InstallCertificateDescription" xml:space="preserve">
2728+
<value>Install selected certificate(s)</value>
2729+
</data>
27272730
<data name="RunAsAdminDescription" xml:space="preserve">
27282731
<value>Run selected application as administrator</value>
27292732
</data>

src/Files.App/UserControls/InnerNavigationToolbar.xaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,19 @@
400400
<!-- TODO: Add Icon -->
401401
</AppBarButton>
402402

403+
<!-- Install Certificate -->
404+
<AppBarButton
405+
x:Name="InstallCertificateButton"
406+
x:Load="{x:Bind Commands.InstallCertificate.IsExecutable, Mode=OneWay, FallbackValue=False}"
407+
Command="{x:Bind Commands.InstallCertificate, Mode=OneWay}"
408+
Label="{x:Bind Commands.InstallCertificate.Label}"
409+
LabelPosition="Default"
410+
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}">
411+
<AppBarButton.Icon>
412+
<FontIcon Glyph="{x:Bind Commands.InstallCertificate.Glyph.BaseGlyph, Mode=OneTime}" />
413+
</AppBarButton.Icon>
414+
</AppBarButton>
415+
403416
<!-- Play All Media -->
404417
<AppBarButton
405418
x:Name="PlayAllMediaButton"

src/Files.Backend/Helpers/FileExtensionHelpers.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ public static bool IsVhdFile(string? fileExtensionToCheck)
144144
public static bool IsMediaFile(string? filePathToCheck)
145145
=> HasExtension(filePathToCheck, ".mp4", ".m4v", ".mp4v", ".3g2", ".3gp2", ".3gp", ".3gpp",
146146
".mpg", ".mp2", ".mpeg", ".mpe", ".mpv", ".ogg", ".avi", ".wmv", ".mov", ".qt");
147-
147+
/// <summary>
148+
/// Check if the file extension is a certificate file.
149+
/// </summary>
150+
/// <param name="filePathToCheck"></param>
151+
/// <returns><c>true</c> if the filePathToCheck is a certificate file;
152+
/// otherwise <c>false</c>.</returns>
153+
public static bool IsCertificateFile(string? filePathToCheck)
154+
=> HasExtension(filePathToCheck, ".cer", ".crt", ".der", ".pfx");
148155
}
149156
}

0 commit comments

Comments
 (0)