1
0
Fork 0

Fix the saving system. It works!

This commit is contained in:
Starbeamrainbowlabs 2017-07-23 19:36:15 +01:00
parent 99ac0634ad
commit fddfa31939
5 changed files with 19 additions and 13 deletions

View File

@ -23,7 +23,7 @@ namespace Nibriboard
private HttpServer httpServer; private HttpServer httpServer;
private ClientSettings clientSettings; private ClientSettings clientSettings;
private RippleSpaceManager planeManager = new RippleSpaceManager() { SourceFilename = "./test.ripplespace.tar.gz" }; private RippleSpaceManager planeManager = new RippleSpaceManager() { SourceFilename = "./test.ripplespace.zip" };
private readonly CancellationTokenSource clientManagerCanceller = new CancellationTokenSource(); private readonly CancellationTokenSource clientManagerCanceller = new CancellationTokenSource();
private NibriClientManager clientManager; private NibriClientManager clientManager;

View File

@ -235,6 +235,7 @@ namespace Nibriboard.RippleSpace
public async Task SaveTo(StreamWriter destination) public async Task SaveTo(StreamWriter destination)
{ {
await destination.WriteLineAsync(JsonConvert.SerializeObject(this)); await destination.WriteLineAsync(JsonConvert.SerializeObject(this));
destination.Close();
} }
public void OnDeserialization(object sender) public void OnDeserialization(object sender)

View File

@ -256,24 +256,28 @@ namespace Nibriboard.RippleSpace
string chunkDestinationFilename = CalcPaths.ChunkFilepath(StorageDirectory, loadedChunkItem.Key); string chunkDestinationFilename = CalcPaths.ChunkFilepath(StorageDirectory, loadedChunkItem.Key);
Directory.CreateDirectory(Path.GetDirectoryName(chunkDestinationFilename)); Directory.CreateDirectory(Path.GetDirectoryName(chunkDestinationFilename));
// Ask the chunk to save itself // Ask the chunk to save itself
using(StreamWriter chunkDestination = new StreamWriter(chunkDestinationFilename)) StreamWriter chunkDestination = new StreamWriter(chunkDestinationFilename);
{ chunkSavers.Add(loadedChunkItem.Value.SaveTo(chunkDestination));
chunkSavers.Add(loadedChunkItem.Value.SaveTo(chunkDestination));
}
} }
await Task.WhenAll(chunkSavers); await Task.WhenAll(chunkSavers);
// Pack the chunks into an nplane file // Pack the chunks into an nplane file
WriterOptions packingOptions = new WriterOptions(CompressionType.GZip); WriterOptions packingOptions = new WriterOptions(CompressionType.Deflate);
IEnumerable<string> chunkFiles = Directory.GetFiles(StorageDirectory); IEnumerable<string> chunkFiles = Directory.GetFiles(StorageDirectory.TrimEnd("/".ToCharArray()));
using(IWriter packer = WriterFactory.Open(destination, ArchiveType.Tar, packingOptions)) using(IWriter packer = WriterFactory.Open(destination, ArchiveType.Zip, packingOptions))
{ {
foreach(string nextChunkFile in chunkFiles) foreach(string nextChunkFile in chunkFiles)
{ {
Console.WriteLine("[Command/Save] Packing {0} as {1}",
nextChunkFile,
$"{Name}/{Path.GetFileName(nextChunkFile)}"
);
packer.Write($"{Name}/{Path.GetFileName(nextChunkFile)}", nextChunkFile); packer.Write($"{Name}/{Path.GetFileName(nextChunkFile)}", nextChunkFile);
} }
} }
destination.Flush();
destination.Close();
} }
/// <summary> /// <summary>

View File

@ -137,15 +137,16 @@ namespace Nibriboard.RippleSpace
// Pack the planes into the ripplespace archive // Pack the planes into the ripplespace archive
Stream destination = File.OpenWrite(SourceFilename); Stream destination = File.OpenWrite(SourceFilename);
string[] planeFiles = Directory.GetFiles(UnpackedDirectory, "*.nplane.tar.gz", SearchOption.TopDirectoryOnly); string[] planeFiles = Directory.GetFiles(UnpackedDirectory, "*.nplane.zip", SearchOption.TopDirectoryOnly);
using(IWriter rippleSpacePacker = WriterFactory.Open(destination, ArchiveType.Tar, new WriterOptions(CompressionType.GZip))) using(IWriter rippleSpacePacker = WriterFactory.Open(destination, ArchiveType.Zip, new WriterOptions(CompressionType.Deflate)))
{ {
foreach(string planeFilename in planeFiles) foreach(string planeFilename in planeFiles)
{ {
rippleSpacePacker.Write(Path.GetFileName(planeFilename), planeFilename); rippleSpacePacker.Write(Path.GetFileName(planeFilename), planeFilename);
} }
} }
destination.Close();
} }
public async Task<RippleSpaceManager> FromFile(string filename) public async Task<RippleSpaceManager> FromFile(string filename)

View File

@ -13,7 +13,7 @@ namespace Nibriboard.Utilities
/// <returns>The directory to which a plane should unpack it's data to.</returns> /// <returns>The directory to which a plane should unpack it's data to.</returns>
public static string UnpackedPlaneDir(string unpackingRoot, string planeName) public static string UnpackedPlaneDir(string unpackingRoot, string planeName)
{ {
string result = $"{unpackingRoot}/Planes/{planeName}/"; string result = $"{unpackingRoot}Planes/{planeName}/";
return result; return result;
} }
@ -35,13 +35,13 @@ namespace Nibriboard.Utilities
/// <returns>The path to the packed plane file.</returns> /// <returns>The path to the packed plane file.</returns>
public static string UnpackedPlaneFile(string unpackingDir, string planeName) public static string UnpackedPlaneFile(string unpackingDir, string planeName)
{ {
return $"{unpackingDir}/{planeName}.nplane.tar.gz"; return $"{unpackingDir}{planeName}.nplane.zip";
} }
public static string ChunkFilepath(string planeStorageDirectory, ChunkReference chunkRef) public static string ChunkFilepath(string planeStorageDirectory, ChunkReference chunkRef)
{ {
return $"{planeStorageDirectory}/{chunkRef.AsFilename()}"; return $"{planeStorageDirectory}{chunkRef.AsFilename()}";
} }
} }
} }