xref: /reactos/dll/shellext/zipfldr/zippidl.cpp (revision 0b366ea1)
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-2019 Mark Jansen (mark.jansen@reactos.org)
6  *              Copyright 2023 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
7  */
8 
9 #include "precomp.h"
10 
11 LPITEMIDLIST _ILCreate(ZipPidlType Type, PCWSTR lpString, unz_file_info64& info)
12 {
13     size_t cbData = sizeof(ZipPidlEntry) + wcslen(lpString) * sizeof(WCHAR);
14     if (cbData > MAXWORD)
15         return NULL;
16 
17     ZipPidlEntry* pidl = (ZipPidlEntry*)SHAlloc(cbData + sizeof(WORD));
18     if (!pidl)
19         return NULL;
20 
21     ZeroMemory(pidl, cbData + sizeof(WORD));
22 
23     pidl->cb = (WORD)cbData;
24     pidl->MagicType = 'z';
25     pidl->ZipType = Type;
26 
27     if (Type != ZIP_PIDL_DIRECTORY)
28     {
29         pidl->CompressedSize = info.compressed_size;
30         pidl->UncompressedSize = info.uncompressed_size;
31         pidl->DosDate = info.dosDate;
32         pidl->Password = info.flag & MINIZIP_PASSWORD_FLAG;
33     }
34 
35     wcscpy(pidl->Name, lpString);
36     *(WORD*)((char*)pidl + cbData) = 0; // The end of an ITEMIDLIST
37 
38     return (LPITEMIDLIST)pidl;
39 }
40 
41 const ZipPidlEntry* _ZipFromIL(LPCITEMIDLIST pidl)
42 {
43     const ZipPidlEntry* zipPidl = (const ZipPidlEntry*)pidl;
44     if (zipPidl->MagicType == 'z')
45         return zipPidl;
46     return NULL;
47 }
48