|
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 #include "../../Common/MethodId.h" |
|
9 #include "7zHeader.h" |
|
10 |
|
11 namespace NArchive { |
|
12 namespace N7z { |
|
13 |
|
14 typedef UInt32 CNum; |
|
15 const CNum kNumMax = 0x7FFFFFFF; |
|
16 const CNum kNumNoIndex = 0xFFFFFFFF; |
|
17 |
|
18 struct CCoderInfo |
|
19 { |
|
20 CMethodId MethodID; |
|
21 CByteBuffer Properties; |
|
22 CNum NumInStreams; |
|
23 CNum NumOutStreams; |
|
24 bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); } |
|
25 }; |
|
26 |
|
27 struct CBindPair |
|
28 { |
|
29 CNum InIndex; |
|
30 CNum OutIndex; |
|
31 }; |
|
32 |
|
33 struct CFolder |
|
34 { |
|
35 CObjectVector<CCoderInfo> Coders; |
|
36 CRecordVector<CBindPair> BindPairs; |
|
37 CRecordVector<CNum> PackStreams; |
|
38 CRecordVector<UInt64> UnPackSizes; |
|
39 UInt32 UnPackCRC; |
|
40 bool UnPackCRCDefined; |
|
41 |
|
42 CFolder(): UnPackCRCDefined(false) {} |
|
43 |
|
44 UInt64 GetUnPackSize() const // test it |
|
45 { |
|
46 if (UnPackSizes.IsEmpty()) |
|
47 return 0; |
|
48 for (int i = UnPackSizes.Size() - 1; i >= 0; i--) |
|
49 if (FindBindPairForOutStream(i) < 0) |
|
50 return UnPackSizes[i]; |
|
51 throw 1; |
|
52 } |
|
53 |
|
54 CNum GetNumOutStreams() const |
|
55 { |
|
56 CNum result = 0; |
|
57 for (int i = 0; i < Coders.Size(); i++) |
|
58 result += Coders[i].NumOutStreams; |
|
59 return result; |
|
60 } |
|
61 |
|
62 int FindBindPairForInStream(CNum inStreamIndex) const |
|
63 { |
|
64 for(int i = 0; i < BindPairs.Size(); i++) |
|
65 if (BindPairs[i].InIndex == inStreamIndex) |
|
66 return i; |
|
67 return -1; |
|
68 } |
|
69 int FindBindPairForOutStream(CNum outStreamIndex) const |
|
70 { |
|
71 for(int i = 0; i < BindPairs.Size(); i++) |
|
72 if (BindPairs[i].OutIndex == outStreamIndex) |
|
73 return i; |
|
74 return -1; |
|
75 } |
|
76 int FindPackStreamArrayIndex(CNum inStreamIndex) const |
|
77 { |
|
78 for(int i = 0; i < PackStreams.Size(); i++) |
|
79 if (PackStreams[i] == inStreamIndex) |
|
80 return i; |
|
81 return -1; |
|
82 } |
|
83 }; |
|
84 |
|
85 typedef FILETIME CArchiveFileTime; |
|
86 |
|
87 class CFileItem |
|
88 { |
|
89 public: |
|
90 CArchiveFileTime CreationTime; |
|
91 CArchiveFileTime LastWriteTime; |
|
92 CArchiveFileTime LastAccessTime; |
|
93 UInt64 UnPackSize; |
|
94 UInt64 StartPos; |
|
95 UInt32 Attributes; |
|
96 UInt32 FileCRC; |
|
97 UString Name; |
|
98 |
|
99 bool HasStream; // Test it !!! it means that there is |
|
100 // stream in some folder. It can be empty stream |
|
101 bool IsDirectory; |
|
102 bool IsAnti; |
|
103 bool IsFileCRCDefined; |
|
104 bool AreAttributesDefined; |
|
105 bool IsCreationTimeDefined; |
|
106 bool IsLastWriteTimeDefined; |
|
107 bool IsLastAccessTimeDefined; |
|
108 bool IsStartPosDefined; |
|
109 |
|
110 /* |
|
111 const bool HasStream() const { |
|
112 return !IsDirectory && !IsAnti && UnPackSize != 0; } |
|
113 */ |
|
114 CFileItem(): |
|
115 HasStream(true), |
|
116 IsDirectory(false), |
|
117 IsAnti(false), |
|
118 IsFileCRCDefined(false), |
|
119 AreAttributesDefined(false), |
|
120 IsCreationTimeDefined(false), |
|
121 IsLastWriteTimeDefined(false), |
|
122 IsLastAccessTimeDefined(false), |
|
123 IsStartPosDefined(false) |
|
124 {} |
|
125 void SetAttributes(UInt32 attributes) |
|
126 { |
|
127 AreAttributesDefined = true; |
|
128 Attributes = attributes; |
|
129 } |
|
130 void SetCreationTime(const CArchiveFileTime &creationTime) |
|
131 { |
|
132 IsCreationTimeDefined = true; |
|
133 CreationTime = creationTime; |
|
134 } |
|
135 void SetLastWriteTime(const CArchiveFileTime &lastWriteTime) |
|
136 { |
|
137 IsLastWriteTimeDefined = true; |
|
138 LastWriteTime = lastWriteTime; |
|
139 } |
|
140 void SetLastAccessTime(const CArchiveFileTime &lastAccessTime) |
|
141 { |
|
142 IsLastAccessTimeDefined = true; |
|
143 LastAccessTime = lastAccessTime; |
|
144 } |
|
145 }; |
|
146 |
|
147 struct CArchiveDatabase |
|
148 { |
|
149 CRecordVector<UInt64> PackSizes; |
|
150 CRecordVector<bool> PackCRCsDefined; |
|
151 CRecordVector<UInt32> PackCRCs; |
|
152 CObjectVector<CFolder> Folders; |
|
153 CRecordVector<CNum> NumUnPackStreamsVector; |
|
154 CObjectVector<CFileItem> Files; |
|
155 void Clear() |
|
156 { |
|
157 PackSizes.Clear(); |
|
158 PackCRCsDefined.Clear(); |
|
159 PackCRCs.Clear(); |
|
160 Folders.Clear(); |
|
161 NumUnPackStreamsVector.Clear(); |
|
162 Files.Clear(); |
|
163 } |
|
164 bool IsEmpty() const |
|
165 { |
|
166 return (PackSizes.IsEmpty() && |
|
167 PackCRCsDefined.IsEmpty() && |
|
168 PackCRCs.IsEmpty() && |
|
169 Folders.IsEmpty() && |
|
170 NumUnPackStreamsVector.IsEmpty() && |
|
171 Files.IsEmpty()); |
|
172 } |
|
173 bool IsSolid() const |
|
174 { |
|
175 for (int i = 0; i < NumUnPackStreamsVector.Size(); i++) |
|
176 if (NumUnPackStreamsVector[i] > 1) |
|
177 return true; |
|
178 return false; |
|
179 } |
|
180 }; |
|
181 |
|
182 }} |
|
183 |
|
184 #endif |