| 82 | //========================================================================== |
| 83 | |
| 84 | static int AppendToZip(FileWriter *zip_file, const FCompressedBuffer &content, std::pair<uint16_t, uint16_t> &dostime) |
| 85 | { |
| 86 | FZipLocalFileHeader local; |
| 87 | int position; |
| 88 | |
| 89 | int flags = 0; |
| 90 | int method = content.mMethod; |
| 91 | if (method >= FileSys::METHOD_IMPLODE_MIN && method <= FileSys::METHOD_IMPLODE_MAX) |
| 92 | { |
| 93 | flags = method - FileSys::METHOD_IMPLODE_MIN; |
| 94 | method = FileSys::METHOD_IMPLODE; |
| 95 | } |
| 96 | else if (method == FileSys::METHOD_DEFLATE) |
| 97 | { |
| 98 | flags = 2; |
| 99 | } |
| 100 | else if (method >= 1337) |
| 101 | return -1; |
| 102 | |
| 103 | local.Magic = ZIP_LOCALFILE; |
| 104 | local.VersionToExtract[0] = 20; |
| 105 | local.VersionToExtract[1] = 0; |
| 106 | local.Flags = LittleShort((uint16_t)flags); |
| 107 | local.Method = LittleShort((uint16_t)method); |
| 108 | local.ModDate = LittleShort(dostime.first); |
| 109 | local.ModTime = LittleShort(dostime.second); |
| 110 | local.CRC32 = content.mCRC32; |
| 111 | local.UncompressedSize = LittleLong((unsigned)content.mSize); |
| 112 | local.CompressedSize = LittleLong((unsigned)content.mCompressedSize); |
| 113 | local.NameLength = LittleShort((unsigned short)strlen(content.filename)); |
| 114 | local.ExtraLength = 0; |
| 115 | |
| 116 | // Fill in local directory header. |
| 117 | |
| 118 | position = (int)zip_file->Tell(); |
| 119 | |
| 120 | // Write out the header, file name, and file data. |
| 121 | if (zip_file->Write(&local, sizeof(local)) != sizeof(local) || |
| 122 | zip_file->Write(content.filename, strlen(content.filename)) != strlen(content.filename) || |
| 123 | zip_file->Write(content.mBuffer, content.mCompressedSize) != content.mCompressedSize) |
| 124 | { |
| 125 | return -1; |
| 126 | } |
| 127 | return position; |
| 128 | } |
| 129 | |
| 130 | |
| 131 | //========================================================================== |
no test coverage detected