From 0b90e87f216a9fb4116c255d2955517b70be3656 Mon Sep 17 00:00:00 2001 From: Juno Kim Date: Mon, 31 Aug 2026 15:52:26 +0900 Subject: [PATCH] test complete. --- .gitignore | 2 +- MyZip.h | 4 +- Target_Dir/{Text.txt => Main_Text.txt} | 0 main.cpp | 83 +++++++++++++++----------- 4 files changed, 50 insertions(+), 39 deletions(-) rename Target_Dir/{Text.txt => Main_Text.txt} (100%) diff --git a/.gitignore b/.gitignore index f35f4c0..349260f 100644 --- a/.gitignore +++ b/.gitignore @@ -73,5 +73,5 @@ ipch/ *.VC.VC.opendb # Zip Foramt Test -Test +Test* *.zip \ No newline at end of file diff --git a/MyZip.h b/MyZip.h index 112ab8a..acbd388 100644 --- a/MyZip.h +++ b/MyZip.h @@ -7,9 +7,9 @@ #include "ZipDefine.h" #include "CRC.h" -#define OUTPUT_FILE_NAME "MyZip.zip" #define INPUT_FILE_NAME "Target_File.txt" -#define INPUT_DIR_NAME "Target_File" +#define INPUT_DIR_NAME "Target_Dir" +#define OUTPUT_FILE_NAME "Test_Out.zip" class MyZip { diff --git a/Target_Dir/Text.txt b/Target_Dir/Main_Text.txt similarity index 100% rename from Target_Dir/Text.txt rename to Target_Dir/Main_Text.txt diff --git a/main.cpp b/main.cpp index 4e8b2b4..a24132b 100644 --- a/main.cpp +++ b/main.cpp @@ -1,32 +1,15 @@ #include #include #include -#include #include -#include #include #include - -#include "ZipDefine.h" -#include "CRC.h" #include "MyZip.h" static uint32_t g_recursive_counter = 0; -bool ZipArchiver(std::string strInputPath, bool bIsFinal = false) -{ - MyZip zip; - bool bRet = false; - - bRet = zip.AddFileToZip(strInputPath); - if(bIsFinal) - bRet = zip.FinalizeZip(); - - return bRet; -} - -bool FileReader(std::string strInputPath) +bool FileReader(MyZip &zip, std::string strInputPath, const std::filesystem::path &rootPath) { using namespace std; bool bRet = true; @@ -54,14 +37,18 @@ bool FileReader(std::string strInputPath) else if (filesystem::is_regular_file(pathObj)) eFileDist = eFILETYPE::isFile; else eFileDist = eFILETYPE::ETC; - const filesystem::path& rootPath = pathObj; switch (eFileDist) { - // case 1 : input file + // case 1 : input one file case eFILETYPE::isFile: { - bool bIsFinal = g_recursive_counter > 0 ? false : true; - bRet = ZipArchiver(pathObj.string(), bIsFinal ); + // TODO : export to debugging log function + string strDbg = "[INFO] Current Entry (File)\t: " + pathObj.string(); + strDbg += "\t Counter : " + to_string(g_recursive_counter); + strDbg += "\r\n"; + OutputDebugStringA(strDbg.c_str()); + + bRet = zip.AddFileToZip(pathObj.string()); break; } @@ -70,6 +57,8 @@ bool FileReader(std::string strInputPath) { // make iterator to traversal filesystem::directory_iterator itrDir(pathObj); + + g_recursive_counter++; while (itrDir != filesystem::end(itrDir)) { // get entry one by one @@ -77,8 +66,6 @@ bool FileReader(std::string strInputPath) const filesystem::path& currentAbsPath = currentEntry.path(); if (filesystem::is_directory(currentEntry)) { - // 있으면 좋을거같아서 만든 변수 "g_recursive_counter" - g_recursive_counter++; // TODO : export to debugging log function string strDbg = "[INFO] Current Entry (Dir)\t: " + currentAbsPath.string(); strDbg += "\t Counter : " + to_string(g_recursive_counter); @@ -86,8 +73,7 @@ bool FileReader(std::string strInputPath) OutputDebugStringA(strDbg.c_str()); // recursive traversal - bRet = FileReader(currentAbsPath.string()); - g_recursive_counter--; + bRet = FileReader(zip, currentAbsPath.string(), rootPath); } else if (filesystem::is_regular_file(currentEntry)) { @@ -99,7 +85,7 @@ bool FileReader(std::string strInputPath) // archiving file auto relativePath = filesystem::relative(currentAbsPath, rootPath); - bRet = ZipArchiver(relativePath.string()); + bRet = zip.AddFileToZip(relativePath.string()); } else { @@ -110,6 +96,7 @@ bool FileReader(std::string strInputPath) // step forward entry itrDir++; } + g_recursive_counter--; break; } @@ -127,29 +114,53 @@ bool FileReader(std::string strInputPath) break; }; - if(bRet) - { - bRet = ZipArchiver(strInputPath, true); - } - // TODO : 실패 상황 별 다른 코드 부여 + 코드 별 처리 어떻게 할 건지? return bRet; } int main(int argc, char* argv[]) { - std::printf("==================== Hello Zip! ====================\r\n"); + 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"); + + string strInputPath; + getline(cin, strInputPath); + + // Testing input + if (stoi(strInputPath) == 1) + strInputPath = INPUT_FILE_NAME; + else if (stoi(strInputPath) == 2) + strInputPath = INPUT_DIR_NAME; + + filesystem::path absPath = filesystem::absolute(strInputPath); + filesystem::path rootPath = absPath.parent_path(); // Main Zip archive method - if (!FileReader(std::string(INPUT_FILE_NAME))) + MyZip zip; + if (!FileReader(zip, strInputPath, rootPath)) { + printf("[ ERROR ](FileReader) Somthing went Wrong... \r\n"); iRet = -1; - std::printf("[ ERROR ] Somthing went Wrong... \r\n"); } else { - std::printf("==================== Good Bye Zip! ====================\r\n"); + if (!zip.FinalizeZip()) + { + printf("[ ERROR ](Finallize) Somthing went Wrong... \r\n"); + iRet = -1; + } + else + { + printf("It Works Fine. \r\n"); + printf("==================== Good Bye Zip! =================\r\n"); + iRet = 0; + } } return iRet;