Skip to content

Commit

Permalink
Restore archive icon; fix problems causing random drawing. NOTE: fb2 …
Browse files Browse the repository at this point in the history
…doesn't yet support
  • Loading branch information
fire-eggs committed Jun 28, 2022
1 parent f423c2e commit 690deb1
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 71 deletions.
25 changes: 14 additions & 11 deletions CBXManager/CBXManager.rc
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ FONT 8, "MS Shell Dlg 2", 400, 0, 1
{
GROUPBOX "", IDC_STATIC, 59, 36, 55, 18
CTEXT "OK", IDC_STATIC, 76, 42, 23, 10, SS_CENTER, WS_EX_TRANSPARENT
CTEXT "DarkThumbs Manager\nVersion 4.9", IDC_STATIC, 10, 9, 152, 25, SS_CENTER
CTEXT "DarkThumbs Manager\nVersion 1.5.1", IDC_STATIC, 10, 9, 152, 25, SS_CENTER
ICON IDR_MAINFRAME, IDC_STATIC, 13, 11, 11, 10, SS_ICON
}

// X,Y,W,H
IDD_MAINDLG DIALOG 0, 0, 190, 210
IDD_MAINDLG DIALOG 0, 0, 190, 230
STYLE DS_CONTEXTHELP | DS_SETFONT | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_SYSMENU
CAPTION "DarkThumbs Manager"
FONT 8, "Ms Shell Dlg"
{
GROUPBOX "File types", IDC_TH_GROUP, 10, 5, 170, 120
GROUPBOX "Advanced", IDC_SORT_ADVOPTGROUP, 10, 130, 170, 50
GROUPBOX "Advanced", IDC_SORT_ADVOPTGROUP, 10, 130, 170, 75

AUTOCHECKBOX "CBZ Image Archives", IDC_CB_CBZ, 20, 20, 145, 10
AUTOCHECKBOX "ZIP Archives", IDC_CB_ZIP, 20, 35, 150, 8
Expand All @@ -42,9 +42,12 @@ FONT 8, "Ms Shell Dlg"
AUTOCHECKBOX "Sort images alphabetically", IDC_CB_SORT, 20, 145, 155, 8
LTEXT "Uncheck to sort images by archive order.\nRequired to display custom thumbnail.", IDC_SORT_DESC, 30, 155, 145, 18, SS_LEFT, WS_EX_TRANSPARENT

DEFPUSHBUTTON "OK", IDOK, 10, 185, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 70, 185, 50, 14
PUSHBUTTON "Apply", IDC_APPLY, 130, 185, 50, 14
AUTOCHECKBOX "Show archive indicator", IDC_CB_SHOWICON, 20, 178, 150, 8
LTEXT "Display a ZIP icon top-left of thumbnail to let you know it's an archive.", IDC_CB_SHOWICON_DESC, 30, 185, 145, 18, SS_LEFT, WS_EX_TRANSPARENT

DEFPUSHBUTTON "OK", IDOK, 10, 210, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 70, 210, 50, 14
PUSHBUTTON "Apply", IDC_APPLY, 130, 210, 50, 14
}


Expand All @@ -60,8 +63,8 @@ IDR_MAINFRAME ICON "DarkThumbsIcon.ico"
// Version Information resources
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,9,0,0
PRODUCTVERSION 4,9,0,0
FILEVERSION 1,5,1,0
PRODUCTVERSION 1,5,1,0
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN
Expand All @@ -74,10 +77,10 @@ VS_VERSION_INFO VERSIONINFO
{
VALUE "CompanyName", "\0"
VALUE "FileDescription", "DarkThumbs Manager\0"
VALUE "FileVersion", "4.10.0.0\0"
VALUE "LegalCopyright", "� 2021\0"
VALUE "FileVersion", "1.5.1.0\0"
VALUE "LegalCopyright", "� 2020-2022 by Kevin Routley\0"
VALUE "ProductName", "DarkThumbs\0"
VALUE "ProductVersion", "4.10.0.0\0"
VALUE "ProductVersion", "1.5.1.0\0"
}
}
BLOCK "VarFileInfo"
Expand Down
4 changes: 2 additions & 2 deletions CBXManager/RegManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CRegManager
if (ERROR_SUCCESS==rk.QueryDWORDValue(_T("NoSort"), d))
return (d==FALSE);
}
return TRUE;
return FALSE;
}

void SetSortOpt(BOOL bSort)
Expand All @@ -87,7 +87,7 @@ class CRegManager
if (ERROR_SUCCESS == rk.QueryDWORDValue(_T("ShowIcon"), d))
return (d == TRUE);
}
return TRUE;
return FALSE;
}

//////////////
Expand Down
11 changes: 6 additions & 5 deletions CBXShell/CBXShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_CBXShell, CCBXShell)
END_OBJECT_MAP()

HICON zipIcon;
HICON zipIcon = NULL;

static void __cdecl logit(LPCWSTR format, ...)
void __cdecl logit(LPCWSTR format, ...)
{
wchar_t buf[4096];
wchar_t* p = buf;
Expand All @@ -40,17 +40,18 @@ static void __cdecl logit(LPCWSTR format, ...)
OutputDebugStringW(buf);
}

HINSTANCE _hInstance;

/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
zipIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));

_hInstance = hInstance;
if (dwReason == DLL_PROCESS_ATTACH)
{
logit(_T("DT:attach"));
zipIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
logit(_T("DT:attach"));
_Module.Init(ObjectMap, hInstance, &LIBID_CBXSHELLLib);
DisableThreadLibraryCalls(hInstance);

Expand Down
2 changes: 1 addition & 1 deletion CBXShell/CBXShellClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
HRESULT CCBXShell::FinalConstruct(void)
{
//ATLTRACE("CCBXShell::FinalConstruct\n");
m_cbx.LoadRegistrySettings();
//m_cbx.LoadRegistrySettings();

return S_OK;
}
Expand Down
63 changes: 20 additions & 43 deletions CBXShell/cbxArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ HRESULT WICCreate32BitsPerPixelHBITMAP(IStream* pstm, HBITMAP* phbmp);

HRESULT ExtractFBCover(CString filepath, HBITMAP* phBmpThumbnail);

extern void __cdecl logit(LPCWSTR format, ...);

namespace __cbx {


Expand Down Expand Up @@ -215,32 +217,6 @@ class CUnRar

class CCBXArchive
{
//#ifdef _DEBUG
void __cdecl logit(LPCWSTR format, ...)
{
wchar_t buf[4096];
wchar_t* p = buf;
va_list args;
int n;

va_start(args, format);
n = _vsnwprintf(p, sizeof(buf) - 3, format, args);
va_end(args);

p += (n < 0) ? sizeof buf - 3 : n;

while (p > buf && isspace(p[-1]))
*--p = '\0';

*p++ = '\r';
*p++ = '\n';
*p = '\0';

OutputDebugStringW(buf);
}
//#endif


public:
CCBXArchive()
{
Expand All @@ -260,7 +236,7 @@ class CCBXArchive
//
// Extrapolated from mobitool.c in the libmobi repo. See https://github.com/bfabiszewski/libmobi
//
int fetchMobiCover(const MOBIData* m, HBITMAP* phBmpThumbnail, SIZE thumbSize)
int fetchMobiCover(const MOBIData* m, HBITMAP* phBmpThumbnail, SIZE thumbSize, BOOL showIcon)
{
MOBIPdbRecord* record = NULL;
MOBIExthHeader* exth = mobi_get_exthrecord_by_tag(m, EXTH_COVEROFFSET);
Expand All @@ -277,7 +253,7 @@ class CCBXArchive
}

HGLOBAL hG = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (SIZE_T)record->size);
HRESULT hr = E_FAIL;
//HRESULT hr = E_FAIL;
if (hG)
{
LPVOID pBuf = ::GlobalLock(hG);
Expand All @@ -289,21 +265,21 @@ class CCBXArchive
IStream* pIs = NULL;
if (S_OK == CreateStreamOnHGlobal(hG, TRUE, (LPSTREAM*)&pIs))//autofree hG
{
//*phBmpThumbnail = ThumbnailFromIStream(pIs, &thumbSize, false);
hr = WICCreate32BitsPerPixelHBITMAP(pIs, phBmpThumbnail);
*phBmpThumbnail = ThumbnailFromIStream(pIs, &thumbSize, showIcon);
//hr = WICCreate32BitsPerPixelHBITMAP(pIs, phBmpThumbnail);
pIs->Release();
pIs = NULL;
}
}
GlobalFree(hG);
}
return hr; // ((*phBmpThumbnail) ? S_OK : E_FAIL);
return ((*phBmpThumbnail) ? S_OK : E_FAIL);
}

//
// Extrapolated from mobitool.c in the libmobi repo. See https://github.com/bfabiszewski/libmobi
//
HRESULT ExtractMobiCover(CString filepath, HBITMAP* phBmpThumbnail)
HRESULT ExtractMobiCover(CString filepath, HBITMAP* phBmpThumbnail, BOOL showIcon)
{
MOBI_RET mobi_ret;
int ret = S_OK;
Expand Down Expand Up @@ -335,7 +311,7 @@ class CCBXArchive
return E_FAIL;
}

ret = fetchMobiCover(m, phBmpThumbnail, m_thumbSize);
ret = fetchMobiCover(m, phBmpThumbnail, m_thumbSize, showIcon);
/* Free MOBIData structure */
mobi_free(m);
return ret;
Expand Down Expand Up @@ -364,7 +340,7 @@ class CCBXArchive
// IExtractImage::GetLocation(LPWSTR pszPathBuffer, DWORD cchMax, DWORD *pdwPriority, const SIZE *prgSize, DWORD dwRecClrDepth, DWORD *pdwFlags)
HRESULT OnGetLocation(const SIZE *prgSize, DWORD *pdwFlags)
{
logit(_T("OnGetLocation"));
logit(_T("OnGetLocation (%d,%d)"), prgSize->cx, prgSize->cy);

//ATLTRACE("IExtractImage2::GetLocation\n");
m_thumbSize.cx=prgSize->cx;
Expand Down Expand Up @@ -396,16 +372,17 @@ class CCBXArchive
//IExtractImage::Extract(HBITMAP* phBmpThumbnail)
HRESULT OnExtract(HBITMAP* phBmpThumbnail)
{
LoadRegistrySettings();
*phBmpThumbnail=NULL;
//ATLTRACE("IExtractImage::Extract\n");
logit(_T("OnExtract '%ls'"), m_cbxFile);
logit(_T("OnExtract '%ls' (%d)"), m_cbxFile, m_showIcon ? 1 : 0);

try {
switch (m_cbxType)
{
#ifdef _WIN64
case CBXTYPE_MOBI:
return ExtractMobiCover(m_cbxFile, phBmpThumbnail);
return ExtractMobiCover(m_cbxFile, phBmpThumbnail, m_showIcon);
#endif

case CBXTYPE_EPUB:
Expand Down Expand Up @@ -471,11 +448,11 @@ try {
IStream* pIs=NULL;
if (S_OK==CreateStreamOnHGlobal(hG, TRUE, (LPSTREAM*)&pIs))//autofree hG
{
//*phBmpThumbnail= ThumbnailFromIStream(pIs, &m_thumbSize, m_showIcon);
HRESULT hr = WICCreate32BitsPerPixelHBITMAP(pIs, phBmpThumbnail);
*phBmpThumbnail= ThumbnailFromIStream(pIs, &m_thumbSize, m_showIcon);
//HRESULT hr = WICCreate32BitsPerPixelHBITMAP(pIs, phBmpThumbnail);
pIs->Release();
pIs=NULL;
return hr;
//return hr;
}
}
}
Expand Down Expand Up @@ -536,8 +513,8 @@ try {
_r.SetIStream(pIs);
if (_r.ProcessItem())
{
//*phBmpThumbnail = ThumbnailFromIStream(pIs, &m_thumbSize, m_showIcon);
HRESULT hr = WICCreate32BitsPerPixelHBITMAP(pIs, phBmpThumbnail);
*phBmpThumbnail = ThumbnailFromIStream(pIs, &m_thumbSize, m_showIcon);
//HRESULT hr = WICCreate32BitsPerPixelHBITMAP(pIs, phBmpThumbnail);
}
}
}
Expand Down Expand Up @@ -786,9 +763,9 @@ catch (...)
if (ERROR_SUCCESS==_rk.Open(HKEY_CURRENT_USER, CBX_APP_KEY, KEY_READ))
{
if (ERROR_SUCCESS==_rk.QueryDWORDValue(_T("NoSort"), _d))
m_bSort=(_d==FALSE);
m_bSort=(_d == 0);
if (ERROR_SUCCESS == _rk.QueryDWORDValue(_T("ShowIcon"), _d))
m_showIcon = (_d == TRUE);
m_showIcon = (_d == 1);
}
}

Expand Down
20 changes: 18 additions & 2 deletions CBXShell/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <wincodec.h> // Windows Imaging Codecs
#include <thumbcache.h> // WTS_ALPHATYPE

#include "resource.h" // zip icon

#define LOGDBG
#define LOGERR

Expand All @@ -22,6 +24,7 @@ BOOL IsImage(LPCTSTR szFile)
if (StrEqual(_e, _T(".tif"))) return TRUE;
if (StrEqual(_e, _T(".tiff"))) return TRUE;
if (StrEqual(_e, _T(".webp"))) return TRUE; // NOTE: works if a webp codec is installed
if (StrEqual(_e, _T(".svg"))) return TRUE; // NOTE: hopefully works if a codec is installed?
return FALSE;
}

Expand Down Expand Up @@ -54,6 +57,9 @@ static inline BOOL Draw(
return status == Gdiplus::Ok;
}

extern HINSTANCE _hInstance;
extern void __cdecl logit(LPCWSTR format, ...);

HBITMAP ThumbnailFromIStream(IStream* pIs, const LPSIZE pThumbSize, bool showIcon)
{
ATLASSERT(pIs);
Expand Down Expand Up @@ -89,8 +95,18 @@ HBITMAP ThumbnailFromIStream(IStream* pIs, const LPSIZE pThumbSize, bool showIco
hdcNew.FillSolidRect(0, 0, tw, th, RGB(255, 255, 255));//white background

Draw(ci, hdcNew, 0, 0, tw, th, 0, 0, ci.GetWidth(), ci.GetHeight(), Gdiplus::InterpolationMode::InterpolationModeHighQualityBicubic);//too late for error checks
//if (showIcon)
// DrawIcon(hdcNew, 0, 0, zipIcon);
if (showIcon)
{
logit(_T("showIcon"));
if (zipIcon == NULL)
{
logit(_T("zipIcon NULL"));
zipIcon = LoadIcon(_hInstance, MAKEINTRESOURCE(IDI_ICON1));
}
BOOL res = DrawIcon(hdcNew, 0, 0, zipIcon);
if (!res)
logit(_T("DrawIcon fail"));
}

hdcNew.SelectBitmap(hbmpOld);

Expand Down
11 changes: 5 additions & 6 deletions CBXShell/epub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#define CBXMEM_MAXBUFFER_SIZE 33554432 //32mb

//HBITMAP ThumbnailFromIStream(IStream* pIs, const LPSIZE pThumbSize, bool showIcon);
HBITMAP ThumbnailFromIStream(IStream* pIs, const LPSIZE pThumbSize, bool showIcon);
BOOL IsImage(LPCTSTR szFile);
HRESULT WICCreate32BitsPerPixelHBITMAP(IStream* pstm, HBITMAP* phbmp);
//HRESULT WICCreate32BitsPerPixelHBITMAP(IStream* pstm, HBITMAP* phbmp);


std::string urlDecode(std::string& SRC)
Expand Down Expand Up @@ -242,7 +242,7 @@ std::string coverHTML(char* pBuf, std::string rootpath) {
}


HRESULT ExtractEpub(CString m_cbxFile, HBITMAP* phBmpThumbnail, SIZE m_thumbSize, BOOL m_showIcon)
HRESULT ExtractEpub(CString m_cbxFile, HBITMAP* phBmpThumbnail, SIZE m_thumbSize, BOOL showIcon)
{
HGLOBAL hGContainer = NULL;

Expand Down Expand Up @@ -400,11 +400,10 @@ HRESULT ExtractEpub(CString m_cbxFile, HBITMAP* phBmpThumbnail, SIZE m_thumbSize
IStream* pIs = NULL;
if (S_OK == CreateStreamOnHGlobal(hG, TRUE, (LPSTREAM*)&pIs))//autofree hG
{
// *phBmpThumbnail = ThumbnailFromIStream(pIs, &m_thumbSize, m_showIcon);
HRESULT hr = WICCreate32BitsPerPixelHBITMAP(pIs, phBmpThumbnail);
*phBmpThumbnail = ThumbnailFromIStream(pIs, &m_thumbSize, showIcon);
//HRESULT hr = WICCreate32BitsPerPixelHBITMAP(pIs, phBmpThumbnail);
pIs->Release();
pIs = NULL;
return hr;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion CBXShell/fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ HRESULT imageFromId(const std::wstring& fb, const std::wstring& imgid, HBITMAP*
if (SUCCEEDED(hr))
{
hr = WICCreate32BitsPerPixelHBITMAP(pImageStream, phbmp);
//*phbmp = ThumbnailFromIStream(pImageStream, &m_thumbSize, showIcon);
pImageStream->Release();
}
return hr;
return hr; // ((*phBmp) ? S_OK : E_FAIL);
}

//HRESULT ExtractFBCover(const std::wstring& filepath, HBITMAP* phBmpThumbnail)
Expand Down

0 comments on commit 690deb1

Please sign in to comment.