ReactOS 0.4.16-dev-2304-g8aed778
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 * Copyright 2023 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
7 */
8
9#include "precomp.h"
10
13
14#include <initguid.h>
15
16DEFINE_GUID(CLSID_ZipFolderStorageHandler, 0xe88dcce0, 0xb7b3, 0x11d1, 0xa9, 0xf0, 0x00, 0xaa, 0x00, 0x60, 0xfa, 0x31);
17DEFINE_GUID(CLSID_ZipFolderSendTo, 0x888dca60, 0xfc0a, 0x11cf, 0x8f, 0x0f, 0x00, 0xc0, 0x4f, 0xd7, 0xd0, 0x62);
18DEFINE_GUID(CLSID_ZipFolderContextMenu, 0xb8cdcb65, 0xb1bf, 0x4b42, 0x94, 0x28, 0x1d, 0xfd, 0xb7, 0xee, 0x92, 0xaf);
19DEFINE_GUID(CLSID_ZipFolderRightDragHandler,0xbd472f60, 0x27fa, 0x11cf, 0xb8, 0xb4, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00);
20DEFINE_GUID(CLSID_ZipFolderDropHandler, 0xed9d80b9, 0xd157, 0x457b, 0x91, 0x92, 0x0e, 0x72, 0x80, 0x31, 0x3b, 0xf0);
21
22/* IExplorerCommand: Extract All */
23DEFINE_GUID(CLSID_ZipFolderExtractAllCommand, 0xc3d9647b, 0x8fd9, 0x4ee6, 0x8b, 0xc7, 0x82, 0x7, 0x80, 0x9, 0x10, 0x5a);
24
25
27{
28public:
29};
30
31
32BEGIN_OBJECT_MAP(ObjectMap)
36 //OBJECT_ENTRY(CLSID_ZipFolderDropHandler, CZipFolderDropHandler) // FIXME: Add this
38
40
41
42#include "minizip/ioapi.h"
43#include "minizip/iowin32.h"
44
46
47static void init_zlib()
48{
50}
51
52static BOOL
54{
59 {
61 return TRUE;
62 }
63 return FALSE;
64}
65
66static HRESULT
68{
69 WCHAR szTarget[MAX_PATH], szSendToFile[MAX_PATH];
70
71 LoadStringW(g_hModule, IDS_FRIENDLYNAME, szTarget, _countof(szTarget));
72
73 StringCbCopyW(szSendToFile, sizeof(szSendToFile), pszSendTo);
74 PathAppendW(szSendToFile, szTarget);
75 StringCbCatW(szSendToFile, sizeof(szSendToFile), L".ZFSendToTarget");
76 if (!CreateEmptyFile(szSendToFile))
77 {
78 DPRINT1("CreateEmptyFile('%ls')\n", szSendToFile);
79 return E_FAIL;
80 }
81 return S_OK;
82}
83
84static HRESULT
86{
88 SHGFP_TYPE_DEFAULT, pszPath);
89}
90
92{
93 WCHAR szValue[16];
94 DWORD dwType, cbValue = sizeof(szValue);
95 UINT nDefaultCodePage = (bUnZip ? CP_ACP : CP_UTF8);
96
97 LONG error = SHGetValueW(HKEY_CURRENT_USER, L"Software\\ReactOS",
98 (bUnZip ? L"UnZipCodePage" : L"ZipCodePage"),
99 &dwType, szValue, &cbValue);
100 if (error != ERROR_SUCCESS)
101 return nDefaultCodePage;
102
103 if (cbValue == sizeof(DWORD) && (dwType == REG_DWORD || dwType == REG_BINARY))
104 return *(DWORD*)szValue;
105
106 if (dwType != REG_SZ && dwType != REG_EXPAND_SZ)
107 return nDefaultCodePage;
108
109 szValue[_countof(szValue) - 1] = UNICODE_NULL;
110 return (UINT)wcstol(szValue, NULL, 0);
111}
112
115{
116 switch (dwReason)
117 {
121 gModule.Init(ObjectMap, hInstance, NULL);
122 init_zlib();
123 break;
124 }
125
126 return TRUE;
127}
128
130{
131 if (g_ModuleRefCnt)
132 return S_FALSE;
133 return gModule.DllCanUnloadNow();
134}
135
137{
138 return gModule.DllGetClassObject(rclsid, riid, ppv);
139}
140
142{
143 HRESULT hr;
144
147 return hr;
148
150 if (FAILED(hr))
151 return hr;
152
153 WCHAR szSendTo[MAX_PATH];
154 hr = GetDefaultUserSendTo(szSendTo);
155 if (SUCCEEDED(hr))
156 CreateSendToZip(szSendTo);
157
158 return S_OK;
159}
160
162{
163 HRESULT hr;
164
167 return hr;
168
170 if (FAILED(hr))
171 return hr;
172
173 return S_OK;
174}
175
178RouteTheCallW(IN HWND hWndOwner, IN HINSTANCE hInstance, IN PCWSTR lpStringArg, IN INT Show)
179{
180 CStringW path = lpStringArg;
181 PathRemoveBlanksW(path.GetBuffer());
182 path.ReleaseBuffer();
183 path = L"\"" + path + L"\"";
184
185 WCHAR app[MAX_PATH];
187 PathAppendW(app, L"explorer.exe");
188
189 ShellExecuteW(NULL, L"open", app, path.GetString(), NULL, Show ? Show : SW_SHOWNORMAL);
190 return TRUE;
191}
#define DPRINT1
Definition: precomp.h:8
DWORD dwReason
Definition: misc.cpp:135
#define STDAPI
Definition: basetyps.h:41
#define EXTERN_C
Definition: basetyps.h:12
HINSTANCE hInstance
Definition: charmap.c:19
HRESULT WINAPI UpdateRegistryFromResource(LPCTSTR lpszRes, BOOL bRegister, struct _ATL_REGMAP_ENTRY *pMapEntries=NULL)
Definition: atlbase.h:489
HRESULT DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: atlbase.h:1037
HRESULT DllUnregisterServer(BOOL bUnRegTypeLib=TRUE)
Definition: atlbase.h:1047
HRESULT Init(_ATL_OBJMAP_ENTRY *p, HINSTANCE, const GUID *plibid)
Definition: atlbase.h:886
HRESULT DllCanUnloadNow()
Definition: atlbase.h:1030
HRESULT DllRegisterServer(BOOL bRegTypeLib=TRUE)
Definition: atlbase.h:1042
#define E_FAIL
Definition: ddrawi.h:102
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
EXTERN_C const GUID CLSID_ZipFolderSendTo
Definition: precomp.h:29
EXTERN_C const GUID CLSID_ZipFolderExtractAllCommand
Definition: precomp.h:34
EXTERN_C const GUID CLSID_ZipFolderContextMenu
Definition: precomp.h:30
EXTERN_C const GUID CLSID_ZipFolderStorageHandler
Definition: precomp.h:28
EXTERN_C const GUID CLSID_ZipFolderDropHandler
Definition: precomp.h:32
EXTERN_C const GUID CLSID_ZipFolderRightDragHandler
Definition: precomp.h:31
#define IDS_FRIENDLYNAME
Definition: resource.h:76
#define IDR_ZIPFLDR
Definition: resource.h:12
#define CloseHandle
Definition: compat.h:739
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define CP_ACP
Definition: compat.h:109
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2271
void WINAPI PathRemoveBlanksW(WCHAR *path)
Definition: path.c:1910
INT WINAPI DECLSPEC_HOTPATCH LoadStringW(HINSTANCE instance, UINT resource_id, LPWSTR buffer, INT buflen)
Definition: string.c:1220
_ACRTIMP __msvcrt_long __cdecl wcstol(const wchar_t *, wchar_t **, int)
Definition: wcs.c:2747
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2716
DWORD WINAPI SHGetValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue, LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)
Definition: reg.c:1236
#define FAILED_UNEXPECTEDLY
Definition: utils.cpp:30
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
Definition: iowin32.c:457
#define REG_SZ
Definition: layer.c:22
#define END_OBJECT_MAP()
Definition: atlcom.h:691
#define OBJECT_ENTRY(clsid, class)
Definition: atlcom.h:693
#define BEGIN_OBJECT_MAP(x)
Definition: atlcom.h:689
#define error(str)
Definition: mkdosfs.c:1605
#define CREATE_ALWAYS
Definition: disk.h:72
_In_ HANDLE hFile
Definition: mswsock.h:90
unsigned int UINT
Definition: ndis.h:50
#define REG_BINARY
Definition: nt_native.h:1499
#define GENERIC_WRITE
Definition: nt_native.h:90
#define REG_EXPAND_SZ
Definition: nt_native.h:1497
#define UNICODE_NULL
#define PathAppendW
Definition: pathcch.h:310
long LONG
Definition: pedump.c:60
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
Definition: guiddef.h:68
#define REFIID
Definition: guiddef.h:118
#define REFCLSID
Definition: guiddef.h:117
#define REG_DWORD
Definition: sdbapi.c:615
#define CP_UTF8
Definition: nls.h:20
HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
Definition: shlexec.cpp:2778
HRESULT hr
Definition: shlfolder.c:183
#define CSIDL_SENDTO
Definition: shlobj.h:2190
@ SHGFP_TYPE_DEFAULT
Definition: shlobj.h:2158
#define _countof(array)
Definition: sndvol32.h:70
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:3451
_In_ DWORD _In_ int _In_ int _In_opt_ LPNLSVERSIONINFO _In_opt_ LPVOID lpReserved
Definition: winnls.h:1268
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define SW_SHOWNORMAL
Definition: winuser.h:781
__wchar_t WCHAR
Definition: xmlstorage.h:180
EXTERN_C BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Definition: zipfldr.cpp:114
static BOOL CreateEmptyFile(PCWSTR pszFile)
Definition: zipfldr.cpp:53
zlib_filefunc64_def g_FFunc
Definition: zipfldr.cpp:45
CZipFldrModule gModule
Definition: zipfldr.cpp:39
STDAPI DllRegisterServer()
Definition: zipfldr.cpp:141
LONG g_ModuleRefCnt
Definition: zipfldr.cpp:12
STDAPI DllCanUnloadNow()
Definition: zipfldr.cpp:129
STDAPI DllUnregisterServer()
Definition: zipfldr.cpp:161
EXTERN_C BOOL WINAPI RouteTheCallW(IN HWND hWndOwner, IN HINSTANCE hInstance, IN PCWSTR lpStringArg, IN INT Show)
Definition: zipfldr.cpp:178
static void init_zlib()
Definition: zipfldr.cpp:47
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: zipfldr.cpp:136
UINT GetZipCodePage(BOOL bUnZip)
Definition: zipfldr.cpp:91
static HRESULT GetDefaultUserSendTo(PWSTR pszPath)
Definition: zipfldr.cpp:85
HMODULE g_hModule
Definition: zipfldr.cpp:11
static HRESULT CreateSendToZip(PCWSTR pszSendTo)
Definition: zipfldr.cpp:67