| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Descent Developers |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | #pragma once |
| 19 | |
| 20 | #include <array> |
| 21 | #include <cstdint> |
| 22 | #include <filesystem> |
| 23 | #include <vector> |
| 24 | |
| 25 | #include "IOOps.h"cxx . . $ `<file>/lib/IOOps.h`/ |
| 26 | |
| 27 | namespace D3cxx . . $ D3/ { |
| 28 | |
| 29 | /* |
| 30 | HOG FILE FORMAT v2.0 |
| 31 | |
| 32 | HOG_TAG_STR [strlen()] |
| 33 | NFILES [int32] |
| 34 | HDRINFO [HOG_HDR_SIZE] |
| 35 | FILE_TABLE [sizeof(FILE_ENTRY) * NFILES] |
| 36 | FILE 0 [filelen(FILE 0)] |
| 37 | FILE 1 [filelen(FILE 1)] |
| 38 | ... |
| 39 | FILE NFILES-1 [filelen(NFILES -1)] |
| 40 | */ |
| 41 | |
| 42 | static inline stdcxx . . $ std/::arraycxx . . $ std/array#<char, 56> array_withcxx . . $ D3/array_with(b07c219066c38f0f).(char val) { |
| 43 | stdcxx . . $ std/::arraycxx . . $ std/array#<char, 56> arr; |
| 44 | arr.fillcxx . . $ std/array#fill(77d9f17553126ecb).(val); |
| 45 | return arr; |
| 46 | } |
| 47 | |
| 48 | struct HogHeadercxx . . $ D3/HogHeader# { |
| 49 | stdcxx . . $ std/::arraycxx . . $ std/array#<char, 4> tagcxx . . $ D3/HogHeader#tag. = {'H', 'O', 'G', '2'}; // "HOG2" |
| 50 | uint32_tcxx . . $ uint32_t# nfilescxx . . $ D3/HogHeader#nfiles. = 0; // number of files in header |
| 51 | uint32_tcxx . . $ uint32_t# file_data_offsetcxx . . $ D3/HogHeader#file_data_offset. = 68; // offset in file to filedata. |
| 52 | stdcxx . . $ std/::arraycxx . . $ std/array#<char, 56> reservedcxx . . $ D3/HogHeader#reserved. = array_withcxx . . $ D3/array_with(b07c219066c38f0f).(-1); // filled with 0xff |
| 53 | }; |
| 54 | |
| 55 | class HogFileEntrycxx . . $ D3/HogFileEntry# { |
| 56 | private: |
| 57 | stdcxx . . $ std/::arraycxx . . $ std/array#<char, 36> m_namecxx . . $ D3/HogFileEntry#m_name. = {}; // file name (36 char max) |
| 58 | uint32_tcxx . . $ uint32_t# m_flagscxx . . $ D3/HogFileEntry#m_flags. = 0; // extra info |
| 59 | uint32_tcxx . . $ uint32_t# m_lencxx . . $ D3/HogFileEntry#m_len. = 0; // length of file |
| 60 | uint32_tcxx . . $ uint32_t# m_timestampcxx . . $ D3/HogFileEntry#m_timestamp. = 0; // time of file |
| 61 | stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# m_real_pathcxx . . $ D3/HogFileEntry#m_real_path. =cxx . . $ std/filesystem/__cxx11/path#path(ced63f7c635d850d). {}; // real path |
| 62 | |
| 63 | public: |
| 64 | HogFileEntrycxx . . $ D3/HogFileEntry#HogFileEntry(49f6e7a06ebc5aa8).() = default; |
| 65 | explicit HogFileEntrycxx . . $ D3/HogFileEntry#HogFileEntry(3f42e2c2fac0d5fc).(const stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# &input); |
| 66 | explicit HogFileEntrycxx . . $ D3/HogFileEntry#HogFileEntry(10a998ea586f42cf).(stdcxx . . $ std/::stringcxx . . $ std/string# name, uint32_tcxx . . $ uint32_t# flags = 0, uint32_tcxx . . $ uint32_t# len = 0, uint32_tcxx . . $ uint32_t# timestamp = 0); |
| 67 | |
| 68 | stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# GetRealPathcxx . . $ D3/HogFileEntry#GetRealPath(159787a050b29eb0).() const { return m_real_pathcxx . . $ std/filesystem/__cxx11/path#path(3f42e2c2fac0d5fc).; } |
| 69 | void SetRealPathcxx . . $ D3/HogFileEntry#SetRealPath(3f42e2c2fac0d5fc).(const stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# &input); |
| 70 | |
| 71 | stdcxx . . $ std/::stringcxx . . $ std/string# GetNamecxx . . $ D3/HogFileEntry#GetName(219584694fe2b248).() const { return {cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).m_namecxx . . $ D3/HogFileEntry#m_name..datacxx . . $ std/array#data(8e614c7de0b1573e).()}; }; |
| 72 | |
| 73 | friend stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &operatorcxx . . $ D3/`operator<<`(54e5c9f58215b93).<<(stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &output, const HogFileEntrycxx . . $ D3/HogFileEntry# &entry); |
| 74 | friend class HogFormatcxx . . $ D3/HogFormat#; |
| 75 | }; |
| 76 | |
| 77 | class HogFormatcxx . . $ D3/HogFormat# { |
| 78 | private: |
| 79 | HogHeadercxx . . $ D3/HogHeader# m_headercxx . . $ D3/HogFormat#m_header.; |
| 80 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<HogFileEntrycxx . . $ D3/HogFileEntry#> m_file_entriescxx . . $ D3/HogFormat#m_file_entries.; |
| 81 | |
| 82 | public: |
| 83 | void AddEntrycxx . . $ D3/HogFormat#AddEntry(de61f79b9371789b).(const HogFileEntrycxx . . $ D3/HogFileEntry# &entry) { |
| 84 | m_file_entriescxx . . $ D3/HogFormat#m_file_entries..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(entry); |
| 85 | m_headercxx . . $ D3/HogFormat#m_header..nfilescxx . . $ D3/HogHeader#nfiles.++; |
| 86 | m_headercxx . . $ D3/HogFormat#m_header..file_data_offsetcxx . . $ D3/HogHeader#file_data_offset. += 48; |
| 87 | }; |
| 88 | |
| 89 | /** |
| 90 | * Sort entries case-insensitive alphabetically. Call this method before any |
| 91 | * writing on disk: Descent 3 expects that entries in HOG are sorted. |
| 92 | */ |
| 93 | void SortEntriescxx . . $ D3/HogFormat#SortEntries(49f6e7a06ebc5aa8).(); |
| 94 | |
| 95 | uint32_tcxx . . $ uint32_t# Countcxx . . $ D3/HogFormat#Count(ddd8539a2fcdd4ce).() const { return m_headercxx . . $ D3/HogFormat#m_header..nfilescxx . . $ D3/HogHeader#nfiles.; } |
| 96 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<HogFileEntrycxx . . $ D3/HogFileEntry#> GetEntriescxx . . $ D3/HogFormat#GetEntries(36904b49bbb244ed).() const { return m_file_entriescxx . . $ D3/HogFormat#m_file_entries.; } |
| 97 | |
| 98 | friend stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &operatorcxx . . $ D3/`operator<<`(ddf1f55e3333f4c5).<<(stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &output, const HogFormatcxx . . $ D3/HogFormat# &format); |
| 99 | }; |
| 100 | |
| 101 | } // namespace D3 |