ReactOS 0.4.16-dev-122-g325d74c
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)
37
39
40
41#include "minizip/ioapi.h"
42#include "minizip/iowin32.h"
43
45
46static void init_zlib()
47{
49}
50
51static BOOL
53{
58 {
60 return TRUE;
61 }
62 return FALSE;
63}
64
65static HRESULT
67{
68 WCHAR szTarget[MAX_PATH], szSendToFile[MAX_PATH];
69
70 LoadStringW(g_hModule, IDS_FRIENDLYNAME, szTarget, _countof(szTarget));
71
72 StringCbCopyW(szSendToFile, sizeof(szSendToFile), pszSendTo);
73 PathAppendW(szSendToFile, szTarget);
74 StringCbCatW(szSendToFile, sizeof(szSendToFile), L".ZFSendToTarget");
75 if (!CreateEmptyFile(szSendToFile))
76 {
77 DPRINT1("CreateEmptyFile('%ls')\n", szSendToFile);
78 return E_FAIL;
79 }
80 return S_OK;
81}
82
83static HRESULT
85{
87 SHGFP_TYPE_DEFAULT, pszPath);
88}
89
91{
92 WCHAR szValue[16];
93 DWORD dwType, cbValue = sizeof(szValue);
94 UINT nDefaultCodePage = (bUnZip ? CP_ACP : CP_UTF8);
95
96 LONG error = SHGetValueW(HKEY_CURRENT_USER, L"Software\\ReactOS",
97 (bUnZip ? L"UnZipCodePage" : L"ZipCodePage"),
98 &dwType, szValue, &cbValue);
99 if (error != ERROR_SUCCESS)
100 return nDefaultCodePage;
101
102 if (cbValue == sizeof(DWORD) && (dwType == REG_DWORD || dwType == REG_BINARY))
103 return *(DWORD*)szValue;
104
105 if (dwType != REG_SZ && dwType != REG_EXPAND_SZ)
106 return nDefaultCodePage;
107
108 szValue[_countof(szValue) - 1] = UNICODE_NULL;
109 return (UINT)wcstol(szValue, NULL, 0);
110}
111
114{
115 switch (dwReason)
116 {
120 gModule.Init(ObjectMap, hInstance, NULL);
121 init_zlib();
122 break;
123 }
124
125 return TRUE;
126}
127
129{
130 if (g_ModuleRefCnt)
131 return S_FALSE;
132 return gModule.DllCanUnloadNow();
133}
134
136{
137 return gModule.DllGetClassObject(rclsid, riid, ppv);
138}
139
141{
142 HRESULT hr;
143
146 return hr;
147
149 if (FAILED(hr))
150 return hr;
151
152 WCHAR szSendTo[MAX_PATH];
153 hr = GetDefaultUserSendTo(szSendTo);
154 if (SUCCEEDED(hr))
155 CreateSendToZip(szSendTo);
156
157 return S_OK;
158}
159
161{
162 HRESULT hr;
163
166 return hr;
167
169 if (FAILED(hr))
170 return hr;
171
172 return S_OK;
173}
174
177RouteTheCallW(IN HWND hWndOwner, IN HINSTANCE hInstance, IN PCWSTR lpStringArg, IN INT Show)
178{
179 CStringW path = lpStringArg;
180 PathRemoveBlanksW(path.GetBuffer());
181 path.ReleaseBuffer();
182 path = L"\"" + path + L"\"";
183
184 WCHAR app[MAX_PATH];
186 PathAppendW(app, L"explorer.exe");
187
188 ShellExecuteW(NULL, L"open", app, path.GetString(), NULL, Show ? Show : SW_SHOWNORMAL);
189 return TRUE;
190}
#define DPRINT1
Definition: precomp.h:8
DWORD dwReason
Definition: misc.cpp:141
#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:75
#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
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2352
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2589
VOID WINAPI PathRemoveBlanksW(LPWSTR lpszPath)
Definition: path.c:920
DWORD WINAPI SHGetValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue, LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)
Definition: reg.c:1236
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_Check_return_ long __cdecl wcstol(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
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:1496
#define GENERIC_WRITE
Definition: nt_native.h:90
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
#define PathAppendW
Definition: pathcch.h:309
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:596
#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:2482
HRESULT hr
Definition: shlfolder.c:183
#define CSIDL_SENDTO
Definition: shlobj.h:2182
@ SHGFP_TYPE_DEFAULT
Definition: shlobj.h:2150
#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:2357
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define SW_SHOWNORMAL
Definition: winuser.h:773
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
__wchar_t WCHAR
Definition: xmlstorage.h:180
EXTERN_C BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Definition: zipfldr.cpp:113
static BOOL CreateEmptyFile(PCWSTR pszFile)
Definition: zipfldr.cpp:52
zlib_filefunc64_def g_FFunc
Definition: zipfldr.cpp:44
CZipFldrModule gModule
Definition: zipfldr.cpp:38
STDAPI DllRegisterServer()
Definition: zipfldr.cpp:140
LONG g_ModuleRefCnt
Definition: zipfldr.cpp:12
STDAPI DllCanUnloadNow()
Definition: zipfldr.cpp:128
STDAPI DllUnregisterServer()
Definition: zipfldr.cpp:160
EXTERN_C BOOL WINAPI RouteTheCallW(IN HWND hWndOwner, IN HINSTANCE hInstance, IN PCWSTR lpStringArg, IN INT Show)
Definition: zipfldr.cpp:177
static void init_zlib()
Definition: zipfldr.cpp:46
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: zipfldr.cpp:135
UINT GetZipCodePage(BOOL bUnZip)
Definition: zipfldr.cpp:90
static HRESULT GetDefaultUserSendTo(PWSTR pszPath)
Definition: zipfldr.cpp:84
HMODULE g_hModule
Definition: zipfldr.cpp:11
static HRESULT CreateSendToZip(PCWSTR pszSendTo)
Definition: zipfldr.cpp:66