EuropaTools/include/europa/io/PakReader.hpp

65 lines
1.3 KiB
C++
Raw Normal View History

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 14:17:50 -05:00
// SPDX-License-Identifier: LGPL-3.0-or-later
2022-09-04 17:11:14 -04:00
//
#ifndef EUROPA_IO_PAKREADER_H
#define EUROPA_IO_PAKREADER_H
#include <europa/io/PakFile.hpp>
#include <europa/structs/Pak.hpp>
2022-09-04 17:11:14 -04:00
#include <iosfwd>
#include <string>
#include <unordered_map>
namespace europa::io {
2025-01-07 15:13:10 -05:00
/// Reader for Europa package files (.pak).
2022-09-04 17:11:14 -04:00
struct PakReader {
using MapType = std::unordered_map<std::string, PakFile>;
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.
2022-09-04 17:11:14 -04:00
explicit PakReader(std::istream& is);
void ReadData();
void ReadFiles();
/**
* Read in a specific file.
*/
void ReadFile(const std::string& file);
2022-09-04 17:11:14 -04:00
bool Invalid() const {
return invalid;
}
MapType& GetFiles();
const MapType& GetFiles() const;
2022-09-04 17:11:14 -04:00
// implement in cpp later, lazy and just wanna get this out :vvv
2025-01-07 15:13:10 -05:00
const structs::PakHeaderVariant& GetHeader() const {
return header;
}
2022-09-04 17:11:14 -04:00
private:
2025-01-07 15:13:10 -05:00
template <class T>
void ReadData_Impl();
2022-09-04 17:11:14 -04:00
std::istream& stream;
bool invalid { false };
2022-09-04 17:11:14 -04:00
structs::PakVersion version;
structs::PakHeaderVariant header {};
2022-09-04 17:11:14 -04:00
MapType files;
2022-09-04 17:11:14 -04:00
};
} // namespace europa::io
2022-09-04 17:11:14 -04:00
#endif // EUROPA_IO_PAKREADER_H