oh my gawd 2
This commit is contained in:
Коммит
72e6bd82f6
|
@ -242,39 +242,41 @@ namespace xPlat {
|
|||
void SetRelativeOffsetOfLocalHeader(std::uint32_t value) { ObjectBase::SetValue(Field(16), value); }
|
||||
|
||||
std::string GetFileName() {
|
||||
auto data = ObjectBase::GetValue<std::uint8_t>(Field(17));
|
||||
auto data = ObjectBase::GetValue<std::vector<std::uint8_t>>(Field(17));
|
||||
return std::string(data.begin(), data.end());
|
||||
}
|
||||
|
||||
void SetFileName(std::string name)
|
||||
{
|
||||
auto data = ObjectBase::GetValue<std::uint8_t>(Field(17));
|
||||
auto data = ObjectBase::GetValue<std::vector<std::uint8_t>>(Field(17));
|
||||
data.resize(name.size());
|
||||
data.assign(name.begin(), name.end());
|
||||
SetFileNameLength(static_cast<std::uint16_t>(name.size()));
|
||||
}
|
||||
|
||||
std::string GetExtraField() {
|
||||
auto data = ObjectBase::GetValue<std::uint8_t>(Field(18));
|
||||
std::string GetExtraField()
|
||||
{
|
||||
auto data = ObjectBase::GetValue<std::vector<std::uint8_t>>(Field(18));
|
||||
return std::string(data.begin(), data.end());
|
||||
}
|
||||
|
||||
void SetExtraField(std::string extra)
|
||||
{
|
||||
auto data = ObjectBase::GetValue<std::uint8_t>(Field(18));
|
||||
auto data = ObjectBase::GetValue<std::vector<std::uint8_t>>(Field(18));
|
||||
data.resize(extra.size());
|
||||
data.assign(extra.begin(), extra.end());
|
||||
SetExtraFieldLength(static_cast<std::uint16_t>(extra.size()));
|
||||
}
|
||||
|
||||
std::string GetComment() {
|
||||
auto data = ObjectBase::GetValue<std::uint8_t>(Field(19));
|
||||
std::string GetComment()
|
||||
{
|
||||
auto data = ObjectBase::GetValue<std::vector<std::uint8_t>>(Field(19));
|
||||
return std::string(data.begin(), data.end());
|
||||
}
|
||||
|
||||
void SetComment(std::string comment)
|
||||
{
|
||||
auto data = ObjectBase::GetValue<std::uint8_t>(Field(19));
|
||||
auto data = ObjectBase::GetValue<std::vector<std::uint8_t>>(Field(19));
|
||||
data.resize(comment.size());
|
||||
data.assign(comment.begin(), comment.end());
|
||||
SetExtraFieldLength(static_cast<std::uint16_t>(comment.size()));
|
||||
|
@ -283,7 +285,7 @@ namespace xPlat {
|
|||
CentralFileHeader(StreamBase* stream) : StructuredObject(
|
||||
{
|
||||
// 0 - central file header signature 4 bytes(0x02014b50)
|
||||
Meta::Field4Bytes(stream, [](std::uint32_t& v)
|
||||
std::make_shared<Meta::Field4Bytes>(stream, [](std::uint32_t& v)
|
||||
{
|
||||
if (v != Signatures::CentralFileHeader)
|
||||
{
|
||||
|
@ -291,64 +293,64 @@ namespace xPlat {
|
|||
}
|
||||
}),
|
||||
// 1 - version made by 2 bytes
|
||||
Meta::Field2Bytes(stream, [](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [](std::uint16_t& v) {}),
|
||||
// 2 - version needed to extract 2 bytes
|
||||
Meta::Field2Bytes(stream, [](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [](std::uint16_t& v) {}),
|
||||
// 3 - general purpose bit flag 2 bytes
|
||||
Meta::Field2Bytes(stream, [](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [](std::uint16_t& v) {}),
|
||||
// 4 - compression method 2 bytes
|
||||
Meta::Field2Bytes(stream, [](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [](std::uint16_t& v) {}),
|
||||
// 5 - last mod file time 2 bytes
|
||||
Meta::Field2Bytes(stream, [](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [](std::uint16_t& v) {}),
|
||||
// 6 - last mod file date 2 bytes
|
||||
Meta::Field2Bytes(stream, [](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [](std::uint16_t& v) {}),
|
||||
// 7 - crc - 32 4 bytes
|
||||
Meta::Field4Bytes(stream,[](std::uint32_t& v) {}),
|
||||
std::make_shared<Meta::Field4Bytes>(stream,[](std::uint32_t& v) {}),
|
||||
// 8 - compressed size 4 bytes
|
||||
Meta::Field4Bytes(stream, [](std::uint32_t& v) {}),
|
||||
std::make_shared<Meta::Field4Bytes>(stream, [](std::uint32_t& v) {}),
|
||||
// 9 - uncompressed size 4 bytes
|
||||
Meta::Field4Bytes(stream, [](std::uint32_t& v) {}),
|
||||
std::make_shared<Meta::Field4Bytes>(stream, [](std::uint32_t& v) {}),
|
||||
//10 - file name length 2 bytes
|
||||
Meta::Field2Bytes(stream, [this](std::uint16_t& v)
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [this](std::uint16_t& v)
|
||||
{
|
||||
if (GetFileNameLength() > std::numeric_limits<std::uint16_t>::max())
|
||||
{
|
||||
throw ZipException("file name exceeds max size", ZipException::Error::FieldOutOfRange);
|
||||
}
|
||||
Field(17).Value<std::vector<std::uint8_t>>().resize(GetFileNameLength(), 0);
|
||||
ObjectBase::GetValue<std::vector<std::uint8_t>>(Field(17)).resize(GetFileNameLength(), 0);
|
||||
}),
|
||||
//11 - extra field length 2 bytes
|
||||
Meta::Field2Bytes(stream, [this](std::uint16_t& v)
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [this](std::uint16_t& v)
|
||||
{
|
||||
if (GetExtraFieldLength() > std::numeric_limits<std::uint16_t>::max())
|
||||
{
|
||||
throw ZipException("file name exceeds max size", ZipException::Error::FieldOutOfRange);
|
||||
}
|
||||
Field(18).Value<std::vector<std::uint8_t>>().resize(GetExtraFieldLength(), 0);
|
||||
ObjectBase::GetValue<std::vector<std::uint8_t>>(Field(18)).resize(GetExtraFieldLength(), 0);
|
||||
}),
|
||||
//12 - file comment length 2 bytes
|
||||
Meta::Field2Bytes(stream, [this](std::uint16_t& v)
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [this](std::uint16_t& v)
|
||||
{
|
||||
if (GetFileCommentLength() > std::numeric_limits<std::uint16_t>::max())
|
||||
{
|
||||
throw ZipException("file comment exceeds max size", ZipException::Error::FieldOutOfRange);
|
||||
}
|
||||
Field(19).Value<std::vector<std::uint8_t>>().resize(GetFileCommentLength(), 0);
|
||||
ObjectBase::GetValue<std::vector<std::uint8_t>>(Field(19)).resize(GetFileCommentLength(), 0);
|
||||
}),
|
||||
//13 - disk number start 2 bytes
|
||||
Meta::Field2Bytes(stream, [](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [](std::uint16_t& v) {}),
|
||||
//14 - internal file attributes 2 bytes
|
||||
Meta::Field2Bytes(stream, [](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [](std::uint16_t& v) {}),
|
||||
//15 - external file attributes 4 bytes
|
||||
Meta::Field4Bytes(stream,[](std::uint32_t& v) {}),
|
||||
std::make_shared<Meta::Field4Bytes>(stream,[](std::uint32_t& v) {}),
|
||||
//16 - relative offset of local header 4 bytes
|
||||
Meta::Field4Bytes(stream,[](std::uint32_t& v) {}),
|
||||
std::make_shared<Meta::Field4Bytes>(stream,[](std::uint32_t& v) {}),
|
||||
//17 - file name(variable size)
|
||||
Meta::FieldNBytes(stream, [](std::vector<std::uint8_t>& data) {}),
|
||||
std::make_shared<Meta::FieldNBytes>(stream, [](std::vector<std::uint8_t>& data) {}),
|
||||
//18 - extra field(variable size)
|
||||
Meta::FieldNBytes(stream, [](std::vector<std::uint8_t>& data) {}),
|
||||
std::make_shared<Meta::FieldNBytes>(stream, [](std::vector<std::uint8_t>& data) {}),
|
||||
//19 - file comment(variable size)
|
||||
Meta::FieldNBytes(stream, [](std::vector<std::uint8_t>& data) {})
|
||||
std::make_shared<Meta::FieldNBytes>(stream, [](std::vector<std::uint8_t>& data) {})
|
||||
})
|
||||
{/*constructor*/
|
||||
}
|
||||
|
@ -366,14 +368,14 @@ namespace xPlat {
|
|||
DigitalSignature(StreamBase* stream) : StructuredObject(
|
||||
{
|
||||
// 0 - header signature 4 bytes(0x05054b50)
|
||||
Meta::Field4Bytes(stream, [](std::uint32_t& v)
|
||||
std::make_shared<Meta::Field4Bytes>(stream, [](std::uint32_t& v)
|
||||
{ if (v != Signatures::DigitalSignature)
|
||||
{
|
||||
throw ZipException("digital signature does not match signature", ZipException::Error::InvalidHeader);
|
||||
}
|
||||
}),
|
||||
// 1 - size of data 2 bytes
|
||||
Meta::Field2Bytes(stream, [this](std::uint16_t& v)
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [this](std::uint16_t& v)
|
||||
{
|
||||
if (GetDataSize() > std::numeric_limits<std::uint16_t>::max())
|
||||
{
|
||||
|
@ -382,7 +384,7 @@ namespace xPlat {
|
|||
Field(2).Value<std::vector<std::uint8_t>>().resize(GetDataSize(), 0);
|
||||
}),
|
||||
// 2 - signature data(variable size)
|
||||
Meta::FieldNBytes(stream, [](std::vector<std::uint8_t>& data) {})
|
||||
std::make_shared<Meta::FieldNBytes>(stream, [](std::vector<std::uint8_t>& data) {})
|
||||
})
|
||||
{/*constructor*/
|
||||
}
|
||||
|
@ -429,7 +431,7 @@ namespace xPlat {
|
|||
Zip64EndOfCentralDirectoryRecord(StreamBase* stream) : StructuredObject(
|
||||
{
|
||||
// 0 - zip64 end of central dir signature 4 bytes(0x06064b50)
|
||||
Meta::Field4Bytes(stream,[](std::uint32_t& v)
|
||||
std::make_shared<Meta::Field4Bytes>(stream,[](std::uint32_t& v)
|
||||
{
|
||||
if (v != Signatures::Zip64EndOfCD)
|
||||
{
|
||||
|
@ -437,25 +439,25 @@ namespace xPlat {
|
|||
}
|
||||
}),
|
||||
// 1 - size of zip64 end of central directory record 8 bytes
|
||||
Meta::Field8Bytes(stream,[](std::uint64_t& v) {}),
|
||||
std::make_shared<Meta::Field8Bytes>(stream,[](std::uint64_t& v) {}),
|
||||
// 2 - version made by 2 bytes
|
||||
Meta::Field2Bytes(stream,[](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream,[](std::uint16_t& v) {}),
|
||||
// 3 - version needed to extract 2 bytes
|
||||
Meta::Field2Bytes(stream,[](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream,[](std::uint16_t& v) {}),
|
||||
// 4 - number of this disk 4 bytes
|
||||
Meta::Field4Bytes(stream,[](std::uint32_t& v) {}),
|
||||
std::make_shared<Meta::Field4Bytes>(stream,[](std::uint32_t& v) {}),
|
||||
// 5 - number of the disk with the start of the central directory 4 bytes
|
||||
Meta::Field4Bytes(stream,[](std::uint32_t& v) {}),
|
||||
std::make_shared<Meta::Field4Bytes>(stream,[](std::uint32_t& v) {}),
|
||||
// 6 - total number of entries in the central directory on this disk 8 bytes
|
||||
Meta::Field8Bytes(stream,[](std::uint64_t& v) {}),
|
||||
std::make_shared<Meta::Field8Bytes>(stream,[](std::uint64_t& v) {}),
|
||||
// 7 - total number of entries in the central directory 8 bytes
|
||||
Meta::Field8Bytes(stream,[](std::uint64_t& v) {}),
|
||||
std::make_shared<Meta::Field8Bytes>(stream,[](std::uint64_t& v) {}),
|
||||
// 8 - size of the central directory 8 bytes
|
||||
Meta::Field8Bytes(stream,[](std::uint64_t& v) {}),
|
||||
std::make_shared<Meta::Field8Bytes>(stream,[](std::uint64_t& v) {}),
|
||||
// 9 - offset of start of central directory with respect to the starting disk number 8 bytes
|
||||
Meta::Field8Bytes(stream,[](std::uint64_t& v) {}),
|
||||
std::make_shared<Meta::Field8Bytes>(stream,[](std::uint64_t& v) {}),
|
||||
//10 - zip64 extensible data sector(variable size)
|
||||
Meta::FieldNBytes(stream, [](std::vector<std::uint8_t>& data) {})
|
||||
std::make_shared<Meta::FieldNBytes>(stream, [](std::vector<std::uint8_t>& data) {})
|
||||
})
|
||||
{/*constructor*/}
|
||||
}; //class Zip64EndOfCentralDirectoryRecord
|
||||
|
@ -478,7 +480,7 @@ namespace xPlat {
|
|||
Zip64EndOfCentralDirectoryLocator(StreamBase* stream) : StructuredObject(
|
||||
{
|
||||
// 0 - zip64 end of central dir locator signature 4 bytes(0x07064b50)
|
||||
Meta::Field4Bytes(stream, [](std::uint32_t& v)
|
||||
std::make_shared<Meta::Field4Bytes>(stream, [](std::uint32_t& v)
|
||||
{
|
||||
if (v != Signatures::Zip64EndOfCDLocator)
|
||||
{
|
||||
|
@ -486,11 +488,11 @@ namespace xPlat {
|
|||
}
|
||||
}),
|
||||
// 1 - number of the disk with the start of the zip64 end of central directory 4 bytes
|
||||
Meta::Field4Bytes(stream, [](std::uint32_t& v) {}),
|
||||
std::make_shared<Meta::Field4Bytes>(stream, [](std::uint32_t& v) {}),
|
||||
// 2 - relative offset of the zip64 end of central directory record 8 bytes
|
||||
Meta::Field8Bytes(stream, [](std::uint64_t& v) {}),
|
||||
std::make_shared<Meta::Field8Bytes>(stream, [](std::uint64_t& v) {}),
|
||||
// 3 - total number of disks 4 bytes
|
||||
Meta::Field4Bytes(stream, [](std::uint32_t& v) {})
|
||||
std::make_shared<Meta::Field4Bytes>(stream, [](std::uint32_t& v) {})
|
||||
})
|
||||
{/*constructor*/}
|
||||
}; //class Zip64EndOfCentralDirectoryLocator
|
||||
|
@ -498,7 +500,8 @@ namespace xPlat {
|
|||
class EndCentralDirectoryRecord : public StructuredObject
|
||||
{
|
||||
public:
|
||||
//std::uint16_t SizeOfEndCentralDirectoryRecord() { return }
|
||||
std::uint16_t GetNumberOfDisk() { return Field(1)->GetValue<std::uint16_t>(); }
|
||||
void SetNumberOfDisk(std::uint16_t value) { Field(1).SetValue(value); }
|
||||
|
||||
std::uint32_t GetSignature() { return ObjectBase::GetValue<std::uint32_t>(Field(0)); }
|
||||
void SetSignature(std::uint32_t value) { Field(0).SetValue(value); }
|
||||
|
@ -538,26 +541,26 @@ namespace xPlat {
|
|||
EndCentralDirectoryRecord(StreamBase* stream) : StructuredObject(
|
||||
{
|
||||
// 0 - end of central dir signature 4 bytes (0x06054b50)
|
||||
Meta::Field4Bytes(stream, [](std::uint32_t& v)
|
||||
std::make_shared<Meta::Field4Bytes>(stream, [](std::uint32_t& v)
|
||||
{ if (v != Signatures::EndOfCentralDirectory)
|
||||
{
|
||||
throw ZipException("file header does not match signature", ZipException::Error::InvalidHeader);
|
||||
}
|
||||
}),
|
||||
// 1 - number of this disk 2 bytes
|
||||
Meta::Field2Bytes(stream, [](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [](std::uint16_t& v) {}),
|
||||
// 2 - number of the disk with the start of the central directory 2 bytes
|
||||
Meta::Field2Bytes(stream, [](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [](std::uint16_t& v) {}),
|
||||
// 3 - total number of entries in the central directory on this disk 2 bytes
|
||||
Meta::Field2Bytes(stream, [](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [](std::uint16_t& v) {}),
|
||||
// 4 - total number of entries in the central directory 2 bytes
|
||||
Meta::Field2Bytes(stream, [](std::uint16_t& v) {}),
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [](std::uint16_t& v) {}),
|
||||
// 5 - size of the central directory 4 bytes
|
||||
Meta::Field4Bytes(stream, [](std::uint32_t& v) {}),
|
||||
std::make_shared<Meta::Field4Bytes>(stream, [](std::uint32_t& v) {}),
|
||||
// 6 - offset of start of centraldirectory with respect to the starting disk number 4 bytes
|
||||
Meta::Field4Bytes(stream, [](std::uint32_t& v) {}),
|
||||
std::make_shared<Meta::Field4Bytes>(stream, [](std::uint32_t& v) {}),
|
||||
// 7 - .ZIP file comment length 2 bytes
|
||||
Meta::Field2Bytes(stream, [this](std::uint16_t& v)
|
||||
std::make_shared<Meta::Field2Bytes>(stream, [this](std::uint16_t& v)
|
||||
{
|
||||
if (GetCommentLength() > std::numeric_limits<std::uint16_t>::max())
|
||||
{
|
||||
|
@ -566,7 +569,7 @@ namespace xPlat {
|
|||
Field(8).Value<std::vector<std::uint8_t>>().resize(GetCommentLength(), 0);
|
||||
}),
|
||||
// 8 - .ZIP file comment (variable size)
|
||||
Meta::FieldNBytes(stream, [](std::vector<std::uint8_t>& data) {})
|
||||
std::make_shared<Meta::FieldNBytes>(stream, [](std::vector<std::uint8_t>& data) {})
|
||||
})
|
||||
{/*constructor*/}
|
||||
};//class EndOfCentralDirectoryRecord
|
||||
|
|
Загрузка…
Ссылка в новой задаче