7zProperties.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // 7zProperties.cpp
  2. #include "StdAfx.h"
  3. #include "7zProperties.h"
  4. #include "7zHeader.h"
  5. #include "7zHandler.h"
  6. // #define _MULTI_PACK
  7. namespace NArchive {
  8. namespace N7z {
  9. struct CPropMap
  10. {
  11. UInt64 FilePropID;
  12. STATPROPSTG StatPROPSTG;
  13. };
  14. CPropMap kPropMap[] =
  15. {
  16. { NID::kName, NULL, kpidPath, VT_BSTR},
  17. { NID::kSize, NULL, kpidSize, VT_UI8},
  18. { NID::kPackInfo, NULL, kpidPackedSize, VT_UI8},
  19. #ifdef _MULTI_PACK
  20. { 100, L"Pack0", kpidPackedSize0, VT_UI8},
  21. { 101, L"Pack1", kpidPackedSize1, VT_UI8},
  22. { 102, L"Pack2", kpidPackedSize2, VT_UI8},
  23. { 103, L"Pack3", kpidPackedSize3, VT_UI8},
  24. { 104, L"Pack4", kpidPackedSize4, VT_UI8},
  25. #endif
  26. { NID::kCreationTime, NULL, kpidCreationTime, VT_FILETIME},
  27. { NID::kLastWriteTime, NULL, kpidLastWriteTime, VT_FILETIME},
  28. { NID::kLastAccessTime, NULL, kpidLastAccessTime, VT_FILETIME},
  29. { NID::kWinAttributes, NULL, kpidAttributes, VT_UI4},
  30. { NID::kStartPos, NULL, kpidPosition, VT_UI4},
  31. { NID::kCRC, NULL, kpidCRC, VT_UI4},
  32. { NID::kAnti, NULL, kpidIsAnti, VT_BOOL},
  33. // { 97, NULL, kpidSolid, VT_BOOL},
  34. #ifndef _SFX
  35. { 98, NULL, kpidMethod, VT_BSTR},
  36. { 99, NULL, kpidBlock, VT_UI4}
  37. #endif
  38. };
  39. static const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);
  40. static int FindPropInMap(UInt64 filePropID)
  41. {
  42. for (int i = 0; i < kPropMapSize; i++)
  43. if (kPropMap[i].FilePropID == filePropID)
  44. return i;
  45. return -1;
  46. }
  47. static void CopyOneItem(CRecordVector<UInt64> &src,
  48. CRecordVector<UInt64> &dest, UInt32 item)
  49. {
  50. for (int i = 0; i < src.Size(); i++)
  51. if (src[i] == item)
  52. {
  53. dest.Add(item);
  54. src.Delete(i);
  55. return;
  56. }
  57. }
  58. static void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)
  59. {
  60. for (int i = 0; i < src.Size(); i++)
  61. if (src[i] == item)
  62. {
  63. src.Delete(i);
  64. return;
  65. }
  66. }
  67. static void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)
  68. {
  69. for (int i = 0; i < dest.Size(); i++)
  70. if (dest[i] == item)
  71. {
  72. dest.Delete(i);
  73. break;
  74. }
  75. dest.Insert(0, item);
  76. }
  77. void CHandler::FillPopIDs()
  78. {
  79. _fileInfoPopIDs.Clear();
  80. #ifdef _7Z_VOL
  81. if(_volumes.Size() < 1)
  82. return;
  83. const CVolume &volume = _volumes.Front();
  84. const CArchiveDatabaseEx &_database = volume.Database;
  85. #endif
  86. CRecordVector<UInt64> fileInfoPopIDs = _database.ArchiveInfo.FileInfoPopIDs;
  87. RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);
  88. RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);
  89. CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);
  90. CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);
  91. CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);
  92. CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);
  93. CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCreationTime);
  94. CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastWriteTime);
  95. CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastAccessTime);
  96. CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);
  97. CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);
  98. CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);
  99. _fileInfoPopIDs += fileInfoPopIDs;
  100. #ifndef _SFX
  101. _fileInfoPopIDs.Add(98);
  102. _fileInfoPopIDs.Add(99);
  103. #endif
  104. #ifdef _MULTI_PACK
  105. _fileInfoPopIDs.Add(100);
  106. _fileInfoPopIDs.Add(101);
  107. _fileInfoPopIDs.Add(102);
  108. _fileInfoPopIDs.Add(103);
  109. _fileInfoPopIDs.Add(104);
  110. #endif
  111. #ifndef _SFX
  112. InsertToHead(_fileInfoPopIDs, NID::kLastWriteTime);
  113. InsertToHead(_fileInfoPopIDs, NID::kPackInfo);
  114. InsertToHead(_fileInfoPopIDs, NID::kSize);
  115. InsertToHead(_fileInfoPopIDs, NID::kName);
  116. #endif
  117. }
  118. STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)
  119. {
  120. *numProperties = _fileInfoPopIDs.Size();
  121. return S_OK;
  122. }
  123. STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index,
  124. BSTR *name, PROPID *propID, VARTYPE *varType)
  125. {
  126. if((int)index >= _fileInfoPopIDs.Size())
  127. return E_INVALIDARG;
  128. int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);
  129. if (indexInMap == -1)
  130. return E_INVALIDARG;
  131. const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;
  132. *propID = srcItem.propid;
  133. *varType = srcItem.vt;
  134. *name = 0;
  135. return S_OK;
  136. }
  137. }}