Files
MyZip/MyZip.h
T
2026-08-31 16:51:47 +09:00

61 lines
1.7 KiB
C++

#pragma once
#include <cstdint>
#include <fstream>
#include <string>
#include <vector>
#include "ZipDefine.h"
#include "CRC.h"
#define INPUT_FILE_NAME "Target_File.txt"
#define INPUT_DIR_NAME "Target_Dir"
#define OUTPUT_FILE_NAME "Test_Out.zip"
class MyZip
{
private:
std::ofstream fileOut;
std::string strOutputPath;
// Zip Format struct
EoCDRecord EOCDR{};
struct ArchivedEntry
{
CentralDirectory header;
std::string fileName;
// TODO : 아래 기본값 어디서 채울 지 고민 (GetFiiled or 여기서)
ArchivedEntry(CentralDirectory cdh, std::string name) : header(cdh), fileName(name)
{
header.signature = PK_SIGNATURE_CENT_DIR;
header.versionMadeBy = 0; // Temp
header.versionNeededToExtract = 0; // Temp
header.generalBitFlag = 0; // Temp
header.compressionMethod = METHOD_UNCOMPRESSED;
}
};
std::vector<ArchivedEntry> vecEntries;
public:
MyZip() : strOutputPath(std::string(OUTPUT_FILE_NAME))
{
fileOut = std::ofstream(strOutputPath, std::ios::binary);
EOCDR.signature = PK_SIGNATURE_EO_CDR;
}
MyZip(const std::string& strfilePath) : strOutputPath(strfilePath)
{
fileOut = std::ofstream(strOutputPath, std::ios::binary);
EOCDR.signature = PK_SIGNATURE_EO_CDR;
}
// Zip 에 파일 추가
bool AddFileToZip(const std::string &strFileDiskPath, const std::string& strFileEntryPath);
// Zip 마무리
bool FinalizeZip();
// Header Functions
void FillLocalFileHeader(LocalFileHeader &targetLF, const uint32_t targetCRC, const uint32_t targetSize, const uint16_t targetNameLeng);
CentralDirectory GetFilledCentDirHeader(CentralDirectory &targetCDH, const uint32_t targetCRC, const uint32_t targetSize, const uint16_t targetNameLeng);
};