2022-09-04 17:11:14 -04:00
|
|
|
//
|
|
|
|
// EuropaTools
|
|
|
|
//
|
2025-01-07 14:17:50 -05:00
|
|
|
// (C) 2021-2025 modeco80 <lily.modeco80@protonmail.ch>
|
2022-09-04 17:11:14 -04:00
|
|
|
//
|
2025-01-07 18:02:27 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-09-04 17:11:14 -04:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef EUROPA_IO_PAKREADER_H
|
|
|
|
#define EUROPA_IO_PAKREADER_H
|
|
|
|
|
2025-01-15 21:50:34 -05:00
|
|
|
#include <europa/io/pak/File.hpp>
|
2022-09-21 03:59:16 -04:00
|
|
|
#include <europa/structs/Pak.hpp>
|
2022-09-04 17:11:14 -04:00
|
|
|
#include <iosfwd>
|
|
|
|
#include <string>
|
|
|
|
|
2025-01-15 21:50:34 -05:00
|
|
|
namespace europa::io::pak {
|
2022-09-04 17:11:14 -04:00
|
|
|
|
2025-01-07 15:13:10 -05:00
|
|
|
/// Reader for Europa package files (.pak).
|
2025-01-19 02:08:43 -05:00
|
|
|
struct Reader {
|
2025-01-15 21:50:34 -05:00
|
|
|
using FlatType = std::pair<std::string, File>;
|
2025-01-15 20:07:47 -05:00
|
|
|
using MapType = std::vector<FlatType>;
|
2022-09-04 17:11:14 -04:00
|
|
|
|
2025-01-07 15:13:10 -05:00
|
|
|
/// Constructor. Takes in a input stream to read pak data from.
|
|
|
|
/// This stream should only be used by the PakReader, nothing else.
|
2025-01-15 21:50:34 -05:00
|
|
|
explicit Reader(std::istream& is);
|
2022-09-04 17:11:14 -04:00
|
|
|
|
2025-01-12 16:15:06 -05:00
|
|
|
/// Reads the header and the file TOC.
|
|
|
|
/// This function should be called first.
|
|
|
|
void ReadHeaderAndTOC();
|
2022-09-04 17:11:14 -04:00
|
|
|
|
2025-01-12 16:15:06 -05:00
|
|
|
/// Reads all files in the package.
|
2022-09-07 05:07:40 -04:00
|
|
|
void ReadFiles();
|
|
|
|
|
2025-01-12 16:15:06 -05:00
|
|
|
/// Reads a file with the path specified as [file].
|
2022-09-07 05:07:40 -04:00
|
|
|
void ReadFile(const std::string& file);
|
|
|
|
|
2022-09-04 17:11:14 -04:00
|
|
|
bool Invalid() const {
|
|
|
|
return invalid;
|
|
|
|
}
|
|
|
|
|
2022-09-07 05:07:40 -04:00
|
|
|
MapType& GetFiles();
|
|
|
|
const MapType& GetFiles() const;
|
2022-09-04 17:11:14 -04:00
|
|
|
|
2025-01-07 15:13:10 -05:00
|
|
|
const structs::PakHeaderVariant& GetHeader() const {
|
|
|
|
return header;
|
|
|
|
}
|
2022-09-22 06:43:35 -04:00
|
|
|
|
2022-09-04 17:11:14 -04:00
|
|
|
private:
|
2025-01-07 15:13:10 -05:00
|
|
|
template <class T>
|
2025-01-16 02:23:52 -05:00
|
|
|
void ReadHeaderAndTOCImpl();
|
2023-08-01 18:18:40 -04:00
|
|
|
|
2022-09-04 17:11:14 -04:00
|
|
|
std::istream& stream;
|
2022-09-05 20:59:46 -04:00
|
|
|
bool invalid { false };
|
2022-09-04 17:11:14 -04:00
|
|
|
|
2023-08-01 18:18:40 -04:00
|
|
|
structs::PakHeaderVariant header {};
|
2022-09-07 05:07:40 -04:00
|
|
|
MapType files;
|
2022-09-04 17:11:14 -04:00
|
|
|
};
|
|
|
|
|
2025-01-15 21:50:34 -05:00
|
|
|
} // namespace europa::io::pak
|
2022-09-04 17:11:14 -04:00
|
|
|
|
|
|
|
#endif // EUROPA_IO_PAKREADER_H
|