mirror of
https://github.com/microsoft/PowerToys
synced 2024-11-22 00:03:48 +00:00
[FileExplorer] Add PDF Thumbnail Provider for Windows Explorer (#13058)
* Add PdfPreviewHandler to build dependency of runner * PDF Thumbnail Provider * Remove using brackets * Pdf Thumbnail - Settings and Unit Tests * Removed resx * Add PDF Thumbnail Provider binary * Install Pdf Thumbnail Provider * Fix pagee spelling error. * Update Windows dependency to version 10.0.18362.0 because that is the minimal required version of the PowerToys. * Add Pdf Preview Handler and Pdf Thumbnail Provider
This commit is contained in:
parent
7e22f26b52
commit
7ac1e00d01
@ -42,8 +42,6 @@ restore:
|
||||
name: 'Restore Tools packages'
|
||||
command: '.pipelines\restore-tools.cmd'
|
||||
|
||||
|
||||
|
||||
build:
|
||||
commands:
|
||||
# Localize the files before the Build PowerToys step to generate translated resx files from the lcl files
|
||||
@ -113,6 +111,8 @@ build:
|
||||
- 'modules\FileExplorerPreview\MarkdownPreviewHandler.comhost.dll'
|
||||
- 'modules\FileExplorerPreview\PdfPreviewHandler.dll'
|
||||
- 'modules\FileExplorerPreview\PdfPreviewHandler.comhost.dll'
|
||||
- 'modules\FileExplorerPreview\PdfThumbnailProvider.dll'
|
||||
- 'modules\FileExplorerPreview\PdfThumbnailProvider.comhost.dll'
|
||||
- 'modules\FileExplorerPreview\powerpreview.dll'
|
||||
- 'modules\FileExplorerPreview\PreviewHandlerCommon.dll'
|
||||
- 'modules\FileExplorerPreview\SvgPreviewHandler.dll'
|
||||
@ -229,7 +229,6 @@ build:
|
||||
signing_options:
|
||||
sign_inline: true # This does signing as soon as this command completes
|
||||
|
||||
|
||||
#package:
|
||||
# commands:
|
||||
# - !!buildcommand
|
||||
|
@ -17,6 +17,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "runner", "src\runner\runner
|
||||
{0B593A6C-4143-4337-860E-DB5710FB87DB} = {0B593A6C-4143-4337-860E-DB5710FB87DB}
|
||||
{E364F67B-BB12-4E91-B639-355866EBCD8B} = {E364F67B-BB12-4E91-B639-355866EBCD8B}
|
||||
{D940E07F-532C-4FF3-883F-790DA014F19A} = {D940E07F-532C-4FF3-883F-790DA014F19A}
|
||||
{69E1EE8D-143A-4060-9129-4658ACF14AAF} = {69E1EE8D-143A-4060-9129-4658ACF14AAF}
|
||||
{DA425894-6E13-404F-8DCB-78584EC0557A} = {DA425894-6E13-404F-8DCB-78584EC0557A}
|
||||
{2BE46397-4DFA-414C-9BD4-41E4BBF8CB34} = {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}
|
||||
{A7D5099E-F0FD-4BF3-8522-5A682759F915} = {A7D5099E-F0FD-4BF3-8522-5A682759F915}
|
||||
@ -362,6 +363,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VideoConferenceProxyFilter"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "VideoConference", "VideoConference", "{470FBAF9-E1F8-4F3E-8786-198A1C81C8A8}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PdfThumbnailProvider", "src\modules\previewpane\PdfThumbnailProvider\PdfThumbnailProvider.csproj", "{11491FD8-F921-48BF-880C-7FEA185B80A1}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests-PdfThumbnailProvider", "src\modules\previewpane\UnitTests-PdfThumbnailProvider\UnitTests-PdfThumbnailProvider.csproj", "{F40C3397-1834-4530-B2D9-8F8B8456BCDF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
@ -948,6 +953,18 @@ Global
|
||||
{AC2857B4-103D-4D6D-9740-926EBF785042}.Release|x64.Build.0 = Release|x64
|
||||
{AC2857B4-103D-4D6D-9740-926EBF785042}.Release|x86.ActiveCfg = Release|Win32
|
||||
{AC2857B4-103D-4D6D-9740-926EBF785042}.Release|x86.Build.0 = Release|Win32
|
||||
{11491FD8-F921-48BF-880C-7FEA185B80A1}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{11491FD8-F921-48BF-880C-7FEA185B80A1}.Debug|x64.Build.0 = Debug|x64
|
||||
{11491FD8-F921-48BF-880C-7FEA185B80A1}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{11491FD8-F921-48BF-880C-7FEA185B80A1}.Release|x64.ActiveCfg = Release|x64
|
||||
{11491FD8-F921-48BF-880C-7FEA185B80A1}.Release|x64.Build.0 = Release|x64
|
||||
{11491FD8-F921-48BF-880C-7FEA185B80A1}.Release|x86.ActiveCfg = Release|x64
|
||||
{F40C3397-1834-4530-B2D9-8F8B8456BCDF}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{F40C3397-1834-4530-B2D9-8F8B8456BCDF}.Debug|x64.Build.0 = Debug|x64
|
||||
{F40C3397-1834-4530-B2D9-8F8B8456BCDF}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{F40C3397-1834-4530-B2D9-8F8B8456BCDF}.Release|x64.ActiveCfg = Release|x64
|
||||
{F40C3397-1834-4530-B2D9-8F8B8456BCDF}.Release|x64.Build.0 = Release|x64
|
||||
{F40C3397-1834-4530-B2D9-8F8B8456BCDF}.Release|x86.ActiveCfg = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -1061,6 +1078,8 @@ Global
|
||||
{5ABA70DE-3A3F-41F6-A1F5-D1F74F54F9BB} = {470FBAF9-E1F8-4F3E-8786-198A1C81C8A8}
|
||||
{AC2857B4-103D-4D6D-9740-926EBF785042} = {470FBAF9-E1F8-4F3E-8786-198A1C81C8A8}
|
||||
{470FBAF9-E1F8-4F3E-8786-198A1C81C8A8} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC}
|
||||
{11491FD8-F921-48BF-880C-7FEA185B80A1} = {2F305555-C296-497E-AC20-5FA1B237996A}
|
||||
{F40C3397-1834-4530-B2D9-8F8B8456BCDF} = {2F305555-C296-497E-AC20-5FA1B237996A}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
|
||||
|
@ -511,6 +511,19 @@
|
||||
<RegistryValue Type="string" Key="InprocServer32\$(var.Version).0" Name="Assembly" Value="PdfPreviewHandler, Version=$(var.Version).0, Culture=neutral" />
|
||||
<RegistryValue Type="string" Key="InprocServer32\$(var.Version).0" Name="Class" Value="Microsoft.PowerToys.PreviewHandler.Pdf.PdfPreviewHandler" />
|
||||
</RegistryKey>
|
||||
<!-- Registry Key for Class Registration of Pdf Thumbnail Provider -->
|
||||
<RegistryKey Root="HKCR" Key="CLSID\{BCC13D15-9720-4CC4-8371-EA74A274741E}">
|
||||
<RegistryValue Type="string" Value="Microsoft.PowerToys.ThumbnailHandler.Pdf.PdfThumbnailProvider" />
|
||||
<RegistryValue Type="string" Name="DisplayName" Value="Pdf Thumbnail Provider" />
|
||||
<RegistryValue Type="string" Name="AppID" Value="{CF142243-F059-45AF-8842-DBBE9783DB14}" />
|
||||
<RegistryValue Type="string" Key="Implemented Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}" Value=""/>
|
||||
<RegistryValue Type="string" Key="InprocServer32" Value="[FileExplorerPreviewInstallFolder]PdfThumbnailProvider.comhost.dll" />
|
||||
<RegistryValue Type="string" Key="InprocServer32" Name="Assembly" Value="PdfThumbnailProvider, Version=$(var.Version).0, Culture=neutral" />
|
||||
<RegistryValue Type="string" Key="InprocServer32" Name="Class" Value="Microsoft.PowerToys.ThumbnailHandler.Pdf.PdfThumbnailProvider" />
|
||||
<RegistryValue Type="string" Key="InprocServer32" Name="ThreadingModel" Value="Both" />
|
||||
<RegistryValue Type="string" Key="InprocServer32\$(var.Version).0" Name="Assembly" Value="PdfThumbnailProvider, Version=$(var.Version).0, Culture=neutral" />
|
||||
<RegistryValue Type="string" Key="InprocServer32\$(var.Version).0" Name="Class" Value="Microsoft.PowerToys.ThumbnailHandler.Pdf.PdfThumbnailProvider" />
|
||||
</RegistryKey>
|
||||
<!-- Registry Key for AppID registration -->
|
||||
<RegistryKey Root="HKCR" Key="AppID\{CF142243-F059-45AF-8842-DBBE9783DB14}">
|
||||
<RegistryValue Type="expandable" Name="DllSurrogate" Value="%SystemRoot%\system32\prevhost.exe" />
|
||||
@ -543,6 +556,10 @@
|
||||
<RegistryKey Root="HKCR" Key=".pdf\shellex">
|
||||
<RegistryValue Type="string" Key="{8895b1c6-b41f-4c1c-a562-0d564250836f}" Value="{07665729-6243-4746-95b7-79579308d1b2}" />
|
||||
</RegistryKey>
|
||||
<!-- Add file type association for Pdf Thumbnail Provider -->
|
||||
<RegistryKey Root="HKCR" Key=".pdf\shellex">
|
||||
<RegistryValue Type="string" Key="{E357FCCD-A995-4576-B01F-234630154E96}" Value="{BCC13D15-9720-4CC4-8371-EA74A274741E}" />
|
||||
</RegistryKey>
|
||||
<!-- Update Key to use IE11 for prevhost.exe -->
|
||||
<RegistryKey Root="HKLM" Key="Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION">
|
||||
<RegistryValue Type="integer" Name="prevhost.exe" Value="11000" />
|
||||
@ -791,7 +808,7 @@
|
||||
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\SvgPreviewHandler.comhost.dll" />
|
||||
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\SvgPreviewHandler.runtimeconfig.json" />
|
||||
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\SvgPreviewHandler.deps.json" />
|
||||
<!-- File to include dll for Svg Preview Handler -->
|
||||
<!-- File to include dll for Svg Thumbnail Provider -->
|
||||
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\SvgThumbnailProvider.dll" />
|
||||
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\SvgThumbnailProvider.comhost.dll" />
|
||||
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\SvgThumbnailProvider.runtimeconfig.json" />
|
||||
@ -809,6 +826,11 @@
|
||||
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\PdfPreviewHandler.comhost.dll" />
|
||||
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\PdfPreviewHandler.runtimeconfig.json" />
|
||||
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\PdfPreviewHandler.deps.json" />
|
||||
<!-- File to include dll for Pdf Thumbnail Provider -->
|
||||
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\PdfThumbnailProvider.dll" />
|
||||
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\PdfThumbnailProvider.comhost.dll" />
|
||||
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\PdfThumbnailProvider.runtimeconfig.json" />
|
||||
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\PdfThumbnailProvider.deps.json" />
|
||||
</Component>
|
||||
</DirectoryRef>
|
||||
|
||||
|
@ -65,7 +65,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Windows">
|
||||
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.17134.0\Windows.winmd</HintPath>
|
||||
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.18362.0\Windows.winmd</HintPath>
|
||||
<IsWinMDFile>true</IsWinMDFile>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
@ -0,0 +1,96 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using Common.ComInterlop;
|
||||
using Common.Utilities;
|
||||
using Windows.Data.Pdf;
|
||||
using Windows.Storage.Streams;
|
||||
|
||||
namespace Microsoft.PowerToys.ThumbnailHandler.Pdf
|
||||
{
|
||||
/// <summary>
|
||||
/// PDF Thumbnail Provider.
|
||||
/// </summary>
|
||||
[Guid("BCC13D15-9720-4CC4-8371-EA74A274741E")]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
[ComVisible(true)]
|
||||
public class PdfThumbnailProvider : IInitializeWithStream, IThumbnailProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the stream object to access file.
|
||||
/// </summary>
|
||||
public IStream Stream { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The maximum dimension (width or height) thumbnail we will generate.
|
||||
/// </summary>
|
||||
private const uint MaxThumbnailSize = 10000;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Initialize(IStream pstream, uint grfMode)
|
||||
{
|
||||
// Ignore the grfMode always use read mode to access the file.
|
||||
this.Stream = pstream;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void GetThumbnail(uint cx, out IntPtr phbmp, out WTS_ALPHATYPE pdwAlpha)
|
||||
{
|
||||
phbmp = IntPtr.Zero;
|
||||
pdwAlpha = WTS_ALPHATYPE.WTSAT_UNKNOWN;
|
||||
|
||||
if (cx == 0 || cx > MaxThumbnailSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using var dataStream = new ReadonlyStream(this.Stream as IStream);
|
||||
using var memStream = new MemoryStream();
|
||||
|
||||
dataStream.CopyTo(memStream);
|
||||
memStream.Position = 0;
|
||||
|
||||
// AsRandomAccessStream() extension method from System.Runtime.WindowsRuntime
|
||||
var pdf = PdfDocument.LoadFromStreamAsync(memStream.AsRandomAccessStream()).GetAwaiter().GetResult();
|
||||
|
||||
if (pdf.PageCount > 0)
|
||||
{
|
||||
using var page = pdf.GetPage(0);
|
||||
|
||||
var image = PageToImage(page, cx);
|
||||
|
||||
using Bitmap thumbnail = new Bitmap(image);
|
||||
|
||||
phbmp = thumbnail.GetHbitmap();
|
||||
pdwAlpha = WTS_ALPHATYPE.WTSAT_RGB;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transform the PdfPage to an Image.
|
||||
/// </summary>
|
||||
/// <param name="page">The page to transform to an Image.</param>
|
||||
/// <param name="height">The height of the page.</param>
|
||||
/// <returns>An object of type <see cref="Image"/></returns>
|
||||
private static Image PageToImage(PdfPage page, uint height)
|
||||
{
|
||||
Image imageOfPage;
|
||||
|
||||
using var stream = new InMemoryRandomAccessStream();
|
||||
|
||||
page.RenderToStreamAsync(stream, new PdfPageRenderOptions()
|
||||
{
|
||||
DestinationHeight = height,
|
||||
}).GetAwaiter().GetResult();
|
||||
|
||||
imageOfPage = Image.FromStream(stream.AsStream());
|
||||
|
||||
return imageOfPage;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
<PropertyGroup>
|
||||
<Platforms>x64</Platforms>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ProjectGuid>{11491FD8-F921-48BF-880C-7FEA185B80A1}</ProjectGuid>
|
||||
<RootNamespace>Microsoft.PowerToys.ThumbnailHandler.Pdf</RootNamespace>
|
||||
<AssemblyName>PdfThumbnailProvider</AssemblyName>
|
||||
<AssemblyTitle>PdfThumbnailProvider</AssemblyTitle>
|
||||
<AssemblyDescription>PowerToys PdfPreviewHandler</AssemblyDescription>
|
||||
<AssemblyCompany>Microsoft Corporation</AssemblyCompany>
|
||||
<AssemblyCopyright>Copyright (C) 2020 Microsoft Corporation</AssemblyCopyright>
|
||||
<AssemblyProduct>PowerToys</AssemblyProduct>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<EnableComHosting>true</EnableComHosting>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Company>Microsoft Corporation</Company>
|
||||
<Product>PowerToys</Product>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<Description>PowerToys PdfPreviewHandler</Description>
|
||||
<Copyright>Copyright (C) 2020 Microsoft Corporation</Copyright>
|
||||
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\modules\FileExplorerPreview\</OutputPath>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="..\..\..\Version.props" />
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.VersionCheckAnalyzer" Version="3.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="3.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="3.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NetFramework.Analyzers" Version="3.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
|
||||
<ProjectReference Include="..\Common\PreviewHandlerCommon.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="..\..\..\codeAnalysis\StyleCop.json">
|
||||
<Link>StyleCop.json</Link>
|
||||
</AdditionalFiles>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Windows">
|
||||
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.18362.0\Windows.winmd</HintPath>
|
||||
<IsWinMDFile>true</IsWinMDFile>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -12,7 +12,6 @@ using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Windows.Forms;
|
||||
using Common.ComInterlop;
|
||||
using Common.Utilities;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using PreviewHandlerCommon;
|
||||
|
||||
namespace Microsoft.PowerToys.ThumbnailHandler.Svg
|
||||
|
Binary file not shown.
@ -0,0 +1,93 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Text;
|
||||
using Common.ComInterlop;
|
||||
using Microsoft.PowerToys.STATestExtension;
|
||||
using Microsoft.PowerToys.ThumbnailHandler.Pdf;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
|
||||
namespace PdfThumbnailProviderUnitTests
|
||||
{
|
||||
[STATestClass]
|
||||
public class PdfThumbnailProviderTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void GetThumbnailValidStreamPDF()
|
||||
{
|
||||
// Act
|
||||
var file = File.ReadAllBytes("HelperFiles/sample.pdf");
|
||||
|
||||
PdfThumbnailProvider provider = new PdfThumbnailProvider();
|
||||
|
||||
provider.Initialize(GetMockStream(file), 0);
|
||||
|
||||
provider.GetThumbnail(256, out IntPtr bitmap, out WTS_ALPHATYPE alphaType);
|
||||
|
||||
Assert.IsTrue(bitmap != IntPtr.Zero);
|
||||
Assert.IsTrue(alphaType == WTS_ALPHATYPE.WTSAT_RGB);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetThumbnailInValidSizePDF()
|
||||
{
|
||||
// Act
|
||||
var file = File.ReadAllBytes("HelperFiles/sample.pdf");
|
||||
|
||||
PdfThumbnailProvider provider = new PdfThumbnailProvider();
|
||||
|
||||
provider.Initialize(GetMockStream(file), 0);
|
||||
|
||||
provider.GetThumbnail(0, out IntPtr bitmap, out WTS_ALPHATYPE alphaType);
|
||||
|
||||
Assert.IsTrue(bitmap == IntPtr.Zero);
|
||||
Assert.IsTrue(alphaType == WTS_ALPHATYPE.WTSAT_UNKNOWN);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetThumbnailToBigPDF()
|
||||
{
|
||||
// Act
|
||||
var file = File.ReadAllBytes("HelperFiles/sample.pdf");
|
||||
|
||||
PdfThumbnailProvider provider = new PdfThumbnailProvider();
|
||||
|
||||
provider.Initialize(GetMockStream(file), 0);
|
||||
|
||||
provider.GetThumbnail(10001, out IntPtr bitmap, out WTS_ALPHATYPE alphaType);
|
||||
|
||||
Assert.IsTrue(bitmap == IntPtr.Zero);
|
||||
Assert.IsTrue(alphaType == WTS_ALPHATYPE.WTSAT_UNKNOWN);
|
||||
}
|
||||
|
||||
private static IStream GetMockStream(byte[] sourceArray)
|
||||
{
|
||||
var streamMock = new Mock<IStream>();
|
||||
var firstCall = true;
|
||||
streamMock
|
||||
.Setup(x => x.Read(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<IntPtr>()))
|
||||
.Callback<byte[], int, IntPtr>((buffer, countToRead, bytesReadPtr) =>
|
||||
{
|
||||
if (firstCall)
|
||||
{
|
||||
Array.Copy(sourceArray, 0, buffer, 0, sourceArray.Length);
|
||||
Marshal.WriteInt32(bytesReadPtr, sourceArray.Length);
|
||||
firstCall = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Marshal.WriteInt32(bytesReadPtr, 0);
|
||||
}
|
||||
});
|
||||
|
||||
return streamMock.Object;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Platforms>x64</Platforms>
|
||||
<AssemblyTitle>UnitTests-PdfThumbnailProvider</AssemblyTitle>
|
||||
<AssemblyDescription>PowerToys UnitTests-PdfThumbnailProvider</AssemblyDescription>
|
||||
<AssemblyCompany>Microsoft Corporation</AssemblyCompany>
|
||||
<AssemblyCopyright>Copyright (C) 2021 Microsoft Corporation</AssemblyCopyright>
|
||||
<AssemblyProduct>PowerToys</AssemblyProduct>
|
||||
<AssemblyTitle>UnitTests-PdfThumbnailProvider</AssemblyTitle>
|
||||
<Company>Microsoft Corporation</Company>
|
||||
<Product>PowerToys</Product>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<Description>PowerToys UnitTests-PdfThumbnailProvider</Description>
|
||||
<Copyright>Copyright (C) 2021 Microsoft Corporation</Copyright>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{F40C3397-1834-4530-B2D9-8F8B8456BCDF}</ProjectGuid>
|
||||
<RootNamespace>PdfThumbnailProviderUnitTests</RootNamespace>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||
<IsCodedUITest>False</IsCodedUITest>
|
||||
<TestProjectType>UnitTest</TestProjectType>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="..\..\..\Version.props" />
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="HelperFiles\sample.pdf" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Castle.Core" Version="4.4.1" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.VersionCheckAnalyzer" Version="3.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="3.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="3.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NetFramework.Analyzers" Version="3.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
|
||||
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Common\PreviewHandlerCommon.csproj" />
|
||||
<ProjectReference Include="..\PdfThumbnailProvider\PdfThumbnailProvider.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
|
||||
<Compile Include="..\STATestClassAttribute.cs" Link="STATestClassAttribute.cs" />
|
||||
<Compile Include="..\STATestMethodAttribute.cs" Link="STATestMethodAttribute.cs" />
|
||||
<AdditionalFiles Include="..\..\..\codeAnalysis\StyleCop.json">
|
||||
<Link>StyleCop.json</Link>
|
||||
</AdditionalFiles>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="HelperFiles\sample.pdf">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
@ -28,6 +28,9 @@ const CLSID CLSID_SHIMActivateSvgThumbnailProvider = { 0x9C723B8C, 0x4F5C, 0x414
|
||||
// 36B27788-A8BB-4698-A756-DF9F11F64F84
|
||||
const CLSID CLSID_SvgThumbnailProvider = { 0x36B27788, 0xA8BB, 0x4698, { 0xA7, 0x56, 0xDF, 0x9F, 0x11, 0xF6, 0x4F, 0x84 } };
|
||||
|
||||
// BCC13D15-9720-4CC4-8371-EA74A274741E
|
||||
const GUID CLSID_PdfThumbnailProvider = { 0xbcc13d15, 0x9720, 0x4cc4, { 0x83, 0x71, 0xea, 0x74, 0xa2, 0x74, 0x74, 0x1e } };
|
||||
|
||||
// Pairs of NativeClsid vs ManagedClsid used for preview handlers.
|
||||
const std::vector<std::pair<CLSID, CLSID>> NativeToManagedClsid({
|
||||
{ CLSID_SHIMActivateMdPreviewHandler, CLSID_MdPreviewHandler },
|
||||
|
@ -174,4 +174,7 @@
|
||||
<data name="Prevpane_Pdf_Settings_Displayname" xml:space="preserve">
|
||||
<value>PDF Previewer</value>
|
||||
</data>
|
||||
<data name="Pdf_Thumbnail_Provider_Settings_Description" xml:space="preserve">
|
||||
<value>Pdf Thumbnail Provider</value>
|
||||
</data>
|
||||
</root>
|
@ -50,6 +50,16 @@ PowerPreviewModule::PowerPreviewModule() :
|
||||
std::make_unique<RegistryWrapper>(),
|
||||
L".svg\\shellex\\{E357FCCD-A995-4576-B01F-234630154E96}"));
|
||||
|
||||
// PDF
|
||||
m_fileExplorerModules.emplace_back(std::make_unique<ThumbnailProviderSettings>(
|
||||
true,
|
||||
L"pdf-thumbnail-toggle-setting",
|
||||
GET_RESOURCE_STRING(IDS_PDF_THUMBNAIL_PROVIDER_SETTINGS_DESCRIPTION),
|
||||
L"{BCC13D15-9720-4CC4-8371-EA74A274741E}",
|
||||
L"Pdf Thumbnail Provider",
|
||||
std::make_unique<RegistryWrapper>(),
|
||||
L".pdf\\shellex\\{E357FCCD-A995-4576-B01F-234630154E96}"));
|
||||
|
||||
// Initialize the toggle states for each module.
|
||||
init_settings();
|
||||
|
||||
|
@ -80,6 +80,23 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
}
|
||||
}
|
||||
|
||||
private bool enablePdfThumbnail = true;
|
||||
|
||||
[JsonPropertyName("pdf-thumbnail-toggle-setting")]
|
||||
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
||||
public bool EnablePdfThumbnail
|
||||
{
|
||||
get => enablePdfThumbnail;
|
||||
set
|
||||
{
|
||||
if (value != enablePdfThumbnail)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
enablePdfThumbnail = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PowerPreviewProperties()
|
||||
{
|
||||
}
|
||||
|
@ -50,12 +50,14 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
_svgThumbnailIsEnabled = Settings.Properties.EnableSvgThumbnail;
|
||||
_mdRenderIsEnabled = Settings.Properties.EnableMdPreview;
|
||||
_pdfRenderIsEnabled = Settings.Properties.EnablePdfPreview;
|
||||
_pdfThumbnailIsEnabled = Settings.Properties.EnablePdfThumbnail;
|
||||
}
|
||||
|
||||
private bool _svgRenderIsEnabled;
|
||||
private bool _mdRenderIsEnabled;
|
||||
private bool _pdfRenderIsEnabled;
|
||||
private bool _svgThumbnailIsEnabled;
|
||||
private bool _pdfThumbnailIsEnabled;
|
||||
|
||||
public bool SVGRenderIsEnabled
|
||||
{
|
||||
@ -129,6 +131,24 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool PDFThumbnailIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _pdfThumbnailIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _pdfThumbnailIsEnabled)
|
||||
{
|
||||
_pdfThumbnailIsEnabled = value;
|
||||
Settings.Properties.EnablePdfThumbnail = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSettingsSubPath()
|
||||
{
|
||||
return _settingsConfigFileFolder + "\\" + ModuleName;
|
||||
|
@ -60,6 +60,7 @@ namespace ViewModelTests
|
||||
Assert.AreEqual(originalSettings.Properties.EnablePdfPreview, viewModel.PDFRenderIsEnabled);
|
||||
Assert.AreEqual(originalSettings.Properties.EnableSvgPreview, viewModel.SVGRenderIsEnabled);
|
||||
Assert.AreEqual(originalSettings.Properties.EnableSvgThumbnail, viewModel.SVGThumbnailIsEnabled);
|
||||
Assert.AreEqual(originalSettings.Properties.EnablePdfThumbnail, viewModel.PDFThumbnailIsEnabled);
|
||||
|
||||
// Verify that the stub file was used
|
||||
var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings<T>)
|
||||
@ -102,6 +103,24 @@ namespace ViewModelTests
|
||||
viewModel.SVGThumbnailIsEnabled = true;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PDFThumbnailIsEnabledShouldPrevHandlerWhenSuccessful()
|
||||
{
|
||||
// Assert
|
||||
Func<string, int> sendMockIPCConfigMSG = msg =>
|
||||
{
|
||||
SndModuleSettings<SndPowerPreviewSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<SndPowerPreviewSettings>>(msg);
|
||||
Assert.IsTrue(snd.PowertoysSetting.FileExplorerPreviewSettings.Properties.EnablePdfThumbnail);
|
||||
return 0;
|
||||
};
|
||||
|
||||
// arrange
|
||||
PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository<PowerPreviewSettings>.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, PowerPreviewSettings.ModuleName);
|
||||
|
||||
// act
|
||||
viewModel.PDFThumbnailIsEnabled = true;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MDRenderIsEnabledShouldPrevHandlerWhenSuccessful()
|
||||
{
|
||||
|
@ -586,6 +586,10 @@
|
||||
<value>Enable SVG (.svg) thumbnails</value>
|
||||
<comment>Do you want this feature on / off</comment>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_ToggleSwitch_PDF_Thumbnail.Header" xml:space="preserve">
|
||||
<value>Enable PDF (.pdf) thumbnails</value>
|
||||
<comment>Do you want this feature on / off</comment>
|
||||
</data>
|
||||
<data name="FileExplorerPreview.ModuleDescription" xml:space="preserve">
|
||||
<value>These settings allow you to manage your Windows File Explorer custom preview handlers.</value>
|
||||
</data>
|
||||
@ -1194,7 +1198,7 @@ Made with 💗 by Microsoft and the PowerToys community.</value>
|
||||
<value>FancyZones is a window manager that makes it easy to create complex window layouts and quickly position windows into those layouts.</value>
|
||||
</data>
|
||||
<data name="Oobe_FileExplorer_Description" xml:space="preserve">
|
||||
<value>PowerToys introduces add-ons to the Window’s File Explorer that will currently enable Markdown files (.md) and SVG icons (.svg) to be viewed in the preview pane.</value>
|
||||
<value>PowerToys introduces add-ons to the Window’s File Explorer that will currently enable Markdown files (.md), PDF files (.pdf) and SVG icons (.svg) to be viewed in the preview pane.</value>
|
||||
</data>
|
||||
<data name="Oobe_ImageResizer_Description" xml:space="preserve">
|
||||
<value>Image Resizer is a Windows shell extension for simple bulk image-resizing.</value>
|
||||
@ -1245,7 +1249,7 @@ Take a moment to preview the various utilities listed or view our comprehensive
|
||||
</data>
|
||||
<data name="Oobe_FileExplorer_HowToEnable.Text" xml:space="preserve">
|
||||
<value>Open File Explorer, **select the View tab** in the File Explorer ribbon, then **select Preview Pane**.
|
||||
From there, simply click on a Markdown file or SVG icon in the File Explorer and observe the content on the preview pane!</value>
|
||||
From there, simply click on a Markdown file, PDF file or SVG icon in the File Explorer and observe the content on the preview pane!</value>
|
||||
</data>
|
||||
<data name="Oobe_HowToCreateMappings.Text" xml:space="preserve">
|
||||
<value>How to create mappings</value>
|
||||
|
@ -67,6 +67,13 @@
|
||||
IsEnabled="{Binding Mode=OneWay, Path=IsElevated}"/>
|
||||
</controls:Setting.ActionContent>
|
||||
</controls:Setting>
|
||||
|
||||
<controls:Setting x:Uid="FileExplorerPreview_ToggleSwitch_PDF_Thumbnail" Icon="">
|
||||
<controls:Setting.ActionContent>
|
||||
<ToggleSwitch IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.PDFThumbnailIsEnabled}"
|
||||
IsEnabled="{Binding Mode=OneWay, Path=IsElevated}"/>
|
||||
</controls:Setting.ActionContent>
|
||||
</controls:Setting>
|
||||
</controls:SettingsGroup>
|
||||
|
||||
</StackPanel>
|
||||
|
@ -13,6 +13,8 @@ namespace
|
||||
{ HKEY_CLASSES_ROOT, L"CLSID\\{36B27788-A8BB-4698-A756-DF9F11F64F84}" },
|
||||
{ HKEY_CLASSES_ROOT, L"CLSID\\{45769bcc-e8fd-42d0-947e-02beef77a1f5}" },
|
||||
{ HKEY_CLASSES_ROOT, L"AppID\\{CF142243-F059-45AF-8842-DBBE9783DB14}" },
|
||||
{ HKEY_CLASSES_ROOT, L"CLSID\\{07665729-6243-4746-95b7-79579308d1b2}" },
|
||||
{ HKEY_CLASSES_ROOT, L"CLSID\\{BCC13D15-9720-4CC4-8371-EA74A274741E}" },
|
||||
{ HKEY_CLASSES_ROOT, L"CLSID\\{51B4D7E5-7568-4234-B4BB-47FB3C016A69}\\InprocServer32" },
|
||||
{ HKEY_CLASSES_ROOT, L"CLSID\\{0440049F-D1DC-4E46-B27B-98393D79486B}" },
|
||||
{ HKEY_CLASSES_ROOT, L"AllFileSystemObjects\\ShellEx\\ContextMenuHandlers\\PowerRenameExt" },
|
||||
@ -20,7 +22,8 @@ namespace
|
||||
{ HKEY_CLASSES_ROOT, L".svg\\shellex\\{8895b1c6-b41f-4c1c-a562-0d564250836f}" },
|
||||
{ HKEY_CLASSES_ROOT, L".svg\\shellex\\{E357FCCD-A995-4576-B01F-234630154E96}" },
|
||||
{ HKEY_CLASSES_ROOT, L".md\\shellex\\{8895b1c6-b41f-4c1c-a562-0d564250836f}" },
|
||||
{ HKEY_CLASSES_ROOT, L".pdf\\shellex\\{8895b1c6-b41f-4c1c-a562-0d564250836f}" }
|
||||
{ HKEY_CLASSES_ROOT, L".pdf\\shellex\\{8895b1c6-b41f-4c1c-a562-0d564250836f}" },
|
||||
{ HKEY_CLASSES_ROOT, L".pdf\\shellex\\{E357FCCD-A995-4576-B01F-234630154E96}" }
|
||||
};
|
||||
|
||||
vector<tuple<HKEY, wstring, wstring>> registryValues = {
|
||||
|
Loading…
Reference in New Issue
Block a user