1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#pragma once
#include "compression.h"
#include "InputOutputStream.h"
using namespace std;
class FileEntry;
class ConsoleSaveFile;
class RegionFile
{
// 4J Stu TEMP FOR TESTING
private:
FileEntry *fileEntry;
private:
static const int VERSION_GZIP = 1;
static const int VERSION_DEFLATE = 2;
static const int VERSION_XBOX = 3;
static const int SECTOR_BYTES = 4096;
static const int SECTOR_INTS = SECTOR_BYTES / 4;
static const int CHUNK_HEADER_SIZE = 8;
static byteArray emptySector;
File *fileName;
//HANDLE file;
ConsoleSaveFile *m_saveFile;
int *offsets;
int *chunkTimestamps;
vector<bool> *sectorFree;
int sizeDelta;
int64_t _lastModified;
bool m_bIsEmpty; // 4J added
public:
RegionFile(ConsoleSaveFile *saveFile, File *path);
~RegionFile();
/* the modification date of the region file when it was first opened */
int64_t lastModified();
/* gets how much the region file has grown since it was last checked */
int getSizeDelta();
/*
* gets an (uncompressed) stream representing the chunk data returns null if
* the chunk is not found or an error occurs
*/
DataInputStream *getChunkDataInputStream(int x, int z);
DataOutputStream *getChunkDataOutputStream(int x, int z);
class ChunkBuffer : public ByteArrayOutputStream
{
private:
RegionFile *rf;
int x, z;
public:
ChunkBuffer( RegionFile *rf, int x, int z ) : ByteArrayOutputStream(8096)
{
this->rf = rf;
this->x = x;
this->z = z;
}
void close()
{
rf->write(x,z,buf.data,count);
}
};
/* write a chunk at (x,z) with length bytes of data to disk */
protected:
void write(int x, int z, byte *data, int length);
/* write a chunk data to the region file at specified sector number */
private:
void write(int sectorNumber, byte *data, int length, unsigned int compLength);
void zero(int sectorNumber, int length); // 4J added
/* is this an invalid chunk coordinate? */
bool outOfBounds(int x, int z);
int getOffset(int x, int z);
public:
bool hasChunk(int x, int z);
private:
void insertInitialSectors(); // 4J added
void setOffset(int x, int z, int offset);
void setTimestamp(int x, int z, int value);
public:
void writeAllOffsets();
void close();
};
|