2b7010c4fad83d50a4871ba38dc8dbfeec91cca5
[reactos.git] / dll / shellext / zipfldr / CZipFolder.hpp
1 /*
2 * PROJECT: ReactOS Zip Shell Extension
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Main class
5 * COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8
9 EXTERN_C HRESULT WINAPI SHCreateFileExtractIconW(LPCWSTR pszPath, DWORD dwFileAttributes, REFIID riid, void **ppv);
10
11
12 struct FolderViewColumns
13 {
14 int iResource;
15 DWORD dwDefaultState;
16 int cxChar;
17 int fmt;
18 };
19
20 static FolderViewColumns g_ColumnDefs[] =
21 {
22 { IDS_COL_NAME, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, 25, LVCFMT_LEFT },
23 { IDS_COL_TYPE, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, 20, LVCFMT_LEFT },
24 { IDS_COL_COMPRSIZE, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, 10, LVCFMT_RIGHT },
25 { IDS_COL_PASSWORD, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, 10, LVCFMT_LEFT },
26 { IDS_COL_SIZE, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, 10, LVCFMT_RIGHT },
27 { IDS_COL_RATIO, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, 10, LVCFMT_LEFT },
28 { IDS_COL_DATE_MOD, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, 15, LVCFMT_LEFT },
29 };
30
31
32 class CZipFolder :
33 public CComCoClass<CZipFolder, &CLSID_ZipFolderStorageHandler>,
34 public CComObjectRootEx<CComMultiThreadModelNoCS>,
35 public IShellFolder2,
36 //public IStorage,
37 public IContextMenu,
38 public IShellExtInit,
39 //public IPersistFile,
40 public IPersistFolder2,
41 public IZip
42 {
43 CStringW m_ZipFile;
44 CStringA m_ZipDir;
45 CComHeapPtr<ITEMIDLIST> m_CurDir;
46 unzFile m_UnzipFile;
47
48 public:
49 CZipFolder()
50 :m_UnzipFile(NULL)
51 {
52 }
53
54 ~CZipFolder()
55 {
56 Close();
57 }
58
59 void Close()
60 {
61 if (m_UnzipFile)
62 unzClose(m_UnzipFile);
63 m_UnzipFile = NULL;
64 }
65
66 // *** IZip methods ***
67 STDMETHODIMP_(unzFile) getZip()
68 {
69 if (!m_UnzipFile)
70 {
71 m_UnzipFile = unzOpen2_64(m_ZipFile, &g_FFunc);
72 }
73
74 return m_UnzipFile;
75 }
76
77 // *** IShellFolder2 methods ***
78 STDMETHODIMP GetDefaultSearchGUID(GUID *pguid)
79 {
80 UNIMPLEMENTED;
81 return E_NOTIMPL;
82 }
83 STDMETHODIMP EnumSearches(IEnumExtraSearch **ppenum)
84 {
85 UNIMPLEMENTED;
86 return E_NOTIMPL;
87 }
88 STDMETHODIMP GetDefaultColumn(DWORD dwRes, ULONG *pSort, ULONG *pDisplay)
89 {
90 UNIMPLEMENTED;
91 return E_NOTIMPL;
92 }
93 STDMETHODIMP GetDefaultColumnState(UINT iColumn, DWORD *pcsFlags)
94 {
95 if (!pcsFlags || iColumn >= _countof(g_ColumnDefs))
96 return E_INVALIDARG;
97 *pcsFlags = g_ColumnDefs[iColumn].dwDefaultState;
98 return S_OK;
99 }
100 STDMETHODIMP GetDetailsEx(PCUITEMID_CHILD pidl, const SHCOLUMNID *pscid, VARIANT *pv)
101 {
102 UNIMPLEMENTED;
103 return E_NOTIMPL;
104 }
105 // Adapted from CFileDefExt::GetFileTimeString
106 BOOL _GetFileTimeString(LPFILETIME lpFileTime, LPWSTR pwszResult, UINT cchResult)
107 {
108 SYSTEMTIME st;
109
110 if (!FileTimeToSystemTime(lpFileTime, &st))
111 return FALSE;
112
113 size_t cchRemaining = cchResult;
114 LPWSTR pwszEnd = pwszResult;
115 int cchWritten = GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, pwszEnd, cchRemaining);
116 if (cchWritten)
117 --cchWritten; // GetDateFormatW returns count with terminating zero
118 else
119 return FALSE;
120 cchRemaining -= cchWritten;
121 pwszEnd += cchWritten;
122
123 StringCchCopyExW(pwszEnd, cchRemaining, L" ", &pwszEnd, &cchRemaining, 0);
124
125 cchWritten = GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, pwszEnd, cchRemaining);
126 if (cchWritten)
127 --cchWritten; // GetTimeFormatW returns count with terminating zero
128 else
129 return FALSE;
130
131 return TRUE;
132 }
133 STDMETHODIMP GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS *psd)
134 {
135 if (iColumn >= _countof(g_ColumnDefs))
136 return E_FAIL;
137
138 psd->cxChar = g_ColumnDefs[iColumn].cxChar;
139 psd->fmt = g_ColumnDefs[iColumn].fmt;
140
141 if (pidl == NULL)
142 {
143 return SHSetStrRet(&psd->str, _AtlBaseModule.GetResourceInstance(), g_ColumnDefs[iColumn].iResource);
144 }
145
146 PCUIDLIST_RELATIVE curpidl = ILGetNext(pidl);
147 if (curpidl->mkid.cb != 0)
148 {
149 DPRINT1("ERROR, unhandled PIDL!\n");
150 return E_FAIL;
151 }
152
153 const ZipPidlEntry* zipEntry = _ZipFromIL(pidl);
154 if (!zipEntry)
155 return E_INVALIDARG;
156
157 WCHAR Buffer[100];
158 bool isDir = zipEntry->ZipType == ZIP_PIDL_DIRECTORY;
159 switch (iColumn)
160 {
161 case 0: /* Name, ReactOS specific? */
162 return GetDisplayNameOf(pidl, 0, &psd->str);
163 case 1: /* Type */
164 {
165 SHFILEINFOA shfi;
166 DWORD dwAttributes = isDir ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL;
167 ULONG_PTR firet = SHGetFileInfoA(zipEntry->Name, dwAttributes, &shfi, sizeof(shfi), SHGFI_USEFILEATTRIBUTES | SHGFI_TYPENAME);
168 if (!firet)
169 return E_FAIL;
170 return SHSetStrRet(&psd->str, shfi.szTypeName);
171 }
172 case 2: /* Compressed size */
173 case 4: /* Size */
174 {
175 if (isDir)
176 return SHSetStrRet(&psd->str, L"");
177
178 ULONG64 Size = iColumn == 2 ? zipEntry->CompressedSize : zipEntry->UncompressedSize;
179 if (!StrFormatByteSizeW(Size, Buffer, _countof(Buffer)))
180 return E_FAIL;
181 return SHSetStrRet(&psd->str, Buffer);
182 }
183 case 3: /* Password */
184 if (isDir)
185 return SHSetStrRet(&psd->str, L"");
186 return SHSetStrRet(&psd->str, _AtlBaseModule.GetResourceInstance(), zipEntry->Password ? IDS_YES : IDS_NO);
187 case 5: /* Ratio */
188 {
189 if (isDir)
190 return SHSetStrRet(&psd->str, L"");
191
192 int ratio = 0;
193 if (zipEntry->UncompressedSize)
194 ratio = 100 - (int)((zipEntry->CompressedSize*100)/zipEntry->UncompressedSize);
195 StringCchPrintfW(Buffer, _countof(Buffer), L"%d%%", ratio);
196 return SHSetStrRet(&psd->str, Buffer);
197 }
198 case 6: /* Date */
199 {
200 if (isDir)
201 return SHSetStrRet(&psd->str, L"");
202 FILETIME ftLocal;
203 DosDateTimeToFileTime((WORD)(zipEntry->DosDate>>16), (WORD)zipEntry->DosDate, &ftLocal);
204 if (!_GetFileTimeString(&ftLocal, Buffer, _countof(Buffer)))
205 return E_FAIL;
206 return SHSetStrRet(&psd->str, Buffer);
207 }
208 }
209
210 UNIMPLEMENTED;
211 return E_NOTIMPL;
212 }
213 STDMETHODIMP MapColumnToSCID(UINT column, SHCOLUMNID *pscid)
214 {
215 UNIMPLEMENTED;
216 return E_NOTIMPL;
217 }
218
219 // *** IShellFolder methods ***
220 STDMETHODIMP ParseDisplayName(HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName, ULONG *pchEaten, PIDLIST_RELATIVE *ppidl, ULONG *pdwAttributes)
221 {
222 UNIMPLEMENTED;
223 return E_NOTIMPL;
224 }
225 STDMETHODIMP EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
226 {
227 return _CEnumZipContents_CreateInstance(this, dwFlags, m_ZipDir, IID_PPV_ARG(IEnumIDList, ppEnumIDList));
228 }
229 STDMETHODIMP BindToObject(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
230 {
231 if (riid == IID_IShellFolder)
232 {
233 CStringA newZipDir = m_ZipDir;
234 PCUIDLIST_RELATIVE curpidl = pidl;
235 while (curpidl->mkid.cb)
236 {
237 const ZipPidlEntry* zipEntry = _ZipFromIL(curpidl);
238 if (!zipEntry)
239 {
240 return E_FAIL;
241 }
242 newZipDir += zipEntry->Name;
243 newZipDir += '/';
244
245 curpidl = ILGetNext(curpidl);
246 }
247 return ShellObjectCreatorInit<CZipFolder>(m_ZipFile, newZipDir, m_CurDir, pidl, riid, ppvOut);
248 }
249 DbgPrint("%s(%S) UNHANDLED\n", __FUNCTION__, guid2string(riid));
250 return E_NOTIMPL;
251 }
252 STDMETHODIMP BindToStorage(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
253 {
254 UNIMPLEMENTED;
255 return E_NOTIMPL;
256 }
257 STDMETHODIMP CompareIDs(LPARAM lParam, PCUIDLIST_RELATIVE pidl1, PCUIDLIST_RELATIVE pidl2)
258 {
259 const ZipPidlEntry* zipEntry1 = _ZipFromIL(pidl1);
260 const ZipPidlEntry* zipEntry2 = _ZipFromIL(pidl2);
261
262 if (!zipEntry1 || !zipEntry2)
263 return E_INVALIDARG;
264
265 int result = 0;
266 if (zipEntry1->ZipType != zipEntry2->ZipType)
267 result = zipEntry1->ZipType - zipEntry2->ZipType;
268 else
269 result = stricmp(zipEntry1->Name, zipEntry2->Name);
270
271 if (!result && zipEntry1->ZipType == ZIP_PIDL_DIRECTORY)
272 {
273 PCUIDLIST_RELATIVE child1 = ILGetNext(pidl1);
274 PCUIDLIST_RELATIVE child2 = ILGetNext(pidl2);
275
276 if (child1->mkid.cb && child2->mkid.cb)
277 return CompareIDs(lParam, child1, child2);
278 else if (child1->mkid.cb)
279 result = 1;
280 else if (child2->mkid.cb)
281 result = -1;
282 }
283
284 return MAKE_COMPARE_HRESULT(result);
285 }
286 STDMETHODIMP CreateViewObject(HWND hwndOwner, REFIID riid, LPVOID *ppvOut)
287 {
288 static const GUID UnknownIID = // {93F81976-6A0D-42C3-94DD-AA258A155470}
289 {0x93F81976, 0x6A0D, 0x42C3, {0x94, 0xDD, 0xAA, 0x25, 0x8A, 0x15, 0x54, 0x70}};
290 if (riid == IID_IShellView)
291 {
292 SFV_CREATE sfvparams = {sizeof(SFV_CREATE), this};
293 CComPtr<IShellFolderViewCB> pcb;
294
295 HRESULT hr = _CFolderViewCB_CreateInstance(IID_PPV_ARG(IShellFolderViewCB, &pcb));
296 if (FAILED_UNEXPECTEDLY(hr))
297 return hr;
298
299 sfvparams.psfvcb = pcb;
300 hr = SHCreateShellFolderView(&sfvparams, (IShellView**)ppvOut);
301
302 return hr;
303 }
304 if (riid == IID_IExplorerCommandProvider)
305 {
306 return _CExplorerCommandProvider_CreateInstance(this, riid, ppvOut);
307 }
308 if (UnknownIID != riid)
309 DbgPrint("%s(%S) UNHANDLED\n", __FUNCTION__, guid2string(riid));
310 return E_NOTIMPL;
311 }
312 STDMETHODIMP GetAttributesOf(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD *rgfInOut)
313 {
314 if (!rgfInOut || !cidl || !apidl)
315 return E_INVALIDARG;
316
317 *rgfInOut = 0;
318
319 //static DWORD dwFileAttrs = SFGAO_STREAM | SFGAO_HASPROPSHEET | SFGAO_CANDELETE | SFGAO_CANCOPY | SFGAO_CANMOVE;
320 //static DWORD dwFolderAttrs = SFGAO_FOLDER | SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANDELETE | SFGAO_STORAGE | SFGAO_CANCOPY | SFGAO_CANMOVE;
321 static DWORD dwFileAttrs = SFGAO_STREAM;
322 static DWORD dwFolderAttrs = SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_BROWSABLE;
323
324
325 while (cidl > 0 && *apidl)
326 {
327 const ZipPidlEntry* zipEntry = _ZipFromIL(*apidl);
328
329 if (zipEntry)
330 {
331 if (zipEntry->ZipType == ZIP_PIDL_FILE)
332 *rgfInOut |= dwFileAttrs;
333 else
334 *rgfInOut |= dwFolderAttrs;
335 }
336 else
337 {
338 *rgfInOut = 0;
339 }
340
341 apidl++;
342 cidl--;
343 }
344
345 *rgfInOut &= ~SFGAO_VALIDATE;
346 return S_OK;
347 }
348 static HRESULT CALLBACK ZipFolderMenuCallback(IShellFolder *psf, HWND hwnd, IDataObject *pdtobj,
349 UINT uMsg, WPARAM wParam, LPARAM lParam)
350 {
351 switch (uMsg)
352 {
353 case DFM_MERGECONTEXTMENU:
354 DPRINT1("FIXME: Add menu items for DFM_MERGECONTEXTMENU\n");
355 return S_OK;
356 case DFM_INVOKECOMMAND:
357 case DFM_INVOKECOMMANDEX:
358 case DFM_GETDEFSTATICID: // Required for Windows 7 to pick a default
359 return S_FALSE;
360 }
361 return E_NOTIMPL;
362 }
363 STDMETHODIMP GetUIObjectOf(HWND hwndOwner, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
364 {
365 if ((riid == IID_IExtractIconA || riid == IID_IExtractIconW) && cidl == 1)
366 {
367 const ZipPidlEntry* zipEntry = _ZipFromIL(*apidl);
368 if (zipEntry)
369 {
370 CComHeapPtr<WCHAR> pathW;
371
372 int len = MultiByteToWideChar(CP_ACP, 0, zipEntry->Name, -1, NULL, 0);
373 pathW.Allocate(len);
374 MultiByteToWideChar(CP_ACP, 0, zipEntry->Name, -1, pathW, len);
375
376 DWORD dwAttributes = (zipEntry->ZipType == ZIP_PIDL_DIRECTORY) ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL;
377 return SHCreateFileExtractIconW(pathW, dwAttributes, riid, ppvOut);
378 }
379 }
380 else if (riid == IID_IContextMenu && cidl >= 0)
381 {
382 const ZipPidlEntry* zipEntry = _ZipFromIL(*apidl);
383 if (zipEntry)
384 {
385 HKEY keys[1] = {0};
386 int nkeys = 0;
387 if (zipEntry->ZipType == ZIP_PIDL_DIRECTORY)
388 {
389 LSTATUS res = RegOpenKeyExW(HKEY_CLASSES_ROOT, L"Folder", 0, KEY_READ | KEY_QUERY_VALUE, keys);
390 if (res != ERROR_SUCCESS)
391 return E_FAIL;
392 nkeys++;
393 }
394 return CDefFolderMenu_Create2(NULL, hwndOwner, cidl, apidl, this, ZipFolderMenuCallback, nkeys, keys, (IContextMenu**)ppvOut);
395 }
396 }
397 else if (riid == IID_IDataObject && cidl >= 1)
398 {
399 return CIDLData_CreateFromIDArray(m_CurDir, cidl, apidl, (IDataObject**)ppvOut);
400 }
401
402 DbgPrint("%s(%S) UNHANDLED\n", __FUNCTION__ , guid2string(riid));
403 return E_NOINTERFACE;
404 }
405 STDMETHODIMP GetDisplayNameOf(PCUITEMID_CHILD pidl, DWORD dwFlags, LPSTRRET strRet)
406 {
407 if (!pidl)
408 return S_FALSE;
409
410 PCUIDLIST_RELATIVE curpidl = ILGetNext(pidl);
411 if (curpidl->mkid.cb != 0)
412 {
413 DPRINT1("ERROR, unhandled PIDL!\n");
414 return E_FAIL;
415 }
416
417 const ZipPidlEntry* zipEntry = _ZipFromIL(pidl);
418 if (!zipEntry)
419 return E_FAIL;
420
421 return SHSetStrRet(strRet, (LPCSTR)zipEntry->Name);
422 }
423 STDMETHODIMP SetNameOf(HWND hwndOwner, PCUITEMID_CHILD pidl, LPCOLESTR lpName, DWORD dwFlags, PITEMID_CHILD *pPidlOut)
424 {
425 UNIMPLEMENTED;
426 return E_NOTIMPL;
427 }
428 //// IStorage
429 //STDMETHODIMP CreateStream(LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved1, DWORD reserved2, IStream **ppstm);
430 //STDMETHODIMP OpenStream(LPCOLESTR pwcsName, void *reserved1, DWORD grfMode, DWORD reserved2, IStream **ppstm);
431 //STDMETHODIMP CreateStorage(LPCOLESTR pwcsName, DWORD grfMode, DWORD dwStgFmt, DWORD reserved2, IStorage **ppstg);
432 //STDMETHODIMP OpenStorage(LPCOLESTR pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstg);
433 //STDMETHODIMP CopyTo(DWORD ciidExclude, const IID *rgiidExclude, SNB snbExclude, IStorage *pstgDest);
434 //STDMETHODIMP MoveElementTo(LPCOLESTR pwcsName, IStorage *pstgDest, LPCOLESTR pwcsNewName, DWORD grfFlags);
435 //STDMETHODIMP Commit(DWORD grfCommitFlags);
436 //STDMETHODIMP Revert();
437 //STDMETHODIMP EnumElements(DWORD reserved1, void *reserved2, DWORD reserved3, IEnumSTATSTG **ppenum);
438 //STDMETHODIMP DestroyElement(LPCOLESTR pwcsName);
439 //STDMETHODIMP RenameElement(LPCOLESTR pwcsOldName, LPCOLESTR pwcsNewName);
440 //STDMETHODIMP SetElementTimes(LPCOLESTR pwcsName, const FILETIME *pctime, const FILETIME *patime, const FILETIME *pmtime);
441 //STDMETHODIMP SetClass(REFCLSID clsid);
442 //STDMETHODIMP SetStateBits(DWORD grfStateBits, DWORD grfMask);
443 //STDMETHODIMP Stat(STATSTG *pstatstg, DWORD grfStatFlag);
444
445 // *** IContextMenu methods ***
446 STDMETHODIMP GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT *pwReserved, LPSTR pszName, UINT cchMax)
447 {
448 if (idCmd != 0)
449 return E_INVALIDARG;
450
451 switch (uFlags)
452 {
453 case GCS_VERBA:
454 return StringCchCopyA(pszName, cchMax, EXTRACT_VERBA);
455 case GCS_VERBW:
456 return StringCchCopyW((LPWSTR)pszName, cchMax, EXTRACT_VERBW);
457 case GCS_HELPTEXTA:
458 {
459 CStringA helpText(MAKEINTRESOURCEA(IDS_HELPTEXT));
460 return StringCchCopyA(pszName, cchMax, helpText);
461 }
462 case GCS_HELPTEXTW:
463 {
464 CStringW helpText(MAKEINTRESOURCEA(IDS_HELPTEXT));
465 return StringCchCopyW((LPWSTR)pszName, cchMax, helpText);
466 }
467 case GCS_VALIDATEA:
468 case GCS_VALIDATEW:
469 return S_OK;
470 }
471
472 return E_INVALIDARG;
473 }
474 STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO pici)
475 {
476 if (!pici || pici->cbSize != sizeof(*pici))
477 return E_INVALIDARG;
478
479 if (pici->lpVerb == MAKEINTRESOURCEA(0) || (HIWORD(pici->lpVerb) && !strcmp(pici->lpVerb, EXTRACT_VERBA)))
480 {
481 BSTR ZipFile = m_ZipFile.AllocSysString();
482 InterlockedIncrement(&g_ModuleRefCnt);
483
484 DWORD tid;
485 HANDLE hThread = CreateThread(NULL, 0, s_ExtractProc, ZipFile, NULL, &tid);
486 if (hThread)
487 {
488 CloseHandle(hThread);
489 return S_OK;
490 }
491 }
492 return E_INVALIDARG;
493 }
494 STDMETHODIMP QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
495 {
496 int Entries = 0;
497
498 CStringW menuText(MAKEINTRESOURCEW(IDS_MENUITEM));
499
500 InsertMenuW(hmenu, indexMenu++, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
501 Entries++;
502 InsertMenuW(hmenu, indexMenu++, MF_BYPOSITION | MF_STRING, idCmdFirst++, menuText);
503 Entries++;
504
505 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, Entries);
506 }
507
508 // *** IShellExtInit methods ***
509 STDMETHODIMP Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hkeyProgID)
510 {
511 FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
512 STGMEDIUM stg;
513
514 HRESULT hr = pDataObj->GetData(&etc, &stg);
515 if (FAILED_UNEXPECTEDLY(hr))
516 {
517 return hr;
518 }
519 hr = E_FAIL;
520 HDROP hdrop = (HDROP)GlobalLock(stg.hGlobal);
521 if (hdrop)
522 {
523 UINT uNumFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, NULL, 0);
524 if (uNumFiles == 1)
525 {
526 WCHAR szFile[MAX_PATH * 2];
527 if (DragQueryFileW(hdrop, 0, szFile, _countof(szFile)))
528 {
529 CComHeapPtr<ITEMIDLIST> pidl;
530 hr = SHParseDisplayName(szFile, NULL, &pidl, 0, NULL);
531 if (!FAILED_UNEXPECTEDLY(hr))
532 {
533 hr = Initialize(pidl);
534 }
535 }
536 else
537 {
538 DbgPrint("Failed to query the file.\r\n");
539 }
540 }
541 else
542 {
543 DbgPrint("Invalid number of files: %d\r\n", uNumFiles);
544 }
545 GlobalUnlock(stg.hGlobal);
546 }
547 else
548 {
549 DbgPrint("Could not lock stg.hGlobal\r\n");
550 }
551 ReleaseStgMedium(&stg);
552 return hr;
553
554 }
555
556 //// IPersistFile
557 ////STDMETHODIMP GetClassID(CLSID *pclsid);
558 //STDMETHODIMP IsDirty();
559 //STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode);
560 //STDMETHODIMP Save(LPCOLESTR pszFileName, BOOL fRemember);
561 //STDMETHODIMP SaveCompleted(LPCOLESTR pszFileName);
562 //STDMETHODIMP GetCurFile(LPOLESTR *ppszFileName);
563
564 //// *** IPersistFolder2 methods ***
565 STDMETHODIMP GetCurFolder(LPITEMIDLIST * pidl)
566 {
567 *pidl = ILClone(m_CurDir);
568 return S_OK;
569 }
570
571 // *** IPersistFolder methods ***
572 STDMETHODIMP Initialize(LPCITEMIDLIST pidl)
573 {
574 WCHAR tmpPath[MAX_PATH];
575
576 if (SHGetPathFromIDListW(pidl, tmpPath))
577 {
578 m_ZipFile = tmpPath;
579 m_CurDir.Attach(ILClone(pidl));
580 return S_OK;
581 }
582 DbgPrint("%s() => Unable to parse pidl\n", __FUNCTION__);
583 return E_INVALIDARG;
584 }
585
586 // *** IPersist methods ***
587 STDMETHODIMP GetClassID(CLSID *lpClassId)
588 {
589 DbgPrint("%s\n", __FUNCTION__);
590 return E_NOTIMPL;
591 }
592
593
594 STDMETHODIMP Initialize(PCWSTR zipFile, PCSTR zipDir, PCUIDLIST_ABSOLUTE curDir, PCUIDLIST_RELATIVE pidl)
595 {
596 m_ZipFile = zipFile;
597 m_ZipDir = zipDir;
598
599 m_CurDir.Attach(ILCombine(curDir, pidl));
600 return S_OK;
601 }
602 static DWORD WINAPI s_ExtractProc(LPVOID arg)
603 {
604 CComBSTR ZipFile;
605 ZipFile.Attach((BSTR)arg);
606
607 _CZipExtract_runWizard(ZipFile);
608
609 InterlockedDecrement(&g_ModuleRefCnt);
610 return 0;
611 }
612
613 public:
614 DECLARE_NO_REGISTRY() // Handled manually because this object is exposed via multiple clsid's
615 DECLARE_NOT_AGGREGATABLE(CZipFolder)
616
617 DECLARE_PROTECT_FINAL_CONSTRUCT()
618
619 BEGIN_COM_MAP(CZipFolder)
620 COM_INTERFACE_ENTRY_IID(IID_IShellFolder2, IShellFolder2)
621 COM_INTERFACE_ENTRY_IID(IID_IShellFolder, IShellFolder)
622 // COM_INTERFACE_ENTRY_IID(IID_IStorage, IStorage)
623 COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu)
624 COM_INTERFACE_ENTRY_IID(IID_IShellExtInit, IShellExtInit)
625 //COM_INTERFACE_ENTRY_IID(IID_IPersistFile, IPersistFile)
626 COM_INTERFACE_ENTRY_IID(IID_IPersistFolder2, IPersistFolder2)
627 COM_INTERFACE_ENTRY_IID(IID_IPersistFolder, IPersistFolder)
628 COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersist)
629 END_COM_MAP()
630 };
631