Skip to content

Added Install button on toolbar when selecting INF files #7860

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 11 commits into from
Jan 25, 2022
12 changes: 12 additions & 0 deletions src/Files.Launcher/MessageHandlers/InstallOperationsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ private async Task ParseInstallOperationAsync(PipeStream connection, Dictionary<
{
switch (message.Get("installop", ""))
{
case "InstallInf":
{
var filePath = (string)message["filepath"];
var fileExtension = (string)message["extension"];
var isInf = new[] { ".inf" }.Contains(fileExtension, StringComparer.OrdinalIgnoreCase);

if (isInf)
{
Win32API.InfDefaultInstall(filePath);
}
break;
}
case "InstallFont":
{
var filePath = (string)message["filepath"];
Expand Down
26 changes: 25 additions & 1 deletion src/Files.Launcher/Win32API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,5 +640,29 @@ public static void OpenFolderInExistingShellWindow(string folderPath)
[DllImport(Lib.Shell32, SetLastError = false, CharSet = CharSet.Auto)]
public static extern int SHQueryRecycleBin(string pszRootPath,
ref SHQUERYRBINFO pSHQueryRBInfo);

public static bool InfDefaultInstall(string filePath)
{
try
{
using Process process = new Process();
process.StartInfo.FileName = "InfDefaultInstall.exe";
process.StartInfo.Verb = "runas";
process.StartInfo.UseShellExecute = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Arguments = $"{filePath}";
process.Start();
if (process.WaitForExit(30 * 1000))
{
return process.ExitCode == 0;
}
return false;
}
catch (Win32Exception)
{
// If user cancels UAC
return false;
}
}
}
}
}
12 changes: 11 additions & 1 deletion src/Files/Helpers/FileExtensionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public static bool IsZipFile(string fileExtensionToCheck)
fileExtensionToCheck.Equals(".msixbundle", StringComparison.OrdinalIgnoreCase);
}

public static bool IsInfFile(string fileExtensionToCheck)
{
if (string.IsNullOrEmpty(fileExtensionToCheck))
{
return false;
}

return fileExtensionToCheck.Equals(".inf", StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Check if the file extension is a font file.
/// </summary>
Expand All @@ -71,7 +81,7 @@ public static bool IsFontFile(string fileExtensionToCheck)
return false;
}

return fileExtensionToCheck.Equals(".fon", StringComparison.OrdinalIgnoreCase) ||
return fileExtensionToCheck.Equals(".fon", StringComparison.OrdinalIgnoreCase) ||
fileExtensionToCheck.Equals(".otf", StringComparison.OrdinalIgnoreCase) ||
fileExtensionToCheck.Equals(".ttc", StringComparison.OrdinalIgnoreCase) ||
fileExtensionToCheck.Equals(".ttf", StringComparison.OrdinalIgnoreCase);
Expand Down
19 changes: 19 additions & 0 deletions src/Files/Interacts/BaseLayoutCommandImplementationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,25 @@ public async void DecompressArchiveToChildFolder()
}
}

public async Task InstallInfDriver()
{
var connection = await AppServiceConnectionHelper.Instance;
if (connection != null)
{
foreach (ListedItem selectedItem in SlimContentPage.SelectedItems)
{
var value = new ValueSet
{
{ "Arguments", "InstallOperation" },
{ "installop", "InstallInf" },
{ "filepath", selectedItem.ItemPath },
{ "extension", selectedItem.FileExtension },
};
await connection.SendMessageAsync(value);
}
}
}

public async void RotateImageLeft()
{
await BitmapHelper.Rotate(PathNormalization.NormalizePath(SlimContentPage?.SelectedItems.First().ItemPath), BitmapRotation.Clockwise270Degrees);
Expand Down
3 changes: 3 additions & 0 deletions src/Files/Interacts/BaseLayoutCommandsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private void InitializeCommands()
DecompressArchiveCommand = new RelayCommand(CommandsModel.DecompressArchive);
DecompressArchiveHereCommand = new RelayCommand(CommandsModel.DecompressArchiveHere);
DecompressArchiveToChildFolderCommand = new RelayCommand(CommandsModel.DecompressArchiveToChildFolder);
InstallInfDriver = new AsyncRelayCommand(CommandsModel.InstallInfDriver);
RotateImageLeftCommand = new RelayCommand(CommandsModel.RotateImageLeft);
RotateImageRightCommand = new RelayCommand(CommandsModel.RotateImageRight);
InstallFontCommand = new RelayCommand(CommandsModel.InstallFont);
Expand Down Expand Up @@ -171,6 +172,8 @@ private void InitializeCommands()

public ICommand DecompressArchiveToChildFolderCommand { get; private set; }

public ICommand InstallInfDriver { get; set; }

public ICommand RotateImageLeftCommand { get; private set; }

public ICommand RotateImageRightCommand { get; private set; }
Expand Down
2 changes: 2 additions & 0 deletions src/Files/Interacts/IBaseLayoutCommandImplementationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public interface IBaseLayoutCommandImplementationModel : IDisposable

void DecompressArchiveToChildFolder();

Task InstallInfDriver();

void RotateImageLeft();

void RotateImageRight();
Expand Down
12 changes: 12 additions & 0 deletions src/Files/UserControls/InnerNavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,18 @@
<FontIcon Glyph="&#xE91B;" />
</AppBarButton.Icon>
</AppBarButton>
<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}"
LabelPosition="Default"
ToolTipService.ToolTip="{helpers:ResourceString Name=Install}">
<AppBarButton.Icon>
<FontIcon Glyph="&#xE9F5;" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton
x:Name="RotateImageLeftButton"
x:Load="{x:Bind ViewModel.IsImage, Mode=OneWay, FallbackValue=False}"
Expand Down
6 changes: 5 additions & 1 deletion src/Files/ViewModels/NavToolbarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,8 @@ public void SearchRegion_LostFocus(object sender, RoutedEventArgs e)

public ICommand SetAsBackgroundCommand { get; set; }

public ICommand InstallInfCommand { get; set; }

public ICommand RotateImageLeftCommand { get; set; }

public ICommand RotateImageRightCommand { get; set; }
Expand Down Expand Up @@ -1132,6 +1134,7 @@ public List<ListedItem> SelectedItems
OnPropertyChanged(nameof(CanViewProperties));
OnPropertyChanged(nameof(CanExtract));
OnPropertyChanged(nameof(ExtractToText));
OnPropertyChanged(nameof(IsInfFile));
OnPropertyChanged(nameof(IsPowerShellScript));
OnPropertyChanged(nameof(IsImage));
OnPropertyChanged(nameof(IsFont));
Expand All @@ -1140,7 +1143,7 @@ public List<ListedItem> SelectedItems
}
}

public bool HasAdditionalAction => InstanceViewModel.IsPageTypeRecycleBin || IsPowerShellScript || CanExtract || IsImage || IsFont;
public bool HasAdditionalAction => InstanceViewModel.IsPageTypeRecycleBin || IsPowerShellScript || CanExtract || IsImage || IsFont || IsInfFile;

public bool CanCopy => SelectedItems is not null && SelectedItems.Any();
public bool CanShare => SelectedItems is not null && SelectedItems.Any() && DataTransferManager.IsSupported() && !SelectedItems.Any(x => (x.IsShortcutItem && !x.IsLinkItem) || x.IsHiddenItem || (x.PrimaryItemAttribute == StorageItemTypes.Folder && !x.IsZipItem));
Expand All @@ -1151,6 +1154,7 @@ public List<ListedItem> SelectedItems
public string ExtractToText => SelectedItems is not null && SelectedItems.Count == 1 ? string.Format("ExtractToChildFolder".GetLocalized() + "\\", Path.GetFileNameWithoutExtension(selectedItems.First().ItemName)) : "ExtractToChildFolder".GetLocalized();
public bool IsPowerShellScript => SelectedItems is not null && SelectedItems.Count == 1 && FileExtensionHelpers.IsPowerShellFile(SelectedItems.First().FileExtension);
public bool IsImage => SelectedItems is not null && SelectedItems.Count == 1 && FileExtensionHelpers.IsImageFile(SelectedItems.First().FileExtension);
public bool IsInfFile => SelectedItems is not null && SelectedItems.Count == 1 && FileExtensionHelpers.IsInfFile(SelectedItems.First().FileExtension);
public bool IsFont => SelectedItems is not null && SelectedItems.Any() && SelectedItems.All(x => FileExtensionHelpers.IsFontFile(x.FileExtension));

public void Dispose()
Expand Down
1 change: 1 addition & 0 deletions src/Files/Views/ColumnShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ private void InitToolbarCommands()
NavToolbarViewModel.ExtractCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.DecompressArchiveCommand.Execute(null));
NavToolbarViewModel.ExtractHereCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.DecompressArchiveHereCommand.Execute(null));
NavToolbarViewModel.ExtractToCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.DecompressArchiveToChildFolderCommand.Execute(null));
NavToolbarViewModel.InstallInfCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.InstallInfDriver.Execute(null));
NavToolbarViewModel.RotateImageLeftCommand = new RelayCommand(async () => SlimContentPage?.CommandsViewModel.RotateImageLeftCommand.Execute(null));
NavToolbarViewModel.RotateImageRightCommand = new RelayCommand(async () => SlimContentPage?.CommandsViewModel.RotateImageRightCommand.Execute(null));
NavToolbarViewModel.InstallFontCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.InstallFontCommand.Execute(null));
Expand Down
1 change: 1 addition & 0 deletions src/Files/Views/ModernShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ private void InitToolbarCommands()
NavToolbarViewModel.ExtractCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.DecompressArchiveCommand.Execute(null));
NavToolbarViewModel.ExtractHereCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.DecompressArchiveHereCommand.Execute(null));
NavToolbarViewModel.ExtractToCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.DecompressArchiveToChildFolderCommand.Execute(null));
NavToolbarViewModel.InstallInfCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.InstallInfDriver.Execute(null));
NavToolbarViewModel.RotateImageLeftCommand = new RelayCommand(async () => SlimContentPage?.CommandsViewModel.RotateImageLeftCommand.Execute(null));
NavToolbarViewModel.RotateImageRightCommand = new RelayCommand(async () => SlimContentPage?.CommandsViewModel.RotateImageRightCommand.Execute(null));
NavToolbarViewModel.InstallFontCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.InstallFontCommand.Execute(null));
Expand Down