test complete.
This commit is contained in:
+1
-1
@@ -73,5 +73,5 @@ ipch/
|
|||||||
*.VC.VC.opendb
|
*.VC.VC.opendb
|
||||||
|
|
||||||
# Zip Foramt Test
|
# Zip Foramt Test
|
||||||
Test
|
Test*
|
||||||
*.zip
|
*.zip
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
#include "ZipDefine.h"
|
#include "ZipDefine.h"
|
||||||
#include "CRC.h"
|
#include "CRC.h"
|
||||||
|
|
||||||
#define OUTPUT_FILE_NAME "MyZip.zip"
|
|
||||||
#define INPUT_FILE_NAME "Target_File.txt"
|
#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
|
class MyZip
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,32 +1,15 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstring>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <debugapi.h>
|
#include <debugapi.h>
|
||||||
|
|
||||||
#include "ZipDefine.h"
|
|
||||||
#include "CRC.h"
|
|
||||||
#include "MyZip.h"
|
#include "MyZip.h"
|
||||||
|
|
||||||
static uint32_t g_recursive_counter = 0;
|
static uint32_t g_recursive_counter = 0;
|
||||||
|
|
||||||
bool ZipArchiver(std::string strInputPath, bool bIsFinal = false)
|
bool FileReader(MyZip &zip, std::string strInputPath, const std::filesystem::path &rootPath)
|
||||||
{
|
|
||||||
MyZip zip;
|
|
||||||
bool bRet = false;
|
|
||||||
|
|
||||||
bRet = zip.AddFileToZip(strInputPath);
|
|
||||||
if(bIsFinal)
|
|
||||||
bRet = zip.FinalizeZip();
|
|
||||||
|
|
||||||
return bRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileReader(std::string strInputPath)
|
|
||||||
{
|
{
|
||||||
using namespace std;
|
using namespace std;
|
||||||
bool bRet = true;
|
bool bRet = true;
|
||||||
@@ -54,14 +37,18 @@ bool FileReader(std::string strInputPath)
|
|||||||
else if (filesystem::is_regular_file(pathObj)) eFileDist = eFILETYPE::isFile;
|
else if (filesystem::is_regular_file(pathObj)) eFileDist = eFILETYPE::isFile;
|
||||||
else eFileDist = eFILETYPE::ETC;
|
else eFileDist = eFILETYPE::ETC;
|
||||||
|
|
||||||
const filesystem::path& rootPath = pathObj;
|
|
||||||
switch (eFileDist)
|
switch (eFileDist)
|
||||||
{
|
{
|
||||||
// case 1 : input file
|
// case 1 : input one file
|
||||||
case eFILETYPE::isFile:
|
case eFILETYPE::isFile:
|
||||||
{
|
{
|
||||||
bool bIsFinal = g_recursive_counter > 0 ? false : true;
|
// TODO : export to debugging log function
|
||||||
bRet = ZipArchiver(pathObj.string(), bIsFinal );
|
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;
|
break;
|
||||||
}
|
}
|
||||||
@@ -70,6 +57,8 @@ bool FileReader(std::string strInputPath)
|
|||||||
{
|
{
|
||||||
// make iterator to traversal
|
// make iterator to traversal
|
||||||
filesystem::directory_iterator itrDir(pathObj);
|
filesystem::directory_iterator itrDir(pathObj);
|
||||||
|
|
||||||
|
g_recursive_counter++;
|
||||||
while (itrDir != filesystem::end(itrDir))
|
while (itrDir != filesystem::end(itrDir))
|
||||||
{
|
{
|
||||||
// get entry one by one
|
// get entry one by one
|
||||||
@@ -77,8 +66,6 @@ bool FileReader(std::string strInputPath)
|
|||||||
const filesystem::path& currentAbsPath = currentEntry.path();
|
const filesystem::path& currentAbsPath = currentEntry.path();
|
||||||
if (filesystem::is_directory(currentEntry))
|
if (filesystem::is_directory(currentEntry))
|
||||||
{
|
{
|
||||||
// 있으면 좋을거같아서 만든 변수 "g_recursive_counter"
|
|
||||||
g_recursive_counter++;
|
|
||||||
// TODO : export to debugging log function
|
// TODO : export to debugging log function
|
||||||
string strDbg = "[INFO] Current Entry (Dir)\t: " + currentAbsPath.string();
|
string strDbg = "[INFO] Current Entry (Dir)\t: " + currentAbsPath.string();
|
||||||
strDbg += "\t Counter : " + to_string(g_recursive_counter);
|
strDbg += "\t Counter : " + to_string(g_recursive_counter);
|
||||||
@@ -86,8 +73,7 @@ bool FileReader(std::string strInputPath)
|
|||||||
OutputDebugStringA(strDbg.c_str());
|
OutputDebugStringA(strDbg.c_str());
|
||||||
|
|
||||||
// recursive traversal
|
// recursive traversal
|
||||||
bRet = FileReader(currentAbsPath.string());
|
bRet = FileReader(zip, currentAbsPath.string(), rootPath);
|
||||||
g_recursive_counter--;
|
|
||||||
}
|
}
|
||||||
else if (filesystem::is_regular_file(currentEntry))
|
else if (filesystem::is_regular_file(currentEntry))
|
||||||
{
|
{
|
||||||
@@ -99,7 +85,7 @@ bool FileReader(std::string strInputPath)
|
|||||||
|
|
||||||
// archiving file
|
// archiving file
|
||||||
auto relativePath = filesystem::relative(currentAbsPath, rootPath);
|
auto relativePath = filesystem::relative(currentAbsPath, rootPath);
|
||||||
bRet = ZipArchiver(relativePath.string());
|
bRet = zip.AddFileToZip(relativePath.string());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -110,6 +96,7 @@ bool FileReader(std::string strInputPath)
|
|||||||
// step forward entry
|
// step forward entry
|
||||||
itrDir++;
|
itrDir++;
|
||||||
}
|
}
|
||||||
|
g_recursive_counter--;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -127,29 +114,53 @@ bool FileReader(std::string strInputPath)
|
|||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
if(bRet)
|
|
||||||
{
|
|
||||||
bRet = ZipArchiver(strInputPath, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO : 실패 상황 별 다른 코드 부여 + 코드 별 처리 어떻게 할 건지?
|
// TODO : 실패 상황 별 다른 코드 부여 + 코드 별 처리 어떻게 할 건지?
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
std::printf("==================== Hello Zip! ====================\r\n");
|
using namespace std;
|
||||||
|
|
||||||
int iRet = 0;
|
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
|
// 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;
|
iRet = -1;
|
||||||
std::printf("[ ERROR ] Somthing went Wrong... \r\n");
|
|
||||||
}
|
}
|
||||||
else
|
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;
|
return iRet;
|
||||||
|
|||||||
Reference in New Issue
Block a user