📄 stafzipcentraldir.cpp
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2004 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/#include "STAF.h"#include "STAFString.h"#include "STAFTrace.h"#include <vector>#include <map>#include "zlib.h"#include "STAFZip.h"#include "STAFZipUtil.h"#include "STAFZipFileHeader.h"#include "STAFZipCentralDirEndRecord.h"#include "STAFZipFileAttribute.h"#include "STAFZipCentralDirExtension.h"#include "STAFZipLocalFileHeader.h"#include "STAFZipCentralDir.h"STAFZipCentralDir::STAFZipCentralDir(){ cder = new STAFZipCentralDirEndRecord();}// write Central Dir data into zip archiveSTAFRC_t STAFZipCentralDir::flush(FILE *zf, STAFString *result){ STAFRC_t rc = kSTAFOk; std::vector<STAFZipFileHeader*>::iterator i; STAFZipUtil util = STAFZipUtil(); STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP1")); for (i = fileHeaderList.begin(); i != fileHeaderList.end(); i++) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP2") + " signature [" + (*i)->signature + "]"); // local header signature rc = util.putValue(zf, (uLong)(*i)->signature, 4); // version made by if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP3") + " versionMadeBy [" + (*i)->versionMadeBy + "]"); rc = util.putValue(zf, (uLong)(*i)->versionMadeBy, 2); } // version needed to extract if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP4") + " versionNeededToExtract [" + (*i)->versionNeededToExtract + "]"); rc = util.putValue(zf, (uLong)(*i)->versionNeededToExtract, 2); } // general purpose bit flag, 2 for Maximum (-exx/-ex) compression option // was used for method 8 and 9 - deflating if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP5") + " generalPurposeBitFlag [" + (*i)->generalPurposeBitFlag + "]"); rc = util.putValue(zf, (uLong)(*i)->generalPurposeBitFlag, 2); } // compression method if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP6") + " compressionMethod [" + (*i)->compressionMethod + "]"); rc = util.putValue(zf, (uLong)(*i)->compressionMethod, 2); } // last mod time date if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP7") + " lastModifiedTimeDate [" + (*i)->lastModifiedTimeDate + "]"); rc = util.putValue(zf, (uLong)(*i)->lastModifiedTimeDate, 4); } // crc if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP8") + " crc [" + (*i)->crc + "]"); rc = util.putValue(zf, (uLong)(*i)->crc, 4); } // compressed size if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP9") + " compressedSize [" + (*i)->compressedSize + "]"); rc = util.putValue(zf, (uLong)(*i)->compressedSize, 4); } // uncompressed size if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP10") + " uncompressedSize [" + (*i)->uncompressedSize + "]"); rc = util.putValue(zf, (uLong)(*i)->uncompressedSize, 4); } // fileName length if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP11") + " fileNameLength [" + (*i)->fileNameLength + "]"); rc = util.putValue(zf, (uLong)(*i)->fileNameLength, 2); } // fileName length if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP12") + " extraFieldLength [" + (*i)->extraFieldLength + "]"); rc = util.putValue(zf, (uLong)(*i)->extraFieldLength, 2); } // file comment length if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP13") + " fileCommentLength [" + (*i)->fileCommentLength + "]"); rc = util.putValue(zf, (uLong)(*i)->fileCommentLength, 2); } // disk number start if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP14") + " diskNumberStart [" + (*i)->diskNumberStart + "]"); rc = util.putValue(zf, (uLong)(*i)->diskNumberStart, 2); } // internal file attributes if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP15") + " internalFileAttributes [" + (*i)->internalFileAttributes + "]"); rc = util.putValue(zf, (uLong)(*i)->internalFileAttributes, 2); } // external file attributes if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP16") + " externalFileAttributes [" + (*i)->externalFileAttributes + "]"); rc = util.putValue(zf, (uLong)(*i)->externalFileAttributes, 4); } // local header offset if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP17") + " localFileHeaderOffset [" + (*i)->localFileHeaderOffset + "]"); rc = util.putValue(zf, (uLong)(*i)->localFileHeaderOffset, 4); } // file name if (rc == kSTAFOk && (*i)->fileNameLength > 0) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP18") + " fileName [" + (*i)->fileName + "]"); if (fwrite((*i)->fileName, (uInt)(*i)->fileNameLength, 1, zf) != 1) { *result = STAFString("STAFZipCentralDir::flush: ") + "Error writing filename to file header [" + (*i)->fileName + "].\n"; rc = kZIPGeneralZipError; } } // extra field if (rc == kSTAFOk && (*i)->extraFieldLength > 0) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP19") + " extraField offset [" + ftell(zf) + "]"); if (fwrite((*i)->extraField, (uInt)(*i)->extraFieldLength, 1, zf) != 1) { *result = STAFString("STAFZipCentralDir::flush: ") + "Error writing extraField to file header [" + (char*)((*i)->extraField) + "].\n"; rc = kZIPGeneralZipError; } } // file comment if (rc == kSTAFOk && (*i)->fileCommentLength > 0) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP20") + " fileComment [" + (*i)->fileComment + "]"); if (fwrite((*i)->fileComment, (uInt)(*i)->fileCommentLength, 1, zf) != 1) { *result = STAFString("STAFZipCentralDir::flush: ") + "Error writing fileComment to file header [" + (*i)->fileComment + "].\n"; rc = kZIPGeneralZipError; } } if (rc != kSTAFOk) { if ((*result).length() == 0) { *result = STAFString("STAFZipCentralDir::flush: ") + "Error writing data to file header.\n"; } break; } } // flush file headers // flush end of central dir STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP21") + " signature [" + cder->signature + "]"); // end of central dir signature rc = util.putValue(zf, (uLong)cder->signature, 4); // number of disk if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP22") + " numberDisk [" + cder->numberDisk + "]"); rc = util.putValue(zf, (uLong)cder->numberDisk, 2); } // number of disk with central dir if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP23") + " numberDiskWithCentralDir [" + cder->numberDiskWithCentralDir + "]"); rc = util.putValue(zf, (uLong)cder->numberDiskWithCentralDir, 2); } // number of entries on this disk if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP24") + " numberEntry [" + STAFString(cder->numberEntry) + "]"); rc = util.putValue(zf, (uLong)cder->numberEntry, 2); } // number of entries if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP25") + " numberEntryWithCentralDir [" + STAFString(cder->numberEntryWithCentralDir) + "]"); rc = util.putValue(zf, (uLong)cder->numberEntryWithCentralDir, 2); } // central dir size if (rc == kSTAFOk) { STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::flush_CP26") + " centralDirSize [" + cder->centralDirSize + "]");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -