view src/win32/7zip/7z/CPP/7zip/Archive/7z/7zProperties.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line source
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
15 {
16 UInt64 FilePropID;
17 STATPROPSTG StatPROPSTG;
18 };
20 CPropMap kPropMap[] =
21 {
22 { NID::kName, NULL, kpidPath, VT_BSTR},
23 { NID::kSize, NULL, kpidSize, VT_UI8},
24 { NID::kPackInfo, NULL, kpidPackSize, 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::kCTime, NULL, kpidCTime, VT_FILETIME},
35 { NID::kMTime, NULL, kpidMTime, VT_FILETIME},
36 { NID::kATime, NULL, kpidATime, VT_FILETIME},
37 { NID::kWinAttributes, NULL, kpidAttrib, VT_UI4},
38 { NID::kStartPos, NULL, kpidPosition, VT_UI4},
40 { NID::kCRC, NULL, kpidCRC, VT_UI4},
42 { NID::kAnti, NULL, kpidIsAnti, VT_BOOL},
44 #ifndef _SFX
45 { 97, NULL, kpidEncrypted, VT_BOOL},
46 { 98, NULL, kpidMethod, VT_BSTR},
47 { 99, NULL, kpidBlock, VT_UI4}
48 #endif
49 };
51 static const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);
53 static int FindPropInMap(UInt64 filePropID)
54 {
55 for (int i = 0; i < kPropMapSize; i++)
56 if (kPropMap[i].FilePropID == filePropID)
57 return i;
58 return -1;
59 }
61 static void CopyOneItem(CRecordVector<UInt64> &src,
62 CRecordVector<UInt64> &dest, UInt32 item)
63 {
64 for (int i = 0; i < src.Size(); i++)
65 if (src[i] == item)
66 {
67 dest.Add(item);
68 src.Delete(i);
69 return;
70 }
71 }
73 static void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)
74 {
75 for (int i = 0; i < src.Size(); i++)
76 if (src[i] == item)
77 {
78 src.Delete(i);
79 return;
80 }
81 }
83 static void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)
84 {
85 for (int i = 0; i < dest.Size(); i++)
86 if (dest[i] == item)
87 {
88 dest.Delete(i);
89 break;
90 }
91 dest.Insert(0, item);
92 }
94 void CHandler::FillPopIDs()
95 {
96 _fileInfoPopIDs.Clear();
98 #ifdef _7Z_VOL
99 if(_volumes.Size() < 1)
100 return;
101 const CVolume &volume = _volumes.Front();
102 const CArchiveDatabaseEx &_db = volume.Database;
103 #endif
105 CRecordVector<UInt64> fileInfoPopIDs = _db.ArchiveInfo.FileInfoPopIDs;
107 RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);
108 RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);
110 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);
111 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);
112 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);
113 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);
114 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCTime);
115 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kMTime);
116 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kATime);
117 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);
118 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);
119 CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);
120 _fileInfoPopIDs += fileInfoPopIDs;
122 #ifndef _SFX
123 _fileInfoPopIDs.Add(97);
124 _fileInfoPopIDs.Add(98);
125 _fileInfoPopIDs.Add(99);
126 #endif
127 #ifdef _MULTI_PACK
128 _fileInfoPopIDs.Add(100);
129 _fileInfoPopIDs.Add(101);
130 _fileInfoPopIDs.Add(102);
131 _fileInfoPopIDs.Add(103);
132 _fileInfoPopIDs.Add(104);
133 #endif
135 #ifndef _SFX
136 InsertToHead(_fileInfoPopIDs, NID::kMTime);
137 InsertToHead(_fileInfoPopIDs, NID::kPackInfo);
138 InsertToHead(_fileInfoPopIDs, NID::kSize);
139 InsertToHead(_fileInfoPopIDs, NID::kName);
140 #endif
141 }
143 STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)
144 {
145 *numProperties = _fileInfoPopIDs.Size();
146 return S_OK;
147 }
149 STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)
150 {
151 if ((int)index >= _fileInfoPopIDs.Size())
152 return E_INVALIDARG;
153 int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);
154 if (indexInMap == -1)
155 return E_INVALIDARG;
156 const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;
157 *propID = srcItem.propid;
158 *varType = srcItem.vt;
159 *name = 0;
160 return S_OK;
161 }
163 }}