Skip to content
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

RichCommand: Install Inf Driver #11812

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class InstallFontAction : ObservableObject, IAction

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

public InstallFontAction()
{
Expand Down
49 changes: 49 additions & 0 deletions src/Files.App/Actions/Content/Install/InstallInfDriverAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Commands;
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.Filesystem;
using Files.App.Shell;
using Files.Backend.Helpers;
using System.Threading.Tasks;

namespace Files.App.Actions
{
internal class InstallInfDriverAction : ObservableObject, IAction
{
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>();

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

public string Description => "TODO: Need to be described.";

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

public bool IsExecutable => context.SelectedItems.Count == 1 &&
FileExtensionHelpers.IsInfFile(context.SelectedItems[0].FileExtension) &&
context.PageType is not ContentPageTypes.RecycleBin and not ContentPageTypes.ZipFolder;

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

public async Task ExecuteAsync()
{
foreach (ListedItem selectedItem in context.SelectedItems)
await Win32API.InstallInf(selectedItem.ItemPath);
}

public void Context_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.SelectedItems):
case nameof(IContentPageContext.PageType):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using Files.App.Contexts;
using Files.App.Extensions;
using Files.App.Helpers;
using Files.App.Shell;
using Files.Backend.Helpers;
using System.Threading.Tasks;
using Windows.System;

Expand Down
7 changes: 4 additions & 3 deletions src/Files.App/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public enum CommandCodes
SetAsSlideshowBackground,
SetAsLockscreenBackground,

// Install
InstallFont,
InstallInfDriver,

// Run
RunAsAdmin,
RunAsAnotherUser,
Expand Down Expand Up @@ -126,8 +130,5 @@ public enum CommandCodes
CloseTabsToTheRightSelected,
CloseOtherTabsCurrent,
CloseOtherTabsSelected,

// Other
InstallFont,
}
}
6 changes: 4 additions & 2 deletions src/Files.App/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ internal class CommandManager : ICommandManager
public IRichCommand PasteItem => commands[CommandCodes.PasteItem];
public IRichCommand PasteItemToSelection => commands[CommandCodes.PasteItemToSelection];
public IRichCommand DeleteItem => commands[CommandCodes.DeleteItem];
public IRichCommand InstallFont => commands[CommandCodes.InstallFont];
public IRichCommand InstallInfDriver => commands[CommandCodes.InstallInfDriver];
public IRichCommand RunAsAdmin => commands[CommandCodes.RunAsAdmin];
public IRichCommand RunAsAnotherUser => commands[CommandCodes.RunAsAnotherUser];
public IRichCommand LaunchQuickLook => commands[CommandCodes.LaunchQuickLook];
Expand Down Expand Up @@ -114,7 +116,6 @@ internal class CommandManager : ICommandManager
public IRichCommand CloseTabsToTheRightSelected => commands[CommandCodes.CloseTabsToTheRightSelected];
public IRichCommand CloseOtherTabsCurrent => commands[CommandCodes.CloseOtherTabsCurrent];
public IRichCommand CloseOtherTabsSelected => commands[CommandCodes.CloseOtherTabsSelected];
public IRichCommand InstallFont => commands[CommandCodes.InstallFont];

public CommandManager()
{
Expand Down Expand Up @@ -174,6 +175,8 @@ public CommandManager()
[CommandCodes.PasteItem] = new PasteItemAction(),
[CommandCodes.PasteItemToSelection] = new PasteItemToSelectionAction(),
[CommandCodes.DeleteItem] = new DeleteItemAction(),
[CommandCodes.InstallFont] = new InstallFontAction(),
[CommandCodes.InstallInfDriver] = new InstallInfDriverAction(),
[CommandCodes.RunAsAdmin] = new RunAsAdminAction(),
[CommandCodes.RunAsAnotherUser] = new RunAsAnotherUserAction(),
[CommandCodes.LaunchQuickLook] = new LaunchQuickLookAction(),
Expand Down Expand Up @@ -235,7 +238,6 @@ public CommandManager()
[CommandCodes.CloseTabsToTheRightSelected] = new CloseTabsToTheRightSelectedAction(),
[CommandCodes.CloseOtherTabsCurrent] = new CloseOtherTabsCurrentAction(),
[CommandCodes.CloseOtherTabsSelected] = new CloseOtherTabsSelectedAction(),
[CommandCodes.InstallFont] = new InstallFontAction(),
};

[DebuggerDisplay("Command None")]
Expand Down
5 changes: 3 additions & 2 deletions src/Files.App/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand SetAsSlideshowBackground { get; }
IRichCommand SetAsLockscreenBackground { get; }

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

IRichCommand RunAsAdmin { get; }
IRichCommand RunAsAnotherUser { get; }

Expand Down Expand Up @@ -114,7 +117,5 @@ public interface ICommandManager : IEnumerable<IRichCommand>
IRichCommand CloseTabsToTheRightSelected { get; }
IRichCommand CloseOtherTabsCurrent { get; }
IRichCommand CloseOtherTabsSelected { get; }

IRichCommand InstallFont { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,6 @@ public async Task CreateFolderWithSelection(RoutedEventArgs e)
await UIFilesystemHelpers.CreateFolderWithSelectionAsync(associatedInstance);
}

public async Task InstallInfDriver()
{
foreach (ListedItem selectedItem in SlimContentPage.SelectedItems)
await Win32API.InstallInf(selectedItem.ItemPath);
}

public async Task PlayAll()
{
await NavigationHelpers.OpenSelectedItems(associatedInstance);
Expand Down
3 changes: 0 additions & 3 deletions src/Files.App/Interacts/BaseLayoutCommandsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ private void InitializeCommands()
RefreshCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.RefreshItems);
SearchUnindexedItems = new RelayCommand<RoutedEventArgs>(CommandsModel.SearchUnindexedItems);
CreateFolderWithSelection = new AsyncRelayCommand<RoutedEventArgs>(CommandsModel.CreateFolderWithSelection);
InstallInfDriver = new AsyncRelayCommand(CommandsModel.InstallInfDriver);
PlayAllCommand = new AsyncRelayCommand(CommandsModel.PlayAll);
FormatDriveCommand = new RelayCommand<ListedItem>(CommandsModel.FormatDrive);
}
Expand Down Expand Up @@ -81,8 +80,6 @@ private void InitializeCommands()

public ICommand CreateFolderWithSelection { get; private set; }

public ICommand InstallInfDriver { get; set; }

public ICommand PlayAllCommand { get; private set; }

public ICommand FormatDriveCommand { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public interface IBaseLayoutCommandImplementationModel : IDisposable

Task CreateFolderWithSelection(RoutedEventArgs e);

Task InstallInfDriver();

Task PlayAll();

void FormatDrive(ListedItem? obj);
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Shell/Win32API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,12 @@ public static async Task<bool> InstallInf(string filePath)
{
var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(30 * 1000));

using Process process = new Process();
using Process process = new();
process.StartInfo.FileName = "InfDefaultInstall.exe";
process.StartInfo.Verb = "runas";
process.StartInfo.UseShellExecute = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Arguments = $"{filePath}";
process.StartInfo.Arguments = $"\"{filePath}\"";
process.Start();

await process.WaitForExitAsync(cts.Token);
Expand Down
9 changes: 4 additions & 5 deletions src/Files.App/UserControls/InnerNavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,13 @@
ToolTipService.ToolTip="{x:Bind Commands.SetAsSlideshowBackground.LabelWithHotKey}" />
<AppBarButton
x:Name="InstallInfButton"
x:Load="{x:Bind ViewModel.IsInfFile, Mode=OneWay, FallbackValue=False}"
AutomationProperties.Name="InstallInf"
Command="{x:Bind ViewModel.InstallInfCommand, Mode=OneWay}"
Label="{helpers:ResourceString Name=Install}"
x:Load="{x:Bind Commands.InstallInfDriver.IsExecutable, Mode=OneWay, FallbackValue=False}"
Command="{x:Bind Commands.InstallInfDriver, Mode=OneWay}"
Label="{x:Bind Commands.InstallInfDriver.Label}"
LabelPosition="Default"
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}">
<AppBarButton.Icon>
<FontIcon Glyph="&#xE9F5;" />
<FontIcon Glyph="{x:Bind Commands.InstallInfDriver.Glyph.BaseGlyph}" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton
Expand Down
3 changes: 0 additions & 3 deletions src/Files.App/ViewModels/ToolbarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
using System.Windows.Input;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
using Windows.UI.Input.Inking.Analysis;
using Windows.UI.Text;
using static Files.App.UserControls.IAddressToolbar;
using FocusManager = Microsoft.UI.Xaml.Input.FocusManager;
Expand Down Expand Up @@ -589,8 +588,6 @@ private void SearchRegion_Escaped(object? sender, ISearchBox searchBox)

public ICommand? RunWithPowerShellCommand { get; set; }

public ICommand? InstallInfCommand { get; set; }

public ICommand? UpdateCommand { get; set; }

public ICommand? PlayAllCommand { get; set; }
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/Views/BaseShellPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ protected void InitToolbarCommands()
ToolbarViewModel.Share = new RelayCommand(() => SlimContentPage?.CommandsViewModel.ShareItemCommand.Execute(null));
ToolbarViewModel.RunWithPowerShellCommand = new RelayCommand(async () => await Win32Helpers.InvokeWin32ComponentAsync("powershell", this, PathNormalization.NormalizePath(SlimContentPage?.SelectedItem.ItemPath)));
ToolbarViewModel.PropertiesCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.ShowPropertiesCommand.Execute(null));
ToolbarViewModel.InstallInfCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.InstallInfDriver.Execute(null));;
ToolbarViewModel.UpdateCommand = new AsyncRelayCommand(async () => await updateSettingsService.DownloadUpdates());
ToolbarViewModel.PlayAllCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.PlayAllCommand.Execute(null));
}
Expand Down