Mercurial > vba-linux
comparison src/win32/7zip/7z/CPP/7zip/Archive/7z/7zItem.h @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 // 7zItem.h | |
2 | |
3 #ifndef __7Z_ITEM_H | |
4 #define __7Z_ITEM_H | |
5 | |
6 #include "../../../Common/Buffer.h" | |
7 #include "../../../Common/MyString.h" | |
8 | |
9 #include "../../Common/MethodId.h" | |
10 | |
11 #include "7zHeader.h" | |
12 | |
13 namespace NArchive { | |
14 namespace N7z { | |
15 | |
16 typedef UInt32 CNum; | |
17 const CNum kNumMax = 0x7FFFFFFF; | |
18 const CNum kNumNoIndex = 0xFFFFFFFF; | |
19 | |
20 struct CCoderInfo | |
21 { | |
22 CMethodId MethodID; | |
23 CByteBuffer Props; | |
24 CNum NumInStreams; | |
25 CNum NumOutStreams; | |
26 bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); } | |
27 }; | |
28 | |
29 struct CBindPair | |
30 { | |
31 CNum InIndex; | |
32 CNum OutIndex; | |
33 }; | |
34 | |
35 struct CFolder | |
36 { | |
37 CObjectVector<CCoderInfo> Coders; | |
38 CRecordVector<CBindPair> BindPairs; | |
39 CRecordVector<CNum> PackStreams; | |
40 CRecordVector<UInt64> UnpackSizes; | |
41 UInt32 UnpackCRC; | |
42 bool UnpackCRCDefined; | |
43 | |
44 CFolder(): UnpackCRCDefined(false) {} | |
45 | |
46 UInt64 GetUnpackSize() const // test it | |
47 { | |
48 if (UnpackSizes.IsEmpty()) | |
49 return 0; | |
50 for (int i = UnpackSizes.Size() - 1; i >= 0; i--) | |
51 if (FindBindPairForOutStream(i) < 0) | |
52 return UnpackSizes[i]; | |
53 throw 1; | |
54 } | |
55 | |
56 CNum GetNumOutStreams() const | |
57 { | |
58 CNum result = 0; | |
59 for (int i = 0; i < Coders.Size(); i++) | |
60 result += Coders[i].NumOutStreams; | |
61 return result; | |
62 } | |
63 | |
64 int FindBindPairForInStream(CNum inStreamIndex) const | |
65 { | |
66 for(int i = 0; i < BindPairs.Size(); i++) | |
67 if (BindPairs[i].InIndex == inStreamIndex) | |
68 return i; | |
69 return -1; | |
70 } | |
71 int FindBindPairForOutStream(CNum outStreamIndex) const | |
72 { | |
73 for(int i = 0; i < BindPairs.Size(); i++) | |
74 if (BindPairs[i].OutIndex == outStreamIndex) | |
75 return i; | |
76 return -1; | |
77 } | |
78 int FindPackStreamArrayIndex(CNum inStreamIndex) const | |
79 { | |
80 for(int i = 0; i < PackStreams.Size(); i++) | |
81 if (PackStreams[i] == inStreamIndex) | |
82 return i; | |
83 return -1; | |
84 } | |
85 | |
86 bool CheckStructure() const; | |
87 }; | |
88 | |
89 struct CUInt64DefVector | |
90 { | |
91 CRecordVector<UInt64> Values; | |
92 CRecordVector<bool> Defined; | |
93 | |
94 void Clear() | |
95 { | |
96 Values.Clear(); | |
97 Defined.Clear(); | |
98 } | |
99 | |
100 void ReserveDown() | |
101 { | |
102 Values.ReserveDown(); | |
103 Values.ReserveDown(); | |
104 } | |
105 | |
106 bool GetItem(int index, UInt64 &value) const | |
107 { | |
108 if (index < Defined.Size() && Defined[index]) | |
109 { | |
110 value = Values[index]; | |
111 return true; | |
112 } | |
113 value = 0; | |
114 return false; | |
115 } | |
116 | |
117 void SetItem(int index, bool defined, UInt64 value) | |
118 { | |
119 while (index >= Defined.Size()) | |
120 Defined.Add(false); | |
121 Defined[index] = defined; | |
122 if (!defined) | |
123 return; | |
124 while (index >= Values.Size()) | |
125 Values.Add(0); | |
126 Values[index] = value; | |
127 } | |
128 | |
129 bool CheckSize(int size) const { return Defined.Size() == size || Defined.Size() == 0; } | |
130 }; | |
131 | |
132 struct CFileItem | |
133 { | |
134 UInt64 Size; | |
135 UInt32 Attrib; | |
136 UInt32 Crc; | |
137 UString Name; | |
138 | |
139 bool HasStream; // Test it !!! it means that there is | |
140 // stream in some folder. It can be empty stream | |
141 bool IsDir; | |
142 bool CrcDefined; | |
143 bool AttribDefined; | |
144 | |
145 CFileItem(): | |
146 HasStream(true), | |
147 IsDir(false), | |
148 CrcDefined(false), | |
149 AttribDefined(false) | |
150 {} | |
151 void SetAttrib(UInt32 attrib) | |
152 { | |
153 AttribDefined = true; | |
154 Attrib = attrib; | |
155 } | |
156 }; | |
157 | |
158 struct CFileItem2 | |
159 { | |
160 UInt64 CTime; | |
161 UInt64 ATime; | |
162 UInt64 MTime; | |
163 UInt64 StartPos; | |
164 bool CTimeDefined; | |
165 bool ATimeDefined; | |
166 bool MTimeDefined; | |
167 bool StartPosDefined; | |
168 bool IsAnti; | |
169 }; | |
170 | |
171 struct CArchiveDatabase | |
172 { | |
173 CRecordVector<UInt64> PackSizes; | |
174 CRecordVector<bool> PackCRCsDefined; | |
175 CRecordVector<UInt32> PackCRCs; | |
176 CObjectVector<CFolder> Folders; | |
177 CRecordVector<CNum> NumUnpackStreamsVector; | |
178 CObjectVector<CFileItem> Files; | |
179 | |
180 CUInt64DefVector CTime; | |
181 CUInt64DefVector ATime; | |
182 CUInt64DefVector MTime; | |
183 CUInt64DefVector StartPos; | |
184 CRecordVector<bool> IsAnti; | |
185 | |
186 void Clear() | |
187 { | |
188 PackSizes.Clear(); | |
189 PackCRCsDefined.Clear(); | |
190 PackCRCs.Clear(); | |
191 Folders.Clear(); | |
192 NumUnpackStreamsVector.Clear(); | |
193 Files.Clear(); | |
194 CTime.Clear(); | |
195 ATime.Clear(); | |
196 MTime.Clear(); | |
197 StartPos.Clear(); | |
198 IsAnti.Clear(); | |
199 } | |
200 | |
201 void ReserveDown() | |
202 { | |
203 PackSizes.ReserveDown(); | |
204 PackCRCsDefined.ReserveDown(); | |
205 PackCRCs.ReserveDown(); | |
206 Folders.ReserveDown(); | |
207 NumUnpackStreamsVector.ReserveDown(); | |
208 Files.ReserveDown(); | |
209 CTime.ReserveDown(); | |
210 ATime.ReserveDown(); | |
211 MTime.ReserveDown(); | |
212 StartPos.ReserveDown(); | |
213 IsAnti.ReserveDown(); | |
214 } | |
215 | |
216 bool IsEmpty() const | |
217 { | |
218 return (PackSizes.IsEmpty() && | |
219 PackCRCsDefined.IsEmpty() && | |
220 PackCRCs.IsEmpty() && | |
221 Folders.IsEmpty() && | |
222 NumUnpackStreamsVector.IsEmpty() && | |
223 Files.IsEmpty()); | |
224 } | |
225 | |
226 bool CheckNumFiles() const | |
227 { | |
228 int size = Files.Size(); | |
229 return ( | |
230 CTime.CheckSize(size) && | |
231 ATime.CheckSize(size) && | |
232 MTime.CheckSize(size) && | |
233 StartPos.CheckSize(size) && | |
234 (size == IsAnti.Size() || IsAnti.Size() == 0)); | |
235 } | |
236 | |
237 bool IsSolid() const | |
238 { | |
239 for (int i = 0; i < NumUnpackStreamsVector.Size(); i++) | |
240 if (NumUnpackStreamsVector[i] > 1) | |
241 return true; | |
242 return false; | |
243 } | |
244 bool IsItemAnti(int index) const { return (index < IsAnti.Size() && IsAnti[index]); } | |
245 void SetItemAnti(int index, bool isAnti) | |
246 { | |
247 while (index >= IsAnti.Size()) | |
248 IsAnti.Add(false); | |
249 IsAnti[index] = isAnti; | |
250 } | |
251 | |
252 void GetFile(int index, CFileItem &file, CFileItem2 &file2) const; | |
253 void AddFile(const CFileItem &file, const CFileItem2 &file2); | |
254 }; | |
255 | |
256 }} | |
257 | |
258 #endif |