diff --git a/.gitignore b/.gitignore index 076209e..df27ccd 100644 --- a/.gitignore +++ b/.gitignore @@ -75,4 +75,5 @@ ipch/ # Zip Foramt Test Test* !TestFiles -*.zip \ No newline at end of file +*.zip +Docs/ \ No newline at end of file diff --git a/src/MyZip.cpp b/src/MyZip.cpp index 2a3161b..bc19bea 100644 --- a/src/MyZip.cpp +++ b/src/MyZip.cpp @@ -91,11 +91,20 @@ bool MyZip::FinalizeZip() this->EOCDR.numOfCentralDir = static_cast(vecEntries.size()); this->EOCDR.numOfEntries = static_cast(vecEntries.size()); this->EOCDR.lengthOfCommentLength = 0; + this->EOCDR.sizeOfCentralDir = 0; + for (const auto &p : vecEntries) { this->EOCDR.sizeOfCentralDir += (sizeof(p.header) + p.header.lengthOfFileName); } - this->EOCDR.offsetCentralDir = static_cast(fileOut.tellp()); + + auto offset = static_cast(fileOut.tellp()); + if (offset == static_cast(-1)) + { + printf("[ ERROR ](FinalizeZip) Failed to get offset"); + fileOut.close(); + } + this->EOCDR.offsetCentralDir = static_cast(offset); // Write to file (archiving) for (const auto &p : vecEntries) @@ -103,12 +112,31 @@ bool MyZip::FinalizeZip() // CentralDirectory, file name (var) fileOut.write(reinterpret_cast(&p.header), sizeof(p.header)); fileOut.write(p.fileName.c_str(), p.header.lengthOfFileName); + + if (fileOut.fail()) + { + printf("[ ERROR ](FinalizeZip) Disk write failed while writing central directory entries (Disk full?)\n"); + fileOut.close(); + return false; + } } - // End of CentralDirectory Record + // fileOut 예외처리 추가 fileOut.write(reinterpret_cast(&this->EOCDR), sizeof(this->EOCDR)); + if (fileOut.fail()) + { + printf("[ ERROR ](FinalizeZip) Disk write failed while writing EOCDR\n"); + fileOut.close(); + return false; + } + // fileOut 예외처리 추가 fileOut.close(); + if (fileOut.fail()) + { + printf("[ ERROR ](FinalizeZip) Failed to close/flush file (Disk full?)\n"); + return false; + } } // TODO : 성공여부 처리 어떻게 할 건지? diff --git a/src/MyZip.h b/src/MyZip.h index dae6e8c..4c3aa5c 100644 --- a/src/MyZip.h +++ b/src/MyZip.h @@ -54,6 +54,7 @@ public: // Zip 마무리 bool FinalizeZip(); +private: // 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); diff --git a/src/main.cpp b/src/main.cpp index d51a669..8afdd48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,7 +48,7 @@ bool FileReader(MyZip &zip, std::string strInputPath, const std::filesystem::pat OutputDebugStringA(strDbg.c_str()); auto absPathOjb = filesystem::absolute(pathObj); - bRet = zip.AddFileToZip(absPathOjb.generic_string(), pathObj.generic_string()); + bRet = zip.AddFileToZip(absPathOjb.generic_string(), rootPath.generic_string()); break; } @@ -133,11 +133,23 @@ int main(int argc, char* argv[]) - 원인 : 입력 경로를 상대 경로로 정규화하지 않고 절대 경로 전체를 압축 내부 엔트리 경로로 사용 - 기대값 : 입력 파일 (혹은 디렉토리) 만 압축되어 저장. - 2. 내부 상태 플래그 (bRet) 의 미구현 + 2. 폴더 순회구조의 문제 + - 문제 : 전역변수(g_recursive_counter)및 함수(FileReader) 의 전역사용 + - 기대값 : 폴더 순회구조 또한 클래스화 + + 3. CentralDirectory 설계문제 + - 문제 : CentralDirectory 를 채우는 코드가 분산됨. + - 기대값 : 한 곳으로 집중. + + 4. 내부 상태 플래그 (bRet) 의 미구현 - 현상 : 프로그램의 실패 상황 별 플래그값인 "bool bRet" 의 미구현 - 기대값 : 일반적인 error code 로써 동작하는 리턴 값으로 사용. - 3. 별도 Unit Test 미구현 + 5. 예외처리 설계 및 구현의 부재 + - 현상 : File I/O, 경로검사 등 일관된 형식의 예외처리와 Message 처리가 없음. + - 기대값 : 에러 조기발견 + + 5. 별도 Unit Test 미구현 - 현상 : 프로젝트의 디버깅 및 테스트를 위해서는 프로그램의 전체 Work flow 를 따라가야 함. - 기대값 : 단일 기능 (예 : CRC 값 검증, Output File 테스트) 을 테스트 하기 위한 Unit Test 구현 */