Skip to content

Feature: Added "install" toolbar button for certificate files #12518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/Files.App/Actions/Content/Install/InstallCertificateAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Shell;
using Files.Backend.Helpers;

namespace Files.App.Actions;

internal class InstallCertificateAction : ObservableObject, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

public string Label => "Install".GetLocalizedResource();

public string Description => "InstallCertificateDescription".GetLocalizedResource();

public RichGlyph Glyph { get; } = new("\uEB95");

public bool IsExecutable => context.SelectedItems.Any() &&
context.SelectedItems.All(x => FileExtensionHelpers.IsCertificateFile(x.FileExtension)) &&
context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder;

public InstallCertificateAction()
{
context.PropertyChanged += Context_PropertyChanged;
}

public async Task ExecuteAsync()
{
await ContextMenu.InvokeVerb("add", context.SelectedItems.Select(x => x.ItemPath).ToArray());
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(IContentPageContext.SelectedItems))
{
OnPropertyChanged(nameof(IsExecutable));
}
}
}
1 change: 1 addition & 0 deletions src/Files.App/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public enum CommandCodes
// Install
InstallFont,
InstallInfDriver,
InstallCertificate,

// Run
RunAsAdmin,
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public IRichCommand this[HotKey hotKey]
public IRichCommand DeleteItemPermanently => commands[CommandCodes.DeleteItemPermanently];
public IRichCommand InstallFont => commands[CommandCodes.InstallFont];
public IRichCommand InstallInfDriver => commands[CommandCodes.InstallInfDriver];
public IRichCommand InstallCertificate => commands[CommandCodes.InstallCertificate];
public IRichCommand RunAsAdmin => commands[CommandCodes.RunAsAdmin];
public IRichCommand RunAsAnotherUser => commands[CommandCodes.RunAsAnotherUser];
public IRichCommand RunWithPowershell => commands[CommandCodes.RunWithPowershell];
Expand Down Expand Up @@ -219,6 +220,7 @@ public CommandManager()
[CommandCodes.DeleteItemPermanently] = new DeleteItemPermanentlyAction(),
[CommandCodes.InstallFont] = new InstallFontAction(),
[CommandCodes.InstallInfDriver] = new InstallInfDriverAction(),
[CommandCodes.InstallCertificate] = new InstallCertificateAction(),
[CommandCodes.RunAsAdmin] = new RunAsAdminAction(),
[CommandCodes.RunAsAnotherUser] = new RunAsAnotherUserAction(),
[CommandCodes.RunWithPowershell] = new RunWithPowershellAction(),
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>

IRichCommand InstallFont { get; }
IRichCommand InstallInfDriver { get; }
IRichCommand InstallCertificate { get; }

IRichCommand RunAsAdmin { get; }
IRichCommand RunAsAnotherUser { get; }
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2724,6 +2724,9 @@
<data name="InstallInfDriverDescription" xml:space="preserve">
<value>Install driver(s) using selected inf file(s)</value>
</data>
<data name="InstallCertificateDescription" xml:space="preserve">
<value>Install selected certificate(s)</value>
</data>
<data name="RunAsAdminDescription" xml:space="preserve">
<value>Run selected application as administrator</value>
</data>
Expand Down
13 changes: 13 additions & 0 deletions src/Files.App/UserControls/InnerNavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,19 @@
<!-- TODO: Add Icon -->
</AppBarButton>

<!-- Install Certificate -->
<AppBarButton
x:Name="InstallCertificateButton"
x:Load="{x:Bind Commands.InstallCertificate.IsExecutable, Mode=OneWay, FallbackValue=False}"
Command="{x:Bind Commands.InstallCertificate, Mode=OneWay}"
Label="{x:Bind Commands.InstallCertificate.Label}"
LabelPosition="Default"
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}">
<AppBarButton.Icon>
<FontIcon Glyph="{x:Bind Commands.InstallCertificate.Glyph.BaseGlyph, Mode=OneTime}" />
</AppBarButton.Icon>
</AppBarButton>

<!-- Play All Media -->
<AppBarButton
x:Name="PlayAllMediaButton"
Expand Down
9 changes: 8 additions & 1 deletion src/Files.Backend/Helpers/FileExtensionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ public static bool IsVhdFile(string? fileExtensionToCheck)
public static bool IsMediaFile(string? filePathToCheck)
=> HasExtension(filePathToCheck, ".mp4", ".m4v", ".mp4v", ".3g2", ".3gp2", ".3gp", ".3gpp",
".mpg", ".mp2", ".mpeg", ".mpe", ".mpv", ".ogg", ".avi", ".wmv", ".mov", ".qt");

/// <summary>
/// Check if the file extension is a certificate file.
/// </summary>
/// <param name="filePathToCheck"></param>
/// <returns><c>true</c> if the filePathToCheck is a certificate file;
/// otherwise <c>false</c>.</returns>
public static bool IsCertificateFile(string? filePathToCheck)
=> HasExtension(filePathToCheck, ".cer", ".crt", ".der", ".pfx");
}
}