mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
Fix the saving system. It works!
This commit is contained in:
parent
99ac0634ad
commit
fddfa31939
5 changed files with 19 additions and 13 deletions
|
@ -23,7 +23,7 @@ namespace Nibriboard
|
|||
private HttpServer httpServer;
|
||||
|
||||
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 NibriClientManager clientManager;
|
||||
|
|
|
@ -235,6 +235,7 @@ namespace Nibriboard.RippleSpace
|
|||
public async Task SaveTo(StreamWriter destination)
|
||||
{
|
||||
await destination.WriteLineAsync(JsonConvert.SerializeObject(this));
|
||||
destination.Close();
|
||||
}
|
||||
|
||||
public void OnDeserialization(object sender)
|
||||
|
|
|
@ -256,24 +256,28 @@ namespace Nibriboard.RippleSpace
|
|||
string chunkDestinationFilename = CalcPaths.ChunkFilepath(StorageDirectory, loadedChunkItem.Key);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(chunkDestinationFilename));
|
||||
// Ask the chunk to save itself
|
||||
using(StreamWriter chunkDestination = new StreamWriter(chunkDestinationFilename))
|
||||
{
|
||||
StreamWriter chunkDestination = new StreamWriter(chunkDestinationFilename);
|
||||
chunkSavers.Add(loadedChunkItem.Value.SaveTo(chunkDestination));
|
||||
}
|
||||
}
|
||||
await Task.WhenAll(chunkSavers);
|
||||
|
||||
// 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);
|
||||
using(IWriter packer = WriterFactory.Open(destination, ArchiveType.Tar, packingOptions))
|
||||
IEnumerable<string> chunkFiles = Directory.GetFiles(StorageDirectory.TrimEnd("/".ToCharArray()));
|
||||
using(IWriter packer = WriterFactory.Open(destination, ArchiveType.Zip, packingOptions))
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
destination.Flush();
|
||||
destination.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -137,15 +137,16 @@ namespace Nibriboard.RippleSpace
|
|||
|
||||
// Pack the planes into the ripplespace archive
|
||||
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)
|
||||
{
|
||||
rippleSpacePacker.Write(Path.GetFileName(planeFilename), planeFilename);
|
||||
}
|
||||
}
|
||||
destination.Close();
|
||||
}
|
||||
|
||||
public async Task<RippleSpaceManager> FromFile(string filename)
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Nibriboard.Utilities
|
|||
/// <returns>The directory to which a plane should unpack it's data to.</returns>
|
||||
public static string UnpackedPlaneDir(string unpackingRoot, string planeName)
|
||||
{
|
||||
string result = $"{unpackingRoot}/Planes/{planeName}/";
|
||||
string result = $"{unpackingRoot}Planes/{planeName}/";
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -35,13 +35,13 @@ namespace Nibriboard.Utilities
|
|||
/// <returns>The path to the packed plane file.</returns>
|
||||
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)
|
||||
{
|
||||
return $"{planeStorageDirectory}/{chunkRef.AsFilename()}";
|
||||
return $"{planeStorageDirectory}{chunkRef.AsFilename()}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue