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)
|
||||
{
|
||||
BinaryReader binaryReader = new BinaryReader(File.OpenRead(Paths.GetWorldSaveFilePath(saveName)));
|
||||
ushort fileVersion = binaryReader.ReadUInt16();
|
||||
binaryReader.Close();
|
||||
ushort fileVersion;
|
||||
BinaryReader? binaryReader = null;
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
@@ -115,7 +115,7 @@ internal class WorldReaderV1 : IWorldReader
|
||||
}
|
||||
finally
|
||||
{
|
||||
reader?.Dispose();
|
||||
reader?.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user