Mercurial > vba-linux
view 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 source
1 // 7zItem.h3 #ifndef __7Z_ITEM_H4 #define __7Z_ITEM_H6 #include "../../../Common/Buffer.h"7 #include "../../../Common/MyString.h"9 #include "../../Common/MethodId.h"11 #include "7zHeader.h"13 namespace NArchive {14 namespace N7z {16 typedef UInt32 CNum;17 const CNum kNumMax = 0x7FFFFFFF;18 const CNum kNumNoIndex = 0xFFFFFFFF;20 struct CCoderInfo21 {22 CMethodId MethodID;23 CByteBuffer Props;24 CNum NumInStreams;25 CNum NumOutStreams;26 bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }27 };29 struct CBindPair30 {31 CNum InIndex;32 CNum OutIndex;33 };35 struct CFolder36 {37 CObjectVector<CCoderInfo> Coders;38 CRecordVector<CBindPair> BindPairs;39 CRecordVector<CNum> PackStreams;40 CRecordVector<UInt64> UnpackSizes;41 UInt32 UnpackCRC;42 bool UnpackCRCDefined;44 CFolder(): UnpackCRCDefined(false) {}46 UInt64 GetUnpackSize() const // test it47 {48 if (UnpackSizes.IsEmpty())49 return 0;50 for (int i = UnpackSizes.Size() - 1; i >= 0; i--)51 if (FindBindPairForOutStream(i) < 0)52 return UnpackSizes[i];53 throw 1;54 }56 CNum GetNumOutStreams() const57 {58 CNum result = 0;59 for (int i = 0; i < Coders.Size(); i++)60 result += Coders[i].NumOutStreams;61 return result;62 }64 int FindBindPairForInStream(CNum inStreamIndex) const65 {66 for(int i = 0; i < BindPairs.Size(); i++)67 if (BindPairs[i].InIndex == inStreamIndex)68 return i;69 return -1;70 }71 int FindBindPairForOutStream(CNum outStreamIndex) const72 {73 for(int i = 0; i < BindPairs.Size(); i++)74 if (BindPairs[i].OutIndex == outStreamIndex)75 return i;76 return -1;77 }78 int FindPackStreamArrayIndex(CNum inStreamIndex) const79 {80 for(int i = 0; i < PackStreams.Size(); i++)81 if (PackStreams[i] == inStreamIndex)82 return i;83 return -1;84 }86 bool CheckStructure() const;87 };89 struct CUInt64DefVector90 {91 CRecordVector<UInt64> Values;92 CRecordVector<bool> Defined;94 void Clear()95 {96 Values.Clear();97 Defined.Clear();98 }100 void ReserveDown()101 {102 Values.ReserveDown();103 Values.ReserveDown();104 }106 bool GetItem(int index, UInt64 &value) const107 {108 if (index < Defined.Size() && Defined[index])109 {110 value = Values[index];111 return true;112 }113 value = 0;114 return false;115 }117 void SetItem(int index, bool defined, UInt64 value)118 {119 while (index >= Defined.Size())120 Defined.Add(false);121 Defined[index] = defined;122 if (!defined)123 return;124 while (index >= Values.Size())125 Values.Add(0);126 Values[index] = value;127 }129 bool CheckSize(int size) const { return Defined.Size() == size || Defined.Size() == 0; }130 };132 struct CFileItem133 {134 UInt64 Size;135 UInt32 Attrib;136 UInt32 Crc;137 UString Name;139 bool HasStream; // Test it !!! it means that there is140 // stream in some folder. It can be empty stream141 bool IsDir;142 bool CrcDefined;143 bool AttribDefined;145 CFileItem():146 HasStream(true),147 IsDir(false),148 CrcDefined(false),149 AttribDefined(false)150 {}151 void SetAttrib(UInt32 attrib)152 {153 AttribDefined = true;154 Attrib = attrib;155 }156 };158 struct CFileItem2159 {160 UInt64 CTime;161 UInt64 ATime;162 UInt64 MTime;163 UInt64 StartPos;164 bool CTimeDefined;165 bool ATimeDefined;166 bool MTimeDefined;167 bool StartPosDefined;168 bool IsAnti;169 };171 struct CArchiveDatabase172 {173 CRecordVector<UInt64> PackSizes;174 CRecordVector<bool> PackCRCsDefined;175 CRecordVector<UInt32> PackCRCs;176 CObjectVector<CFolder> Folders;177 CRecordVector<CNum> NumUnpackStreamsVector;178 CObjectVector<CFileItem> Files;180 CUInt64DefVector CTime;181 CUInt64DefVector ATime;182 CUInt64DefVector MTime;183 CUInt64DefVector StartPos;184 CRecordVector<bool> IsAnti;186 void Clear()187 {188 PackSizes.Clear();189 PackCRCsDefined.Clear();190 PackCRCs.Clear();191 Folders.Clear();192 NumUnpackStreamsVector.Clear();193 Files.Clear();194 CTime.Clear();195 ATime.Clear();196 MTime.Clear();197 StartPos.Clear();198 IsAnti.Clear();199 }201 void ReserveDown()202 {203 PackSizes.ReserveDown();204 PackCRCsDefined.ReserveDown();205 PackCRCs.ReserveDown();206 Folders.ReserveDown();207 NumUnpackStreamsVector.ReserveDown();208 Files.ReserveDown();209 CTime.ReserveDown();210 ATime.ReserveDown();211 MTime.ReserveDown();212 StartPos.ReserveDown();213 IsAnti.ReserveDown();214 }216 bool IsEmpty() const217 {218 return (PackSizes.IsEmpty() &&219 PackCRCsDefined.IsEmpty() &&220 PackCRCs.IsEmpty() &&221 Folders.IsEmpty() &&222 NumUnpackStreamsVector.IsEmpty() &&223 Files.IsEmpty());224 }226 bool CheckNumFiles() const227 {228 int size = Files.Size();229 return (230 CTime.CheckSize(size) &&231 ATime.CheckSize(size) &&232 MTime.CheckSize(size) &&233 StartPos.CheckSize(size) &&234 (size == IsAnti.Size() || IsAnti.Size() == 0));235 }237 bool IsSolid() const238 {239 for (int i = 0; i < NumUnpackStreamsVector.Size(); i++)240 if (NumUnpackStreamsVector[i] > 1)241 return true;242 return false;243 }244 bool IsItemAnti(int index) const { return (index < IsAnti.Size() && IsAnti[index]); }245 void SetItemAnti(int index, bool isAnti)246 {247 while (index >= IsAnti.Size())248 IsAnti.Add(false);249 IsAnti[index] = isAnti;250 }252 void GetFile(int index, CFileItem &file, CFileItem2 &file2) const;253 void AddFile(const CFileItem &file, const CFileItem2 &file2);254 };256 }}258 #endif