• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 7zItem.h
2 
3 #ifndef __7Z_ITEM_H
4 #define __7Z_ITEM_H
5 
6 #include "../../../Common/MyBuffer.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   UInt32 NumStreams;
25 
IsSimpleCoderCCoderInfo26   bool IsSimpleCoder() const { return NumStreams == 1; }
27 };
28 
29 struct CBond
30 {
31   UInt32 PackIndex;
32   UInt32 UnpackIndex;
33 };
34 
35 struct CFolder
36 {
37   CLASS_NO_COPY(CFolder)
38 public:
39   CObjArray2<CCoderInfo> Coders;
40   CObjArray2<CBond> Bonds;
41   CObjArray2<UInt32> PackStreams;
42 
CFolderCFolder43   CFolder() {}
44 
IsDecodingSupportedCFolder45   bool IsDecodingSupported() const { return Coders.Size() <= 32; }
46 
Find_in_PackStreamsCFolder47   int Find_in_PackStreams(UInt32 packStream) const
48   {
49     FOR_VECTOR(i, PackStreams)
50       if (PackStreams[i] == packStream)
51         return i;
52     return -1;
53   }
54 
FindBond_for_PackStreamCFolder55   int FindBond_for_PackStream(UInt32 packStream) const
56   {
57     FOR_VECTOR(i, Bonds)
58       if (Bonds[i].PackIndex == packStream)
59         return i;
60     return -1;
61   }
62 
63   /*
64   int FindBond_for_UnpackStream(UInt32 unpackStream) const
65   {
66     FOR_VECTOR(i, Bonds)
67       if (Bonds[i].UnpackIndex == unpackStream)
68         return i;
69     return -1;
70   }
71 
72   int FindOutCoder() const
73   {
74     for (int i = (int)Coders.Size() - 1; i >= 0; i--)
75       if (FindBond_for_UnpackStream(i) < 0)
76         return i;
77     return -1;
78   }
79   */
80 
IsEncryptedCFolder81   bool IsEncrypted() const
82   {
83     FOR_VECTOR(i, Coders)
84       if (Coders[i].MethodID == k_AES)
85         return true;
86     return false;
87   }
88 };
89 
90 struct CUInt32DefVector
91 {
92   CBoolVector Defs;
93   CRecordVector<UInt32> Vals;
94 
ClearAndSetSizeCUInt32DefVector95   void ClearAndSetSize(unsigned newSize)
96   {
97     Defs.ClearAndSetSize(newSize);
98     Vals.ClearAndSetSize(newSize);
99   }
100 
ClearCUInt32DefVector101   void Clear()
102   {
103     Defs.Clear();
104     Vals.Clear();
105   }
106 
ReserveDownCUInt32DefVector107   void ReserveDown()
108   {
109     Defs.ReserveDown();
110     Vals.ReserveDown();
111   }
112 
ValidAndDefinedCUInt32DefVector113   bool ValidAndDefined(unsigned i) const { return i < Defs.Size() && Defs[i]; }
114 };
115 
116 struct CUInt64DefVector
117 {
118   CBoolVector Defs;
119   CRecordVector<UInt64> Vals;
120 
ClearCUInt64DefVector121   void Clear()
122   {
123     Defs.Clear();
124     Vals.Clear();
125   }
126 
ReserveDownCUInt64DefVector127   void ReserveDown()
128   {
129     Defs.ReserveDown();
130     Vals.ReserveDown();
131   }
132 
GetItemCUInt64DefVector133   bool GetItem(unsigned index, UInt64 &value) const
134   {
135     if (index < Defs.Size() && Defs[index])
136     {
137       value = Vals[index];
138       return true;
139     }
140     value = 0;
141     return false;
142   }
143 
144   void SetItem(unsigned index, bool defined, UInt64 value);
145 
CheckSizeCUInt64DefVector146   bool CheckSize(unsigned size) const { return Defs.Size() == size || Defs.Size() == 0; }
147 };
148 
149 struct CFileItem
150 {
151   UInt64 Size;
152   UInt32 Attrib;
153   UInt32 Crc;
154   /*
155   int Parent;
156   bool IsAltStream;
157   */
158   bool HasStream; // Test it !!! it means that there is
159                   // stream in some folder. It can be empty stream
160   bool IsDir;
161   bool CrcDefined;
162   bool AttribDefined;
163 
CFileItemCFileItem164   CFileItem():
165     /*
166     Parent(-1),
167     IsAltStream(false),
168     */
169     HasStream(true),
170     IsDir(false),
171     CrcDefined(false),
172     AttribDefined(false)
173       {}
SetAttribCFileItem174   void SetAttrib(UInt32 attrib)
175   {
176     AttribDefined = true;
177     Attrib = attrib;
178   }
179 };
180 
181 }}
182 
183 #endif
184