From 3d013e208cdf4864d93e81afa7f0f8495845a3a0 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 20 Jul 2017 13:27:13 +0100 Subject: [PATCH] Start creating logic for saving planes & chunks --- Nibriboard/RippleSpace/Chunk.cs | 5 +++++ Nibriboard/RippleSpace/Plane.cs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/Nibriboard/RippleSpace/Chunk.cs b/Nibriboard/RippleSpace/Chunk.cs index 1d5aa20..9cc745e 100644 --- a/Nibriboard/RippleSpace/Chunk.cs +++ b/Nibriboard/RippleSpace/Chunk.cs @@ -227,6 +227,11 @@ namespace Nibriboard.RippleSpace return loadedChunk; } + public async Task SaveTo(Stream destination) + { + throw new NotImplementedException("Error: Chunk saving hasn't been implemented yet!"); + } + public void OnDeserialization(object sender) { UpdateAccessTime(); diff --git a/Nibriboard/RippleSpace/Plane.cs b/Nibriboard/RippleSpace/Plane.cs index 891ec7f..46f9169 100644 --- a/Nibriboard/RippleSpace/Plane.cs +++ b/Nibriboard/RippleSpace/Plane.cs @@ -164,6 +164,34 @@ namespace Nibriboard.RippleSpace return loadedChunk; } + /// + /// Works out whether a chunk currently exists. + /// + /// The chunk location to check. + /// Whether the chunk at specified location exists or not. + public bool HasChunk(ChunkReference chunkLocation) + { + if(loadedChunkspace.ContainsKey(chunkLocation)) + return true; + + string chunkFilePath = Path.Combine(StorageDirectory, chunkLocation.AsFilename()); + if(File.Exists(chunkFilePath)) + return true; + + return false; + } + + public async Task SaveChunk(ChunkReference chunkLocation) + { + // It doesn't exist, so we can't save it :P + if(!loadedChunkspace.ContainsKey(chunkLocation)) + return; + + Chunk chunk = loadedChunkspace[chunkLocation]; + string chunkFilePath = Path.Combine(StorageDirectory, chunkLocation.AsFilename()); + await chunk.SaveTo(File.OpenWrite(chunkFilePath)); + } + public async Task AddLine(DrawnLine newLine) { List chunkedLineParts; @@ -216,6 +244,8 @@ namespace Nibriboard.RippleSpace public void Save(Stream destination) { + + WriterOptions packingOptions = new WriterOptions(CompressionType.GZip); IEnumerable chunkFiles = Directory.GetFiles(StorageDirectory);