void LoadBlocks()
{
mBlocks.Clear();
mCurrentHeight = 1;
mArchiveMarker = 0;
while (true)
{
string filename = String.Format("/{0:D5}.blocks", mArchiveMarker / 10000);
string filepath = mDataPath + filename;
if (!File.Exists(filepath))
{
// File doesnt exist, likely didnt hit a partial block so load the last archive chunk
if (mArchiveMarker > 0 && mBlocks.Count == 0)
{
filename = String.Format("/{0:D5}.blocks", (mArchiveMarker - 10000) / 10000);
filepath = mDataPath + filename;
try
{
FileStream fs = File.OpenRead(filepath);
BinaryReader br = new BinaryReader(fs);
int version = br.ReadInt32();
int blockCount = br.ReadInt32();
mCurrentHeight -= 10000;
for (int i = 0; i < blockCount; i++)
{
Block b = new Block();
b.Load(br);
b.mHeight = mCurrentHeight++;
mBlocks.Add(b);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
break;
}
try
{
FileStream fs = File.OpenRead(filepath);
BinaryReader br = new BinaryReader(fs);
int version = br.ReadInt32();
int blockCount = br.ReadInt32();
if (blockCount == 10000 || (blockCount == 9999 && mArchiveMarker == 0))
{
// This is a fully archived chunk, just skip past it
mCurrentHeight += 10000;
mArchiveMarker += 10000;
}
else
{
// Load all the blocks in this chunk
for (int i = 0; i < blockCount; i++)
{
Block b = new Block();
b.Load(br);
b.mHeight = mCurrentHeight++;
mBlocks.Add(b);
}
// Break out of the larger loop since this is an incomplete chunk it must be the last one.
break;
}
br.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
break;
}
}
}