edit to C++20, etc..

This commit is contained in:
2026-08-27 16:31:21 +09:00
parent 3b69a9a197
commit e5fca22c7d
5 changed files with 36 additions and 37 deletions
+2
View File
@@ -0,0 +1,2 @@
[*]
charset = utf-8
+1 -1
View File
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <cstdint>
// CRC-32
+6
View File
@@ -102,6 +102,9 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -116,6 +119,9 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
+10 -1
View File
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <cstdint>
@@ -70,6 +70,9 @@ constexpr int LOCAL_FILE_HEADER_BYTE = 30;
// var[lengthOfExtraField] extraField
};
// 정적 메모리 사이즈 검사
static_assert(sizeof(LocalFileHeader) == LOCAL_FILE_HEADER_BYTE, "LocalFileHeader Size is mismatch");
/** Central directory structure:
[central directory header 1]
@@ -130,6 +133,9 @@ constexpr int LOCAL_FILE_HEADER_BYTE = 30;
// var[lengthOfFileComment] fileComment
};
// 정적 메모리 사이즈 검사
static_assert(sizeof(CentralDirectory) == CENTRAL_DIRECTORY_BYTE, "CentralDirectory Size is mismatch");
/** End of central directory record:
end of central dir signature 4 bytes (0x0605 + 4b50)
@@ -179,4 +185,7 @@ constexpr int LOCAL_FILE_HEADER_BYTE = 30;
// var[LengthOfCommentLength] zipFileComment
};
// 정적 메모리 사이즈 검사
static_assert(sizeof(EoCDRecord) == EOCD_BYTE);
#pragma pack(pop)
+14 -32
View File
@@ -1,4 +1,4 @@
#include <cstdio>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <fstream>
@@ -17,46 +17,25 @@ int main()
std::printf("==================== Hello Zip! ====================\r\n");
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
if (iRet != -1)
{
if(!ZipArchiver())
{
iRet = -1;
std::printf("[ ERROR ] Somthing went Wrong... \r\n");
}
else
{
std::printf("==================== Good Bye Zip! ====================\r\n");
}
std::printf("==================== Good Bye Zip! ====================\r\n");
return iRet;
}
bool ZipArchiver()
{
LocalFileHeader LFHeader = {};
CentralDirectory CentDir = {};
EoCDRecord EOCDR = {};
LocalFileHeader LFHeader{};
CentralDirectory CentDir{};
EoCDRecord EOCDR{};
using namespace std;
@@ -77,6 +56,7 @@ bool ZipArchiver()
// TODO : Buffering 으로 구현. 현재는 파일 통짜로 읽음.
// 메모리 할당
// TODO : 자동으로 free 되는 구조로 변경
auto pFile = (char *)malloc(fileInSize);
// Read
@@ -117,7 +97,7 @@ bool ZipArchiver()
CentDir.sizeOfCompressed = CentDir.sizeOfUncompressed;
// 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;
CentDir.lengthOfFileName = fileNameLeng;
@@ -153,8 +133,10 @@ bool ZipArchiver()
else
{
// 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 에 종속적)
// : offsetof((LocalFileHeader, crc32) 으로 멤버별 static_assert 로 변경할 지 고민.
// : 아니면 필드 단위 직접쓰기로 struct 분해하기?
fileOut.write(reinterpret_cast<const char*>(&LFHeader), sizeof(LFHeader));
fileOut.write(INPUT_FILE_NAME, LFHeader.lengthOfFileName);
//fileOut.write(NOT_USED, LFHeader.LFHeader.lengthOfExtraField);
@@ -163,7 +145,7 @@ bool ZipArchiver()
fileOut.write(pFile, fileInSize);
// 3. CentralDirectory, file name (var)
EOCDR.offsetCentralDir = fileOut.tellp();
EOCDR.offsetCentralDir = static_cast<uint32_t>(fileOut.tellp());
// TODO : sizeof 의 값이 스펙과 정확히 일치한다는 보장 필요 (현재는 compiler 에 종속적)
fileOut.write(reinterpret_cast<const char*>(&CentDir), sizeof(CentDir));
fileOut.write(INPUT_FILE_NAME, CentDir.lengthOfFileName);