WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
GameFile.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5#include "Component.h"
6
11class GameFile : public Component
12{
13public:
14 GameFile(std::string path, int id = -1)
15 : eof(true), buffer(nullptr), pointer(0), size(0),
16 filepath(std::move(path)), m_useMemoryBuffer(true), m_fileDataId(id),
17 originalBuffer(nullptr), curChunk("")
18 {
19 }
20
21 virtual ~GameFile() = default;
22
25 virtual size_t read(void* dest, size_t bytes);
26
28 size_t getSize();
29
31 size_t getPos();
32
34 unsigned char* getBuffer() const;
35
37 unsigned char* getPointer();
38
40 bool isEof();
41
43 virtual void seek(size_t offset);
44
46 void seekRelative(size_t offset);
47
50 bool open(bool useMemoryBuffer = true);
51
53 bool close();
54
55 void setFullName(const std::string& name) { filepath = name; }
56 const std::string& fullname() const { return filepath; }
57 int fileDataId() { return m_fileDataId; }
58
60 void allocate(unsigned long long size);
61
66 bool setChunk(std::string chunkName, bool resetToStart = true);
67
69 bool isChunked() { return chunks.size() > 0; }
70
71 virtual void dumpStructure();
72
73protected:
74 virtual bool openFile() = 0;
75 virtual bool isAlreadyOpened() = 0;
76 virtual bool getFileSize(unsigned long long& s) = 0;
77 virtual unsigned long readFile() = 0;
78 virtual void doPostOpenOperation() = 0;
79 virtual bool doPostCloseOperation() = 0;
80
81 bool eof;
82 unsigned char* buffer;
83 unsigned long long pointer, size;
84 std::string filepath;
86
87 struct Chunk
88 {
89 std::string magic;
90 unsigned int start;
91 unsigned int size;
92 unsigned int pointer;
93 };
94
95 std::vector<Chunk> chunks;
97
98private:
99 GameFile(const GameFile&) = delete;
100 GameFile& operator=(const GameFile&) = delete;
101 unsigned char* originalBuffer;
102 std::string curChunk;
103};
Base class for all scene-graph nodes in the component hierarchy.
Definition Component.h:11
std::string name() const
Definition Component.cpp:52
Abstract base class representing a file within the game data archive.
Definition GameFile.h:12
GameFile & operator=(const GameFile &)=delete
virtual void doPostOpenOperation()=0
bool eof
Definition GameFile.h:81
unsigned char * getPointer()
Pointer to the current read position within the buffer.
Definition GameFile.cpp:149
virtual ~GameFile()=default
virtual bool doPostCloseOperation()=0
bool m_useMemoryBuffer
Definition GameFile.h:96
bool open(bool useMemoryBuffer=true)
Open the file, optionally loading into a memory buffer.
Definition GameFile.cpp:41
std::string filepath
Definition GameFile.h:84
std::string curChunk
Definition GameFile.h:102
virtual void seek(size_t offset)
Seek to an absolute byte offset.
Definition GameFile.cpp:29
GameFile(std::string path, int id=-1)
Definition GameFile.h:14
size_t getPos()
Current read position.
Definition GameFile.cpp:139
size_t getSize()
Total size of the file in bytes.
Definition GameFile.cpp:134
std::vector< Chunk > chunks
Definition GameFile.h:95
unsigned char * buffer
Definition GameFile.h:82
virtual void dumpStructure()
Definition GameFile.cpp:154
virtual unsigned long readFile()=0
virtual bool isAlreadyOpened()=0
virtual bool openFile()=0
unsigned char * getBuffer() const
Pointer to the start of the internal buffer.
Definition GameFile.cpp:144
unsigned long long size
Definition GameFile.h:83
bool close()
Close the file and release the internal buffer.
Definition GameFile.cpp:74
virtual size_t read(void *dest, size_t bytes)
Read bytes from the file into dest.
Definition GameFile.cpp:5
int m_fileDataId
Definition GameFile.h:85
unsigned long long pointer
Definition GameFile.h:83
void seekRelative(size_t offset)
Advance the read pointer by offset bytes.
Definition GameFile.cpp:35
void setFullName(const std::string &name)
Definition GameFile.h:55
const std::string & fullname() const
Definition GameFile.h:56
unsigned char * originalBuffer
Definition GameFile.h:101
bool setChunk(std::string chunkName, bool resetToStart=true)
Switch the active read window to the named chunk.
Definition GameFile.cpp:100
GameFile(const GameFile &)=delete
virtual bool getFileSize(unsigned long long &s)=0
int fileDataId()
Definition GameFile.h:57
void allocate(unsigned long long size)
Allocate (or reallocate) the internal buffer to the given size.
Definition GameFile.cpp:84
bool isChunked()
True if the file has been parsed into named chunks.
Definition GameFile.h:69
bool isEof()
True if the read pointer has reached the end of the file.
Definition GameFile.cpp:24
unsigned int start
Definition GameFile.h:90
unsigned int size
Definition GameFile.h:91
std::string magic
Definition GameFile.h:89
unsigned int pointer
Definition GameFile.h:92