Skip to content

Commit

Permalink
Merge pull request #71 from tibold/develop
Browse files Browse the repository at this point in the history
Release of v.1.1.0
  • Loading branch information
tibold authored May 31, 2020
2 parents c7de9df + 45e3fc8 commit 7788ad2
Show file tree
Hide file tree
Showing 23 changed files with 1,108 additions and 368 deletions.
39 changes: 35 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,47 @@
Extension module for Windows Explorer to render SVG thumbnails, so that you can have an overview of your SVG files.

## Installation
From _[Releases](https://github.com/tibold/svg-explorer-extension/releases)_ download and run appropriate binary for your system. Note: you probably need an _unsigned_ version as the signed binary certificate was revoked (#29) around Dec 2019.
From _[Releases](https://github.com/tibold/svg-explorer-extension/releases)_ download and run appropriate binary for your system. There are no further actions required after installations.

Then kill `explorer.exe` and icon cache
> Make sure you download the right architecture (the 32 bit installer will run on a 64 bit system, but the extension will not function).
## Troubleshooting

----
> Thumbnails do no show after installation
### Method 1:

This may happen if the thumbnail's are disabled in the system. To verify that it is indeed turned on:

* Open the start menu
* Search for `File Explorer Options` and open it
* Under the `View` tab make sure that the `Always show icons, never thumbnails` is __unchecked__

### Method 2:

This may happen if the system already contains cached thumbnails for the SVGs you are trying to view. This can be fixed by clearing the system's thumbnail cache.

* Open the start menu
* Search for "Disk cleanup" and open it
* In the dialog there is a list of items that can be cleaned. Select `Thumbnails` at the end of the list. You may unselect the rest or leave the default selection.
* Click `OK`

### Method 3:

Kill `explorer.exe` and delete the icon cache manually
([ref](https://superuser.com/questions/342052/how-to-get-svg-thumbnails-in-windows-explorer)):

TASKKILL /IM explorer* /F
DEL "%localappdata%\IconCache.db" /A
explorer.exe

Make sure you download the right architecture (the 32 bit installer will run on a 64 bit system, but the extension will not function).

If neither of the above helped please open an issue on our github page.

----
> An error is thrown during the installation.
Please open an issue on our github page, and include a screen shot and the exact error message.

### Automatic builds
Development install exe's are created from every commit through the continual-integration system.
Expand Down
11 changes: 11 additions & 0 deletions SVGThumbnailExtension/Logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <QtCore/QDebug>

#if QT_VERSION < 0x050200
#define debugLog qDebug()
#else
#include <QtCore/QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(svgExtension)
#define debugLog qCDebug(svgExtension)
#endif
42 changes: 32 additions & 10 deletions SVGThumbnailExtension/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
#define INITGUID
#include "Logging.h"
#include "Registry.h"

#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QtCore/QString>
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>

HINSTANCE g_hinstDll = NULL;
LONG g_cRef = 0;

QApplication * app;

#if QT_VERSION >= 0x050200
Q_LOGGING_CATEGORY(svgExtension, "SvgSee")
#endif

void Initialize(HMODULE module) {
int c = 0;
WCHAR path[2048];
memset(path, 0, 2048);
GetModuleFileNameW(module, path, 2048);
auto modulePath = QString::fromWCharArray(path, 2048);
ZeroMemory(path, sizeof(path));
auto length = GetModuleFileNameW(module, path, 2048);
if (GetLastError() != ERROR_SUCCESS || length <= 0) {
debugLog << "Failed to retrieve module name";
}
auto modulePath = QString::fromWCharArray(path, length);
debugLog << "Module path is: " << modulePath;
QFileInfo dll(modulePath);
QDir libraryPath = dll.dir();
QStringList libraryPaths = (QStringList() << libraryPath.absolutePath());
qDebug() << libraryPaths;
QApplication::setLibraryPaths(libraryPaths);
app = new QApplication(c, (char **)0, 0);
}
Expand All @@ -33,6 +42,7 @@ BOOL APIENTRY DllMain(HINSTANCE hinstDll,
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
debugLog << "DLL_PROCESS_ATTACH";
g_hinstDll = hinstDll;
Initialize(hinstDll);
break;
Expand Down Expand Up @@ -65,23 +75,35 @@ STDAPI_(ULONG) DllRelease()

STDAPI DllRegisterServer()
{
debugLog << "Enter: DLLRegisterServer";
WCHAR szModule[MAX_PATH];

ZeroMemory(szModule, sizeof(szModule));
GetModuleFileName(g_hinstDll, szModule, ARRAYSIZE(szModule));

REGKEY_SUBKEY_AND_VALUE keys[] = {
{HKEY_CLASSES_ROOT, L"CLSID\\" szCLSID_SampleThumbnailProvider, NULL, REG_SZ, (DWORD_PTR)L"Sample Thumbnail Provider"},
{HKEY_CLASSES_ROOT, L"CLSID\\" szCLSID_SampleThumbnailProvider, NULL, REG_SZ, (DWORD_PTR)L"SvgSee"},
{HKEY_CLASSES_ROOT, L"CLSID\\" szCLSID_SampleThumbnailProvider L"\\InprocServer32", NULL, REG_SZ, (DWORD_PTR)szModule},
{HKEY_CLASSES_ROOT, L"CLSID\\" szCLSID_SampleThumbnailProvider L"\\InprocServer32", L"ThreadingModel", REG_SZ, (DWORD_PTR)L"Apartment"},
{HKEY_CLASSES_ROOT, L".SVG\\shellex\\{E357FCCD-A995-4576-B01F-234630154E96}", NULL, REG_SZ, (DWORD_PTR)szCLSID_SampleThumbnailProvider},
{HKEY_CLASSES_ROOT, L".SVGZ\\shellex\\{E357FCCD-A995-4576-B01F-234630154E96}", NULL, REG_SZ, (DWORD_PTR)szCLSID_SampleThumbnailProvider}
};
return CreateRegistryKeys(keys, ARRAYSIZE(keys));


auto result = CreateRegistryKeys(keys, ARRAYSIZE(keys));

debugLog << "Leaving: DLLRegisterServer";

return result;
}

STDAPI DllUnregisterServer()
{
debugLog << "Enter: DLLRegisterServer";

REGKEY_SUBKEY keys[] = {{HKEY_CLASSES_ROOT, L"CLSID\\" szCLSID_SampleThumbnailProvider}};
return DeleteRegistryKeys(keys, ARRAYSIZE(keys));
auto result = DeleteRegistryKeys(keys, ARRAYSIZE(keys));

debugLog << "Leaving: DLLRegisterServer";
return result;
}
14 changes: 14 additions & 0 deletions SVGThumbnailExtension/Registry.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "Registry.h"
#include "Logging.h"

STDAPI CreateRegistryKey(REGKEY_SUBKEY_AND_VALUE* pKey)
{
debugLog << "Enter: Create single registry key";
size_t cbData;
LPVOID pvData = NULL;
HRESULT hr = S_OK;
Expand Down Expand Up @@ -29,18 +31,23 @@ STDAPI CreateRegistryKey(REGKEY_SUBKEY_AND_VALUE* pKey)

if (SUCCEEDED(hr))
{
QString keyName = QString::fromWCharArray(pKey->lpszSubKey);
debugLog << "Setting key: " << keyName;
LSTATUS status = SHSetValue(pKey->hKey, pKey->lpszSubKey, pKey->lpszValue, pKey->dwType, pvData, (DWORD)cbData);
if (NOERROR != status)
{
hr = HRESULT_FROM_WIN32(status);
debugLog << "Failed to set registry key.";
}
}

debugLog << "Leave: Create single registry key";
return hr;
}

STDAPI CreateRegistryKeys(REGKEY_SUBKEY_AND_VALUE* aKeys, ULONG cKeys)
{
debugLog << "Enter: Create multiple registry key";
HRESULT hr = S_OK;

for (ULONG iKey = 0; iKey < cKeys; iKey++)
Expand All @@ -51,21 +58,28 @@ STDAPI CreateRegistryKeys(REGKEY_SUBKEY_AND_VALUE* aKeys, ULONG cKeys)
hr = hrTemp;
}
}

debugLog << "Leave: Create multiple registry key";
return hr;
}

STDAPI DeleteRegistryKeys(REGKEY_SUBKEY* aKeys, ULONG cKeys)
{
debugLog << "Enter: Delete registry keys";
HRESULT hr = S_OK;
LSTATUS status;

for (ULONG iKey = 0; iKey < cKeys; iKey++)
{
QString keyName = QString::fromWCharArray(aKeys[iKey].lpszSubKey);
debugLog << "Deleting key: " << keyName;
status = RegDeleteTree(aKeys[iKey].hKey, aKeys[iKey].lpszSubKey);
if (NOERROR != status)
{
hr = HRESULT_FROM_WIN32(status);
debugLog << "Failed to delete registry key";
}
}
debugLog << "Leave: Delete registry keys";
return hr;
}
4 changes: 3 additions & 1 deletion SVGThumbnailExtension/SVGThumbnailExtension.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
QT += svg
QT += winextras

TARGET = SVGThumbnailExtension
TARGET = SvgSee
TEMPLATE = lib
CONFIG += c++1z

CONFIG(release, debug|release):DEFINES += NDEBUG

Expand All @@ -25,6 +26,7 @@ SOURCES += \
ClassFactory.cpp

HEADERS +=\
Logging.h \
Registry.h \
ThumbnailProvider.h \
ClassFactory.h \
Expand Down
21 changes: 16 additions & 5 deletions SVGThumbnailExtension/ThumbnailProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#include <assert.h>

#include <QtCore/QDateTime>
#ifndef NDEBUG
#include <QtCore/QString>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QString>
#endif
#include <QtGui/QImage>
#include <QtGui/QPainter>
#include <QtGui/QPixmap>
Expand Down Expand Up @@ -103,11 +105,14 @@ STDMETHODIMP CThumbnailProvider::Initialize(IStream *pstm,
STATSTG stat;
Q_UNUSED(grfMode)

if(loaded) {
return HRESULT_FROM_WIN32(ERROR_ALREADY_INITIALIZED);
}

if(pstm->Stat(&stat, STATFLAG_DEFAULT) != S_OK){
return S_FALSE;
}


char * data = new char[stat.cbSize.QuadPart];

if(pstm->Read(data, stat.cbSize.QuadPart, &len) != S_OK){
Expand Down Expand Up @@ -140,6 +145,12 @@ STDMETHODIMP CThumbnailProvider::GetThumbnail(UINT cx,
*phbmp = NULL;
*pdwAlpha = WTSAT_ARGB;

#ifdef NDEBUG
if(!loaded) {
return S_FALSE;
}
#endif

// Fit the render into a (cx * cx) square while maintaining the aspect ratio.
QSize size = renderer.defaultSize();
size.scale(cx, cx, Qt::AspectRatioMode::KeepAspectRatio);
Expand Down Expand Up @@ -190,7 +201,7 @@ STDMETHODIMP CThumbnailProvider::GetThumbnail(UINT cx,
// Old syntax: HBITMAP QPixmap::toWinHBITMAP(HBitmapFormat format = NoAlpha) const
// New syntax: HBITMAP QtWin::toHBITMAP(const QPixmap &p, QtWin::HBitmapFormat format = HBitmapNoAlpha)
#if QT_VERSION < 0x050200
*phbmp = QPixmap::fromImage(device).toWinHBITMAP(QPixmap::Alpha);
*phbmp = QPixmap::fromImage(*device).toWinHBITMAP(QPixmap::Alpha);
#else
*phbmp = QtWin::toHBITMAP(QPixmap::fromImage(*device), QtWin::HBitmapAlpha);
#endif
Expand All @@ -199,8 +210,8 @@ STDMETHODIMP CThumbnailProvider::GetThumbnail(UINT cx,
delete device;

if( *phbmp != NULL )
return NOERROR;
return E_NOTIMPL;
return S_OK;
return S_FALSE;
}

/*
Expand Down
Loading

0 comments on commit 7788ad2

Please sign in to comment.