Skip to content

Commit

Permalink
various bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AngusJohnson committed Oct 14, 2023
1 parent 5365a0d commit 63b7b84
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 51 deletions.
Binary file modified dll_binary/SvgShellExtensions.dll
Binary file not shown.
32 changes: 17 additions & 15 deletions source/SvgPreview.pas
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ interface

const
extension = '.svg';
appId = 'SVGShellExtensions';
appDescription = 'SVG Shell Extensions';
SID_EXT_ShellExtensions = '{B2980224-58B3-478C-B596-7D2B23F2C041}';
IID_EXT_ShellExtensions: TGUID = SID_EXT_ShellExtensions;
extFile = 'svgFile';
appId = 'SVGShellHandler';
appDescription = 'SVG Shell Handler';

SID_SVG_ShellHandler = '{B2980224-58B3-478C-B596-7D2B23F2C041}';
IID_SVG_ShellHandler: TGUID = SID_SVG_ShellHandler;
SID_IThumbnailProvider = '{E357FCCD-A995-4576-B01F-234630154E96}';
IID_IThumbnailProvider: TGUID = SID_IThumbnailProvider;

darkBkColor = $202020;
type
TWTS_ALPHATYPE = (WTSAT_UNKNOWN, WTSAT_RGB, WTSAT_ARGB);

IThumbnailProvider = interface(IUnknown)
[SID_IThumbnailProvider]
function GetThumbnail(cx: Cardinal; out hbmp: HBITMAP;
Expand Down Expand Up @@ -314,15 +316,6 @@ function TSvgShellExt.Unload: HRESULT;
end;
//------------------------------------------------------------------------------

function TSvgShellExt.IInitializeWithStream_Init(const pstream: IStream;
grfMode: DWORD): HRESULT;
begin
fStream := nil;
fStream := pstream;
result := S_OK;
end;
//------------------------------------------------------------------------------

function TSvgShellExt.GetThumbnail(cx: Cardinal;
out hbmp: HBITMAP; out at: TWTS_ALPHATYPE): HRESULT;
var
Expand Down Expand Up @@ -366,6 +359,15 @@ function TSvgShellExt.GetThumbnail(cx: Cardinal;
img.Free;
end;
end;
//------------------------------------------------------------------------------

function TSvgShellExt.IInitializeWithStream_Init(const pstream: IStream;
grfMode: DWORD): HRESULT;
begin
fStream := nil;
fStream := pstream;
result := S_OK;
end;

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
Expand All @@ -387,8 +389,8 @@ initialization

LoadFonts; //needed when displaying SVG text
TComObjectFactory.Create(ComServer,
TSvgShellExt, IID_EXT_ShellExtensions,
appId, appDescription, ciMultiInstance, tmApartment);
TSvgShellExt, IID_SVG_ShellHandler,
extFile, appDescription, ciMultiInstance, tmApartment);

finalization
if res = S_OK then OleUninitialize();
Expand Down
71 changes: 35 additions & 36 deletions source/SvgShellExtensions.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ library SvgShellExtensions;
(*******************************************************************************
* Author : Angus Johnson *
* Version : 1.1 *
* Date : 21 January 2022 *
* Date : 14 October 2023 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2022 *
* Copyright : Angus Johnson 2022-2023 *
* *
* Purpose : 64bit Windows Explorer Preview Handler for QOI image files *
* *
Expand All @@ -27,7 +27,9 @@ uses
{$R *.res}

const
sSurrogateAppId = '{6D2B5079-2F0B-48DD-AB7F-97CEC514D30B}'; //64bit
// Preview Handler Surrogate Host (Prevhost.exe)
// see HKEY_CLASSES_ROOT\AppID
sSurrogateAppId = '{6D2B5079-2F0B-48DD-AB7F-97CEC514D30B}';

function GetModuleName: string;
var
Expand All @@ -45,62 +47,56 @@ var
reg: TRegistry;
begin
Result := E_UNEXPECTED; //will fail if not ADMIN

reg := TRegistry.Create(KEY_ALL_ACCESS);
try
reg.RootKey := HKEY_CLASSES_ROOT;
if not reg.OpenKey(extension, true) then Exit;
reg.WriteString('', appId);
reg.WriteString('', extFile); //'svgFile' (see SvgPreview.pas)
reg.CloseKey;

if reg.OpenKey(appId+'\Clsid', true) then
begin
reg.WriteString('', SID_EXT_ShellExtensions);
reg.CloseKey;
end;

//REGISTER PREVIEW HANDLER
if not reg.OpenKey(appId+'\ShellEx\'+SID_IPreviewHandler, true) then Exit;
reg.WriteString('', SID_EXT_ShellExtensions);
if not reg.OpenKey(extFile, true) then Exit;
reg.CloseKey;
//REGISTER THUMBNAIL PROVIDER
if not reg.OpenKey(appId+'\ShellEx\'+SID_IThumbnailProvider, true) then Exit;
reg.WriteString('', SID_EXT_ShellExtensions);

if not reg.OpenKey(extFile+'\CLSID', true) then Exit;
reg.WriteString('', SID_SVG_ShellHandler);
reg.CloseKey;

////////////////////////////////////////////////////////////////////////////
//the following also seems necessary (at least for SVG files)
//REGISTER PREVIEW HANDLER and THUMBNAIL PROVIDER (under .svg)
if not reg.OpenKey(extension+'\ShellEx\'+SID_IPreviewHandler, true) then Exit;
reg.WriteString('', SID_EXT_ShellExtensions);
reg.WriteString('', SID_SVG_ShellHandler);
reg.CloseKey;
if not reg.OpenKey(extension+'\ShellEx\'+SID_IThumbnailProvider, true) then Exit;
reg.WriteString('', SID_EXT_ShellExtensions);
reg.WriteString('', SID_SVG_ShellHandler);
reg.CloseKey;
////////////////////////////////////////////////////////////////////////////

if not reg.OpenKey('CLSID\'+ SID_EXT_ShellExtensions, true) then Exit;
//REGISTER PREVIEW HANDLER and THUMBNAIL PROVIDER (under .svgFile)
if not reg.OpenKey(extFile +'\ShellEx\'+SID_IPreviewHandler, true) then Exit;
reg.WriteString('', SID_SVG_ShellHandler);
reg.CloseKey;
if not reg.OpenKey(extFile +'\ShellEx\'+SID_IThumbnailProvider, true) then Exit;
reg.WriteString('', SID_SVG_ShellHandler);
reg.CloseKey;

if not reg.OpenKey('CLSID\'+ SID_SVG_ShellHandler, true) then Exit;
reg.WriteString('', appDescription);
reg.WriteString('AppID', sSurrogateAppId);
reg.CloseKey;

reg.OpenKey('CLSID\'+ SID_EXT_ShellExtensions+'\InProcServer32', true);
reg.OpenKey('CLSID\'+ SID_SVG_ShellHandler+'\InProcServer32', true);
reg.WriteString('', GetModuleName);
reg.WriteString('ThreadingModel', 'Apartment');
reg.WriteString('ProgId', appId);
reg.WriteString('VersionIndependentProgID', appId);
reg.CloseKey;

reg.OpenKey('CLSID\' + SID_EXT_ShellExtensions + '\ProgId', true);
reg.WriteString('', appId);
reg.OpenKey('CLSID\' + SID_SVG_ShellHandler + '\ProgId', true);
reg.WriteString('', extFile);
reg.CloseKey;

reg.RootKey := HKEY_LOCAL_MACHINE;
if reg.OpenKey('SOFTWARE\Microsoft\Windows\'+
'CurrentVersion\PreviewHandlers', true) then
if reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\PreviewHandlers', true) then
begin
reg.WriteString(SID_EXT_ShellExtensions, appDescription);
reg.WriteString(SID_SVG_ShellHandler, appDescription);
reg.CloseKey;
end;

finally
reg.Free;
end;
Expand All @@ -121,17 +117,20 @@ begin
reg.RootKey := HKEY_LOCAL_MACHINE;
if reg.OpenKey('SOFTWARE\Microsoft\Windows\'+
'CurrentVersion\PreviewHandlers', true) and
reg.ValueExists(SID_EXT_ShellExtensions) then
reg.DeleteValue(SID_EXT_ShellExtensions);
reg.ValueExists(SID_SVG_ShellHandler) then
reg.DeleteValue(SID_SVG_ShellHandler);

reg.RootKey := HKEY_CLASSES_ROOT;
if reg.KeyExists(extension + '\ShellEx\'+SID_IPreviewHandler) then
reg.DeleteKey(extension + '\ShellEx\'+SID_IPreviewHandler);
if reg.KeyExists(extension + '\ShellEx\'+SID_IThumbnailProvider) then
reg.DeleteKey(extension + '\ShellEx\'+SID_IThumbnailProvider);

reg.DeleteKey('CLSID\'+SID_EXT_ShellExtensions);
reg.DeleteKey(appId);
reg.DeleteKey('CLSID\'+SID_SVG_ShellHandler);
reg.DeleteKey(extFile+'\ShellEx\'+SID_IPreviewHandler);
reg.DeleteKey(extFile+'\ShellEx\'+SID_IThumbnailProvider);
reg.DeleteKey(extFile+'\Clsid');

finally
reg.Free;
end;
Expand Down

0 comments on commit 63b7b84

Please sign in to comment.