Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / other-licenses / 7zstub / src / 7zip / Archive / 7z / 7zProperties.cpp
blobd474be09576a807db4226b3c624b38c32c112c20
1 // 7zProperties.cpp
3 #include "StdAfx.h"
5 #include "7zProperties.h"
6 #include "7zHeader.h"
7 #include "7zHandler.h"
9 // #define _MULTI_PACK
11 namespace NArchive {
12 namespace N7z {
14 struct CPropMap
16 UInt64 FilePropID;
17 STATPROPSTG StatPROPSTG;
20 CPropMap kPropMap[] =
22 { NID::kName, NULL, kpidPath, VT_BSTR},
23 { NID::kSize, NULL, kpidSize, VT_UI8},
24 { NID::kPackInfo, NULL, kpidPackedSize, VT_UI8},
26 #ifdef _MULTI_PACK
27 { 100, L"Pack0", kpidPackedSize0, VT_UI8},
28 { 101, L"Pack1", kpidPackedSize1, VT_UI8},
29 { 102, L"Pack2", kpidPackedSize2, VT_UI8},
30 { 103, L"Pack3", kpidPackedSize3, VT_UI8},
31 { 104, L"Pack4", kpidPackedSize4, VT_UI8},
32 #endif
34 { NID::kCreationTime, NULL, kpidCreationTime, VT_FILETIME},
35 { NID::kLastWriteTime, NULL, kpidLastWriteTime, VT_FILETIME},
36 { NID::kLastAccessTime, NULL, kpidLastAccessTime, VT_FILETIME},
37 { NID::kWinAttributes, NULL, kpidAttributes, VT_UI4},
38 { NID::kStartPos, NULL, kpidPosition, VT_UI4},
41 { NID::kCRC, NULL, kpidCRC, VT_UI4},
43 { NID::kAnti, L"Anti", kpidIsAnti, VT_BOOL},
44 // { 97, NULL, kpidSolid, VT_BOOL},
45 #ifndef _SFX
46 { 98, NULL, kpidMethod, VT_BSTR},
47 { 99, L"Block", kpidBlock, VT_UI4}
48 #endif
49 // { L"ID", kpidID, VT_BSTR},
50 // { L"UnPack Version", kpidUnPackVersion, VT_UI1},
51 // { L"Host OS", kpidHostOS, VT_BSTR}
54 static const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);
56 static int FindPropInMap(UInt64 filePropID)
58 for (int i = 0; i < kPropMapSize; i++)
59 if (kPropMap[i].FilePropID == filePropID)
60 return i;
61 return -1;
64 static void CopyOneItem(CRecordVector<UInt64> &src,
65 CRecordVector<UInt64> &dest, UInt32 item)
67 for (int i = 0; i < src.Size(); i++)
68 if (src[i] == item)
70 dest.Add(item);
71 src.Delete(i);
72 return;
76 static void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)
78 for (int i = 0; i < src.Size(); i++)
79 if (src[i] == item)
81 src.Delete(i);
82 return;
86 static void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)
88 for (int i = 0; i < dest.Size(); i++)
89 if (dest[i] == item)
91 dest.Delete(i);
92 break;
94 dest.Insert(0, item);
97 void CHandler::FillPopIDs()
99 _fileInfoPopIDs.Clear();
101 #ifdef _7Z_VOL
102 if(_volumes.Size() < 1)
103 return;
104 const CVolume &volume = _volumes.Front();
105 const CArchiveDatabaseEx &_database = volume.Database;
106 #endif
108 CRecordVector<UInt64> fileInfoPopIDs = _database.ArchiveInfo.FileInfoPopIDs;
110 RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);
111 RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);
113 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);
114 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);
115 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);
116 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);
117 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCreationTime);
118 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastWriteTime);
119 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastAccessTime);
120 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);
121 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);
122 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);
123 _fileInfoPopIDs += fileInfoPopIDs;
125 #ifndef _SFX
126 _fileInfoPopIDs.Add(98);
127 _fileInfoPopIDs.Add(99);
128 #endif
129 #ifdef _MULTI_PACK
130 _fileInfoPopIDs.Add(100);
131 _fileInfoPopIDs.Add(101);
132 _fileInfoPopIDs.Add(102);
133 _fileInfoPopIDs.Add(103);
134 _fileInfoPopIDs.Add(104);
135 #endif
137 #ifndef _SFX
138 InsertToHead(_fileInfoPopIDs, NID::kLastWriteTime);
139 InsertToHead(_fileInfoPopIDs, NID::kPackInfo);
140 InsertToHead(_fileInfoPopIDs, NID::kSize);
141 InsertToHead(_fileInfoPopIDs, NID::kName);
142 #endif
145 STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)
147 *numProperties = _fileInfoPopIDs.Size();
148 return S_OK;
151 STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index,
152 BSTR *name, PROPID *propID, VARTYPE *varType)
154 if((int)index >= _fileInfoPopIDs.Size())
155 return E_INVALIDARG;
156 int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);
157 if (indexInMap == -1)
158 return E_INVALIDARG;
159 const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;
160 *propID = srcItem.propid;
161 *varType = srcItem.vt;
162 *name = 0;
163 return S_OK;