1 // Archive/ZipItem.cpp
\r
5 #include "ZipHeader.h"
\r
7 #include "../Common/ItemNameUtils.h"
\r
8 #include "../../../../C/CpuArch.h"
\r
10 namespace NArchive {
\r
13 bool operator==(const CVersion &v1, const CVersion &v2)
\r
15 return (v1.Version == v2.Version) && (v1.HostOS == v2.HostOS);
\r
18 bool operator!=(const CVersion &v1, const CVersion &v2)
\r
23 bool CExtraSubBlock::ExtractNtfsTime(int index, FILETIME &ft) const
\r
25 ft.dwHighDateTime = ft.dwLowDateTime = 0;
\r
26 UInt32 size = (UInt32)Data.GetCapacity();
\r
27 if (ID != NFileHeader::NExtraID::kNTFS || size < 32)
\r
29 const Byte *p = (const Byte *)Data;
\r
30 p += 4; // for reserved
\r
34 UInt16 tag = GetUi16(p);
\r
35 UInt32 attrSize = GetUi16(p + 2);
\r
38 if (attrSize > size)
\r
41 if (tag == NFileHeader::NNtfsExtra::kTagTime && attrSize >= 24)
\r
44 ft.dwLowDateTime = GetUi32(p);
\r
45 ft.dwHighDateTime = GetUi32(p + 4);
\r
54 bool CExtraSubBlock::ExtractUnixTime(int index, UInt32 &res) const
\r
57 UInt32 size = (UInt32)Data.GetCapacity();
\r
58 if (ID != NFileHeader::NExtraID::kUnixTime || size < 5)
\r
60 const Byte *p = (const Byte *)Data;
\r
63 for (int i = 0; i < 3; i++)
\r
64 if ((flags & (1 << i)) != 0)
\r
79 bool CLocalItem::IsDir() const
\r
81 return NItemName::HasTailSlash(Name, GetCodePage());
\r
84 bool CItem::IsDir() const
\r
86 if (NItemName::HasTailSlash(Name, GetCodePage()))
\r
90 WORD highAttributes = WORD((ExternalAttributes >> 16 ) & 0xFFFF);
\r
91 switch(MadeByVersion.HostOS)
\r
93 case NFileHeader::NHostOS::kAMIGA:
\r
94 switch (highAttributes & NFileHeader::NAmigaAttribute::kIFMT)
\r
96 case NFileHeader::NAmigaAttribute::kIFDIR: return true;
\r
97 case NFileHeader::NAmigaAttribute::kIFREG: return false;
\r
98 default: return false; // change it throw kUnknownAttributes;
\r
100 case NFileHeader::NHostOS::kFAT:
\r
101 case NFileHeader::NHostOS::kNTFS:
\r
102 case NFileHeader::NHostOS::kHPFS:
\r
103 case NFileHeader::NHostOS::kVFAT:
\r
104 return ((ExternalAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
\r
105 case NFileHeader::NHostOS::kAtari:
\r
106 case NFileHeader::NHostOS::kMac:
\r
107 case NFileHeader::NHostOS::kVMS:
\r
108 case NFileHeader::NHostOS::kVM_CMS:
\r
109 case NFileHeader::NHostOS::kAcorn:
\r
110 case NFileHeader::NHostOS::kMVS:
\r
111 return false; // change it throw kUnknownAttributes;
\r
114 switch (highAttributes & NFileHeader::NUnixAttribute::kIFMT)
\r
116 case NFileHeader::NUnixAttribute::kIFDIR:
\r
126 UInt32 CLocalItem::GetWinAttributes() const
\r
128 DWORD winAttributes = 0;
\r
130 winAttributes |= FILE_ATTRIBUTE_DIRECTORY;
\r
131 return winAttributes;
\r
134 UInt32 CItem::GetWinAttributes() const
\r
136 DWORD winAttributes = 0;
\r
137 switch(MadeByVersion.HostOS)
\r
139 case NFileHeader::NHostOS::kFAT:
\r
140 case NFileHeader::NHostOS::kNTFS:
\r
142 winAttributes = ExternalAttributes;
\r
145 winAttributes = 0; // must be converted from unix value;
\r
147 if (IsDir()) // test it;
\r
148 winAttributes |= FILE_ATTRIBUTE_DIRECTORY;
\r
149 return winAttributes;
\r
152 void CLocalItem::SetFlagBits(int startBitNumber, int numBits, int value)
\r
154 UInt16 mask = (UInt16)(((1 << numBits) - 1) << startBitNumber);
\r
156 Flags |= value << startBitNumber;
\r
159 void CLocalItem::SetBitMask(int bitMask, bool enable)
\r
167 void CLocalItem::SetEncrypted(bool encrypted)
\r
168 { SetBitMask(NFileHeader::NFlags::kEncrypted, encrypted); }
\r
169 void CLocalItem::SetUtf8(bool isUtf8)
\r
170 { SetBitMask(NFileHeader::NFlags::kUtf8, isUtf8); }
\r