72 lines
2.6 KiB
C++
72 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include "eterpack/types.h"
|
|
#include <string>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
#include <span>
|
|
#include <memory>
|
|
#include <fstream>
|
|
|
|
namespace eterpack {
|
|
|
|
class EterPackArchive {
|
|
public:
|
|
EterPackArchive();
|
|
~EterPackArchive();
|
|
|
|
// Open from file path (e.g., "pack/root" or "root.eix")
|
|
bool open(const std::string& base_or_eix_path,
|
|
const uint32_t index_key[4] = DEFAULT_ETERPACK_KEY,
|
|
const uint32_t security_key[4] = DEFAULT_SECURITY_KEY);
|
|
|
|
// Open from memory buffers (for tests and embedded use)
|
|
bool open_memory(std::span<const uint8_t> eix_data,
|
|
std::span<const uint8_t> epk_data,
|
|
const uint32_t index_key[4] = DEFAULT_ETERPACK_KEY,
|
|
const uint32_t security_key[4] = DEFAULT_SECURITY_KEY);
|
|
|
|
void close();
|
|
|
|
bool is_open() const { return m_is_open; }
|
|
const std::string& get_name() const { return m_archive_name; }
|
|
size_t get_entry_count() const { return m_entries.size(); }
|
|
const std::vector<EterPackIndexEntry>& get_entries() const { return m_entries; }
|
|
|
|
bool has_file(std::string_view filename) const;
|
|
bool has_file(uint32_t crc) const;
|
|
|
|
const EterPackIndexEntry* find_entry(std::string_view filename) const;
|
|
const EterPackIndexEntry* find_entry(uint32_t crc) const;
|
|
|
|
bool extract(std::string_view filename, std::vector<uint8_t>& out_data) const;
|
|
bool extract(const EterPackIndexEntry& entry, std::vector<uint8_t>& out_data) const;
|
|
|
|
// Pack creator / writer helper (writes .eix and .epk pair)
|
|
static bool create_archive(const std::string& base_path,
|
|
const std::vector<std::pair<std::string, std::vector<uint8_t>>>& files,
|
|
bool encrypt_index = true,
|
|
const uint32_t index_key[4] = DEFAULT_ETERPACK_KEY,
|
|
CompressionType comp_type = CompressionType::Compress,
|
|
const uint32_t security_key[4] = DEFAULT_SECURITY_KEY);
|
|
|
|
private:
|
|
bool parse_index_buffer(std::span<const uint8_t> eix_bytes, const uint32_t index_key[4]);
|
|
std::string resolve_case_insensitive(const std::string& path);
|
|
|
|
std::string m_archive_name;
|
|
std::string m_epk_path;
|
|
bool m_is_open = false;
|
|
uint32_t m_security_key[4] = {0};
|
|
|
|
// Stored either as file or in-memory buffer
|
|
std::vector<uint8_t> m_epk_memory;
|
|
mutable std::ifstream m_epk_file;
|
|
|
|
std::vector<EterPackIndexEntry> m_entries;
|
|
std::unordered_map<uint32_t, size_t> m_crc_map;
|
|
std::unordered_map<std::string, size_t> m_name_map;
|
|
};
|
|
|
|
} // namespace eterpack
|