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>
+85 -11
View File
@@ -1,16 +1,22 @@
#include <cstdio>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <fstream>
#include <vector>
#include <fstream>
#include <iostream>
#include <filesystem>
#include <string>
#include <debugapi.h>
#include "ZipDefine.h"
#include "CRC.h"
#define INPUT_FILE_NAME "MyZip.txt"
#define OUTPUT_FILE_NAME "MyZip.zip"
bool ZipArchiver();
bool FileReader();
int main()
{
@@ -18,7 +24,7 @@ int main()
int iRet = 0;
// Main Zip archive method
if(!ZipArchiver())
if(!FileReader())
{
iRet = -1;
std::printf("[ ERROR ] Somthing went Wrong... \r\n");
@@ -30,8 +36,13 @@ int main()
return iRet;
}
bool searchDir()
{
bool ZipArchiver()
}
bool FileReader()
{
LocalFileHeader LFHeader{};
CentralDirectory CentDir{};
@@ -47,9 +58,76 @@ bool ZipArchiver()
}
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 으로 구현. 현재는 파일 통짜로 읽음.
fileIn.seekg(0, ios::end); // seekg(offset, 목표점)
fileIn.seekg(0, ios::end); // seekg (offset, 목표점)
streamsize fileInSize = fileIn.tellg();
fileIn.seekg(0, ios::beg); // beg == begin
@@ -155,9 +233,5 @@ bool ZipArchiver()
}
}
// Free
free(pInBuffer);
}
return iRet;
}