101 lines
2.1 KiB
C++
101 lines
2.1 KiB
C++
#ifndef WC3RE_TREFILE_HH__
|
|
#define WC3RE_TREFILE_HH__
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include <cstdio>
|
|
#include <vector>
|
|
#include <tuple>
|
|
|
|
class TreFile {
|
|
public:
|
|
TreFile(char const* base, size_t length);
|
|
|
|
~TreFile();
|
|
|
|
std::vector<std::string> getNames() const;
|
|
std::vector<uint32_t> getCRCs() const;
|
|
|
|
void dumpName(std::string path, std::string const& name) const;
|
|
void dumpCRC(std::string path, uint32_t crc) const;
|
|
void dumpAll(std::string path) const;
|
|
|
|
void printStructure();
|
|
|
|
class Object {
|
|
public:
|
|
Object() : base_(nullptr), length_(0) {
|
|
}
|
|
|
|
Object(Object const& copy) = delete;
|
|
Object(Object && move)
|
|
: base_(move.base_), length_(move.length_) {
|
|
move.base_ = nullptr;
|
|
move.length_ = 0;
|
|
}
|
|
|
|
Object& operator=(Object const& copy) = delete;
|
|
Object& operator=(Object && move) {
|
|
base_ = move.base_;
|
|
length_ = move.length_;
|
|
move.base_ = nullptr;
|
|
move.length_ = 0;
|
|
return *this;
|
|
}
|
|
|
|
char const* data() const {
|
|
return base_;
|
|
}
|
|
|
|
size_t size() const {
|
|
return length_;
|
|
}
|
|
|
|
operator bool() const {
|
|
return base_;
|
|
}
|
|
|
|
private:
|
|
char const* base_;
|
|
size_t length_;
|
|
|
|
Object(char const* base, size_t length)
|
|
: base_(base), length_(length) {
|
|
}
|
|
|
|
friend class TreFile;
|
|
};
|
|
|
|
Object openName(std::string const& name) const;
|
|
Object openCRC(uint32_t crc) const;
|
|
|
|
struct Stat {
|
|
uint32_t size;
|
|
uint32_t csize;
|
|
uint8_t flags;
|
|
};
|
|
|
|
Stat statName(std::string const& name) const;
|
|
Stat statCRC(uint32_t crc) const;
|
|
|
|
private:
|
|
void construct_();
|
|
|
|
size_t findName_(std::string const& name) const;
|
|
size_t findCRC_(uint32_t crc) const;
|
|
|
|
void dumpIdx_(std::string const& name, size_t table3Idx) const;
|
|
Object openIdx_(size_t table3Idx) const;
|
|
Stat statIdx_(size_t table3Idx) const;
|
|
|
|
std::map<uint32_t, size_t> table1_;
|
|
std::map<std::string, size_t> table2_;
|
|
// base, size, comp. size, flags
|
|
std::vector<std::tuple<uint32_t, uint32_t, uint32_t, uint8_t> > table3_;
|
|
|
|
char const* base_;
|
|
size_t length_;
|
|
};
|
|
|
|
#endif
|