Skip to content

Commit

Permalink
revert PDF support
Browse files Browse the repository at this point in the history
  • Loading branch information
udaken committed May 11, 2022
1 parent a0810ba commit a6445ae
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 232 deletions.
2 changes: 0 additions & 2 deletions CbzDiffPlugin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="guids.cpp" />
<ClCompile Include="PdfToImage.cpp" />
<ClCompile Include="SettingsDialog.cpp" />
<ClCompile Include="StdAfx.cpp">
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down Expand Up @@ -521,7 +520,6 @@
<ItemGroup>
<ClInclude Include="CbzDiffPlugin.h" />
<ClInclude Include="Config.h" />
<ClInclude Include="PdfToImage.h" />
<ClInclude Include="Streams.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="StdAfx.h" />
Expand Down
6 changes: 0 additions & 6 deletions CbzDiffPlugin.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
<ClCompile Include="SettingsDialog.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PdfToImage.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="WinMergeScript.rgs">
Expand Down Expand Up @@ -65,9 +62,6 @@
<ClInclude Include="Config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PdfToImage.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Midl Include="CbzDiffPlugin.idl">
Expand Down
131 changes: 0 additions & 131 deletions PdfToImage.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions PdfToImage.h

This file was deleted.

8 changes: 1 addition & 7 deletions StdAfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@

#define STRICT
#ifndef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_WIN8
#define _WIN32_WINNT _WIN32_WINNT_VISTA
#endif
#define _ATL_APARTMENT_THREADED
//#define _ATL_NO_AUTOMATIC_NAMESPACE

#define WIN32_LEAN_AND_MEAN
#define WINRT_LEAN_AND_MEAN
#define NOMINMAX

#define STRICT_TYPED_ITEMIDS
Expand All @@ -41,11 +40,6 @@ extern CComModule _Module;

#include <algorithm>

#include <unknwn.h>

#include "winrt/base.h"
#include "winrt/Windows.Storage.Streams.h"

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

Expand Down
75 changes: 15 additions & 60 deletions WinMergeScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "Streams.h"
#include "WinMergeScript.h"
#include "resource.h"
#include "PdfToImage.h"

#include <algorithm>
#include <assert.h>
Expand Down Expand Up @@ -126,12 +125,6 @@ class StreamWrapper final : public ISequentialOutStream
}
};

inline bool IsPdfFile(const BYTE *pv, size_t length)
{
constexpr BYTE magic[] = {'%', 'P', 'D', 'F'};
return memcmp(magic, pv, std::min(sizeof(magic), length)) == 0;
}

inline HRESULT GetExteinsionFromEncoder(IWICBitmapEncoder *pngEncoder, std::wstring &ext)
{
HRESULT hr = E_FAIL;
Expand Down Expand Up @@ -305,7 +298,7 @@ inline HRESULT ScaleImage(IWICImagingFactory *factory, IWICBitmapSource *srcImag
return hr;
}

HRESULT ConcatPages(IWICImagingFactory *factory, const Config &config, std::vector<winrt::com_ptr<IWICBitmap>> pages,
HRESULT ConcatPages(IWICImagingFactory *factory, const Config &config, std::vector<CComPtr<IWICBitmap>> pages,
IWICBitmap **target)
{
HRESULT hr;
Expand Down Expand Up @@ -360,7 +353,7 @@ HRESULT ConcatPages(IWICImagingFactory *factory, const Config &config, std::vect
}

CComPtr<ID2D1Bitmap> pD2dBitmap1;
hr = pRT->CreateBitmapFromWicBitmap(img.get(), &pD2dBitmap1);
hr = pRT->CreateBitmapFromWicBitmap(img, &pD2dBitmap1);
CHECK_return(hr);

if (pDC && not config.forceD2D1())
Expand Down Expand Up @@ -477,7 +470,7 @@ class CbzToImage final : IArchiveExtractCallback, ICryptoGetTextPassword2

CComPtr<IWICImagingFactory> m_pWicFactory;

std::vector<winrt::com_ptr<IWICBitmap>> m_pages;
std::vector<CComPtr<IWICBitmap>> m_pages;

Config const &m_config;

Expand Down Expand Up @@ -669,12 +662,13 @@ class CbzToImage final : IArchiveExtractCallback, ICryptoGetTextPassword2
auto cultureCompareFunc = [](const ItemInfo &a, const ItemInfo &b) -> bool {
return StrCmpICW(a.name, b.name) < 0;
};

#ifndef __INTELLISENSE__ // workaround
// sort
std::sort(items.begin(), items.end(),
(m_config.fileNameOrdering() == FileNameOrdering::Natural) ? naturalCompareFunc
: (m_config.fileNameOrdering() == FileNameOrdering::Culture) ? cultureCompareFunc
: ordinalCompareFunc);
#endif
}

IFACEMETHODIMP QueryInterface(REFIID riid, void **ppv) override
Expand Down Expand Up @@ -759,7 +753,7 @@ class CbzToImage final : IArchiveExtractCallback, ICryptoGetTextPassword2

CComPtr<IWICBitmap> page;
hr = ScaleImage(m_pWicFactory, pFrame, m_config.scale(), &page);
m_pages.emplace_back(page, winrt::take_ownership_from_abi_t{});
m_pages.emplace_back(page);

m_lastExtractImageSream = nullptr;
return hr;
Expand Down Expand Up @@ -817,24 +811,15 @@ IFACEMETHODIMP CWinMergeScript::UnpackFile(
auto config = Config::Load();

HRESULT hr;
if (PathMatchSpec(fileSrc, L"*.pdf"))
{
PdfToImage pdf{*config};
hr = pdf.ProcessFile(fileSrc, fileDst);
if (FAILED(hr))
return hr;
}
else
{
CbzToImage sevenzip{*config};
hr = sevenzip.Init();
if (FAILED(hr))
return hr;
CbzToImage sevenzip{*config};
hr = sevenzip.Init();
if (FAILED(hr))
return hr;

hr = sevenzip.ProcessFile(fileSrc, fileDst);
if (FAILED(hr))
return hr;

hr = sevenzip.ProcessFile(fileSrc, fileDst);
if (FAILED(hr))
return hr;
}
*pbChanged = VARIANT_TRUE;
*pSubcode = 0;
*pbSuccess = VARIANT_TRUE;
Expand Down Expand Up @@ -873,39 +858,9 @@ IFACEMETHODIMP CWinMergeScript::UnpackFolder(
/* [in] */ BSTR folderDst, VARIANT_BOOL *pbChanged, INT *pSubcode,
/* [retval][out] */ VARIANT_BOOL *pbSuccess)
{
if (fileSrc == nullptr || folderDst == nullptr)
return E_INVALIDARG;

*pbSuccess = VARIANT_FALSE;
auto config = Config::Load();

WCHAR fileDest[MAX_PATH]{};
PathCombine(fileDest, folderDst, L"image.png");

HRESULT hr;
if (PathMatchSpec(fileSrc, L"*.pdf"))
{
PdfToImage pdf{*config};
hr = pdf.ProcessFile(fileSrc, fileDest);
if (FAILED(hr))
return hr;
}
else
{
CbzToImage sevenzip{*config};
hr = sevenzip.Init();
if (FAILED(hr))
return hr;

hr = sevenzip.ProcessFile(fileSrc, fileDest);
if (FAILED(hr))
return hr;
}

*pbChanged = VARIANT_TRUE;
*pSubcode = 0;
*pbSuccess = VARIANT_TRUE;
return S_OK;
return UnpackFile(fileSrc, fileDest, pbChanged, pSubcode, pbChanged);
}

IFACEMETHODIMP CWinMergeScript::ShowSettingsDialog(VARIANT_BOOL *pbHandled)
Expand Down
6 changes: 3 additions & 3 deletions WinMergeScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class ATL_NO_VTABLE CWinMergeScript
}
IFACEMETHODIMP get_PluginFileFilters(/*[out, retval]*/ BSTR *pVal) override
{
*pVal = SysAllocString(LR"(\.pdf$;\.cbz$;\.cbr$;\.cb7$)");
*pVal = SysAllocString(LR"(\.cbz$;\.cbr$;\.cb7$)");
return S_OK;
}
IFACEMETHODIMP get_PluginDescription(/*[out, retval]*/ BSTR *pVal) override
{
*pVal = SysAllocString(L"Compare .PDF/.CBZ/.CBR/.CB7 as Image");
*pVal = SysAllocString(L"Compare .CBZ/.CBR/.CB7 as Image");
return S_OK;
}

Expand All @@ -64,7 +64,7 @@ class ATL_NO_VTABLE CWinMergeScript

IFACEMETHODIMP get_PluginExtendedProperties(/* [retval][out] */ BSTR *pVal) override
{
*pVal = SysAllocString(L"ProcessType=Content Extraction;FileType=PDF/CBZ/CBR/CB7;MenuCaption=PDF/CBZ/CBR/CB7");
*pVal = SysAllocString(L"ProcessType=Content Extraction;FileType=CBZ/CBR/CB7;MenuCaption=CBZ/CBR/CB7");
return S_OK;
}

Expand Down

0 comments on commit a6445ae

Please sign in to comment.