ReactOS 0.4.17-dev-966-gf06eace
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
43
44static void init_zlib()
45{
47}
48
49static BOOL
51{
56 {
58 return TRUE;
59 }
60 return FALSE;
61}
62
63static HRESULT
65{
66 WCHAR szTarget[MAX_PATH], szSendToFile[MAX_PATH];
67
68 LoadStringW(g_hModule, IDS_FRIENDLYNAME, szTarget, _countof(szTarget));
69
70 StringCbCopyW(szSendToFile, sizeof(szSendToFile), pszSendTo);
71 PathAppendW(szSendToFile, szTarget);
72 StringCbCatW(szSendToFile, sizeof(szSendToFile), L".ZFSendToTarget");
73 if (!CreateEmptyFile(szSendToFile))
74 {
75 DPRINT1("CreateEmptyFile('%ls')\n", szSendToFile);
76 return E_FAIL;
77 }
78 return S_OK;
79}
80
81static HRESULT
83{
85 SHGFP_TYPE_DEFAULT, pszPath);
86}
87
89{
90 WCHAR szValue[16];
91 DWORD dwType, cbValue = sizeof(szValue);
92 UINT nDefaultCodePage = (bUnZip ? CP_ACP : CP_UTF8);
93
94 LONG error = SHGetValueW(HKEY_CURRENT_USER, L"Software\\ReactOS",
95 (bUnZip ? L"UnZipCodePage" : L"ZipCodePage"),
96 &dwType, szValue, &cbValue);
97 if (error != ERROR_SUCCESS)
98 return nDefaultCodePage;
99
100 if (cbValue == sizeof(DWORD) && (dwType == REG_DWORD || dwType == REG_BINARY))
101 return *(DWORD*)szValue;
102
103 if (dwType != REG_SZ && dwType != REG_EXPAND_SZ)
104 return nDefaultCodePage;
105
106 szValue[_countof(szValue) - 1] = UNICODE_NULL;
107 return (UINT)wcstol(szValue, NULL, 0);
108}
109
112{
113 switch (dwReason)
114 {
118 gModule.Init(ObjectMap, hInstance, NULL);
119 init_zlib();
120 break;
121 }
122
123 return TRUE;
124}
125
127{
128 if (g_ModuleRefCnt)
129 return S_FALSE;
130 return gModule.DllCanUnloadNow();
131}
132
134{
135 return gModule.DllGetClassObject(rclsid, riid, ppv);
136}
137
139{
140 HRESULT hr;
141
144 return hr;
145
147 if (FAILED(hr))
148 return hr;
149
150 WCHAR szSendTo[MAX_PATH];
151 hr = GetDefaultUserSendTo(szSendTo);
152 if (SUCCEEDED(hr))
153 CreateSendToZip(szSendTo);
154
155 return S_OK;
156}
157
159{
160 HRESULT hr;
161
164 return hr;
165
167 if (FAILED(hr))
168 return hr;
169
170 return S_OK;
171}
172
175RouteTheCallW(IN HWND hWndOwner, IN HINSTANCE hInstance, IN PCWSTR lpStringArg, IN INT Show)
176{
177 CStringW path = lpStringArg;
178 PathRemoveBlanksW(path.GetBuffer());
179 path.ReleaseBuffer();
180 path = L"\"" + path + L"\"";
181
182 WCHAR app[MAX_PATH];
184 PathAppendW(app, L"explorer.exe");
185
186 ShellExecuteW(NULL, L"open", app, path.GetString(), NULL, Show ? Show : SW_SHOWNORMAL);
187 return TRUE;
188}
#define REG_SZ
Definition: layer.c:22
#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
HRESULT hr
Definition: delayimp.cpp:582
#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:2370
void WINAPI PathRemoveBlanksW(WCHAR *path)
Definition: path.c:1886
_ACRTIMP __msvcrt_long __cdecl wcstol(const wchar_t *, wchar_t **, int)
Definition: wcs.c:2752
DWORD WINAPI SHGetValueW(HKEY hkey, const WCHAR *subkey, const WCHAR *value, DWORD *type, void *data, DWORD *data_len)
Definition: main.c:2222
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2717
#define FAILED_UNEXPECTEDLY
Definition: utils.cpp:33
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned int UINT
Definition: sysinfo.c:13
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 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
#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
short WCHAR
Definition: pedump.c:58
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 SW_SHOWNORMAL
Definition: winuser.h:781
#define REG_DWORD
Definition: sdbapi.c:615
#define CP_UTF8
Definition: nls.h:20
#define LoadStringW
Definition: utils.h:64
HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
Definition: shlexec.cpp:2787
#define CSIDL_SENDTO
Definition: shlobj.h:2200
@ SHGFP_TYPE_DEFAULT
Definition: shlobj.h:2168
#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:1279
#define HKEY_CURRENT_USER
Definition: winreg.h:11
EXTERN_C BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Definition: zipfldr.cpp:111
static BOOL CreateEmptyFile(PCWSTR pszFile)
Definition: zipfldr.cpp:50
zlib_filefunc64_def g_FFunc
Definition: zipfldr.cpp:42
CZipFldrModule gModule
Definition: zipfldr.cpp:39
STDAPI DllRegisterServer()
Definition: zipfldr.cpp:138
LONG g_ModuleRefCnt
Definition: zipfldr.cpp:12
STDAPI DllCanUnloadNow()
Definition: zipfldr.cpp:126
STDAPI DllUnregisterServer()
Definition: zipfldr.cpp:158
EXTERN_C BOOL WINAPI RouteTheCallW(IN HWND hWndOwner, IN HINSTANCE hInstance, IN PCWSTR lpStringArg, IN INT Show)
Definition: zipfldr.cpp:175
static void init_zlib()
Definition: zipfldr.cpp:44
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: zipfldr.cpp:133
UINT GetZipCodePage(BOOL bUnZip)
Definition: zipfldr.cpp:88
static HRESULT GetDefaultUserSendTo(PWSTR pszPath)
Definition: zipfldr.cpp:82
HMODULE g_hModule
Definition: zipfldr.cpp:11
static HRESULT CreateSendToZip(PCWSTR pszSendTo)
Definition: zipfldr.cpp:64