| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <expected> | ||
| 2 | #include <spanstream> | ||
| 3 | |||
| 4 | #include <platform.hpp> | ||
| 5 | #include <exception.hpp> | ||
| 6 | #include <map/w3m.hpp> | ||
| 7 | |||
| 8 | #include "assets_mpq_importer/w3m.hpp" | ||
| 9 | |||
| 10 | |||
| 11 | namespace assmpq::w3m { | ||
| 12 | |||
| 13 | using format_getter_t = const char*(*)(const wc3lib::map::W3m& map); | ||
| 14 | |||
| 15 | 1 | static auto extract_file(const FileData& w3m_file, format_getter_t fmt_getter) | |
| 16 | -> std::expected<FileData, ErrorMessage> | ||
| 17 | try { | ||
| 18 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | wc3lib::map::W3m map; |
| 19 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | std::ispanstream input(w3m_file); |
| 20 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | map.read(input); |
| 21 | |||
| 22 |
3/6✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
|
1 | const wc3lib::mpq::File file = map.findFile(fmt_getter(map)); |
| 23 | |||
| 24 |
2/4✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
3 | std::vector<char> output_buffer(file.size()); |
| 25 |
1/2✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | std::ospanstream output_stream(output_buffer, std::ios::out | std::ios::binary); |
| 26 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | file.decompress(input, output_stream); |
| 27 | 1 | return output_buffer; | |
| 28 | |||
| 29 |
0/2✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
1 | } catch (const wc3lib::Exception &exception) { |
| 30 | ✗ | return std::unexpected(exception.what()); | |
| 31 | ✗ | } | |
| 32 | |||
| 33 | 1 | auto extract_w3e_file(const FileData& w3m_file) | |
| 34 | -> std::expected<FileData, ErrorMessage> | ||
| 35 | { | ||
| 36 | 1 | return extract_file(w3m_file, [](const auto& map) -> const char* { | |
| 37 | 1 | return map.environment().get()->fileName(); | |
| 38 |
1/2✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | }); |
| 39 | } | ||
| 40 | |||
| 41 | ✗ | auto extract_shd_file(const FileData& w3m_file) | |
| 42 | -> std::expected<FileData, ErrorMessage> | ||
| 43 | { | ||
| 44 | ✗ | return extract_file(w3m_file, [](const auto& map) -> const char* { | |
| 45 | ✗ | return map.shadow().get()->fileName(); | |
| 46 | ✗ | }); | |
| 47 | } | ||
| 48 | |||
| 49 | ✗ | auto extract_wpm_file(const FileData& w3m_file) | |
| 50 | -> std::expected<FileData, ErrorMessage> | ||
| 51 | { | ||
| 52 | ✗ | return extract_file(w3m_file, [](const auto& map) -> const char* { | |
| 53 | ✗ | return map.pathmap().get()->fileName(); | |
| 54 | ✗ | }); | |
| 55 | } | ||
| 56 | |||
| 57 | ✗ | auto extract_doo_file(const FileData& w3m_file) | |
| 58 | -> std::expected<FileData, ErrorMessage> | ||
| 59 | { | ||
| 60 | ✗ | return extract_file(w3m_file, [](const auto& map) -> const char* { | |
| 61 | ✗ | return map.trees().get()->fileName(); | |
| 62 | ✗ | }); | |
| 63 | } | ||
| 64 | |||
| 65 | } // namespace assmpq::w3m | ||
| 66 |