7zItem.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // 7zItem.h
  2. #ifndef __7Z_ITEM_H
  3. #define __7Z_ITEM_H
  4. #include "../../../Common/Buffer.h"
  5. #include "../../../Common/MyString.h"
  6. #include "../../Common/MethodId.h"
  7. #include "7zHeader.h"
  8. namespace NArchive {
  9. namespace N7z {
  10. typedef UInt32 CNum;
  11. const CNum kNumMax = 0x7FFFFFFF;
  12. const CNum kNumNoIndex = 0xFFFFFFFF;
  13. struct CCoderInfo
  14. {
  15. CMethodId MethodID;
  16. CByteBuffer Properties;
  17. CNum NumInStreams;
  18. CNum NumOutStreams;
  19. bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }
  20. };
  21. struct CBindPair
  22. {
  23. CNum InIndex;
  24. CNum OutIndex;
  25. };
  26. struct CFolder
  27. {
  28. CObjectVector<CCoderInfo> Coders;
  29. CRecordVector<CBindPair> BindPairs;
  30. CRecordVector<CNum> PackStreams;
  31. CRecordVector<UInt64> UnPackSizes;
  32. UInt32 UnPackCRC;
  33. bool UnPackCRCDefined;
  34. CFolder(): UnPackCRCDefined(false) {}
  35. UInt64 GetUnPackSize() const // test it
  36. {
  37. if (UnPackSizes.IsEmpty())
  38. return 0;
  39. for (int i = UnPackSizes.Size() - 1; i >= 0; i--)
  40. if (FindBindPairForOutStream(i) < 0)
  41. return UnPackSizes[i];
  42. throw 1;
  43. }
  44. CNum GetNumOutStreams() const
  45. {
  46. CNum result = 0;
  47. for (int i = 0; i < Coders.Size(); i++)
  48. result += Coders[i].NumOutStreams;
  49. return result;
  50. }
  51. int FindBindPairForInStream(CNum inStreamIndex) const
  52. {
  53. for(int i = 0; i < BindPairs.Size(); i++)
  54. if (BindPairs[i].InIndex == inStreamIndex)
  55. return i;
  56. return -1;
  57. }
  58. int FindBindPairForOutStream(CNum outStreamIndex) const
  59. {
  60. for(int i = 0; i < BindPairs.Size(); i++)
  61. if (BindPairs[i].OutIndex == outStreamIndex)
  62. return i;
  63. return -1;
  64. }
  65. int FindPackStreamArrayIndex(CNum inStreamIndex) const
  66. {
  67. for(int i = 0; i < PackStreams.Size(); i++)
  68. if (PackStreams[i] == inStreamIndex)
  69. return i;
  70. return -1;
  71. }
  72. };
  73. typedef FILETIME CArchiveFileTime;
  74. class CFileItem
  75. {
  76. public:
  77. CArchiveFileTime CreationTime;
  78. CArchiveFileTime LastWriteTime;
  79. CArchiveFileTime LastAccessTime;
  80. UInt64 UnPackSize;
  81. UInt64 StartPos;
  82. UInt32 Attributes;
  83. UInt32 FileCRC;
  84. UString Name;
  85. bool HasStream; // Test it !!! it means that there is
  86. // stream in some folder. It can be empty stream
  87. bool IsDirectory;
  88. bool IsAnti;
  89. bool IsFileCRCDefined;
  90. bool AreAttributesDefined;
  91. bool IsCreationTimeDefined;
  92. bool IsLastWriteTimeDefined;
  93. bool IsLastAccessTimeDefined;
  94. bool IsStartPosDefined;
  95. /*
  96. const bool HasStream() const {
  97. return !IsDirectory && !IsAnti && UnPackSize != 0; }
  98. */
  99. CFileItem():
  100. HasStream(true),
  101. IsDirectory(false),
  102. IsAnti(false),
  103. IsFileCRCDefined(false),
  104. AreAttributesDefined(false),
  105. IsCreationTimeDefined(false),
  106. IsLastWriteTimeDefined(false),
  107. IsLastAccessTimeDefined(false),
  108. IsStartPosDefined(false)
  109. {}
  110. void SetAttributes(UInt32 attributes)
  111. {
  112. AreAttributesDefined = true;
  113. Attributes = attributes;
  114. }
  115. void SetCreationTime(const CArchiveFileTime &creationTime)
  116. {
  117. IsCreationTimeDefined = true;
  118. CreationTime = creationTime;
  119. }
  120. void SetLastWriteTime(const CArchiveFileTime &lastWriteTime)
  121. {
  122. IsLastWriteTimeDefined = true;
  123. LastWriteTime = lastWriteTime;
  124. }
  125. void SetLastAccessTime(const CArchiveFileTime &lastAccessTime)
  126. {
  127. IsLastAccessTimeDefined = true;
  128. LastAccessTime = lastAccessTime;
  129. }
  130. };
  131. struct CArchiveDatabase
  132. {
  133. CRecordVector<UInt64> PackSizes;
  134. CRecordVector<bool> PackCRCsDefined;
  135. CRecordVector<UInt32> PackCRCs;
  136. CObjectVector<CFolder> Folders;
  137. CRecordVector<CNum> NumUnPackStreamsVector;
  138. CObjectVector<CFileItem> Files;
  139. void Clear()
  140. {
  141. PackSizes.Clear();
  142. PackCRCsDefined.Clear();
  143. PackCRCs.Clear();
  144. Folders.Clear();
  145. NumUnPackStreamsVector.Clear();
  146. Files.Clear();
  147. }
  148. bool IsEmpty() const
  149. {
  150. return (PackSizes.IsEmpty() &&
  151. PackCRCsDefined.IsEmpty() &&
  152. PackCRCs.IsEmpty() &&
  153. Folders.IsEmpty() &&
  154. NumUnPackStreamsVector.IsEmpty() &&
  155. Files.IsEmpty());
  156. }
  157. bool IsSolid() const
  158. {
  159. for (int i = 0; i < NumUnPackStreamsVector.Size(); i++)
  160. if (NumUnPackStreamsVector[i] > 1)
  161. return true;
  162. return false;
  163. }
  164. };
  165. }}
  166. #endif