wavelength 1.0.0
Loading...
Searching...
No Matches
arkreader.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <expected>
5#include <filesystem>
6#include <fstream>
7#include <optional>
8#include <string>
9#include <string_view>
10#include <vector>
11
12#include "error.h"
13
14namespace Tools::Ark {
15
16using Common::Error;
17
19struct ArkEntry {
20 std::string path;
21 std::uint32_t offset = 0;
22 std::uint32_t size = 0;
23 std::uint32_t uncompressedSize = 0;
24};
25
33class ArkReader {
34public:
36 static constexpr std::uint32_t kVersion = 2;
37
45 static std::expected<ArkReader, Error> open(const std::filesystem::path &path,
46 std::uint64_t base = 0);
47
53 [[nodiscard]] const std::vector<ArkEntry> &entries() const;
54
61 [[nodiscard]] std::optional<ArkEntry> locate(std::string_view path) const;
62
69 std::expected<std::vector<std::uint8_t>, Error> read(const ArkEntry &entry);
70
77 std::expected<void, Error> extract(const std::filesystem::path &root);
78
79private:
80 ArkReader() = default;
81
82 [[nodiscard]] int slotOf(std::string_view name) const;
83
84 std::ifstream file_;
85 std::filesystem::path path_;
86 std::uint64_t base_ = 0;
87 std::vector<ArkEntry> entries_;
88 std::vector<std::uint32_t> slots_; // The name slot and directory slot of each record.
89 std::vector<char> strings_;
90 std::vector<std::uint32_t> table_;
91};
92
93} // namespace Tools::Ark
const std::vector< ArkEntry > & entries() const
List the files in record order.
std::expected< std::vector< std::uint8_t >, Error > read(const ArkEntry &entry)
Read the bytes of a file.
static std::expected< ArkReader, Error > open(const std::filesystem::path &path, std::uint64_t base=0)
Open an archive and read its directory.
static constexpr std::uint32_t kVersion
The archive version the game reads.
Definition arkreader.h:36
std::expected< void, Error > extract(const std::filesystem::path &root)
Copy every file into a directory, at its path below the directory.
std::optional< ArkEntry > locate(std::string_view path) const
Find a file the way Archive::GetFileInfo does, through the name hash table.
Readers and writers of Harmonix archives and compiled DataArray files.
Definition arkreader.h:14
A file of an archive.
Definition arkreader.h:19
std::uint32_t size
Definition arkreader.h:22
std::string path
Definition arkreader.h:20
std::uint32_t uncompressedSize
Definition arkreader.h:23
std::uint32_t offset
Definition arkreader.h:21
Failure returned through std::expected.
Definition error.h:17