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 const UInt64 k_AES = 0x06F10701; 17 18 typedef UInt32 CNum; 19 const CNum kNumMax = 0x7FFFFFFF; 20 const CNum kNumNoIndex = 0xFFFFFFFF; 21 22 struct CCoderInfo 23 { 24 CMethodId MethodID; 25 CByteBuffer Props; 26 CNum NumInStreams; 27 CNum NumOutStreams; 28 29 bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); } 30 }; 31 32 struct CBindPair 33 { 34 CNum InIndex; 35 CNum OutIndex; 36 }; 37 38 struct CFolder 39 { 40 CObjArray2<CCoderInfo> Coders; 41 CObjArray2<CBindPair> BindPairs; 42 CObjArray2<CNum> PackStreams; 43 44 CNum GetNumOutStreams() const 45 { 46 CNum result = 0; 47 FOR_VECTOR(i, Coders) 48 result += Coders[i].NumOutStreams; 49 return result; 50 } 51 52 int FindBindPairForInStream(CNum inStreamIndex) const 53 { 54 FOR_VECTOR(i, BindPairs) 55 if (BindPairs[i].InIndex == inStreamIndex) 56 return i; 57 return -1; 58 } 59 int FindBindPairForOutStream(CNum outStreamIndex) const 60 { 61 FOR_VECTOR(i, BindPairs) 62 if (BindPairs[i].OutIndex == outStreamIndex) 63 return i; 64 return -1; 65 } 66 int FindPackStreamArrayIndex(CNum inStreamIndex) const 67 { 68 FOR_VECTOR(i, PackStreams) 69 if (PackStreams[i] == inStreamIndex) 70 return i; 71 return -1; 72 } 73 74 int GetIndexOfMainOutStream() const 75 { 76 for (int i = (int)GetNumOutStreams() - 1; i >= 0; i--) 77 if (FindBindPairForOutStream(i) < 0) 78 return i; 79 throw 1; 80 } 81 82 bool IsEncrypted() const 83 { 84 for (int i = Coders.Size() - 1; i >= 0; i--) 85 if (Coders[i].MethodID == k_AES) 86 return true; 87 return false; 88 } 89 90 bool CheckStructure(unsigned numUnpackSizes) const; 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 ValidAndDefined(unsigned i) const { return i < Defs.Size() && Defs[i]; } 117 }; 118 119 struct CUInt64DefVector 120 { 121 CBoolVector Defs; 122 CRecordVector<UInt64> Vals; 123 124 void Clear() 125 { 126 Defs.Clear(); 127 Vals.Clear(); 128 } 129 130 void ReserveDown() 131 { 132 Defs.ReserveDown(); 133 Vals.ReserveDown(); 134 } 135 136 bool GetItem(unsigned index, UInt64 &value) const 137 { 138 if (index < Defs.Size() && Defs[index]) 139 { 140 value = Vals[index]; 141 return true; 142 } 143 value = 0; 144 return false; 145 } 146 147 void SetItem(unsigned index, bool defined, UInt64 value); 148 149 bool CheckSize(unsigned size) const { return Defs.Size() == size || Defs.Size() == 0; } 150 }; 151 152 struct CFileItem 153 { 154 UInt64 Size; 155 UInt32 Attrib; 156 UInt32 Crc; 157 /* 158 int Parent; 159 bool IsAltStream; 160 */ 161 bool HasStream; // Test it !!! it means that there is 162 // stream in some folder. It can be empty stream 163 bool IsDir; 164 bool CrcDefined; 165 bool AttribDefined; 166 167 CFileItem(): 168 /* 169 Parent(-1), 170 IsAltStream(false), 171 */ 172 HasStream(true), 173 IsDir(false), 174 CrcDefined(false), 175 AttribDefined(false) 176 {} 177 void SetAttrib(UInt32 attrib) 178 { 179 AttribDefined = true; 180 Attrib = attrib; 181 } 182 }; 183 184 }} 185 186 #endif 187