edit CWD problem
This commit is contained in:
@@ -3,26 +3,24 @@
|
||||
#include <debugapi.h>
|
||||
#include "MyZip.h"
|
||||
|
||||
// Phase A(AddFile) / Phase B(Finalize) 구조:
|
||||
// - AddFile() : 파일 하나 읽어서 [LocalFileHeader][파일명][데이터]를 fileOut에 이어 쓰고,
|
||||
// 이 파일의 CentralDirectory 정보는 vecEntries에 누적만 해둠 (아직 안 씀).
|
||||
// - Finalize() : 전체 순회가 끝난 뒤 딱 한 번 호출. 누적된 CentralDirectory들을 순서대로 쓰고,
|
||||
// EOCD 작성 후 스트림을 닫음.
|
||||
// Phase A(AddFileToZip) / Phase B(FinalizeZip) 구조:
|
||||
// - AddFileToZip() : 파일 하나 읽어서 [LocalFileHeader][파일명][데이터]를 fileOut에 이어 쓰고,
|
||||
// 이 파일의 CentralDirectory 정보는 vecEntries에 누적만 해둠 (아직 안 씀).
|
||||
// - FinalizeZip() : 전체 순회가 끝난 뒤 딱 한 번 호출. 누적된 CentralDirectory들을 순서대로 쓰고,
|
||||
// EOCD 작성 후 스트림을 닫음.
|
||||
|
||||
// Phase A
|
||||
// - strFilePath 파일을 열어 크기 계산 + CRC 계산
|
||||
// - LocalFileHeader 채워서 [헤더][파일명][데이터] 순서로 fileOut에 씀
|
||||
// - 이 파일의 CentralDirectory를 채워서 vecEntries에 push_back
|
||||
// - 이 시점에는 CentralDirectory/EOCD를 파일에 쓰지 않음 (Finalize 몫)
|
||||
// strFilePath : 디스크 상의 실제 파일 경로 (FileReader가 넘겨주는 경로)
|
||||
// 3. LocalFileHeader 채우기 (signature/crc32/size/lengthOfFileName 등)
|
||||
// 4. fileOut에 [LocalFileHeader][파일명][데이터] 쓰기
|
||||
// 5. 이 파일의 CentralDirectory 채워서 vecEntries.push_back({header, fileName})
|
||||
bool MyZip::AddFileToZip(const std::string &strFilePath)
|
||||
// - 이 시점에는 CentralDirectory/EOCD를 파일에 쓰지 않음 (Finalize 단계)
|
||||
bool MyZip::AddFileToZip(const std::string & strFileDiskPath, const std::string& strFileEntryPath)
|
||||
{
|
||||
std::ifstream fileIn(strFilePath, std::ios::binary);
|
||||
std::ifstream fileIn(strFileDiskPath, std::ios::binary);
|
||||
if (!fileIn.is_open())
|
||||
{
|
||||
printf("[ ERROR ](AddFileToZip) Something went Worng...");
|
||||
printf("fileIn open failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -39,12 +37,14 @@ bool MyZip::AddFileToZip(const std::string &strFilePath)
|
||||
// 파일 읽기
|
||||
if (!fileIn.read(pInBuffer, fileInSize))
|
||||
{
|
||||
printf("[ ERROR ](AddFileToZip) Something went Worng...");
|
||||
printf("fileIn read failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Gathering data
|
||||
uint32_t myCRC = getCRC32(pInBuffer, fileInSize);
|
||||
uint16_t fileNameLeng = static_cast<uint16_t>(strFilePath.length());
|
||||
uint16_t fileNameLeng = static_cast<uint16_t>(strFileEntryPath.length());
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
LocalFileHeader LFHeader{};
|
||||
CentralDirectory CentDir{};
|
||||
@@ -57,11 +57,11 @@ bool MyZip::AddFileToZip(const std::string &strFilePath)
|
||||
fiiledCDH.offsetLocalFileHeader = static_cast<uint32_t>(fileOut.tellp());
|
||||
|
||||
// 우선 CDH 는 vector 에 저장 (나중에 파일 쓸 때 마저 채움.)
|
||||
vecEntries.push_back({fiiledCDH, strFilePath});
|
||||
vecEntries.push_back({fiiledCDH, strFileEntryPath });
|
||||
|
||||
// 1. Local File Header, file name (var), extra field (var)
|
||||
fileOut.write(reinterpret_cast<const char *>(&LFHeader), sizeof(LFHeader));
|
||||
fileOut.write(strFilePath.c_str(), LFHeader.lengthOfFileName);
|
||||
fileOut.write(strFileEntryPath.c_str(), LFHeader.lengthOfFileName);
|
||||
// fileOut.write(NOT_USED, LFHeader.lengthOfExtraField);
|
||||
// 2. File Data
|
||||
fileOut.write(pInBuffer, fileInSize);
|
||||
@@ -74,24 +74,17 @@ bool MyZip::AddFileToZip(const std::string &strFilePath)
|
||||
// - vecEntries를 순서대로 순회하며 [CentralDirectory][파일명] 씀
|
||||
// - EoCDRecord 채우기 (numOfEntries = vecEntries.size() 등 누적값 반영)
|
||||
// - EoCDRecord 쓰기 -> fileOut.close()
|
||||
// TODO : 1. vecEntries 순서대로 [CentralDirectory][파일명] 쓰기
|
||||
// 2. EoCDRecord 채우기 (entries 수, central dir 시작 오프셋/크기 등)
|
||||
// 3. EoCDRecord 쓰기
|
||||
// 4. fileOut.close()
|
||||
bool MyZip::FinalizeZip()
|
||||
{
|
||||
bool iRet = false;
|
||||
iRet = fileOut.is_open();
|
||||
if (!iRet)
|
||||
{
|
||||
printf("[ ERROR ](FinalizeZip) Something went Worng...");
|
||||
printf("FileOut open failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO : sizeof 의 값이 스펙과 정확히 일치한다는 보장 필요 (현재는 compiler 에 종속적)
|
||||
// : offsetof((LocalFileHeader, crc32) 으로 멤버별 static_assert 로 변경할 지 고민.
|
||||
// : 아니면 필드 단위 직접쓰기로 struct 분해하기?
|
||||
|
||||
// TODO : EOCDR Temp format 채우기.
|
||||
this->EOCDR.diskNumber = 0; // Temp
|
||||
this->EOCDR.diskNumber_CentralDirStart = 0; // Temp
|
||||
|
||||
Reference in New Issue
Block a user