diff --git a/StoneRed.LogicSimulator/WorldSaveSystem/WorldLoader.cs b/StoneRed.LogicSimulator/WorldSaveSystem/WorldLoader.cs index d2e7571..32bc131 100644 --- a/StoneRed.LogicSimulator/WorldSaveSystem/WorldLoader.cs +++ b/StoneRed.LogicSimulator/WorldSaveSystem/WorldLoader.cs @@ -20,9 +20,22 @@ internal class WorldLoader public Task> LoadWorld(string saveName, IProgress 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(ex.Message)); + } + finally + { + binaryReader?.Close(); + } IWorldReader? worldReader = fileVersion switch { diff --git a/StoneRed.LogicSimulator/WorldSaveSystem/WorldReaders/WorldReaderV1.cs b/StoneRed.LogicSimulator/WorldSaveSystem/WorldReaders/WorldReaderV1.cs index 7dbb690..2a04977 100644 --- a/StoneRed.LogicSimulator/WorldSaveSystem/WorldReaders/WorldReaderV1.cs +++ b/StoneRed.LogicSimulator/WorldSaveSystem/WorldReaders/WorldReaderV1.cs @@ -115,7 +115,7 @@ internal class WorldReaderV1 : IWorldReader } finally { - reader?.Dispose(); + reader?.Close(); } } } \ No newline at end of file