edit to C++20, etc..
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
// CRC-32
|
// CRC-32
|
||||||
|
|||||||
@@ -102,6 +102,9 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||||
|
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@@ -116,6 +119,9 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||||
|
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||||
|
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
|||||||
+10
-1
@@ -1,4 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
@@ -70,6 +70,9 @@ constexpr int LOCAL_FILE_HEADER_BYTE = 30;
|
|||||||
// var[lengthOfExtraField] extraField
|
// var[lengthOfExtraField] extraField
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 정적 메모리 사이즈 검사
|
||||||
|
static_assert(sizeof(LocalFileHeader) == LOCAL_FILE_HEADER_BYTE, "LocalFileHeader Size is mismatch");
|
||||||
|
|
||||||
/** Central directory structure:
|
/** Central directory structure:
|
||||||
|
|
||||||
[central directory header 1]
|
[central directory header 1]
|
||||||
@@ -130,6 +133,9 @@ constexpr int LOCAL_FILE_HEADER_BYTE = 30;
|
|||||||
// var[lengthOfFileComment] fileComment
|
// var[lengthOfFileComment] fileComment
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 정적 메모리 사이즈 검사
|
||||||
|
static_assert(sizeof(CentralDirectory) == CENTRAL_DIRECTORY_BYTE, "CentralDirectory Size is mismatch");
|
||||||
|
|
||||||
/** End of central directory record:
|
/** End of central directory record:
|
||||||
|
|
||||||
end of central dir signature 4 bytes (0x0605 + 4b50)
|
end of central dir signature 4 bytes (0x0605 + 4b50)
|
||||||
@@ -179,4 +185,7 @@ constexpr int LOCAL_FILE_HEADER_BYTE = 30;
|
|||||||
// var[LengthOfCommentLength] zipFileComment
|
// var[LengthOfCommentLength] zipFileComment
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 정적 메모리 사이즈 검사
|
||||||
|
static_assert(sizeof(EoCDRecord) == EOCD_BYTE);
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -17,46 +17,25 @@ int main()
|
|||||||
std::printf("==================== Hello Zip! ====================\r\n");
|
std::printf("==================== Hello Zip! ====================\r\n");
|
||||||
int iRet = 0;
|
int iRet = 0;
|
||||||
|
|
||||||
// Zip Format define check
|
|
||||||
// 생성자를 만들어서, 생성되면서 사이즈 검사?
|
|
||||||
|
|
||||||
size_t iSizeTest = sizeof(LocalFileHeader);
|
|
||||||
if (LOCAL_FILE_HEADER_BYTE != iSizeTest)
|
|
||||||
{
|
|
||||||
std::printf("1 Wrong Header Size : %zu / %d \r\n", iSizeTest, LOCAL_FILE_HEADER_BYTE);
|
|
||||||
iRet = -1;
|
|
||||||
}
|
|
||||||
iSizeTest = sizeof(CentralDirectory);
|
|
||||||
if (CENTRAL_DIRECTORY_BYTE != iSizeTest)
|
|
||||||
{
|
|
||||||
std::printf("2 Wrong Header Size : %zu / %d \r\n", iSizeTest, CENTRAL_DIRECTORY_BYTE);
|
|
||||||
iRet = -1;
|
|
||||||
}
|
|
||||||
iSizeTest = sizeof(EoCDRecord);
|
|
||||||
if (EOCD_BYTE != iSizeTest)
|
|
||||||
{
|
|
||||||
std::printf("3 Wrong Header Size : %zu / %d \r\n", iSizeTest, EOCD_BYTE);
|
|
||||||
iRet = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main Zip archive method
|
// Main Zip archive method
|
||||||
if (iRet != -1)
|
if(!ZipArchiver())
|
||||||
{
|
{
|
||||||
if(!ZipArchiver())
|
iRet = -1;
|
||||||
{
|
std::printf("[ ERROR ] Somthing went Wrong... \r\n");
|
||||||
iRet = -1;
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
std::printf("==================== Good Bye Zip! ====================\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::printf("==================== Good Bye Zip! ====================\r\n");
|
|
||||||
return iRet;
|
return iRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZipArchiver()
|
bool ZipArchiver()
|
||||||
{
|
{
|
||||||
LocalFileHeader LFHeader = {};
|
LocalFileHeader LFHeader{};
|
||||||
CentralDirectory CentDir = {};
|
CentralDirectory CentDir{};
|
||||||
EoCDRecord EOCDR = {};
|
EoCDRecord EOCDR{};
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -77,6 +56,7 @@ bool ZipArchiver()
|
|||||||
|
|
||||||
// TODO : Buffering 으로 구현. 현재는 파일 통짜로 읽음.
|
// TODO : Buffering 으로 구현. 현재는 파일 통짜로 읽음.
|
||||||
// 메모리 할당
|
// 메모리 할당
|
||||||
|
// TODO : 자동으로 free 되는 구조로 변경
|
||||||
auto pFile = (char *)malloc(fileInSize);
|
auto pFile = (char *)malloc(fileInSize);
|
||||||
|
|
||||||
// Read
|
// Read
|
||||||
@@ -117,7 +97,7 @@ bool ZipArchiver()
|
|||||||
CentDir.sizeOfCompressed = CentDir.sizeOfUncompressed;
|
CentDir.sizeOfCompressed = CentDir.sizeOfUncompressed;
|
||||||
|
|
||||||
// Put File name length
|
// Put File name length
|
||||||
uint16_t fileNameLeng = strlen(INPUT_FILE_NAME);
|
uint16_t fileNameLeng = static_cast<uint16_t>(strlen(INPUT_FILE_NAME));
|
||||||
LFHeader.lengthOfFileName = fileNameLeng;
|
LFHeader.lengthOfFileName = fileNameLeng;
|
||||||
CentDir.lengthOfFileName = fileNameLeng;
|
CentDir.lengthOfFileName = fileNameLeng;
|
||||||
|
|
||||||
@@ -153,8 +133,10 @@ bool ZipArchiver()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 1. Local File Header, file name (var), extra field (var)
|
// 1. Local File Header, file name (var), extra field (var)
|
||||||
CentDir.offsetLocalFileHeader = fileOut.tellp();
|
CentDir.offsetLocalFileHeader = static_cast<uint32_t>(fileOut.tellp());
|
||||||
// TODO : sizeof 의 값이 스펙과 정확히 일치한다는 보장 필요 (현재는 compiler 에 종속적)
|
// TODO : sizeof 의 값이 스펙과 정확히 일치한다는 보장 필요 (현재는 compiler 에 종속적)
|
||||||
|
// : offsetof((LocalFileHeader, crc32) 으로 멤버별 static_assert 로 변경할 지 고민.
|
||||||
|
// : 아니면 필드 단위 직접쓰기로 struct 분해하기?
|
||||||
fileOut.write(reinterpret_cast<const char*>(&LFHeader), sizeof(LFHeader));
|
fileOut.write(reinterpret_cast<const char*>(&LFHeader), sizeof(LFHeader));
|
||||||
fileOut.write(INPUT_FILE_NAME, LFHeader.lengthOfFileName);
|
fileOut.write(INPUT_FILE_NAME, LFHeader.lengthOfFileName);
|
||||||
//fileOut.write(NOT_USED, LFHeader.LFHeader.lengthOfExtraField);
|
//fileOut.write(NOT_USED, LFHeader.LFHeader.lengthOfExtraField);
|
||||||
@@ -163,7 +145,7 @@ bool ZipArchiver()
|
|||||||
fileOut.write(pFile, fileInSize);
|
fileOut.write(pFile, fileInSize);
|
||||||
|
|
||||||
// 3. CentralDirectory, file name (var)
|
// 3. CentralDirectory, file name (var)
|
||||||
EOCDR.offsetCentralDir = fileOut.tellp();
|
EOCDR.offsetCentralDir = static_cast<uint32_t>(fileOut.tellp());
|
||||||
// TODO : sizeof 의 값이 스펙과 정확히 일치한다는 보장 필요 (현재는 compiler 에 종속적)
|
// TODO : sizeof 의 값이 스펙과 정확히 일치한다는 보장 필요 (현재는 compiler 에 종속적)
|
||||||
fileOut.write(reinterpret_cast<const char*>(&CentDir), sizeof(CentDir));
|
fileOut.write(reinterpret_cast<const char*>(&CentDir), sizeof(CentDir));
|
||||||
fileOut.write(INPUT_FILE_NAME, CentDir.lengthOfFileName);
|
fileOut.write(INPUT_FILE_NAME, CentDir.lengthOfFileName);
|
||||||
|
|||||||
Reference in New Issue
Block a user