mirror of
https://github.com/Stone-Red-Code/StoneRed.LogicSimulator.git
synced 2026-09-04 00:56:23 +02:00
Improve saving and loading classes
This commit is contained in:
@@ -20,9 +20,22 @@ internal class WorldLoader
|
|||||||
|
|
||||||
public Task<Result<WorldData>> LoadWorld(string saveName, IProgress<WorldSaveLoadProgress> progress)
|
public Task<Result<WorldData>> LoadWorld(string saveName, IProgress<WorldSaveLoadProgress> progress)
|
||||||
{
|
{
|
||||||
BinaryReader binaryReader = new BinaryReader(File.OpenRead(Paths.GetWorldSaveFilePath(saveName)));
|
ushort fileVersion;
|
||||||
ushort fileVersion = binaryReader.ReadUInt16();
|
BinaryReader? binaryReader = null;
|
||||||
binaryReader.Close();
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
binaryReader = new BinaryReader(File.OpenRead(Paths.GetWorldSaveFilePath(saveName)));
|
||||||
|
fileVersion = binaryReader.ReadUInt16();
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
return Task.FromResult(Result.Fail<WorldData>(ex.Message));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
binaryReader?.Close();
|
||||||
|
}
|
||||||
|
|
||||||
IWorldReader? worldReader = fileVersion switch
|
IWorldReader? worldReader = fileVersion switch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ internal class WorldReaderV1 : IWorldReader
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
reader?.Dispose();
|
reader?.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user