ReactOS  0.4.15-dev-1206-g731eddf
zipfldr.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Zip Shell Extension
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: zipfldr entrypoint
5  * COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen@reactos.org)
6  */
7 
8 #include "precomp.h"
9 
12 
13 #include <initguid.h>
14 
15 DEFINE_GUID(CLSID_ZipFolderStorageHandler, 0xe88dcce0, 0xb7b3, 0x11d1, 0xa9, 0xf0, 0x00, 0xaa, 0x00, 0x60, 0xfa, 0x31);
16 DEFINE_GUID(CLSID_ZipFolderSendTo, 0x888dca60, 0xfc0a, 0x11cf, 0x8f, 0x0f, 0x00, 0xc0, 0x4f, 0xd7, 0xd0, 0x62);
17 DEFINE_GUID(CLSID_ZipFolderContextMenu, 0xb8cdcb65, 0xb1bf, 0x4b42, 0x94, 0x28, 0x1d, 0xfd, 0xb7, 0xee, 0x92, 0xaf);
18 DEFINE_GUID(CLSID_ZipFolderRightDragHandler,0xbd472f60, 0x27fa, 0x11cf, 0xb8, 0xb4, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00);
19 DEFINE_GUID(CLSID_ZipFolderDropHandler, 0xed9d80b9, 0xd157, 0x457b, 0x91, 0x92, 0x0e, 0x72, 0x80, 0x31, 0x3b, 0xf0);
20 
21 /* IExplorerCommand: Extract All */
22 DEFINE_GUID(CLSID_ZipFolderExtractAllCommand, 0xc3d9647b, 0x8fd9, 0x4ee6, 0x8b, 0xc7, 0x82, 0x7, 0x80, 0x9, 0x10, 0x5a);
23 
24 
25 class CZipFldrModule : public CComModule
26 {
27 public:
28 };
29 
30 
31 BEGIN_OBJECT_MAP(ObjectMap)
36 
38 
39 
40 #include "minizip/ioapi.h"
41 #include "minizip/iowin32.h"
42 
44 
45 static void init_zlib()
46 {
48 }
49 
50 static BOOL
52 {
53  HANDLE hFile;
57  {
59  return TRUE;
60  }
61  return FALSE;
62 }
63 
64 static HRESULT
66 {
67  WCHAR szTarget[MAX_PATH], szSendToFile[MAX_PATH];
68 
69  LoadStringW(g_hModule, IDS_FRIENDLYNAME, szTarget, _countof(szTarget));
70 
71  StringCbCopyW(szSendToFile, sizeof(szSendToFile), pszSendTo);
72  PathAppendW(szSendToFile, szTarget);
73  StringCbCatW(szSendToFile, sizeof(szSendToFile), L".ZFSendToTarget");
74  if (!CreateEmptyFile(szSendToFile))
75  {
76  DPRINT1("CreateEmptyFile('%ls')\n", szSendToFile);
77  return E_FAIL;
78  }
79  return S_OK;
80 }
81 
82 static HRESULT
84 {
86  SHGFP_TYPE_DEFAULT, pszPath);
87 }
88 
91 {
92  switch (dwReason)
93  {
94  case DLL_PROCESS_ATTACH:
97  gModule.Init(ObjectMap, hInstance, NULL);
98  init_zlib();
99  break;
100  }
101 
102  return TRUE;
103 }
104 
106 {
107  if (g_ModuleRefCnt)
108  return S_FALSE;
109  return gModule.DllCanUnloadNow();
110 }
111 
113 {
114  return gModule.DllGetClassObject(rclsid, riid, ppv);
115 }
116 
118 {
119  HRESULT hr;
120 
122  if (FAILED_UNEXPECTEDLY(hr))
123  return hr;
124 
126  if (FAILED(hr))
127  return hr;
128 
129  WCHAR szSendTo[MAX_PATH];
130  hr = GetDefaultUserSendTo(szSendTo);
131  if (SUCCEEDED(hr))
132  CreateSendToZip(szSendTo);
133 
134  return S_OK;
135 }
136 
138 {
139  HRESULT hr;
140 
142  if (FAILED_UNEXPECTEDLY(hr))
143  return hr;
144 
146  if (FAILED(hr))
147  return hr;
148 
149  return S_OK;
150 }
151 
152 EXTERN_C
153 BOOL WINAPI
155  IN HWND hWndOwner,
157  IN LPCSTR lpStringArg,
158  IN INT Show)
159 {
160  CStringW path = lpStringArg;
161  PathRemoveBlanksW(path.GetBuffer());
162  path.ReleaseBuffer();
163  path = L"\"" + path + L"\"";
164  ShellExecuteW(NULL, L"open", L"explorer.exe", path.GetString(), NULL, SW_SHOWNORMAL);
165  return TRUE;
166 }
#define STDAPI
Definition: basetyps.h:41
HRESULT DllCanUnloadNow()
Definition: atlbase.h:928
static HRESULT GetDefaultUserSendTo(LPWSTR pszPath)
Definition: zipfldr.cpp:83
#define IN
Definition: typedefs.h:39
#define IDS_FRIENDLYNAME
Definition: resource.h:69
#define REFIID
Definition: guiddef.h:118
HRESULT DllRegisterServer(BOOL bRegTypeLib=TRUE)
Definition: atlbase.h:940
#define CloseHandle
Definition: compat.h:598
EXTERN_C const GUID CLSID_ZipFolderExtractAllCommand
Definition: precomp.h:35
LONG g_ModuleRefCnt
Definition: zipfldr.cpp:11
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
STDAPI DllUnregisterServer()
Definition: zipfldr.cpp:137
#define TRUE
Definition: types.h:120
#define OBJECT_ENTRY(clsid, class)
Definition: atlcom.h:653
REFIID riid
Definition: precomp.h:44
#define REFCLSID
Definition: guiddef.h:117
void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
Definition: iowin32.c:452
REFIID LPVOID * ppv
Definition: atlbase.h:39
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define IDR_ZIPFLDR
Definition: resource.h:9
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
VOID WINAPI PathRemoveBlanksW(LPWSTR lpszPath)
Definition: path.c:915
#define E_FAIL
Definition: ddrawi.h:102
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:58
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:121
DWORD dwReason
Definition: misc.cpp:154
HRESULT Init(_ATL_OBJMAP_ENTRY *p, HINSTANCE, const GUID *plibid)
Definition: atlbase.h:797
HINSTANCE hInstance
Definition: charmap.c:20
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
EXTERN_C BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Definition: zipfldr.cpp:90
#define GENERIC_WRITE
Definition: nt_native.h:90
#define S_FALSE
Definition: winerror.h:2357
HRESULT DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: atlbase.h:935
smooth NULL
Definition: ftsmooth.c:416
STDAPI DllCanUnloadNow()
Definition: zipfldr.cpp:105
const char * LPCSTR
Definition: xmlstorage.h:183
STDAPI DllRegisterServer()
Definition: zipfldr.cpp:117
static BOOL CreateEmptyFile(LPCWSTR pszFile)
Definition: zipfldr.cpp:51
__wchar_t WCHAR
Definition: xmlstorage.h:180
HRESULT WINAPI UpdateRegistryFromResource(LPCTSTR lpszRes, BOOL bRegister, struct _ATL_REGMAP_ENTRY *pMapEntries=NULL)
Definition: atlbase.h:439
LONG HRESULT
Definition: typedefs.h:79
#define _countof(array)
Definition: sndvol32.h:68
#define CSIDL_SENDTO
Definition: shlobj.h:2021
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:34
#define WINAPI
Definition: msvc.h:6
EXTERN_C const GUID CLSID_ZipFolderRightDragHandler
Definition: precomp.h:32
unsigned long DWORD
Definition: ntddk_ex.h:95
static void init_zlib()
Definition: zipfldr.cpp:45
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
static const WCHAR L[]
Definition: oid.c:1250
_In_ HANDLE hFile
Definition: mswsock.h:90
DEFINE_GUID(CLSID_ZipFolderStorageHandler, 0xe88dcce0, 0xb7b3, 0x11d1, 0xa9, 0xf0, 0x00, 0xaa, 0x00, 0x60, 0xfa, 0x31)
#define S_OK
Definition: intsafe.h:51
#define CREATE_ALWAYS
Definition: disk.h:72
#define SW_SHOWNORMAL
Definition: winuser.h:764
CZipFldrModule gModule
Definition: zipfldr.cpp:37
EXTERN_C const GUID CLSID_ZipFolderDropHandler
Definition: precomp.h:33
HMODULE g_hModule
Definition: zipfldr.cpp:10
EXTERN_C BOOL WINAPI RouteTheCall(IN HWND hWndOwner, IN HINSTANCE hInstance, IN LPCSTR lpStringArg, IN INT Show)
Definition: zipfldr.cpp:154
zlib_filefunc64_def g_FFunc
Definition: zipfldr.cpp:43
#define DPRINT1
Definition: precomp.h:8
#define CreateFileW
Definition: compat.h:600
EXTERN_C const GUID CLSID_ZipFolderSendTo
Definition: precomp.h:30
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2208
HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
Definition: shlexec.cpp:2274
#define BEGIN_OBJECT_MAP(x)
Definition: atlcom.h:649
EXTERN_C const GUID CLSID_ZipFolderContextMenu
Definition: precomp.h:31
HRESULT DllUnregisterServer(BOOL bUnRegTypeLib=TRUE)
Definition: atlbase.h:945
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: zipfldr.cpp:112
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define EXTERN_C
Definition: basetyps.h:12
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
EXTERN_C const GUID CLSID_ZipFolderStorageHandler
Definition: precomp.h:29
#define SUCCEEDED(hr)
Definition: intsafe.h:49
#define END_OBJECT_MAP()
Definition: atlcom.h:651
static HRESULT CreateSendToZip(LPCWSTR pszSendTo)
Definition: zipfldr.cpp:65