diff src/win32/7zip/7z/CPP/7zip/Archive/Zip/ZipItem.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/Zip/ZipItem.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,147 @@
     1.4 +// Archive/ZipItem.cpp
     1.5 +
     1.6 +#include "StdAfx.h"
     1.7 +
     1.8 +#include "ZipHeader.h"
     1.9 +#include "ZipItem.h"
    1.10 +#include "../Common/ItemNameUtils.h"
    1.11 +#include "../../../../C/CpuArch.h"
    1.12 +
    1.13 +namespace NArchive {
    1.14 +namespace NZip {
    1.15 +
    1.16 +bool operator==(const CVersion &v1, const CVersion &v2)
    1.17 +{
    1.18 +  return (v1.Version == v2.Version) && (v1.HostOS == v2.HostOS);
    1.19 +}
    1.20 +
    1.21 +bool operator!=(const CVersion &v1, const CVersion &v2)
    1.22 +{
    1.23 +  return !(v1 == v2);
    1.24 +}
    1.25 +
    1.26 +bool CExtraSubBlock::ExtractNtfsTime(int index, FILETIME &ft) const
    1.27 +{
    1.28 +  ft.dwHighDateTime = ft.dwLowDateTime = 0;
    1.29 +  UInt32 size = (UInt32)Data.GetCapacity();
    1.30 +  if (ID != NFileHeader::NExtraID::kNTFS || size < 32)
    1.31 +    return false;
    1.32 +  const Byte *p = (const Byte *)Data;
    1.33 +  p += 4; // for reserved
    1.34 +  size -= 4;
    1.35 +  while (size > 4)
    1.36 +  {
    1.37 +    UInt16 tag = GetUi16(p);
    1.38 +    UInt32 attrSize = GetUi16(p + 2);
    1.39 +    p += 4;
    1.40 +    size -= 4;
    1.41 +    if (attrSize > size)
    1.42 +      attrSize = size;
    1.43 +    
    1.44 +    if (tag == NFileHeader::NNtfsExtra::kTagTime && attrSize >= 24)
    1.45 +    {
    1.46 +      p += 8 * index;
    1.47 +      ft.dwLowDateTime = GetUi32(p);
    1.48 +      ft.dwHighDateTime = GetUi32(p + 4);
    1.49 +      return true;
    1.50 +    }
    1.51 +    p += attrSize;
    1.52 +    size -= attrSize;
    1.53 +  }
    1.54 +  return false;
    1.55 +}
    1.56 +
    1.57 +bool CLocalItem::IsDir() const
    1.58 +{
    1.59 +  return NItemName::HasTailSlash(Name, GetCodePage());
    1.60 +}
    1.61 +
    1.62 +bool CItem::IsDir() const
    1.63 +{
    1.64 +  if (NItemName::HasTailSlash(Name, GetCodePage()))
    1.65 +    return true;
    1.66 +  if (!FromCentral)
    1.67 +    return false;
    1.68 +  WORD highAttributes = WORD((ExternalAttributes >> 16 ) & 0xFFFF);
    1.69 +  switch(MadeByVersion.HostOS)
    1.70 +  {
    1.71 +    case NFileHeader::NHostOS::kAMIGA:
    1.72 +      switch (highAttributes & NFileHeader::NAmigaAttribute::kIFMT)
    1.73 +      {
    1.74 +        case NFileHeader::NAmigaAttribute::kIFDIR: return true;
    1.75 +        case NFileHeader::NAmigaAttribute::kIFREG: return false;
    1.76 +        default: return false; // change it throw kUnknownAttributes;
    1.77 +      }
    1.78 +    case NFileHeader::NHostOS::kFAT:
    1.79 +    case NFileHeader::NHostOS::kNTFS:
    1.80 +    case NFileHeader::NHostOS::kHPFS:
    1.81 +    case NFileHeader::NHostOS::kVFAT:
    1.82 +      return ((ExternalAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
    1.83 +    case NFileHeader::NHostOS::kAtari:
    1.84 +    case NFileHeader::NHostOS::kMac:
    1.85 +    case NFileHeader::NHostOS::kVMS:
    1.86 +    case NFileHeader::NHostOS::kVM_CMS:
    1.87 +    case NFileHeader::NHostOS::kAcorn:
    1.88 +    case NFileHeader::NHostOS::kMVS:
    1.89 +      return false; // change it throw kUnknownAttributes;
    1.90 +    default:
    1.91 +      /*
    1.92 +      switch (highAttributes & NFileHeader::NUnixAttribute::kIFMT)
    1.93 +      {
    1.94 +        case NFileHeader::NUnixAttribute::kIFDIR:
    1.95 +          return true;
    1.96 +        default:
    1.97 +          return false;
    1.98 +      }
    1.99 +      */
   1.100 +      return false;
   1.101 +  }
   1.102 +}
   1.103 +
   1.104 +UInt32 CLocalItem::GetWinAttributes() const
   1.105 +{
   1.106 +  DWORD winAttributes = 0;
   1.107 +  if (IsDir())
   1.108 +    winAttributes |= FILE_ATTRIBUTE_DIRECTORY;
   1.109 +  return winAttributes;
   1.110 +}
   1.111 +
   1.112 +UInt32 CItem::GetWinAttributes() const
   1.113 +{
   1.114 +  DWORD winAttributes = 0;
   1.115 +  switch(MadeByVersion.HostOS)
   1.116 +  {
   1.117 +    case NFileHeader::NHostOS::kFAT:
   1.118 +    case NFileHeader::NHostOS::kNTFS:
   1.119 +      if (FromCentral)
   1.120 +        winAttributes = ExternalAttributes;
   1.121 +      break;
   1.122 +    default:
   1.123 +      winAttributes = 0; // must be converted from unix value;
   1.124 +  }
   1.125 +  if (IsDir())       // test it;
   1.126 +    winAttributes |= FILE_ATTRIBUTE_DIRECTORY;
   1.127 +  return winAttributes;
   1.128 +}
   1.129 +
   1.130 +void CLocalItem::SetFlagBits(int startBitNumber, int numBits, int value)
   1.131 +{
   1.132 +  UInt16 mask = (UInt16)(((1 << numBits) - 1) << startBitNumber);
   1.133 +  Flags &= ~mask;
   1.134 +  Flags |= value << startBitNumber;
   1.135 +}
   1.136 +
   1.137 +void CLocalItem::SetBitMask(int bitMask, bool enable)
   1.138 +{
   1.139 +  if(enable)
   1.140 +    Flags |= bitMask;
   1.141 +  else
   1.142 +    Flags &= ~bitMask;
   1.143 +}
   1.144 +
   1.145 +void CLocalItem::SetEncrypted(bool encrypted)
   1.146 +  { SetBitMask(NFileHeader::NFlags::kEncrypted, encrypted); }
   1.147 +void CLocalItem::SetUtf8(bool isUtf8)
   1.148 +  { SetBitMask(NFileHeader::NFlags::kUtf8, isUtf8); }
   1.149 +
   1.150 +}}