public void Save(Map mapToSave, string path) {
if (mapToSave == null) throw new ArgumentNullException("mapToSave");
if (path == null) throw new ArgumentNullException("path");
if (!Directory.Exists(path)) {
Directory.CreateDirectory(path);
}
// Write metadata/config file
using (StreamWriter sw = File.CreateText(Path.Combine(path, ConfigFileName))) {
sw.WriteLine("; Converted by {0} on {1}", Updater.UserAgent, DateTime.Now.ToCompactString());
sw.WriteLine("Size_X = {0}", mapToSave.Width);
sw.WriteLine("Size_Y = {0}", mapToSave.Length);
sw.WriteLine("Size_Z = {0}", mapToSave.Height);
sw.WriteLine("Spawn_X = {0}", FromPositionCoord(mapToSave.Spawn.X));
sw.WriteLine("Spawn_Y = {0}", FromPositionCoord(mapToSave.Spawn.Y));
sw.WriteLine("Spawn_Z = {0}", FromPositionCoord(mapToSave.Spawn.Z));
sw.WriteLine("Spawn_Rot = {0}", FromPositionAngle(mapToSave.Spawn.R));
sw.WriteLine("Spawn_Look = {0}", FromPositionAngle(mapToSave.Spawn.L));
}
// Write compressed block data
using (FileStream fs = File.Create(Path.Combine(path, DataFileName))) {
using (GZipStream gs = new GZipStream(fs, CompressionMode.Compress)) {
// Buffering necessary to avoid overhead of writing byte-at-a-time
using (BufferedStream bs = new BufferedStream(gs, WriteBufferSize)) {
for (int i = 0; i < mapToSave.Volume; i++) {
bs.WriteByte(mapToSave.Blocks[i]);
bs.WriteByte(0);
bs.WriteByte(0xFF);
bs.WriteByte(0xFF);
}
}
}
}
}