done with FileReader
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
Hello DNS!
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Hello DNS!
|
||||||
@@ -1,122 +1,26 @@
|
|||||||
#include <cstdio>
|
// 1. C++ 표준 라이브러리 (C 호환 및 C++ 표준을 알파벳 순으로 통합하거나 C/C++ 분리)
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <vector>
|
#include <filesystem>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// 2. OS 전용 / 플랫폼 API (Windows)
|
||||||
|
#include <Windows.h>
|
||||||
#include <debugapi.h>
|
#include <debugapi.h>
|
||||||
|
|
||||||
#include "ZipDefine.h"
|
#include "ZipDefine.h"
|
||||||
#include "CRC.h"
|
#include "CRC.h"
|
||||||
|
|
||||||
#define INPUT_FILE_NAME "MyZip.txt"
|
#define INPUT_FILE_NAME "Target_Dir"
|
||||||
#define OUTPUT_FILE_NAME "MyZip.zip"
|
#define OUTPUT_FILE_NAME "MyZip.zip"
|
||||||
|
|
||||||
static uint32_t RECURSIVE_COUNTER = 0;
|
static uint32_t g_recursive_counter = 0;
|
||||||
|
|
||||||
bool searchDir()
|
bool ZipArchiver(std::string strInputPath, std::string strFileName)
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileReader(std::string strInputPath)
|
|
||||||
{
|
|
||||||
using namespace std;
|
|
||||||
bool iRet = true;
|
|
||||||
|
|
||||||
// path class obj 생성.
|
|
||||||
filesystem::path pathObj(strInputPath);
|
|
||||||
|
|
||||||
// file valid check
|
|
||||||
if (!filesystem::exists(pathObj))
|
|
||||||
{
|
|
||||||
string strDbg = "[ERROR] File not found : " + pathObj.string();
|
|
||||||
OutputDebugStringA(strDbg.c_str());
|
|
||||||
iRet = false;
|
|
||||||
}
|
|
||||||
enum class eFILETYPE
|
|
||||||
{
|
|
||||||
isFile, isDir, ETC
|
|
||||||
};
|
|
||||||
|
|
||||||
// distinguish file type
|
|
||||||
eFILETYPE eFileDist;
|
|
||||||
if (filesystem::is_directory(pathObj)) eFileDist = eFILETYPE::isDir;
|
|
||||||
else if (filesystem::is_regular_file(pathObj)) eFileDist = eFILETYPE::isFile;
|
|
||||||
else eFileDist = eFILETYPE::ETC;
|
|
||||||
|
|
||||||
switch (eFileDist)
|
|
||||||
{
|
|
||||||
// case 1 : input file
|
|
||||||
case eFILETYPE::isFile:
|
|
||||||
{
|
|
||||||
ZipArchiver(pathObj.string());
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// case 2 : input directory
|
|
||||||
case eFILETYPE::isDir:
|
|
||||||
{
|
|
||||||
// make iterator to traversal
|
|
||||||
filesystem::directory_iterator itrDir(pathObj);
|
|
||||||
while (itrDir != filesystem::end(itrDir))
|
|
||||||
{
|
|
||||||
// get entry one by one
|
|
||||||
const filesystem::directory_entry& currentEntry = *itrDir;
|
|
||||||
if (filesystem::is_directory(currentEntry))
|
|
||||||
{
|
|
||||||
RECURSIVE_COUNTER++;
|
|
||||||
string strDbg = "[INFO] Current Entry (Dir)\t: " + currentEntry.path().string() + "\t Counter : " + to_string(RECURSIVE_COUNTER);
|
|
||||||
OutputDebugStringA(strDbg.c_str());
|
|
||||||
|
|
||||||
// recursive traversal
|
|
||||||
iRet = FileReader(currentEntry.path().string());
|
|
||||||
}
|
|
||||||
else if (filesystem::is_regular_file(currentEntry))
|
|
||||||
{
|
|
||||||
RECURSIVE_COUNTER++;
|
|
||||||
string strDbg = "[INFO] Current Entry (File)\t: " + currentEntry.path().string() + "\t Counter : " + to_string(RECURSIVE_COUNTER);
|
|
||||||
OutputDebugStringA(strDbg.c_str());
|
|
||||||
|
|
||||||
// archiving file
|
|
||||||
ZipArchiver(currentEntry.path().string());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// TODO : 근데 애초에 제 3의 Type 이 있나? (여기 의미 있는건가?)
|
|
||||||
OutputDebugStringA("[ERROR] Wrong Type of File");
|
|
||||||
iRet = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// step forward entry
|
|
||||||
itrDir++;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// case 3 : ERROR
|
|
||||||
case eFILETYPE::ETC:
|
|
||||||
{
|
|
||||||
// 이런 경우가 있으려나? 일단 혹시 모르니까
|
|
||||||
string strErr = "[ERROR] Something went Wrong..!!";
|
|
||||||
OutputDebugStringA(strErr.c_str());
|
|
||||||
|
|
||||||
iRet = false;
|
|
||||||
//break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO : 실패 상황 별 다른 코드 부여 + 코드 별 처리 어떻게 할 건지?
|
|
||||||
return iRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ZipArchiver(std::string strInputPath)
|
|
||||||
{
|
{
|
||||||
LocalFileHeader LFHeader{};
|
LocalFileHeader LFHeader{};
|
||||||
CentralDirectory CentDir{};
|
CentralDirectory CentDir{};
|
||||||
@@ -174,7 +78,7 @@ bool ZipArchiver(std::string strInputPath)
|
|||||||
CentDir.sizeOfCompressed = CentDir.sizeOfUncompressed;
|
CentDir.sizeOfCompressed = CentDir.sizeOfUncompressed;
|
||||||
|
|
||||||
// Put File name length
|
// Put File name length
|
||||||
uint16_t fileNameLeng = static_cast<uint16_t>(strlen(INPUT_FILE_NAME));
|
uint16_t fileNameLeng = static_cast<uint16_t>(strFileName.length());
|
||||||
LFHeader.lengthOfFileName = fileNameLeng;
|
LFHeader.lengthOfFileName = fileNameLeng;
|
||||||
CentDir.lengthOfFileName = fileNameLeng;
|
CentDir.lengthOfFileName = fileNameLeng;
|
||||||
|
|
||||||
@@ -238,13 +142,115 @@ bool ZipArchiver(std::string strInputPath)
|
|||||||
return iRet;
|
return iRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileReader(std::string strInputPath)
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
bool iRet = true;
|
||||||
|
|
||||||
|
// path class obj 생성.
|
||||||
|
filesystem::path pathObj(strInputPath);
|
||||||
|
|
||||||
|
// file valid check
|
||||||
|
if (!filesystem::exists(pathObj))
|
||||||
|
{
|
||||||
|
string strDbg = "[ERROR] File not found : " + pathObj.string();
|
||||||
|
strDbg += "\r\n";
|
||||||
|
OutputDebugStringA(strDbg.c_str());
|
||||||
|
iRet = false;
|
||||||
|
}
|
||||||
|
enum class eFILETYPE
|
||||||
|
{
|
||||||
|
isFile, isDir, ETC
|
||||||
|
};
|
||||||
|
|
||||||
|
// distinguish file type
|
||||||
|
eFILETYPE eFileDist;
|
||||||
|
if (filesystem::is_directory(pathObj)) eFileDist = eFILETYPE::isDir;
|
||||||
|
else if (filesystem::is_regular_file(pathObj)) eFileDist = eFILETYPE::isFile;
|
||||||
|
else eFileDist = eFILETYPE::ETC;
|
||||||
|
|
||||||
|
switch (eFileDist)
|
||||||
|
{
|
||||||
|
// case 1 : input file
|
||||||
|
case eFILETYPE::isFile:
|
||||||
|
{
|
||||||
|
iRet = ZipArchiver(pathObj.string(), pathObj.filename().string());
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// case 2 : input directory
|
||||||
|
case eFILETYPE::isDir:
|
||||||
|
{
|
||||||
|
// make iterator to traversal
|
||||||
|
filesystem::directory_iterator itrDir(pathObj);
|
||||||
|
while (itrDir != filesystem::end(itrDir))
|
||||||
|
{
|
||||||
|
// get entry one by one
|
||||||
|
const filesystem::directory_entry& currentEntry = *itrDir;
|
||||||
|
const filesystem::path& currentPath = currentEntry.path();
|
||||||
|
if (filesystem::is_directory(currentEntry))
|
||||||
|
{
|
||||||
|
g_recursive_counter++;
|
||||||
|
// TODO : export to debugging log function
|
||||||
|
string strDbg = "[INFO] Current Entry (Dir)\t: " + currentPath.string();
|
||||||
|
strDbg += "\t Counter : " + to_string(g_recursive_counter);
|
||||||
|
strDbg += "\r\n";
|
||||||
|
OutputDebugStringA(strDbg.c_str());
|
||||||
|
|
||||||
|
// recursive traversal
|
||||||
|
iRet = FileReader(currentPath.string());
|
||||||
|
g_recursive_counter--;
|
||||||
|
}
|
||||||
|
else if (filesystem::is_regular_file(currentEntry))
|
||||||
|
{
|
||||||
|
// TODO : export to debugging log function
|
||||||
|
string strDbg = "[INFO] Current Entry (File)\t: " + currentPath.string();
|
||||||
|
strDbg += "\t Counter : " + to_string(g_recursive_counter);
|
||||||
|
strDbg += "\r\n";
|
||||||
|
|
||||||
|
OutputDebugStringA(strDbg.c_str());
|
||||||
|
|
||||||
|
// archiving file
|
||||||
|
iRet = ZipArchiver(currentPath.string(), currentPath.filename().string());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO : 근데 애초에 제 3의 Type 이 있나? (여기 의미 있는건가?)
|
||||||
|
OutputDebugStringA("[ERROR] Wrong Type of File");
|
||||||
|
iRet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// step forward entry
|
||||||
|
itrDir++;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// case 3 : ERROR
|
||||||
|
case eFILETYPE::ETC:
|
||||||
|
{
|
||||||
|
// 이런 경우가 있으려나? 일단 혹시 모르니까
|
||||||
|
string strErr = "[ERROR] Something went Wrong..!!";
|
||||||
|
OutputDebugStringA(strErr.c_str());
|
||||||
|
|
||||||
|
iRet = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO : 실패 상황 별 다른 코드 부여 + 코드 별 처리 어떻게 할 건지?
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::printf("==================== Hello Zip! ====================\r\n");
|
std::printf("==================== Hello Zip! ====================\r\n");
|
||||||
int iRet = 0;
|
int iRet = 0;
|
||||||
|
|
||||||
// Main Zip archive method
|
// Main Zip archive method
|
||||||
if (!FileReader())
|
if (!FileReader(INPUT_FILE_NAME))
|
||||||
{
|
{
|
||||||
iRet = -1;
|
iRet = -1;
|
||||||
std::printf("[ ERROR ] Somthing went Wrong... \r\n");
|
std::printf("[ ERROR ] Somthing went Wrong... \r\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user