diff options
| author | Dan Engelbrecht <[email protected]> | 2022-03-21 12:42:45 +0100 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-03-21 12:42:45 +0100 |
| commit | d35df614722024ccdb746332eceda2b7a6cd0b80 (patch) | |
| tree | 57203b27fd9fd76a62b066140a0a7cf307012eb4 /zenserver/frontend/zipfs.cpp | |
| parent | Missing return statement in websocket.h (diff) | |
| download | zen-d35df614722024ccdb746332eceda2b7a6cd0b80.tar.xz zen-d35df614722024ccdb746332eceda2b7a6cd0b80.zip | |
clang-format
Diffstat (limited to 'zenserver/frontend/zipfs.cpp')
| -rw-r--r-- | zenserver/frontend/zipfs.cpp | 151 |
1 files changed, 75 insertions, 76 deletions
diff --git a/zenserver/frontend/zipfs.cpp b/zenserver/frontend/zipfs.cpp index 5fb9d0177..91c6629a0 100644 --- a/zenserver/frontend/zipfs.cpp +++ b/zenserver/frontend/zipfs.cpp @@ -12,83 +12,84 @@ namespace { # pragma warning(disable : 4200) #endif -using ZipInt16 = uint16_t; + using ZipInt16 = uint16_t; -struct ZipInt32 -{ - operator uint32_t () const { return *(uint32_t*)Parts; } - uint16_t Parts[2]; -}; - -struct EocdRecord -{ - enum : uint32_t { - Magic = 0x0605'4b50, + struct ZipInt32 + { + operator uint32_t() const { return *(uint32_t*)Parts; } + uint16_t Parts[2]; }; - ZipInt32 Signature; - ZipInt16 ThisDiskIndex; - ZipInt16 CdStartDiskIndex; - ZipInt16 CdRecordThisDiskCount; - ZipInt16 CdRecordCount; - ZipInt32 CdSize; - ZipInt32 CdOffset; - ZipInt16 CommentSize; - char Comment[]; -}; - -struct CentralDirectoryRecord -{ - enum : uint32_t { - Magic = 0x0201'4b50, + + struct EocdRecord + { + enum : uint32_t + { + Magic = 0x0605'4b50, + }; + ZipInt32 Signature; + ZipInt16 ThisDiskIndex; + ZipInt16 CdStartDiskIndex; + ZipInt16 CdRecordThisDiskCount; + ZipInt16 CdRecordCount; + ZipInt32 CdSize; + ZipInt32 CdOffset; + ZipInt16 CommentSize; + char Comment[]; }; - ZipInt32 Signature; - ZipInt16 VersionMadeBy; - ZipInt16 VersionRequired; - ZipInt16 Flags; - ZipInt16 CompressionMethod; - ZipInt16 LastModTime; - ZipInt16 LastModDate; - ZipInt32 Crc32; - ZipInt32 CompressedSize; - ZipInt32 OriginalSize; - ZipInt16 FileNameLength; - ZipInt16 ExtraFieldLength; - ZipInt16 CommentLength; - ZipInt16 DiskIndex; - ZipInt16 InternalFileAttr; - ZipInt32 ExternalFileAttr; - ZipInt32 Offset; - char FileName[]; -}; - -struct LocalFileHeader -{ - enum : uint32_t { - Magic = 0x0304'4b50, + struct CentralDirectoryRecord + { + enum : uint32_t + { + Magic = 0x0201'4b50, + }; + + ZipInt32 Signature; + ZipInt16 VersionMadeBy; + ZipInt16 VersionRequired; + ZipInt16 Flags; + ZipInt16 CompressionMethod; + ZipInt16 LastModTime; + ZipInt16 LastModDate; + ZipInt32 Crc32; + ZipInt32 CompressedSize; + ZipInt32 OriginalSize; + ZipInt16 FileNameLength; + ZipInt16 ExtraFieldLength; + ZipInt16 CommentLength; + ZipInt16 DiskIndex; + ZipInt16 InternalFileAttr; + ZipInt32 ExternalFileAttr; + ZipInt32 Offset; + char FileName[]; }; - ZipInt32 Signature; - ZipInt16 VersionRequired; - ZipInt16 Flags; - ZipInt16 CompressionMethod; - ZipInt16 LastModTime; - ZipInt16 LastModDate; - ZipInt32 Crc32; - ZipInt32 CompressedSize; - ZipInt32 OriginalSize; - ZipInt16 FileNameLength; - ZipInt16 ExtraFieldLength; - char FileName[]; -}; + struct LocalFileHeader + { + enum : uint32_t + { + Magic = 0x0304'4b50, + }; + + ZipInt32 Signature; + ZipInt16 VersionRequired; + ZipInt16 Flags; + ZipInt16 CompressionMethod; + ZipInt16 LastModTime; + ZipInt16 LastModDate; + ZipInt32 Crc32; + ZipInt32 CompressedSize; + ZipInt32 OriginalSize; + ZipInt16 FileNameLength; + ZipInt16 ExtraFieldLength; + char FileName[]; + }; #if ZEN_COMPILER_MSC # pragma warning(pop) #endif -} // namespace - - +} // namespace ////////////////////////////////////////////////////////////////////////// ZipFs::ZipFs(IoBuffer&& Buffer) @@ -102,7 +103,7 @@ ZipFs::ZipFs(IoBuffer&& Buffer) } const auto* EocdCursor = (EocdRecord*)(Cursor - sizeof(EocdRecord)); - + // It is more correct to search backwards for EocdRecord::Magic as the // comment can be of a variable length. But here we're not going to support // zip files with comments. @@ -138,19 +139,20 @@ ZipFs::ZipFs(IoBuffer&& Buffer) } uint32_t ExtraBytes = Cd.FileNameLength + Cd.ExtraFieldLength + Cd.CommentLength; - CdCursor = (CentralDirectoryRecord*)(Cd.FileName + ExtraBytes); + CdCursor = (CentralDirectoryRecord*)(Cd.FileName + ExtraBytes); } - + m_Buffer = std::move(Buffer); } ////////////////////////////////////////////////////////////////////////// -IoBuffer ZipFs::GetFile(const std::string_view& FileName) const +IoBuffer +ZipFs::GetFile(const std::string_view& FileName) const { FileMap::iterator Iter = m_Files.find(FileName); if (Iter == m_Files.end()) { - return{}; + return {}; } FileItem& Item = Iter->second; @@ -160,11 +162,8 @@ IoBuffer ZipFs::GetFile(const std::string_view& FileName) const } const auto* Lfh = (LocalFileHeader*)(Item.GetData()); - Item = MemoryView( - Lfh->FileName + Lfh->FileNameLength + Lfh->ExtraFieldLength, - Lfh->OriginalSize - ); + Item = MemoryView(Lfh->FileName + Lfh->FileNameLength + Lfh->ExtraFieldLength, Lfh->OriginalSize); return IoBuffer(IoBuffer::Wrap, Item.GetData(), Item.GetSize()); } -} // namespace zen +} // namespace zen |