From 4a15cf75ba589da3eed30d8e7ed59eaaa6490509 Mon Sep 17 00:00:00 2001 From: Juno Kim Date: Tue, 1 Sep 2026 11:35:58 +0900 Subject: [PATCH] edit stdout log message --- src/MyZip.cpp | 20 +++++------ src/main.cpp | 91 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 64 insertions(+), 47 deletions(-) diff --git a/src/MyZip.cpp b/src/MyZip.cpp index 3f505e3..d3e888a 100644 --- a/src/MyZip.cpp +++ b/src/MyZip.cpp @@ -19,8 +19,8 @@ bool MyZip::AddFileToZip(const std::string & strFileDiskPath, const std::string& std::ifstream fileIn(strFileDiskPath, std::ios::binary); if (!fileIn.is_open()) { - printf("[ ERROR ](AddFileToZip) Something went Worng..."); - printf("fileIn open failed"); + printf("[ ERROR ](AddFileToZip) Something went Worng...\r\n"); + printf("fileIn open failed\r\n"); return false; } @@ -37,8 +37,8 @@ bool MyZip::AddFileToZip(const std::string & strFileDiskPath, const std::string& // 파일 읽기 if (!fileIn.read(pInBuffer, fileInSize)) { - printf("[ ERROR ](AddFileToZip) Something went Worng..."); - printf("fileIn read failed"); + printf("[ ERROR ](AddFileToZip) Something went Worng...\r\n"); + printf("fileIn read failed\r\n"); return false; } @@ -80,8 +80,8 @@ bool MyZip::FinalizeZip() iRet = fileOut.is_open(); if (!iRet) { - printf("[ ERROR ](FinalizeZip) Something went Worng..."); - printf("FileOut open failed"); + printf("[ ERROR ](FinalizeZip) Something went Worng...\r\n"); + printf("FileOut open failed\r\n"); } else { @@ -101,7 +101,7 @@ bool MyZip::FinalizeZip() auto offset = fileOut.tellp(); if (offset == static_cast(-1)) { - printf("[ ERROR ](FinalizeZip) Failed to get offset"); + printf("[ ERROR ](FinalizeZip) Failed to get offset\r\n"); fileOut.close(); return false; } @@ -116,7 +116,7 @@ bool MyZip::FinalizeZip() if (fileOut.fail()) { - printf("[ ERROR ](FinalizeZip) Disk write failed \n"); + printf("[ ERROR ](FinalizeZip) Disk write failed\r\n"); fileOut.close(); return false; } @@ -126,7 +126,7 @@ bool MyZip::FinalizeZip() fileOut.write(reinterpret_cast(&this->EOCDR), sizeof(this->EOCDR)); if (fileOut.fail()) { - printf("[ ERROR ](FinalizeZip) Disk write failed \n"); + printf("[ ERROR ](FinalizeZip) Disk write failed\r\n"); fileOut.close(); return false; } @@ -135,7 +135,7 @@ bool MyZip::FinalizeZip() fileOut.close(); if (fileOut.fail()) { - printf("[ ERROR ](FinalizeZip) Failed to close/flush file (Maybe Disk full?)\n"); + printf("[ ERROR ](FinalizeZip) Failed to close/flush file (Maybe Disk full?)\r\n"); return false; } } diff --git a/src/main.cpp b/src/main.cpp index 2e4b74d..bc50e37 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ bool FileReader(MyZip &zip, std::string strInputPath, const std::filesystem::pat if (!filesystem::exists(pathObj)) { printf("[ERROR](FileReader) Something went Wrong..!! \r\n"); - printf("[ERROR] File not found : %s ", pathObj.string().c_str()); + printf("[ERROR] File not found : %s \r\n", pathObj.string().c_str()); bRet = false; } @@ -130,69 +130,86 @@ int main(int argc, char* argv[]) 1. 폴더 순회구조의 문제 - 문제 : 전역변수(g_recursive_counter)및 함수(FileReader) 의 전역사용 - - 기대값 : 폴더 순회구조 또한 클래스화 + - 기대값 : 폴더를 순회하는 로직 또한 클래스화 2. CentralDirectory 설계문제 - 문제 : CentralDirectory 를 채우는 코드가 분산됨. - - 기대값 : 한 곳으로 집중. + - 기대값 : CentralDirectory 를 채우는 코드를 한 곳으로 집중. 3. 내부 상태 플래그 (bRet) 의 미구현 - - 현상 : 프로그램의 실패 상황 별 플래그값인 "bool bRet" 의 미구현 + - 현상 : 프로그램의 실패 상황 별 플래그값인 "bool bRet" 의 사용처가 없음. - 기대값 : 일반적인 error code 로써 동작하는 리턴 값으로 사용. 4. 예외처리 설계 및 구현의 부재 - 현상 : File I/O, 경로검사 등 일관된 형식의 예외처리와 Message 처리가 없음. - - 기대값 : 에러 조기발견 + - 기대값 : 에러 조기발견 및 에러코드 가독성 향상 5. 별도 Unit Test 미구현 - 현상 : 프로젝트의 디버깅 및 테스트를 위해서는 프로그램의 전체 Work flow 를 따라가야 함. - 기대값 : 단일 기능 (예 : CRC 값 검증, Output File 테스트) 을 테스트 하기 위한 Unit Test 구현 + + 6. 사용자 편의 StdOut 부족 + - 현상 : 출력 파일의 경로, 크기, 구조 등등 편의를 위한 Output 부족 + - 기대값 : 굳이 파일을 직접 열지 않아도 출력결과를 확인 할 수 있음. + */ using namespace std; int iRet = 0; - printf("==================== Hello Zip! ====================\r\n"); - printf("=== Please enter Target Path ===\r\n"); - printf("=== (FOR TEST, Input below) ===\r\n"); - printf("=== (1 : File Test, 2 : Dir Test) ===\r\n"); - printf("====================================================\r\n"); - printf("Input Path: "); + int iCounter = 0; - string strInputPath; - getline(cin, strInputPath); - - - // Testing input - if (strInputPath == "1") - strInputPath = INPUT_FILE_NAME; - else if (strInputPath == "2") - strInputPath = INPUT_DIR_NAME; - - filesystem::path absPath = filesystem::absolute(strInputPath); - filesystem::path rootPath = absPath.parent_path(); - - // Main Zip archive method - MyZip zip; - if (!FileReader(zip, strInputPath, rootPath)) + while (true) { - printf("[ ERROR ](FileReader) Somthing went Wrong... \r\n"); - iRet = -1; - } - else - { - if (!zip.FinalizeZip()) + if (++iCounter > 1) + printf("==================== Hello Zip! (%d th)=============\r\n", iCounter); + else + printf("==================== Hello Zip! ====================\r\n"); + printf("=== Please enter Target Path ===\r\n"); + printf("=== (1 : File Test, 2 : Dir Test, q : Exit) ===\r\n"); + printf("=== ===\r\n"); + printf("=== [File Test : TestFiles/Target_File.txt] ===\r\n"); + printf("=== [Dir Test : TestFiles/Target_Dir ] ===\r\n"); + printf("====================================================\r\n"); + printf("Input Path: "); + + string strInputPath; + getline(cin, strInputPath); + + + // Testing input + if (strInputPath == "1") + strInputPath = INPUT_FILE_NAME; + else if (strInputPath == "2") + strInputPath = INPUT_DIR_NAME; + else if (strInputPath == "q") + break; + + filesystem::path absPath = filesystem::absolute(strInputPath); + filesystem::path rootPath = absPath.parent_path(); + + // Main Zip archive method + MyZip zip; + if (!FileReader(zip, strInputPath, rootPath)) { - printf("[ ERROR ](Finallize) Somthing went Wrong... \r\n"); + printf("[ ERROR ](FileReader) Somthing went Wrong... \r\n"); iRet = -1; } else { - printf("It Works Fine. \r\n"); - printf("==================== Good Bye Zip! =================\r\n"); - iRet = 0; + if (!zip.FinalizeZip()) + { + printf("[ ERROR ](Finallize) Somthing went Wrong... \r\n"); + iRet = -1; + } + else + { + printf("It Works Fine. \r\n"); + iRet = 0; + } } } + printf("==================== Good Bye Zip! =================\r\n"); return iRet; } \ No newline at end of file