Skip to content
Open
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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# WinThumbsPreloader
Thumbnails preloader for Windows Explorer

![Screenshot](https://raw.githubusercontent.com/bruhov/WinThumbsPreloader/master/Website/images/preview.gif)
![Screenshot](https://raw.githubusercontent.com/inthebrilliantblue/WinThumbsPreloader/master/Website/images/preview.gif)

### Download: [WinThumbsPreloader-1.0.1-setup.exe](https://github.com/bruhov/WinThumbsPreloader/releases/download/v1.0.1/WinThumbsPreloader-1.0.1-setup.exe)
# CLI Options
-s : Silent mode

-r : Recursive directory search

-m : Multi-threaded generation


### Download: [WinThumbsPreloader.exe](https://github.com/inthebrilliantblue/WinThumbsPreloader/releases/download/v1.0.2/WinThumbsPreloader.exe)
6 changes: 6 additions & 0 deletions WinThumbsPreloader/ConsoleWTP/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
77 changes: 77 additions & 0 deletions WinThumbsPreloader/ConsoleWTP/ConsoleWTP.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3B8D4D60-2087-42E3-B074-3AC3159FBDFE}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ConsoleWTP</RootNamespace>
<AssemblyName>ConsoleWTP</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DirectoryScanner.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ThumbnailPreloader.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
27 changes: 27 additions & 0 deletions WinThumbsPreloader/ConsoleWTP/DirectoryScanner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleWTP
{
class DirectoryScanner
{

public static List<string> GetItemsBulk(string path, bool includeNestedDirectories)
{
List<string> items = new List<string>();
if (includeNestedDirectories)
{
items = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).ToList();
}
else
{
items = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly).ToList();
}
return items;
}
}
}
32 changes: 32 additions & 0 deletions WinThumbsPreloader/ConsoleWTP/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleWTP
{
class Program
{
static void Main(string[] args)
{
//Check args
if (string.IsNullOrWhiteSpace(args[0])) {
Console.WriteLine("Please provide a location to scan!");
return;
}
//Get the items first before doing work
List<string> items = DirectoryScanner.GetItemsBulk(args[0], true);
Parallel.ForEach(
items,
new ParallelOptions { MaxDegreeOfParallelism = 2048 },
item =>
{
ThumbnailPreloader thumbnailPreloader = new ThumbnailPreloader();
Console.WriteLine(item);
thumbnailPreloader.PreloadThumbnail(item);
}
);
}
}
}
36 changes: 36 additions & 0 deletions WinThumbsPreloader/ConsoleWTP/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ConsoleWTP")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConsoleWTP")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3b8d4d60-2087-42e3-b074-3ac3159fbdfe")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
177 changes: 177 additions & 0 deletions WinThumbsPreloader/ConsoleWTP/ThumbnailPreloader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
using System;
using System.Runtime.InteropServices;

namespace ConsoleWTP
{
class ThumbnailPreloader
{
private Guid iIdIShellItem;
private IThumbnailCache TBCache;

public ThumbnailPreloader()
{
iIdIShellItem = new Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe");
Guid CLSIDLocalThumbnailCache = new Guid("50ef4544-ac9f-4a8e-b21b-8a26180db13f");
var TBCacheType = Type.GetTypeFromCLSID(CLSIDLocalThumbnailCache);
TBCache = (IThumbnailCache)Activator.CreateInstance(TBCacheType);
}

public void PreloadThumbnail(string filePath)
{
IShellItem shellItem = null;
ISharedBitmap bmp = null;
WTS_CACHEFLAGS cFlags;
WTS_THUMBNAILID bmpId;
try
{
SHCreateItemFromParsingName(filePath, IntPtr.Zero, iIdIShellItem, out shellItem);
TBCache.GetThumbnail(shellItem, 128, WTS_FLAGS.WTS_EXTRACTINPROC, out bmp, out cFlags, out bmpId);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
if (bmp != null) Marshal.ReleaseComObject(bmp);
if (shellItem != null) Marshal.ReleaseComObject(shellItem);
bmp = null;
shellItem = null;
}

//Import native functions
[DllImport("shell32.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
static extern void SHCreateItemFromParsingName(
[In][MarshalAs(UnmanagedType.LPWStr)] string pszPath,
[In] IntPtr pbc,
[In][MarshalAs(UnmanagedType.LPStruct)] Guid riid,
[Out][MarshalAs(UnmanagedType.Interface, IidParameterIndex = 2)] out IShellItem ppv);

[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("F676C15D-596A-4ce2-8234-33996F445DB1")]
interface IThumbnailCache
{
uint GetThumbnail(
[In] IShellItem pShellItem,
[In] uint cxyRequestedThumbSize,
[In] WTS_FLAGS flags /*default: WTS_FLAGS.WTS_EXTRACT*/,
[Out][MarshalAs(UnmanagedType.Interface)] out ISharedBitmap ppvThumb,
[Out] out WTS_CACHEFLAGS pOutFlags,
[Out] out WTS_THUMBNAILID pThumbnailID
);

void GetThumbnailByID(
[In, MarshalAs(UnmanagedType.Struct)] WTS_THUMBNAILID thumbnailID,
[In] uint cxyRequestedThumbSize,
[Out][MarshalAs(UnmanagedType.Interface)] out ISharedBitmap ppvThumb,
[Out] out WTS_CACHEFLAGS pOutFlags
);
}

[Flags]
enum WTS_FLAGS : uint
{
WTS_EXTRACT = 0x00000000,
WTS_INCACHEONLY = 0x00000001,
WTS_FASTEXTRACT = 0x00000002,
WTS_SLOWRECLAIM = 0x00000004,
WTS_FORCEEXTRACTION = 0x00000008,
WTS_EXTRACTDONOTCACHE = 0x00000020,
WTS_SCALETOREQUESTEDSIZE = 0x00000040,
WTS_SKIPFASTEXTRACT = 0x00000080,
WTS_EXTRACTINPROC = 0x00000100
}

[Flags]
enum WTS_CACHEFLAGS : uint
{
WTS_DEFAULT = 0x00000000,
WTS_LOWQUALITY = 0x00000001,
WTS_CACHED = 0x00000002
}

[StructLayout(LayoutKind.Sequential, Size = 16), Serializable]
struct WTS_THUMBNAILID
{
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 16)]
byte[] rgbKey;
}

[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")]
public interface IShellItem
{
void BindToHandler(IntPtr pbc,
[MarshalAs(UnmanagedType.LPStruct)] Guid bhid,
[MarshalAs(UnmanagedType.LPStruct)] Guid riid,
out IntPtr ppv);

void GetParent(out IShellItem ppsi);

void GetDisplayName(SIGDN sigdnName, out IntPtr ppszName);

void GetAttributes(uint sfgaoMask, out uint psfgaoAttribs);

void Compare(IShellItem psi, uint hint, out int piOrder);
};

public enum SIGDN : uint
{
NORMALDISPLAY = 0,
PARENTRELATIVEPARSING = 0x80018001,
PARENTRELATIVEFORADDRESSBAR = 0x8001c001,
DESKTOPABSOLUTEPARSING = 0x80028000,
PARENTRELATIVEEDITING = 0x80031001,
DESKTOPABSOLUTEEDITING = 0x8004c000,
FILESYSPATH = 0x80058000,
URL = 0x80068000
}

[ComImportAttribute()]
[GuidAttribute("091162a4-bc96-411f-aae8-c5122cd03363")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface ISharedBitmap
{
uint Detach(
[Out] out IntPtr phbm
);

uint GetFormat(
[Out] out WTS_ALPHATYPE pat
);

uint GetSharedBitmap(
[Out] out IntPtr phbm
);

uint GetSize(
[Out, MarshalAs(UnmanagedType.Struct)] out SIZE pSize
);

uint InitializeBitmap(
[In] IntPtr hbm,
[In] WTS_ALPHATYPE wtsAT
);
}

[StructLayout(LayoutKind.Sequential)]
public struct SIZE
{
public int cx;
public int cy;

public SIZE(int cx, int cy)
{
this.cx = cx;
this.cy = cy;
}
}

public enum WTS_ALPHATYPE : uint
{
WTSAT_UNKNOWN = 0,
WTSAT_RGB = 1,
WTSAT_ARGB = 2
}
}
}
Binary file not shown.
6 changes: 6 additions & 0 deletions WinThumbsPreloader/ConsoleWTP/bin/Debug/ConsoleWTP.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
Binary file not shown.
Binary file not shown.
Loading