Mercurial > vba-linux
diff 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 |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/7z/7zItem.h Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,258 @@ 1.4 +// 7zItem.h 1.5 + 1.6 +#ifndef __7Z_ITEM_H 1.7 +#define __7Z_ITEM_H 1.8 + 1.9 +#include "../../../Common/Buffer.h" 1.10 +#include "../../../Common/MyString.h" 1.11 + 1.12 +#include "../../Common/MethodId.h" 1.13 + 1.14 +#include "7zHeader.h" 1.15 + 1.16 +namespace NArchive { 1.17 +namespace N7z { 1.18 + 1.19 +typedef UInt32 CNum; 1.20 +const CNum kNumMax = 0x7FFFFFFF; 1.21 +const CNum kNumNoIndex = 0xFFFFFFFF; 1.22 + 1.23 +struct CCoderInfo 1.24 +{ 1.25 + CMethodId MethodID; 1.26 + CByteBuffer Props; 1.27 + CNum NumInStreams; 1.28 + CNum NumOutStreams; 1.29 + bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); } 1.30 +}; 1.31 + 1.32 +struct CBindPair 1.33 +{ 1.34 + CNum InIndex; 1.35 + CNum OutIndex; 1.36 +}; 1.37 + 1.38 +struct CFolder 1.39 +{ 1.40 + CObjectVector<CCoderInfo> Coders; 1.41 + CRecordVector<CBindPair> BindPairs; 1.42 + CRecordVector<CNum> PackStreams; 1.43 + CRecordVector<UInt64> UnpackSizes; 1.44 + UInt32 UnpackCRC; 1.45 + bool UnpackCRCDefined; 1.46 + 1.47 + CFolder(): UnpackCRCDefined(false) {} 1.48 + 1.49 + UInt64 GetUnpackSize() const // test it 1.50 + { 1.51 + if (UnpackSizes.IsEmpty()) 1.52 + return 0; 1.53 + for (int i = UnpackSizes.Size() - 1; i >= 0; i--) 1.54 + if (FindBindPairForOutStream(i) < 0) 1.55 + return UnpackSizes[i]; 1.56 + throw 1; 1.57 + } 1.58 + 1.59 + CNum GetNumOutStreams() const 1.60 + { 1.61 + CNum result = 0; 1.62 + for (int i = 0; i < Coders.Size(); i++) 1.63 + result += Coders[i].NumOutStreams; 1.64 + return result; 1.65 + } 1.66 + 1.67 + int FindBindPairForInStream(CNum inStreamIndex) const 1.68 + { 1.69 + for(int i = 0; i < BindPairs.Size(); i++) 1.70 + if (BindPairs[i].InIndex == inStreamIndex) 1.71 + return i; 1.72 + return -1; 1.73 + } 1.74 + int FindBindPairForOutStream(CNum outStreamIndex) const 1.75 + { 1.76 + for(int i = 0; i < BindPairs.Size(); i++) 1.77 + if (BindPairs[i].OutIndex == outStreamIndex) 1.78 + return i; 1.79 + return -1; 1.80 + } 1.81 + int FindPackStreamArrayIndex(CNum inStreamIndex) const 1.82 + { 1.83 + for(int i = 0; i < PackStreams.Size(); i++) 1.84 + if (PackStreams[i] == inStreamIndex) 1.85 + return i; 1.86 + return -1; 1.87 + } 1.88 + 1.89 + bool CheckStructure() const; 1.90 +}; 1.91 + 1.92 +struct CUInt64DefVector 1.93 +{ 1.94 + CRecordVector<UInt64> Values; 1.95 + CRecordVector<bool> Defined; 1.96 + 1.97 + void Clear() 1.98 + { 1.99 + Values.Clear(); 1.100 + Defined.Clear(); 1.101 + } 1.102 + 1.103 + void ReserveDown() 1.104 + { 1.105 + Values.ReserveDown(); 1.106 + Values.ReserveDown(); 1.107 + } 1.108 + 1.109 + bool GetItem(int index, UInt64 &value) const 1.110 + { 1.111 + if (index < Defined.Size() && Defined[index]) 1.112 + { 1.113 + value = Values[index]; 1.114 + return true; 1.115 + } 1.116 + value = 0; 1.117 + return false; 1.118 + } 1.119 + 1.120 + void SetItem(int index, bool defined, UInt64 value) 1.121 + { 1.122 + while (index >= Defined.Size()) 1.123 + Defined.Add(false); 1.124 + Defined[index] = defined; 1.125 + if (!defined) 1.126 + return; 1.127 + while (index >= Values.Size()) 1.128 + Values.Add(0); 1.129 + Values[index] = value; 1.130 + } 1.131 + 1.132 + bool CheckSize(int size) const { return Defined.Size() == size || Defined.Size() == 0; } 1.133 +}; 1.134 + 1.135 +struct CFileItem 1.136 +{ 1.137 + UInt64 Size; 1.138 + UInt32 Attrib; 1.139 + UInt32 Crc; 1.140 + UString Name; 1.141 + 1.142 + bool HasStream; // Test it !!! it means that there is 1.143 + // stream in some folder. It can be empty stream 1.144 + bool IsDir; 1.145 + bool CrcDefined; 1.146 + bool AttribDefined; 1.147 + 1.148 + CFileItem(): 1.149 + HasStream(true), 1.150 + IsDir(false), 1.151 + CrcDefined(false), 1.152 + AttribDefined(false) 1.153 + {} 1.154 + void SetAttrib(UInt32 attrib) 1.155 + { 1.156 + AttribDefined = true; 1.157 + Attrib = attrib; 1.158 + } 1.159 +}; 1.160 + 1.161 +struct CFileItem2 1.162 +{ 1.163 + UInt64 CTime; 1.164 + UInt64 ATime; 1.165 + UInt64 MTime; 1.166 + UInt64 StartPos; 1.167 + bool CTimeDefined; 1.168 + bool ATimeDefined; 1.169 + bool MTimeDefined; 1.170 + bool StartPosDefined; 1.171 + bool IsAnti; 1.172 +}; 1.173 + 1.174 +struct CArchiveDatabase 1.175 +{ 1.176 + CRecordVector<UInt64> PackSizes; 1.177 + CRecordVector<bool> PackCRCsDefined; 1.178 + CRecordVector<UInt32> PackCRCs; 1.179 + CObjectVector<CFolder> Folders; 1.180 + CRecordVector<CNum> NumUnpackStreamsVector; 1.181 + CObjectVector<CFileItem> Files; 1.182 + 1.183 + CUInt64DefVector CTime; 1.184 + CUInt64DefVector ATime; 1.185 + CUInt64DefVector MTime; 1.186 + CUInt64DefVector StartPos; 1.187 + CRecordVector<bool> IsAnti; 1.188 + 1.189 + void Clear() 1.190 + { 1.191 + PackSizes.Clear(); 1.192 + PackCRCsDefined.Clear(); 1.193 + PackCRCs.Clear(); 1.194 + Folders.Clear(); 1.195 + NumUnpackStreamsVector.Clear(); 1.196 + Files.Clear(); 1.197 + CTime.Clear(); 1.198 + ATime.Clear(); 1.199 + MTime.Clear(); 1.200 + StartPos.Clear(); 1.201 + IsAnti.Clear(); 1.202 + } 1.203 + 1.204 + void ReserveDown() 1.205 + { 1.206 + PackSizes.ReserveDown(); 1.207 + PackCRCsDefined.ReserveDown(); 1.208 + PackCRCs.ReserveDown(); 1.209 + Folders.ReserveDown(); 1.210 + NumUnpackStreamsVector.ReserveDown(); 1.211 + Files.ReserveDown(); 1.212 + CTime.ReserveDown(); 1.213 + ATime.ReserveDown(); 1.214 + MTime.ReserveDown(); 1.215 + StartPos.ReserveDown(); 1.216 + IsAnti.ReserveDown(); 1.217 + } 1.218 + 1.219 + bool IsEmpty() const 1.220 + { 1.221 + return (PackSizes.IsEmpty() && 1.222 + PackCRCsDefined.IsEmpty() && 1.223 + PackCRCs.IsEmpty() && 1.224 + Folders.IsEmpty() && 1.225 + NumUnpackStreamsVector.IsEmpty() && 1.226 + Files.IsEmpty()); 1.227 + } 1.228 + 1.229 + bool CheckNumFiles() const 1.230 + { 1.231 + int size = Files.Size(); 1.232 + return ( 1.233 + CTime.CheckSize(size) && 1.234 + ATime.CheckSize(size) && 1.235 + MTime.CheckSize(size) && 1.236 + StartPos.CheckSize(size) && 1.237 + (size == IsAnti.Size() || IsAnti.Size() == 0)); 1.238 + } 1.239 + 1.240 + bool IsSolid() const 1.241 + { 1.242 + for (int i = 0; i < NumUnpackStreamsVector.Size(); i++) 1.243 + if (NumUnpackStreamsVector[i] > 1) 1.244 + return true; 1.245 + return false; 1.246 + } 1.247 + bool IsItemAnti(int index) const { return (index < IsAnti.Size() && IsAnti[index]); } 1.248 + void SetItemAnti(int index, bool isAnti) 1.249 + { 1.250 + while (index >= IsAnti.Size()) 1.251 + IsAnti.Add(false); 1.252 + IsAnti[index] = isAnti; 1.253 + } 1.254 + 1.255 + void GetFile(int index, CFileItem &file, CFileItem2 &file2) const; 1.256 + void AddFile(const CFileItem &file, const CFileItem2 &file2); 1.257 +}; 1.258 + 1.259 +}} 1.260 + 1.261 +#endif