This commit is contained in:
Igor Pavlov
2014-11-23 00:00:00 +00:00
committed by Kornel Lesiński
parent 83f8ddcc5b
commit f08f4dcc3c
1158 changed files with 76451 additions and 35082 deletions

109
CPP/7zip/Archive/Zip/ZipItem.cpp Executable file → Normal file
View File

@@ -10,21 +10,13 @@
namespace NArchive {
namespace NZip {
bool operator==(const CVersion &v1, const CVersion &v2)
{
return (v1.Version == v2.Version) && (v1.HostOS == v2.HostOS);
}
using namespace NFileHeader;
bool operator!=(const CVersion &v1, const CVersion &v2)
{
return !(v1 == v2);
}
bool CExtraSubBlock::ExtractNtfsTime(int index, FILETIME &ft) const
bool CExtraSubBlock::ExtractNtfsTime(unsigned index, FILETIME &ft) const
{
ft.dwHighDateTime = ft.dwLowDateTime = 0;
UInt32 size = (UInt32)Data.GetCapacity();
if (ID != NFileHeader::NExtraID::kNTFS || size < 32)
UInt32 size = (UInt32)Data.Size();
if (ID != NExtraID::kNTFS || size < 32)
return false;
const Byte *p = (const Byte *)Data;
p += 4; // for reserved
@@ -32,13 +24,13 @@ bool CExtraSubBlock::ExtractNtfsTime(int index, FILETIME &ft) const
while (size > 4)
{
UInt16 tag = GetUi16(p);
UInt32 attrSize = GetUi16(p + 2);
unsigned attrSize = GetUi16(p + 2);
p += 4;
size -= 4;
if (attrSize > size)
attrSize = size;
if (tag == NFileHeader::NNtfsExtra::kTagTime && attrSize >= 24)
if (tag == NNtfsExtra::kTagTime && attrSize >= 24)
{
p += 8 * index;
ft.dwLowDateTime = GetUi32(p);
@@ -51,25 +43,25 @@ bool CExtraSubBlock::ExtractNtfsTime(int index, FILETIME &ft) const
return false;
}
bool CExtraSubBlock::ExtractUnixTime(bool isCentral, int index, UInt32 &res) const
bool CExtraSubBlock::ExtractUnixTime(bool isCentral, unsigned index, UInt32 &res) const
{
res = 0;
UInt32 size = (UInt32)Data.GetCapacity();
if (ID != NFileHeader::NExtraID::kUnixTime || size < 5)
UInt32 size = (UInt32)Data.Size();
if (ID != NExtraID::kUnixTime || size < 5)
return false;
const Byte *p = (const Byte *)Data;
Byte flags = *p++;
size--;
if (isCentral)
{
if (index != NFileHeader::NUnixTime::kMTime ||
(flags & (1 << NFileHeader::NUnixTime::kMTime)) == 0 ||
if (index != NUnixTime::kMTime ||
(flags & (1 << NUnixTime::kMTime)) == 0 ||
size < 4)
return false;
res = GetUi32(p);
return true;
}
for (int i = 0; i < 3; i++)
for (unsigned i = 0; i < 3; i++)
if ((flags & (1 << i)) != 0)
{
if (size < 4)
@@ -96,30 +88,33 @@ bool CItem::IsDir() const
return true;
if (!FromCentral)
return false;
WORD highAttributes = WORD((ExternalAttributes >> 16 ) & 0xFFFF);
switch (MadeByVersion.HostOS)
UInt16 highAttrib = (UInt16)((ExternalAttrib >> 16 ) & 0xFFFF);
Byte hostOS = GetHostOS();
switch (hostOS)
{
case NFileHeader::NHostOS::kAMIGA:
switch (highAttributes & NFileHeader::NAmigaAttribute::kIFMT)
case NHostOS::kAMIGA:
switch (highAttrib & NAmigaAttrib::kIFMT)
{
case NFileHeader::NAmigaAttribute::kIFDIR: return true;
case NFileHeader::NAmigaAttribute::kIFREG: return false;
case NAmigaAttrib::kIFDIR: return true;
case NAmigaAttrib::kIFREG: return false;
default: return false; // change it throw kUnknownAttributes;
}
case NFileHeader::NHostOS::kFAT:
case NFileHeader::NHostOS::kNTFS:
case NFileHeader::NHostOS::kHPFS:
case NFileHeader::NHostOS::kVFAT:
return ((ExternalAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
case NFileHeader::NHostOS::kAtari:
case NFileHeader::NHostOS::kMac:
case NFileHeader::NHostOS::kVMS:
case NFileHeader::NHostOS::kVM_CMS:
case NFileHeader::NHostOS::kAcorn:
case NFileHeader::NHostOS::kMVS:
case NHostOS::kFAT:
case NHostOS::kNTFS:
case NHostOS::kHPFS:
case NHostOS::kVFAT:
return ((ExternalAttrib & FILE_ATTRIBUTE_DIRECTORY) != 0);
case NHostOS::kAtari:
case NHostOS::kMac:
case NHostOS::kVMS:
case NHostOS::kVM_CMS:
case NHostOS::kAcorn:
case NHostOS::kMVS:
return false; // change it throw kUnknownAttributes;
case NFileHeader::NHostOS::kUnix:
return (highAttributes & NFileHeader::NUnixAttribute::kIFDIR) != 0;
case NHostOS::kUnix:
return (highAttrib & NUnixAttrib::kIFDIR) != 0;
default:
return false;
}
@@ -127,13 +122,13 @@ bool CItem::IsDir() const
UInt32 CItem::GetWinAttrib() const
{
DWORD winAttrib = 0;
switch (MadeByVersion.HostOS)
UInt32 winAttrib = 0;
switch (GetHostOS())
{
case NFileHeader::NHostOS::kFAT:
case NFileHeader::NHostOS::kNTFS:
case NHostOS::kFAT:
case NHostOS::kNTFS:
if (FromCentral)
winAttrib = ExternalAttributes;
winAttrib = ExternalAttrib;
break;
}
if (IsDir()) // test it;
@@ -144,35 +139,15 @@ UInt32 CItem::GetWinAttrib() const
bool CItem::GetPosixAttrib(UInt32 &attrib) const
{
// some archivers can store PosixAttrib in high 16 bits even with HostOS=FAT.
if (FromCentral && MadeByVersion.HostOS == NFileHeader::NHostOS::kUnix)
if (FromCentral && GetHostOS() == NHostOS::kUnix)
{
attrib = ExternalAttributes >> 16;
attrib = ExternalAttrib >> 16;
return (attrib != 0);
}
attrib = 0;
if (IsDir())
attrib = NFileHeader::NUnixAttribute::kIFDIR;
attrib = NUnixAttrib::kIFDIR;
return false;
}
void CLocalItem::SetFlagBits(int startBitNumber, int numBits, int value)
{
UInt16 mask = (UInt16)(((1 << numBits) - 1) << startBitNumber);
Flags &= ~mask;
Flags |= value << startBitNumber;
}
void CLocalItem::SetBitMask(int bitMask, bool enable)
{
if(enable)
Flags |= bitMask;
else
Flags &= ~bitMask;
}
void CLocalItem::SetEncrypted(bool encrypted)
{ SetBitMask(NFileHeader::NFlags::kEncrypted, encrypted); }
void CLocalItem::SetUtf8(bool isUtf8)
{ SetBitMask(NFileHeader::NFlags::kUtf8, isUtf8); }
}}