restructure projects
This commit is contained in:
parent
3a948f2063
commit
0f48dbe845
@ -7,7 +7,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PhotoThumbnail", "PhotoThum
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsoleApp", "TestConsoleApp\TestConsoleApp.csproj", "{C2573376-C9CF-41DE-B9A6-22790C048062}"
|
||||
EndProject
|
||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ShellExtensions", "ShellExtensions\ShellExtensions.shproj", "{50974517-2D52-4470-9F60-E37B30D1491E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
ShellExtensions\ShellExtensions.projitems*{08c34c77-b778-46aa-a48b-bea6b9fe07fe}*SharedItemsImports = 4
|
||||
ShellExtensions\ShellExtensions.projitems*{50974517-2d52-4470-9f60-e37b30d1491e}*SharedItemsImports = 13
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
|
@ -50,18 +50,6 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Definitions\Reference.cs">
|
||||
<Link>Definitions\Reference.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Definitions\StorageStream.cs">
|
||||
<Link>Definitions\StorageStream.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Definitions\ThumbnailProvider.cs">
|
||||
<Link>Definitions\ThumbnailProvider.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Definitions\ThumbnailProviderAttribute.cs">
|
||||
<Link>Definitions\ThumbnailProviderAttribute.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TgaDecoder.cs" />
|
||||
<Compile Include="TgaThumbnailer.cs" />
|
||||
@ -69,5 +57,6 @@
|
||||
<ItemGroup>
|
||||
<None Include="PhotoThumbnail.pfx" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\ShellExtensions\ShellExtensions.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
@ -1,4 +1,4 @@
|
||||
using PhotoThumbnail.Definitions;
|
||||
using ShellExtensions;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
@ -11,7 +11,7 @@ namespace PhotoThumbnail
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
[ProgId("PhotoThumbnail.TgaThumbnailer")]
|
||||
[ThumbnailProvider("TgaThumbnailer", ".tga", ThumbnailAdornment = ThumbnailAdornment.PhotoBorder)]
|
||||
public class TgaThumbnailer : ThumbnailProvider, IThumbnailFromStream
|
||||
public class TgaThumbnailer : ThumbnailProvider, IThumbnailFromStream, IThumbnailFromFile
|
||||
{
|
||||
#region IThumbnailFromStream Members
|
||||
|
||||
@ -40,5 +40,17 @@ namespace PhotoThumbnail
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IThumbnailFromFile Members
|
||||
|
||||
public Bitmap ConstructBitmap(FileInfo info, int sideSize)
|
||||
{
|
||||
using (FileStream stream = File.OpenRead(info.FullName))
|
||||
{
|
||||
return ConstructBitmap(stream, sideSize);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,47 +1,7 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
|
||||
namespace PhotoThumbnail.Definitions
|
||||
namespace ShellExtensions.Interop.Common
|
||||
{
|
||||
internal static class HandlerNativeMethods
|
||||
{
|
||||
internal static readonly Guid IThumbnailProviderGuid = new Guid("e357fccd-a995-4576-b01f-234630154e96");
|
||||
|
||||
//internal static readonly Guid IInitializeWithFileGuid = new Guid("b7d14566-0509-4cce-a71f-0a554233bd9b");
|
||||
internal static readonly Guid IInitializeWithStreamGuid = new Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f");
|
||||
//internal static readonly Guid IInitializeWithItemGuid = new Guid("7f73be3f-fb79-493c-a6c7-7ee14e245841");
|
||||
|
||||
internal static readonly Guid IMarshalGuid = new Guid("00000003-0000-0000-C000-000000000046");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This interface exposes the <see cref="ConsructBitmap"/> function for initializing the
|
||||
/// Thumbnail Provider with a <typeparamref name="Stream"/>.
|
||||
/// If this interfaces is not used, then the handler must opt out of process isolation.
|
||||
/// This interface can be used in conjunction with the other intialization interfaces,
|
||||
/// but only 1 will be accessed according to the priorities preset by the Windows Shell:
|
||||
/// <typeparamref name="IThumbnailFromStream"/>
|
||||
/// <typeparamref name="IThumbnailFromShellObject"/>
|
||||
/// <typeparamref name="IThumbnailFromFile"/>
|
||||
/// </summary>
|
||||
public interface IThumbnailFromStream
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides the <typeparamref name="Stream"/> to the item from which a thumbnail should be created.
|
||||
/// <remarks>Only 32bpp bitmaps support adornments.
|
||||
/// While 24bpp bitmaps will be displayed they will not display adornments.
|
||||
/// Additional guidelines for developing thumbnails can be found at http://msdn.microsoft.com/en-us/library/cc144115(v=VS.85).aspx
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream to initialize the thumbnail</param>
|
||||
/// <param name="sideSize">Square side dimension in which the thumbnail should fit; the thumbnail will be scaled otherwise.</param>
|
||||
/// <returns></returns>
|
||||
Bitmap ConstructBitmap(Stream stream, int sideSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The STGM constants are flags that indicate
|
||||
/// conditions for creating and deleting the object and access modes
|
||||
@ -162,58 +122,4 @@ namespace PhotoThumbnail.Definitions
|
||||
/// </summary>
|
||||
DirectSingleWriterMultipleReader = 0x00400000
|
||||
}
|
||||
|
||||
// <summary>
|
||||
/// Thumbnail Alpha Types
|
||||
/// </summary>
|
||||
public enum ThumbnailAlphaType
|
||||
{
|
||||
/// <summary>
|
||||
/// Let the system decide.
|
||||
/// </summary>
|
||||
Unknown = 0,
|
||||
|
||||
/// <summary>
|
||||
/// No transparency
|
||||
/// </summary>
|
||||
NoAlphaChannel = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Has transparency
|
||||
/// </summary>
|
||||
HasAlphaChannel = 2,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ComVisible interface for native IThumbnailProvider
|
||||
/// </summary>
|
||||
[ComImport]
|
||||
[Guid("e357fccd-a995-4576-b01f-234630154e96")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
interface IThumbnailProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a pointer to a bitmap to display as a thumbnail
|
||||
/// </summary>
|
||||
/// <param name="squareLength"></param>
|
||||
/// <param name="bitmapHandle"></param>
|
||||
/// <param name="bitmapType"></param>
|
||||
void GetThumbnail(uint squareLength, [Out] out IntPtr bitmapHandle, [Out] out uint bitmapType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides means by which to initialize with a stream.
|
||||
/// </summary>
|
||||
[ComImport]
|
||||
[Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
interface IInitializeWithStream
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes with a stream.
|
||||
/// </summary>
|
||||
/// <param name="stream"></param>
|
||||
/// <param name="fileMode"></param>
|
||||
void Initialize(IStream stream, AccessModes fileMode);
|
||||
}
|
||||
}
|
92
ShellExtensions/Interop/HandlerNativeMethods.cs
Normal file
92
ShellExtensions/Interop/HandlerNativeMethods.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using ShellExtensions.Interop.Common;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
|
||||
namespace ShellExtensions.Interop
|
||||
{
|
||||
internal static class HandlerNativeMethods
|
||||
{
|
||||
internal static readonly Guid IThumbnailProviderGuid = new Guid("e357fccd-a995-4576-b01f-234630154e96");
|
||||
|
||||
internal static readonly Guid IInitializeWithFileGuid = new Guid("b7d14566-0509-4cce-a71f-0a554233bd9b");
|
||||
internal static readonly Guid IInitializeWithStreamGuid = new Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f");
|
||||
//internal static readonly Guid IInitializeWithItemGuid = new Guid("7f73be3f-fb79-493c-a6c7-7ee14e245841");
|
||||
|
||||
internal static readonly Guid IMarshalGuid = new Guid("00000003-0000-0000-C000-000000000046");
|
||||
}
|
||||
|
||||
#region Interfaces
|
||||
|
||||
/// <summary>
|
||||
/// ComVisible interface for native IThumbnailProvider
|
||||
/// </summary>
|
||||
[ComImport]
|
||||
[Guid("e357fccd-a995-4576-b01f-234630154e96")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
interface IThumbnailProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a pointer to a bitmap to display as a thumbnail
|
||||
/// </summary>
|
||||
/// <param name="squareLength"></param>
|
||||
/// <param name="bitmapHandle"></param>
|
||||
/// <param name="bitmapType"></param>
|
||||
void GetThumbnail(uint squareLength, [Out] out IntPtr bitmapHandle, [Out] out uint bitmapType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides means by which to initialize with a file.
|
||||
/// </summary>
|
||||
[ComImport]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
[Guid("b7d14566-0509-4cce-a71f-0a554233bd9b")]
|
||||
interface IInitializeWithFile
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes with a file.
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="fileMode"></param>
|
||||
void Initialize([MarshalAs(UnmanagedType.LPWStr)] string filePath, AccessModes fileMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides means by which to initialize with a stream.
|
||||
/// </summary>
|
||||
[ComImport]
|
||||
[Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
interface IInitializeWithStream
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes with a stream.
|
||||
/// </summary>
|
||||
/// <param name="stream"></param>
|
||||
/// <param name="fileMode"></param>
|
||||
void Initialize(IStream stream, AccessModes fileMode);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// <summary>
|
||||
/// Thumbnail Alpha Types
|
||||
/// </summary>
|
||||
public enum ThumbnailAlphaType
|
||||
{
|
||||
/// <summary>
|
||||
/// Let the system decide.
|
||||
/// </summary>
|
||||
Unknown = 0,
|
||||
|
||||
/// <summary>
|
||||
/// No transparency
|
||||
/// </summary>
|
||||
NoAlphaChannel = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Has transparency
|
||||
/// </summary>
|
||||
HasAlphaChannel = 2,
|
||||
}
|
||||
}
|
13
ShellExtensions/Resources/LocalizedMessages.cs
Normal file
13
ShellExtensions/Resources/LocalizedMessages.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace ShellExtensions.Resources
|
||||
{
|
||||
internal sealed class LocalizedMessages
|
||||
{
|
||||
public const string StorageStreamBufferOverflow = "The sum of offset and count must be less than or equal to the size of the buffer.";
|
||||
public const string StorageStreamCountLessThanZero = "Count must be greater than or equal to zero.";
|
||||
public const string StorageStreamIsReadonly = "The stream was initialized as read-only.";
|
||||
public const string StorageStreamOffsetLessThanZero = "Offset must be greater than or equal to zero.";
|
||||
|
||||
public const string ThumbnailProviderDisabledProcessIsolation = "{0} does not implement IThumbnailFromStream and so requires DisableProcessIsolation set to true.";
|
||||
public const string ThumbnailProviderInterfaceNotImplemented = "{0} must implement one or more of IThumbnailFromStream, IThumbnailFromShellObject or IThumbnailFromFile.";
|
||||
}
|
||||
}
|
20
ShellExtensions/ShellExtensions.projitems
Normal file
20
ShellExtensions/ShellExtensions.projitems
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' < '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>50974517-2d52-4470-9f60-e37b30d1491e</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<Import_RootNamespace>ShellExtensions</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interop\HandlerNativeMethods.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interop\Common\ShellNativeStructs.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Resources\LocalizedMessages.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)StorageStream.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ThumbnailProviders\ManagedInitializationInterfaces.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ThumbnailProviders\ThumbnailProvider.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ThumbnailProviders\ThumbnailProviderAttribute.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
13
ShellExtensions/ShellExtensions.shproj
Normal file
13
ShellExtensions/ShellExtensions.shproj
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>50974517-2d52-4470-9f60-e37b30d1491e</ProjectGuid>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
|
||||
<PropertyGroup />
|
||||
<Import Project="ShellExtensions.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
|
||||
</Project>
|
@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using ShellExtensions.Resources;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
|
||||
namespace PhotoThumbnail.Definitions
|
||||
namespace ShellExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// A wrapper for the native IStream object.
|
||||
@ -15,7 +16,7 @@ namespace PhotoThumbnail.Definitions
|
||||
|
||||
internal StorageStream(IStream stream, bool readOnly)
|
||||
{
|
||||
_stream = stream ?? throw new ArgumentNullException("stream");
|
||||
_stream = stream ?? throw new ArgumentNullException(nameof(stream));
|
||||
_isReadOnly = readOnly;
|
||||
}
|
||||
|
||||
@ -73,10 +74,10 @@ namespace PhotoThumbnail.Definitions
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (buffer == null) { throw new ArgumentNullException("buffer"); }
|
||||
if (offset < 0) { throw new ArgumentOutOfRangeException("offset", "StorageStreamOffsetLessThanZero"); }
|
||||
if (count < 0) { throw new ArgumentOutOfRangeException("count", "StorageStreamCountLessThanZero"); }
|
||||
if (offset + count > buffer.Length) { throw new ArgumentException("StorageStreamBufferOverflow", "count"); }
|
||||
if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); }
|
||||
if (offset < 0) { throw new ArgumentOutOfRangeException(nameof(offset), LocalizedMessages.StorageStreamOffsetLessThanZero); }
|
||||
if (count < 0) { throw new ArgumentOutOfRangeException(nameof(count), LocalizedMessages.StorageStreamCountLessThanZero); }
|
||||
if (offset + count > buffer.Length) { throw new ArgumentException(LocalizedMessages.StorageStreamBufferOverflow, nameof(count)); }
|
||||
|
||||
int bytesRead = 0;
|
||||
if (count > 0)
|
||||
@ -119,11 +120,11 @@ namespace PhotoThumbnail.Definitions
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
if (_isReadOnly) { throw new InvalidOperationException("StorageStreamIsReadonly"); }
|
||||
if (buffer == null) { throw new ArgumentNullException("buffer"); }
|
||||
if (offset < 0) { throw new ArgumentOutOfRangeException("offset", "StorageStreamOffsetLessThanZero"); }
|
||||
if (count < 0) { throw new ArgumentOutOfRangeException("count", "StorageStreamCountLessThanZero"); }
|
||||
if (offset + count > buffer.Length) { throw new ArgumentException("StorageStreamBufferOverflow", "count"); }
|
||||
if (_isReadOnly) { throw new InvalidOperationException(LocalizedMessages.StorageStreamIsReadonly); }
|
||||
if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); }
|
||||
if (offset < 0) { throw new ArgumentOutOfRangeException(nameof(offset), LocalizedMessages.StorageStreamOffsetLessThanZero); }
|
||||
if (count < 0) { throw new ArgumentOutOfRangeException(nameof(count), LocalizedMessages.StorageStreamCountLessThanZero); }
|
||||
if (offset + count > buffer.Length) { throw new ArgumentException(LocalizedMessages.StorageStreamBufferOverflow, nameof(count)); }
|
||||
|
||||
if (count > 0)
|
||||
{
|
@ -0,0 +1,54 @@
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
namespace ShellExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// This interface exposes the <see cref="ConsructBitmap"/> function for initializing the
|
||||
/// Thumbnail Provider with a <typeparamref name="Stream"/>.
|
||||
/// If this interfaces is not used, then the handler must opt out of process isolation.
|
||||
/// This interface can be used in conjunction with the other intialization interfaces,
|
||||
/// but only 1 will be accessed according to the priorities preset by the Windows Shell:
|
||||
/// <typeparamref name="IThumbnailFromStream"/>
|
||||
/// <typeparamref name="IThumbnailFromShellObject"/>
|
||||
/// <typeparamref name="IThumbnailFromFile"/>
|
||||
/// </summary>
|
||||
public interface IThumbnailFromStream
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides the <typeparamref name="Stream"/> to the item from which a thumbnail should be created.
|
||||
/// <remarks>Only 32bpp bitmaps support adornments.
|
||||
/// While 24bpp bitmaps will be displayed they will not display adornments.
|
||||
/// Additional guidelines for developing thumbnails can be found at http://msdn.microsoft.com/en-us/library/cc144115(v=VS.85).aspx
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream to initialize the thumbnail</param>
|
||||
/// <param name="sideSize">Square side dimension in which the thumbnail should fit; the thumbnail will be scaled otherwise.</param>
|
||||
/// <returns></returns>
|
||||
Bitmap ConstructBitmap(Stream stream, int sideSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This interface exposes the <see cref="ConsructBitmap"/> function for initializing the
|
||||
/// Thumbnail Provider with file information.
|
||||
/// This interface can be used in conjunction with the other intialization interfaces,
|
||||
/// but only 1 will be accessed according to the priorities preset by the Windows Shell:
|
||||
/// <typeparamref name="IThumbnailFromStream"/>
|
||||
/// <typeparamref name="IThumbnailFromShellObject"/>
|
||||
/// <typeparamref name="IThumbnailFromFile"/>
|
||||
/// </summary>
|
||||
public interface IThumbnailFromFile
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides the <typeparamref name="FileInfo"/> to the item from which a thumbnail should be created.
|
||||
/// <remarks>Only 32bpp bitmaps support adornments.
|
||||
/// While 24bpp bitmaps will be displayed they will not display adornments.
|
||||
/// Additional guidelines for developing thumbnails can be found at http://msdn.microsoft.com/en-us/library/cc144115(v=VS.85).aspx
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
/// <param name="info">FileInfo to initialize the thumbnail</param>
|
||||
/// <param name="sideSize">Square side dimension in which the thumbnail should fit; the thumbnail will be scaled otherwise.</param>
|
||||
/// <returns>Generated thumbnail</returns>
|
||||
Bitmap ConstructBitmap(FileInfo info, int sideSize);
|
||||
}
|
||||
}
|
@ -1,12 +1,16 @@
|
||||
using Microsoft.Win32;
|
||||
using ShellExtensions.Interop;
|
||||
using ShellExtensions.Interop.Common;
|
||||
using ShellExtensions.Resources;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace PhotoThumbnail.Definitions
|
||||
namespace ShellExtensions
|
||||
{
|
||||
public abstract class ThumbnailProvider : IThumbnailProvider, ICustomQueryInterface, IDisposable, IInitializeWithStream
|
||||
public abstract class ThumbnailProvider : IThumbnailProvider, ICustomQueryInterface, IDisposable, IInitializeWithStream, IInitializeWithFile
|
||||
{
|
||||
private Bitmap GetBitmap(int sideLength)
|
||||
{
|
||||
@ -14,13 +18,21 @@ namespace PhotoThumbnail.Definitions
|
||||
{
|
||||
return stream.ConstructBitmap(_stream, sideLength);
|
||||
}
|
||||
if (_info != null && this is IThumbnailFromFile file)
|
||||
{
|
||||
return file.ConstructBitmap(_info, sideLength);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("ThumbnailProviderInterfaceNotImplemented: " + GetType().Name);
|
||||
throw new InvalidOperationException(
|
||||
string.Format(System.Globalization.CultureInfo.InvariantCulture,
|
||||
LocalizedMessages.ThumbnailProviderInterfaceNotImplemented,
|
||||
GetType().Name));
|
||||
}
|
||||
|
||||
public virtual ThumbnailAlphaType ThumbnailAlphaType => ThumbnailAlphaType.Unknown;
|
||||
|
||||
private StorageStream _stream;
|
||||
private FileInfo _info;
|
||||
|
||||
#region IThumbnailProvider Members
|
||||
|
||||
@ -47,7 +59,8 @@ namespace PhotoThumbnail.Definitions
|
||||
return CustomQueryInterfaceResult.Failed;
|
||||
}
|
||||
|
||||
if (iid == HandlerNativeMethods.IInitializeWithStreamGuid && !(this is IThumbnailFromStream))
|
||||
if ((iid == HandlerNativeMethods.IInitializeWithStreamGuid && !(this is IThumbnailFromStream)) ||
|
||||
(iid == HandlerNativeMethods.IInitializeWithFileGuid && !(this is IThumbnailFromFile)))
|
||||
{
|
||||
return CustomQueryInterfaceResult.Failed;
|
||||
}
|
||||
@ -186,26 +199,30 @@ namespace PhotoThumbnail.Definitions
|
||||
}
|
||||
|
||||
var interfaces = type.GetInterfaces();
|
||||
bool interfaced = interfaces.Any(x => x == typeof(IThumbnailFromStream));
|
||||
bool interfaced = interfaces.Any(x => x is IThumbnailFromStream);
|
||||
|
||||
/*
|
||||
if (interfaces.Any(x => x == typeof(IThumbnailFromShellObject) || x == typeof(IThumbnailFromFile)))
|
||||
if (interfaces.Any(x => x is IThumbnailFromFile))
|
||||
{
|
||||
// According to MSDN (http://msdn.microsoft.com/en-us/library/cc144114(v=VS.85).aspx)
|
||||
// A thumbnail provider that does not implement IInitializeWithStream must opt out of
|
||||
// running in the isolated process. The default behavior of the indexer opts in
|
||||
// to process isolation regardless of which interfaces are implemented.
|
||||
// to process isolation regardless of which interfaces are implemented.
|
||||
if (!interfaced && !attribute.DisableProcessIsolation)
|
||||
{
|
||||
throw new InvalidOperationException("ThumbnailProviderDisabledProcessIsolation: " + type.Name);
|
||||
throw new InvalidOperationException(
|
||||
string.Format(System.Globalization.CultureInfo.InvariantCulture,
|
||||
LocalizedMessages.ThumbnailProviderDisabledProcessIsolation,
|
||||
type.Name));
|
||||
}
|
||||
interfaced = true;
|
||||
}
|
||||
*/
|
||||
|
||||
if (!interfaced)
|
||||
{
|
||||
throw new InvalidOperationException("ThumbnailProviderInterfaceNotImplemented: " + type.Name);
|
||||
throw new InvalidOperationException(
|
||||
string.Format(System.Globalization.CultureInfo.InvariantCulture,
|
||||
LocalizedMessages.ThumbnailProviderInterfaceNotImplemented,
|
||||
type.Name));
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,6 +237,15 @@ namespace PhotoThumbnail.Definitions
|
||||
|
||||
#endregion
|
||||
|
||||
#region IInitializeWithFile Members
|
||||
|
||||
void IInitializeWithFile.Initialize(string filePath, AccessModes fileMode)
|
||||
{
|
||||
_info = new FileInfo(filePath);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
/// <summary>
|
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace PhotoThumbnail.Definitions
|
||||
namespace ShellExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// This class attribute is applied to a Thumbnail Provider to specify registration parameters
|
||||
@ -16,8 +16,8 @@ namespace PhotoThumbnail.Definitions
|
||||
/// <param name="extensions">Semi-colon-separated list of extensions supported by this provider.</param>
|
||||
public ThumbnailProviderAttribute(string name, string extensions)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException("name");
|
||||
Extensions = extensions ?? throw new ArgumentNullException("extensions");
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
Extensions = extensions ?? throw new ArgumentNullException(nameof(extensions));
|
||||
|
||||
DisableProcessIsolation = false;
|
||||
ThumbnailCutoff = ThumbnailCutoffSize.Square20;
|
Loading…
x
Reference in New Issue
Block a user