view 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 source
1 // Archive/ZipItem.cpp
3 #include "StdAfx.h"
5 #include "ZipHeader.h"
6 #include "ZipItem.h"
7 #include "../Common/ItemNameUtils.h"
8 #include "../../../../C/CpuArch.h"
10 namespace NArchive {
11 namespace NZip {
13 bool operator==(const CVersion &v1, const CVersion &v2)
14 {
15 return (v1.Version == v2.Version) && (v1.HostOS == v2.HostOS);
16 }
18 bool operator!=(const CVersion &v1, const CVersion &v2)
19 {
20 return !(v1 == v2);
21 }
23 bool CExtraSubBlock::ExtractNtfsTime(int index, FILETIME &ft) const
24 {
25 ft.dwHighDateTime = ft.dwLowDateTime = 0;
26 UInt32 size = (UInt32)Data.GetCapacity();
27 if (ID != NFileHeader::NExtraID::kNTFS || size < 32)
28 return false;
29 const Byte *p = (const Byte *)Data;
30 p += 4; // for reserved
31 size -= 4;
32 while (size > 4)
33 {
34 UInt16 tag = GetUi16(p);
35 UInt32 attrSize = GetUi16(p + 2);
36 p += 4;
37 size -= 4;
38 if (attrSize > size)
39 attrSize = size;
41 if (tag == NFileHeader::NNtfsExtra::kTagTime && attrSize >= 24)
42 {
43 p += 8 * index;
44 ft.dwLowDateTime = GetUi32(p);
45 ft.dwHighDateTime = GetUi32(p + 4);
46 return true;
47 }
48 p += attrSize;
49 size -= attrSize;
50 }
51 return false;
52 }
54 bool CLocalItem::IsDir() const
55 {
56 return NItemName::HasTailSlash(Name, GetCodePage());
57 }
59 bool CItem::IsDir() const
60 {
61 if (NItemName::HasTailSlash(Name, GetCodePage()))
62 return true;
63 if (!FromCentral)
64 return false;
65 WORD highAttributes = WORD((ExternalAttributes >> 16 ) & 0xFFFF);
66 switch(MadeByVersion.HostOS)
67 {
68 case NFileHeader::NHostOS::kAMIGA:
69 switch (highAttributes & NFileHeader::NAmigaAttribute::kIFMT)
70 {
71 case NFileHeader::NAmigaAttribute::kIFDIR: return true;
72 case NFileHeader::NAmigaAttribute::kIFREG: return false;
73 default: return false; // change it throw kUnknownAttributes;
74 }
75 case NFileHeader::NHostOS::kFAT:
76 case NFileHeader::NHostOS::kNTFS:
77 case NFileHeader::NHostOS::kHPFS:
78 case NFileHeader::NHostOS::kVFAT:
79 return ((ExternalAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
80 case NFileHeader::NHostOS::kAtari:
81 case NFileHeader::NHostOS::kMac:
82 case NFileHeader::NHostOS::kVMS:
83 case NFileHeader::NHostOS::kVM_CMS:
84 case NFileHeader::NHostOS::kAcorn:
85 case NFileHeader::NHostOS::kMVS:
86 return false; // change it throw kUnknownAttributes;
87 default:
88 /*
89 switch (highAttributes & NFileHeader::NUnixAttribute::kIFMT)
90 {
91 case NFileHeader::NUnixAttribute::kIFDIR:
92 return true;
93 default:
94 return false;
95 }
96 */
97 return false;
98 }
99 }
101 UInt32 CLocalItem::GetWinAttributes() const
102 {
103 DWORD winAttributes = 0;
104 if (IsDir())
105 winAttributes |= FILE_ATTRIBUTE_DIRECTORY;
106 return winAttributes;
107 }
109 UInt32 CItem::GetWinAttributes() const
110 {
111 DWORD winAttributes = 0;
112 switch(MadeByVersion.HostOS)
113 {
114 case NFileHeader::NHostOS::kFAT:
115 case NFileHeader::NHostOS::kNTFS:
116 if (FromCentral)
117 winAttributes = ExternalAttributes;
118 break;
119 default:
120 winAttributes = 0; // must be converted from unix value;
121 }
122 if (IsDir()) // test it;
123 winAttributes |= FILE_ATTRIBUTE_DIRECTORY;
124 return winAttributes;
125 }
127 void CLocalItem::SetFlagBits(int startBitNumber, int numBits, int value)
128 {
129 UInt16 mask = (UInt16)(((1 << numBits) - 1) << startBitNumber);
130 Flags &= ~mask;
131 Flags |= value << startBitNumber;
132 }
134 void CLocalItem::SetBitMask(int bitMask, bool enable)
135 {
136 if(enable)
137 Flags |= bitMask;
138 else
139 Flags &= ~bitMask;
140 }
142 void CLocalItem::SetEncrypted(bool encrypted)
143 { SetBitMask(NFileHeader::NFlags::kEncrypted, encrypted); }
144 void CLocalItem::SetUtf8(bool isUtf8)
145 { SetBitMask(NFileHeader::NFlags::kUtf8, isUtf8); }
147 }}