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 26 bool IsSimpleCoder() const { return NumStreams == 1; } 27 }; 28 29 30 struct CBond 31 { 32 UInt32 PackIndex; 33 UInt32 UnpackIndex; 34 }; 35 36 37 struct CFolder 38 { 39 CLASS_NO_COPY(CFolder) 40 public: 41 CObjArray2<CCoderInfo> Coders; 42 CObjArray2<CBond> Bonds; 43 CObjArray2<UInt32> PackStreams; 44 45 CFolder() {} 46 47 bool IsDecodingSupported() const { return Coders.Size() <= 32; } 48 49 int Find_in_PackStreams(UInt32 packStream) const 50 { 51 FOR_VECTOR(i, PackStreams) 52 if (PackStreams[i] == packStream) 53 return i; 54 return -1; 55 } 56 57 int FindBond_for_PackStream(UInt32 packStream) const 58 { 59 FOR_VECTOR(i, Bonds) 60 if (Bonds[i].PackIndex == packStream) 61 return i; 62 return -1; 63 } 64 65 /* 66 int FindBond_for_UnpackStream(UInt32 unpackStream) const 67 { 68 FOR_VECTOR(i, Bonds) 69 if (Bonds[i].UnpackIndex == unpackStream) 70 return i; 71 return -1; 72 } 73 74 int FindOutCoder() const 75 { 76 for (int i = (int)Coders.Size() - 1; i >= 0; i--) 77 if (FindBond_for_UnpackStream(i) < 0) 78 return i; 79 return -1; 80 } 81 */ 82 83 bool IsEncrypted() const 84 { 85 FOR_VECTOR(i, Coders) 86 if (Coders[i].MethodID == k_AES) 87 return true; 88 return false; 89 } 90 }; 91 92 93 struct CUInt32DefVector 94 { 95 CBoolVector Defs; 96 CRecordVector<UInt32> Vals; 97 98 void ClearAndSetSize(unsigned newSize) 99 { 100 Defs.ClearAndSetSize(newSize); 101 Vals.ClearAndSetSize(newSize); 102 } 103 104 void Clear() 105 { 106 Defs.Clear(); 107 Vals.Clear(); 108 } 109 110 void ReserveDown() 111 { 112 Defs.ReserveDown(); 113 Vals.ReserveDown(); 114 } 115 116 bool GetItem(unsigned index, UInt32 &value) const 117 { 118 if (index < Defs.Size() && Defs[index]) 119 { 120 value = Vals[index]; 121 return true; 122 } 123 value = 0; 124 return false; 125 } 126 127 bool ValidAndDefined(unsigned i) const { return i < Defs.Size() && Defs[i]; } 128 129 bool CheckSize(unsigned size) const { return Defs.Size() == size || Defs.Size() == 0; } 130 131 void SetItem(unsigned index, bool defined, UInt32 value); 132 }; 133 134 135 struct CUInt64DefVector 136 { 137 CBoolVector Defs; 138 CRecordVector<UInt64> Vals; 139 140 void Clear() 141 { 142 Defs.Clear(); 143 Vals.Clear(); 144 } 145 146 void ReserveDown() 147 { 148 Defs.ReserveDown(); 149 Vals.ReserveDown(); 150 } 151 152 bool GetItem(unsigned index, UInt64 &value) const 153 { 154 if (index < Defs.Size() && Defs[index]) 155 { 156 value = Vals[index]; 157 return true; 158 } 159 value = 0; 160 return false; 161 } 162 163 bool CheckSize(unsigned size) const { return Defs.Size() == size || Defs.Size() == 0; } 164 165 void SetItem(unsigned index, bool defined, UInt64 value); 166 }; 167 168 169 struct CFileItem 170 { 171 UInt64 Size; 172 UInt32 Crc; 173 /* 174 int Parent; 175 bool IsAltStream; 176 */ 177 bool HasStream; // Test it !!! it means that there is 178 // stream in some folder. It can be empty stream 179 bool IsDir; 180 bool CrcDefined; 181 182 /* 183 void Clear() 184 { 185 HasStream = true; 186 IsDir = false; 187 CrcDefined = false; 188 } 189 190 CFileItem(): 191 // Parent(-1), 192 // IsAltStream(false), 193 HasStream(true), 194 IsDir(false), 195 CrcDefined(false), 196 {} 197 */ 198 }; 199 200 }} 201 202 #endif 203