add dir recursiv search

This commit is contained in:
2026-08-28 13:46:38 +09:00
parent 5c7a33f665
commit ac77b61cc4
2 changed files with 179 additions and 105 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
+84 -10
View File
@@ -1,16 +1,22 @@
#include <cstdio> #include <cstdio>
#include <iostream> #include <cstdint>
#include <cstring> #include <cstring>
#include <fstream>
#include <vector> #include <vector>
#include <fstream>
#include <iostream>
#include <filesystem>
#include <string>
#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 "MyZip.txt"
#define OUTPUT_FILE_NAME "MyZip.zip" #define OUTPUT_FILE_NAME "MyZip.zip"
bool ZipArchiver(); bool FileReader();
int main() int main()
{ {
@@ -18,7 +24,7 @@ int main()
int iRet = 0; int iRet = 0;
// Main Zip archive method // Main Zip archive method
if(!ZipArchiver()) if(!FileReader())
{ {
iRet = -1; iRet = -1;
std::printf("[ ERROR ] Somthing went Wrong... \r\n"); std::printf("[ ERROR ] Somthing went Wrong... \r\n");
@@ -30,8 +36,13 @@ int main()
return iRet; return iRet;
} }
bool searchDir()
{
bool ZipArchiver() }
bool FileReader()
{ {
LocalFileHeader LFHeader{}; LocalFileHeader LFHeader{};
CentralDirectory CentDir{}; CentralDirectory CentDir{};
@@ -46,6 +57,73 @@ bool ZipArchiver()
printf("FileIn open failed"); printf("FileIn open failed");
} }
else else
{
// path class obj 생성.
filesystem::path pathObj(INPUT_FILE_NAME);
// file valid check
if (!filesystem::exists(pathObj))
{
string strErr = "File not found : " + pathObj.string();
OutputDebugStringA(strErr.c_str());
return false;
}
if (!filesystem::is_regular_file(pathObj))
{
string strErr = "File is not regular file : " + pathObj.string();
OutputDebugStringA(strErr.c_str());
// directory recursive search
if (filesystem::is_directory(pathObj))
{
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))
{
// TODO : 다시 위로 돌아가야 함 + 재귀적으로 돌아가면서 처리
// Do Something...
}
else if(filesystem::is_regular_file(currentEntry))
{
// TODO : 파일 Archiving logic
ZipArchiver();
}
else
{
// 애초에 제 3의 Type 이 있나?
OutputDebugStringA("Wrong Type of File");
}
// step forward entry
itrDir++;
}
}
else
{
// 이런 경우가 있으려나? 일단 혹시 모르니까
string strErr = "Something went Wrong..!!";
OutputDebugStringA(strErr.c_str());
return false;
}
}
else
{
ZipArchiver();
}
}
// TODO : 어떤 식으로 Return 할 건지 하나만 정하기
return iRet;
}
bool ZipArchiver()
{ {
// 파일 크기 계산 // 파일 크기 계산
// TODO : Buffering 으로 구현. 현재는 파일 통짜로 읽음. // TODO : Buffering 으로 구현. 현재는 파일 통짜로 읽음.
@@ -155,9 +233,5 @@ bool ZipArchiver()
} }
} }
// Free
free(pInBuffer);
}
return iRet; return iRet;
} }