other-licenses/7zstub/src/7zip/Archive/7z/7zProperties.cpp

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:e21705378307
1 // 7zProperties.cpp
2
3 #include "StdAfx.h"
4
5 #include "7zProperties.h"
6 #include "7zHeader.h"
7 #include "7zHandler.h"
8
9 // #define _MULTI_PACK
10
11 namespace NArchive {
12 namespace N7z {
13
14 struct CPropMap
15 {
16 UInt64 FilePropID;
17 STATPROPSTG StatPROPSTG;
18 };
19
20 CPropMap kPropMap[] =
21 {
22 { NID::kName, NULL, kpidPath, VT_BSTR},
23 { NID::kSize, NULL, kpidSize, VT_UI8},
24 { NID::kPackInfo, NULL, kpidPackedSize, VT_UI8},
25
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
33
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},
39
40
41 { NID::kCRC, NULL, kpidCRC, VT_UI4},
42
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}
52 };
53
54 static const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);
55
56 static int FindPropInMap(UInt64 filePropID)
57 {
58 for (int i = 0; i < kPropMapSize; i++)
59 if (kPropMap[i].FilePropID == filePropID)
60 return i;
61 return -1;
62 }
63
64 static void CopyOneItem(CRecordVector<UInt64> &src,
65 CRecordVector<UInt64> &dest, UInt32 item)
66 {
67 for (int i = 0; i < src.Size(); i++)
68 if (src[i] == item)
69 {
70 dest.Add(item);
71 src.Delete(i);
72 return;
73 }
74 }
75
76 static void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)
77 {
78 for (int i = 0; i < src.Size(); i++)
79 if (src[i] == item)
80 {
81 src.Delete(i);
82 return;
83 }
84 }
85
86 static void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)
87 {
88 for (int i = 0; i < dest.Size(); i++)
89 if (dest[i] == item)
90 {
91 dest.Delete(i);
92 break;
93 }
94 dest.Insert(0, item);
95 }
96
97 void CHandler::FillPopIDs()
98 {
99 _fileInfoPopIDs.Clear();
100
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
107
108 CRecordVector<UInt64> fileInfoPopIDs = _database.ArchiveInfo.FileInfoPopIDs;
109
110 RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);
111 RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);
112
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;
124
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
136
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
143 }
144
145 STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)
146 {
147 *numProperties = _fileInfoPopIDs.Size();
148 return S_OK;
149 }
150
151 STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index,
152 BSTR *name, PROPID *propID, VARTYPE *varType)
153 {
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;
164 }
165
166 }}

mercurial