1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/7zstub/src/7zip/Archive/7z/7zProperties.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,166 @@ 1.4 +// 7zProperties.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +#include "7zProperties.h" 1.9 +#include "7zHeader.h" 1.10 +#include "7zHandler.h" 1.11 + 1.12 +// #define _MULTI_PACK 1.13 + 1.14 +namespace NArchive { 1.15 +namespace N7z { 1.16 + 1.17 +struct CPropMap 1.18 +{ 1.19 + UInt64 FilePropID; 1.20 + STATPROPSTG StatPROPSTG; 1.21 +}; 1.22 + 1.23 +CPropMap kPropMap[] = 1.24 +{ 1.25 + { NID::kName, NULL, kpidPath, VT_BSTR}, 1.26 + { NID::kSize, NULL, kpidSize, VT_UI8}, 1.27 + { NID::kPackInfo, NULL, kpidPackedSize, VT_UI8}, 1.28 + 1.29 + #ifdef _MULTI_PACK 1.30 + { 100, L"Pack0", kpidPackedSize0, VT_UI8}, 1.31 + { 101, L"Pack1", kpidPackedSize1, VT_UI8}, 1.32 + { 102, L"Pack2", kpidPackedSize2, VT_UI8}, 1.33 + { 103, L"Pack3", kpidPackedSize3, VT_UI8}, 1.34 + { 104, L"Pack4", kpidPackedSize4, VT_UI8}, 1.35 + #endif 1.36 + 1.37 + { NID::kCreationTime, NULL, kpidCreationTime, VT_FILETIME}, 1.38 + { NID::kLastWriteTime, NULL, kpidLastWriteTime, VT_FILETIME}, 1.39 + { NID::kLastAccessTime, NULL, kpidLastAccessTime, VT_FILETIME}, 1.40 + { NID::kWinAttributes, NULL, kpidAttributes, VT_UI4}, 1.41 + { NID::kStartPos, NULL, kpidPosition, VT_UI4}, 1.42 + 1.43 + 1.44 + { NID::kCRC, NULL, kpidCRC, VT_UI4}, 1.45 + 1.46 + { NID::kAnti, L"Anti", kpidIsAnti, VT_BOOL}, 1.47 + // { 97, NULL, kpidSolid, VT_BOOL}, 1.48 + #ifndef _SFX 1.49 + { 98, NULL, kpidMethod, VT_BSTR}, 1.50 + { 99, L"Block", kpidBlock, VT_UI4} 1.51 + #endif 1.52 + // { L"ID", kpidID, VT_BSTR}, 1.53 + // { L"UnPack Version", kpidUnPackVersion, VT_UI1}, 1.54 + // { L"Host OS", kpidHostOS, VT_BSTR} 1.55 +}; 1.56 + 1.57 +static const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]); 1.58 + 1.59 +static int FindPropInMap(UInt64 filePropID) 1.60 +{ 1.61 + for (int i = 0; i < kPropMapSize; i++) 1.62 + if (kPropMap[i].FilePropID == filePropID) 1.63 + return i; 1.64 + return -1; 1.65 +} 1.66 + 1.67 +static void CopyOneItem(CRecordVector<UInt64> &src, 1.68 + CRecordVector<UInt64> &dest, UInt32 item) 1.69 +{ 1.70 + for (int i = 0; i < src.Size(); i++) 1.71 + if (src[i] == item) 1.72 + { 1.73 + dest.Add(item); 1.74 + src.Delete(i); 1.75 + return; 1.76 + } 1.77 +} 1.78 + 1.79 +static void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item) 1.80 +{ 1.81 + for (int i = 0; i < src.Size(); i++) 1.82 + if (src[i] == item) 1.83 + { 1.84 + src.Delete(i); 1.85 + return; 1.86 + } 1.87 +} 1.88 + 1.89 +static void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item) 1.90 +{ 1.91 + for (int i = 0; i < dest.Size(); i++) 1.92 + if (dest[i] == item) 1.93 + { 1.94 + dest.Delete(i); 1.95 + break; 1.96 + } 1.97 + dest.Insert(0, item); 1.98 +} 1.99 + 1.100 +void CHandler::FillPopIDs() 1.101 +{ 1.102 + _fileInfoPopIDs.Clear(); 1.103 + 1.104 + #ifdef _7Z_VOL 1.105 + if(_volumes.Size() < 1) 1.106 + return; 1.107 + const CVolume &volume = _volumes.Front(); 1.108 + const CArchiveDatabaseEx &_database = volume.Database; 1.109 + #endif 1.110 + 1.111 + CRecordVector<UInt64> fileInfoPopIDs = _database.ArchiveInfo.FileInfoPopIDs; 1.112 + 1.113 + RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream); 1.114 + RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile); 1.115 + 1.116 + CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName); 1.117 + CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti); 1.118 + CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize); 1.119 + CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo); 1.120 + CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCreationTime); 1.121 + CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastWriteTime); 1.122 + CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastAccessTime); 1.123 + CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes); 1.124 + CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC); 1.125 + CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment); 1.126 + _fileInfoPopIDs += fileInfoPopIDs; 1.127 + 1.128 + #ifndef _SFX 1.129 + _fileInfoPopIDs.Add(98); 1.130 + _fileInfoPopIDs.Add(99); 1.131 + #endif 1.132 + #ifdef _MULTI_PACK 1.133 + _fileInfoPopIDs.Add(100); 1.134 + _fileInfoPopIDs.Add(101); 1.135 + _fileInfoPopIDs.Add(102); 1.136 + _fileInfoPopIDs.Add(103); 1.137 + _fileInfoPopIDs.Add(104); 1.138 + #endif 1.139 + 1.140 + #ifndef _SFX 1.141 + InsertToHead(_fileInfoPopIDs, NID::kLastWriteTime); 1.142 + InsertToHead(_fileInfoPopIDs, NID::kPackInfo); 1.143 + InsertToHead(_fileInfoPopIDs, NID::kSize); 1.144 + InsertToHead(_fileInfoPopIDs, NID::kName); 1.145 + #endif 1.146 +} 1.147 + 1.148 +STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) 1.149 +{ 1.150 + *numProperties = _fileInfoPopIDs.Size(); 1.151 + return S_OK; 1.152 +} 1.153 + 1.154 +STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, 1.155 + BSTR *name, PROPID *propID, VARTYPE *varType) 1.156 +{ 1.157 + if((int)index >= _fileInfoPopIDs.Size()) 1.158 + return E_INVALIDARG; 1.159 + int indexInMap = FindPropInMap(_fileInfoPopIDs[index]); 1.160 + if (indexInMap == -1) 1.161 + return E_INVALIDARG; 1.162 + const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG; 1.163 + *propID = srcItem.propid; 1.164 + *varType = srcItem.vt; 1.165 + *name = 0; 1.166 + return S_OK; 1.167 +} 1.168 + 1.169 +}}