| 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 |
|
| 19 |
#include <algorithm> |
| 20 |
#include <fstream> |
| 21 |
#include <iterator> |
| 22 |
|
| 23 |
#include "HogFormat.h"cxx . . $ `<file>/tools/HogMaker/HogFormat.h`/ |
| 24 |
#include "IOOps.h"cxx . . $ `<file>/lib/IOOps.h`/ |
| 25 |
|
| 26 |
namespace D3cxx . . $ D3/ { |
| 27 |
|
| 28 |
// TODO: To our descendants from the future: remove it when code will support C++20 |
| 29 |
template <typename TP> stdcxx . . $ std/::time_tcxx . . $ std/time_t# to_time_tcxx . . $ D3/to_time_t(5acf241e44d4ac27).(TP tp) { |
| 30 |
auto sctp = stdcxx . . $ std/::chronocxx . . $ std/chrono/::duration_castcxx . . $ std/chrono/duration_cast(b7f67bf9c2f19806).<stdcxx . . $ std/::chronocxx . . $ std/chrono/::system_clockcxx . . $ std/chrono/_V2/system_clock#::durationcxx . . $ std/chrono/_V2/system_clock#duration#>(tp - TP::clock::now()) + |
| 31 |
stdcxx . . $ std/::chronocxx . . $ std/chrono/::system_clockcxx . . $ std/chrono/_V2/system_clock#::nowcxx . . $ std/chrono/_V2/system_clock#now(3657dacbd9b4f607).(); |
| 32 |
return stdcxx . . $ std/::chronocxx . . $ std/chrono/::system_clockcxx . . $ std/chrono/_V2/system_clock#::to_time_tcxx . . $ std/chrono/_V2/system_clock#to_time_t(88d50d0742db4f1).(sctp); |
| 33 |
} |
| 34 |
|
| 35 |
HogFileEntrycxx . . $ D3/HogFileEntry#::HogFileEntrycxx . . $ D3/HogFileEntry#HogFileEntry(3f42e2c2fac0d5fc).(const stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# &input) { |
| 36 |
m_real_pathcxx . . $ D3/HogFileEntry#m_real_path. =cxx . . $ std/filesystem/__cxx11/path#`operator=`(554473e25f389c7d). input; |
| 37 |
m_flagscxx . . $ D3/HogFileEntry#m_flags. = 0; |
| 38 |
m_lencxx . . $ D3/HogFileEntry#m_len. = (uint32_tcxx . . $ uint32_t#)file_sizecxx . . $ std/filesystem/file_size(fef9a1c7f0154599).(input); |
| •39 |
m_timestampcxx . . $ D3/HogFileEntry#m_timestamp. = 0; |
| 40 |
auto name = input.filenamecxx . . $ std/filesystem/__cxx11/path#filename(159787a050b29eb0).().u8stringcxx . . $ std/filesystem/__cxx11/path#u8string(219584694fe2b248).(); |
| 41 |
stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4).(name.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), name.endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), m_namecxx . . $ D3/HogFileEntry#m_name..begincxx . . $ std/array#begin(258ee1c9e0a18a5c).()); |
| 42 |
} |
| 43 |
|
| 44 |
HogFileEntrycxx . . $ D3/HogFileEntry#::HogFileEntrycxx . . $ D3/HogFileEntry#HogFileEntry(10a998ea586f42cf).(stdcxx . . $ std/::stringcxx . . $ std/string# name, uint32_tcxx . . $ uint32_t# flags, uint32_tcxx . . $ uint32_t# len, uint32_tcxx . . $ uint32_t# timestamp) { |
| 45 |
stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4).(name.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), name.endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), m_namecxx . . $ D3/HogFileEntry#m_name..begincxx . . $ std/array#begin(258ee1c9e0a18a5c).()); |
| 46 |
m_flagscxx . . $ D3/HogFileEntry#m_flags. = flags; |
| 47 |
m_lencxx . . $ D3/HogFileEntry#m_len. = len; |
| 48 |
m_timestampcxx . . $ D3/HogFileEntry#m_timestamp. = timestamp; |
| 49 |
} |
| 50 |
|
| 51 |
void HogFileEntrycxx . . $ D3/HogFileEntry#::SetRealPathcxx . . $ D3/HogFileEntry#SetRealPath(3f42e2c2fac0d5fc).(const stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# &input) { |
| 52 |
m_real_pathcxx . . $ D3/HogFileEntry#m_real_path. =cxx . . $ std/filesystem/__cxx11/path#`operator=`(554473e25f389c7d). input; |
| 53 |
m_flagscxx . . $ D3/HogFileEntry#m_flags. = 0; |
| 54 |
m_lencxx . . $ D3/HogFileEntry#m_len. = (uint32_tcxx . . $ uint32_t#)file_sizecxx . . $ std/filesystem/file_size(fef9a1c7f0154599).(input); |
| 55 |
m_timestampcxx . . $ D3/HogFileEntry#m_timestamp. = (uint32_tcxx . . $ uint32_t#)to_time_tcxx . . $ D3/to_time_t(5acf241e44d4ac27).(last_write_timecxx . . $ std/filesystem/last_write_time(63b598588f2cda1a).(input)); |
| 56 |
auto name = input.filenamecxx . . $ std/filesystem/__cxx11/path#filename(159787a050b29eb0).().u8stringcxx . . $ std/filesystem/__cxx11/path#u8string(219584694fe2b248).(); |
| 57 |
stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4).(name.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), name.endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), m_namecxx . . $ D3/HogFileEntry#m_name..begincxx . . $ std/array#begin(258ee1c9e0a18a5c).()); |
| 58 |
} |
| 59 |
|
| 60 |
stdcxx . . $ std/::arraycxx . . $ std/array#<char, 36> char_tolowercxx . . $ D3/char_tolower(6e4ececcd47d60a0).(stdcxx . . $ std/::arraycxx . . $ std/array#<char, 36> s) { |
| 61 |
stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).(s.begincxx . . $ std/array#begin(258ee1c9e0a18a5c).(), s.endcxx . . $ std/array#end(258ee1c9e0a18a5c).(), s.begincxx . . $ std/array#begin(258ee1c9e0a18a5c).(), [](uint8_tcxx . . $ uint8_t# c) { return stdcxx . . $ std/::tolowercxx . . $ std/tolower(a1851578aea3f541).(c); }); |
| 62 |
return s; |
| 63 |
} |
| 64 |
|
| 65 |
stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &operatorcxx . . $ D3/`operator<<`(13d65a7695c851c6).<<(stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &output, const HogHeadercxx . . $ D3/HogHeader# &header) { |
| 66 |
stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4).(header.tagcxx . . $ D3/HogHeader#tag..begincxx . . $ std/array#begin(8e614c7de0b1573e).(), header.tagcxx . . $ D3/HogHeader#tag..endcxx . . $ std/array#end(8e614c7de0b1573e).(), stdcxx . . $ std/::ostream_iteratorcxx . . $ std/ostream_iterator#<char>(output)); |
| 67 |
bin_writecxx . . $ D3/bin_write(b9bf9de5c7808980).(output, header.nfilescxx . . $ D3/HogHeader#nfiles.); |
| 68 |
bin_writecxx . . $ D3/bin_write(b9bf9de5c7808980).(output, header.file_data_offsetcxx . . $ D3/HogHeader#file_data_offset.); |
| 69 |
stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4).(header.reservedcxx . . $ D3/HogHeader#reserved..begincxx . . $ std/array#begin(8e614c7de0b1573e).(), header.reservedcxx . . $ D3/HogHeader#reserved..endcxx . . $ std/array#end(8e614c7de0b1573e).(), stdcxx . . $ std/::ostream_iteratorcxx . . $ std/ostream_iterator#<char>(output)); |
| 70 |
|
| 71 |
return output; |
| 72 |
} |
| 73 |
|
| 74 |
stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &operatorcxx . . $ D3/`operator<<`(54e5c9f58215b93).<<(stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &output, const HogFileEntrycxx . . $ D3/HogFileEntry# &entry) { |
| 75 |
stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4).(entry.m_namecxx . . $ D3/HogFileEntry#m_name..begincxx . . $ std/array#begin(8e614c7de0b1573e).(), entry.m_namecxx . . $ D3/HogFileEntry#m_name..endcxx . . $ std/array#end(8e614c7de0b1573e).(), stdcxx . . $ std/::ostream_iteratorcxx . . $ std/ostream_iterator#<char>(output)); |
| 76 |
bin_writecxx . . $ D3/bin_write(b9bf9de5c7808980).(output, entry.m_flagscxx . . $ D3/HogFileEntry#m_flags.); |
| 77 |
bin_writecxx . . $ D3/bin_write(b9bf9de5c7808980).(output, entry.m_lencxx . . $ D3/HogFileEntry#m_len.); |
| 78 |
bin_writecxx . . $ D3/bin_write(b9bf9de5c7808980).(output, entry.m_timestampcxx . . $ D3/HogFileEntry#m_timestamp.); |
| 79 |
|
| 80 |
return output; |
| 81 |
} |
| 82 |
|
| 83 |
stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &operatorcxx . . $ D3/`operator<<`(ddf1f55e3333f4c5).<<(stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &output, const HogFormatcxx . . $ D3/HogFormat# &format) { |
| 84 |
output <<cxx . . $ D3/`operator<<`(13d65a7695c851c6). format.m_headercxx . . $ D3/HogFormat#m_header.; |
| 85 |
for (const HogFileEntrycxx . . $ D3/HogFileEntry# &entry : format.m_file_entriescxx . . $ D3/HogFormat#m_file_entries.) { |
| 86 |
output <<cxx . . $ D3/`operator<<`(54e5c9f58215b93). entry; |
| 87 |
} |
| 88 |
|
| 89 |
return output; |
| 90 |
} |
| 91 |
|
| 92 |
void HogFormatcxx . . $ D3/HogFormat#::SortEntriescxx . . $ D3/HogFormat#SortEntries(49f6e7a06ebc5aa8).() { |
| 93 |
auto customLess = [](const HogFileEntrycxx . . $ D3/HogFileEntry# &a, const HogFileEntrycxx . . $ D3/HogFileEntry# &b) { |
| 94 |
return (char_tolowercxx . . $ D3/char_tolower(6e4ececcd47d60a0).(a.m_namecxx . . $ D3/HogFileEntry#m_name.) <cxx . . $ std/`operator<`(a474572a1f22b964). char_tolowercxx . . $ D3/char_tolower(6e4ececcd47d60a0).(b.m_namecxx . . $ D3/HogFileEntry#m_name.)); |
| 95 |
}; |
| 96 |
|
| 97 |
stdcxx . . $ std/::sortcxx . . $ std/sort(4d3091562df4e52e).(m_file_entriescxx . . $ D3/HogFormat#m_file_entries..begincxx . . $ std/vector#begin(55a6de06420d4903).(), m_file_entriescxx . . $ D3/HogFormat#m_file_entries..endcxx . . $ std/vector#end(55a6de06420d4903).(), customLess); |
| 98 |
} |
| 99 |
|
| 100 |
} // namespace D3 |