12enum class OLEntryType : uint32_t {
20 if (!std::filesystem::exists(path)) {
25 auto* ol =
new OL{path};
26 auto packFile = std::unique_ptr<PackFile>(ol);
28 FileStream reader{ol->fullFilePath};
36 if (
auto version = reader.read<
float>(); version < 0.05 || version > 0.15) {
41 auto entryOffset = reader.read<uint32_t>();
42 auto entryCount = reader.read<uint32_t>();
44 reader.read(ol->notes);
46 reader.seek_in(entryOffset);
47 for (uint32_t i = 0; i < entryCount; i++) {
50 entry.
offset = reader.read<uint32_t>();
51 entry.
length = reader.read<uint32_t>();
53 const auto baseEntryPath = ol->cleanEntryPath(reader.read_string(31));
54 auto entryPath = baseEntryPath;
56 auto notes = reader.read_string(501);
58 std::string extension;
59 auto type = reader.read<OLEntryType>();
61 case OLEntryType::RMF:
64 case OLEntryType::MAP:
68 entryPath += extension;
71 for (
int j = 1; ol->entries.count(entryPath) > 0; j++) {
72 entryPath = baseEntryPath;
75 .append(std::to_string(j))
81 entry.
extraData = {
reinterpret_cast<const std::byte*
>(
notes.data()),
reinterpret_cast<const std::byte*
>(
notes.data() +
notes.size())};
84 ol->entries.emplace(entryPath, entry);
87 callback(entryPath, entry);
94std::optional<std::vector<std::byte>>
OL::readEntry(
const std::string& path_)
const {
100 if (entry->unbaked) {
109 stream.seek_in_u(entry->offset);
110 return stream.read_bytes(entry->length);
123 const auto entry = this->
findEntry(path);
127 return std::string{
reinterpret_cast<const char*
>(entry->extraData.data()), entry->extraData.size()};
This class represents the metadata that a file has inside a PackFile.
uint64_t offset
Offset, format-specific meaning - 0 if unused, or if the offset genuinely is 0.
uint64_t length
Length in bytes (in formats with compression, this is the uncompressed length)
std::vector< std::byte > extraData
Format-specific (PCK: MD5 hash, VPK: Preloaded data)
Attribute getSupportedEntryAttributes() const override
Returns a list of supported entry attributes Mostly for GUI programs that show entries and their meta...
static std::unique_ptr< PackFile > open(const std::string &path, const EntryCallback &callback=nullptr)
Open an OL file.
std::optional< std::string > getEntryNotes(const std::string &path) const
std::optional< std::vector< std::byte > > readEntry(const std::string &path_) const override
Try to read the entry's data to a bytebuffer.
const std::string & getNotes() const
EntryCallbackBase< void > EntryCallback
std::optional< Entry > findEntry(const std::string &path_, bool includeUnbaked=true) const
Try to find an entry given the file path.
std::string cleanEntryPath(const std::string &path) const
static Entry createNewEntry()
static std::optional< std::vector< std::byte > > readUnbakedEntry(const Entry &entry)
constexpr std::string_view OL_SIGNATURE