ppsspp/file/chunk_file.h
Henrik Rydgard 8b076c5b88 Cleanup
2012-03-31 11:16:13 +02:00

68 lines
1.3 KiB
C++

#pragma once
// RIFF file format reader/writer. Very old code, basically a total mess but it still works.
// TO REMEMBER WHEN USING:
// EITHER a chunk contains ONLY data
// OR it contains ONLY other chunks
// otherwise the scheme breakes.
#include <string>
#include "base/basictypes.h"
#include "base/LAMEString.h"
#include "file/easy_file.h"
inline uint32 flipID(uint32 id) {
return ((id>>24)&0xFF) | ((id>>8)&0xFF00) | ((id<<8)&0xFF0000) | ((id<<24)&0xFF000000);
}
class ChunkFile {
public:
ChunkFile(const char *filename, bool _read);
~ChunkFile();
bool descend(uint32 id);
void ascend();
int readInt();
void readInt(int &i) {i = readInt();}
void readData(void *data, int count);
String readWString();
void writeString(const std::string &str);
std::string readString();
void writeInt(int i);
void writeWString(String str);
void writeData(const void *data, int count);
int getCurrentChunkSize();
bool failed() const {return didFail;}
std::string filename() const { return fn; }
private:
std::string fn;
LAMEFile file;
struct ChunkInfo {
int startLocation;
int parentStartLocation;
int parentEOF;
unsigned int ID;
int length;
};
ChunkInfo stack[8];
int numLevels;
uint8 *data;
int pos,eof;
bool fastMode;
bool read;
bool didFail;
void seekTo(int _pos);
int getPos() const {return pos;}
};