test complete.

This commit is contained in:
2026-08-31 16:26:40 +09:00
parent 1b0cf51c38
commit 0b90e87f21
4 changed files with 50 additions and 39 deletions
+1 -1
View File
@@ -73,5 +73,5 @@ ipch/
*.VC.VC.opendb
# Zip Foramt Test
Test
Test*
*.zip
+2 -2
View File
@@ -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
{
+47 -36
View File
@@ -1,32 +1,15 @@
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <filesystem>
#include <vector>
#include <Windows.h>
#include <debugapi.h>
#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;