[ZIPFLDR] Initial implementation.
[reactos.git] / dll / shellext / zipfldr / zippidl.cpp
1 /*
2 * PROJECT: ReactOS Zip Shell Extension
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: zip pidl handling
5 * COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8 #include "precomp.h"
9
10 LPITEMIDLIST _ILCreate(ZipPidlType Type, LPCSTR lpString, unz_file_info64& info)
11 {
12 int cbData = sizeof(ZipPidlEntry) + strlen(lpString);
13 ZipPidlEntry* pidl = (ZipPidlEntry*)SHAlloc(cbData + sizeof(WORD));
14 if (!pidl)
15 return NULL;
16
17 pidl->cb = cbData;
18 pidl->MagicType = 'z';
19 pidl->ZipType = Type;
20
21 if (Type != ZIP_PIDL_DIRECTORY)
22 {
23 pidl->CompressedSize = info.compressed_size;
24 pidl->UncompressedSize = info.uncompressed_size;
25 pidl->DosDate = info.dosDate;
26 pidl->Password = info.flag & 1;
27 }
28
29 strcpy(pidl->Name, lpString);
30 *(WORD*)((char*)pidl + cbData) = 0;
31
32 return (LPITEMIDLIST)pidl;
33 }
34
35
36 const ZipPidlEntry* _ZipFromIL(LPCITEMIDLIST pidl)
37 {
38 const ZipPidlEntry* zipPidl = (const ZipPidlEntry*)pidl;
39 if (zipPidl->MagicType == 'z')
40 return zipPidl;
41 return NULL;
42 }