diff src/win32/7zip/7z/CPP/7zip/Archive/7z/7zProperties.cpp @ 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/7zProperties.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,163 @@
     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, kpidPackSize, 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::kCTime, NULL, kpidCTime, VT_FILETIME},
    1.38 +  { NID::kMTime, NULL, kpidMTime, VT_FILETIME},
    1.39 +  { NID::kATime, NULL, kpidATime, VT_FILETIME},
    1.40 +  { NID::kWinAttributes, NULL, kpidAttrib, VT_UI4},
    1.41 +  { NID::kStartPos, NULL, kpidPosition, VT_UI4},
    1.42 +
    1.43 +  { NID::kCRC, NULL, kpidCRC, VT_UI4},
    1.44 +  
    1.45 +  { NID::kAnti, NULL, kpidIsAnti, VT_BOOL},
    1.46 +
    1.47 +  #ifndef _SFX
    1.48 +  { 97, NULL, kpidEncrypted, VT_BOOL},
    1.49 +  { 98, NULL, kpidMethod, VT_BSTR},
    1.50 +  { 99, NULL, kpidBlock, VT_UI4}
    1.51 +  #endif
    1.52 +};
    1.53 +
    1.54 +static const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);
    1.55 +
    1.56 +static int FindPropInMap(UInt64 filePropID)
    1.57 +{
    1.58 +  for (int i = 0; i < kPropMapSize; i++)
    1.59 +    if (kPropMap[i].FilePropID == filePropID)
    1.60 +      return i;
    1.61 +  return -1;
    1.62 +}
    1.63 +
    1.64 +static void CopyOneItem(CRecordVector<UInt64> &src,
    1.65 +    CRecordVector<UInt64> &dest, UInt32 item)
    1.66 +{
    1.67 +  for (int i = 0; i < src.Size(); i++)
    1.68 +    if (src[i] == item)
    1.69 +    {
    1.70 +      dest.Add(item);
    1.71 +      src.Delete(i);
    1.72 +      return;
    1.73 +    }
    1.74 +}
    1.75 +
    1.76 +static void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)
    1.77 +{
    1.78 +  for (int i = 0; i < src.Size(); i++)
    1.79 +    if (src[i] == item)
    1.80 +    {
    1.81 +      src.Delete(i);
    1.82 +      return;
    1.83 +    }
    1.84 +}
    1.85 +
    1.86 +static void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)
    1.87 +{
    1.88 +  for (int i = 0; i < dest.Size(); i++)
    1.89 +    if (dest[i] == item)
    1.90 +    {
    1.91 +      dest.Delete(i);
    1.92 +      break;
    1.93 +    }
    1.94 +  dest.Insert(0, item);
    1.95 +}
    1.96 +
    1.97 +void CHandler::FillPopIDs()
    1.98 +{
    1.99 +  _fileInfoPopIDs.Clear();
   1.100 +
   1.101 +  #ifdef _7Z_VOL
   1.102 +  if(_volumes.Size() < 1)
   1.103 +    return;
   1.104 +  const CVolume &volume = _volumes.Front();
   1.105 +  const CArchiveDatabaseEx &_db = volume.Database;
   1.106 +  #endif
   1.107 +
   1.108 +  CRecordVector<UInt64> fileInfoPopIDs = _db.ArchiveInfo.FileInfoPopIDs;
   1.109 +
   1.110 +  RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);
   1.111 +  RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);
   1.112 +
   1.113 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);
   1.114 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);
   1.115 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);
   1.116 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);
   1.117 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCTime);
   1.118 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kMTime);
   1.119 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kATime);
   1.120 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);
   1.121 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);
   1.122 +  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);
   1.123 +  _fileInfoPopIDs += fileInfoPopIDs;
   1.124 + 
   1.125 +  #ifndef _SFX
   1.126 +  _fileInfoPopIDs.Add(97);
   1.127 +  _fileInfoPopIDs.Add(98);
   1.128 +  _fileInfoPopIDs.Add(99);
   1.129 +  #endif
   1.130 +  #ifdef _MULTI_PACK
   1.131 +  _fileInfoPopIDs.Add(100);
   1.132 +  _fileInfoPopIDs.Add(101);
   1.133 +  _fileInfoPopIDs.Add(102);
   1.134 +  _fileInfoPopIDs.Add(103);
   1.135 +  _fileInfoPopIDs.Add(104);
   1.136 +  #endif
   1.137 +
   1.138 +  #ifndef _SFX
   1.139 +  InsertToHead(_fileInfoPopIDs, NID::kMTime);
   1.140 +  InsertToHead(_fileInfoPopIDs, NID::kPackInfo);
   1.141 +  InsertToHead(_fileInfoPopIDs, NID::kSize);
   1.142 +  InsertToHead(_fileInfoPopIDs, NID::kName);
   1.143 +  #endif
   1.144 +}
   1.145 +
   1.146 +STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)
   1.147 +{
   1.148 +  *numProperties = _fileInfoPopIDs.Size();
   1.149 +  return S_OK;
   1.150 +}
   1.151 +
   1.152 +STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)
   1.153 +{
   1.154 +  if ((int)index >= _fileInfoPopIDs.Size())
   1.155 +    return E_INVALIDARG;
   1.156 +  int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);
   1.157 +  if (indexInMap == -1)
   1.158 +    return E_INVALIDARG;
   1.159 +  const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;
   1.160 +  *propID = srcItem.propid;
   1.161 +  *varType = srcItem.vt;
   1.162 +  *name = 0;
   1.163 +  return S_OK;
   1.164 +}
   1.165 +
   1.166 +}}