From e7587329f5908c9561cdee3a3f93e4ef837e4a58 Mon Sep 17 00:00:00 2001 From: TomatechGames Date: Mon, 6 Nov 2023 21:19:24 +0000 Subject: [PATCH] Prevent crash when attempting to save course while it is open elsewhere --- Fushigi/course/CourseArea.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Fushigi/course/CourseArea.cs b/Fushigi/course/CourseArea.cs index abf310ef..d5ce402e 100644 --- a/Fushigi/course/CourseArea.cs +++ b/Fushigi/course/CourseArea.cs @@ -134,13 +134,21 @@ public void Save(RSTB resource_table, string folder) var decomp_size = (uint)mem.Length; - //Compress and save the course area - string levelPath = Path.Combine(folder, $"{mAreaName}.bcett.byml.zs"); - File.WriteAllBytes(levelPath, FileUtil.CompressData(mem.ToArray())); + try + { + //Compress and save the course area + string levelPath = Path.Combine(folder, $"{mAreaName}.bcett.byml.zs"); + File.WriteAllBytes(levelPath, FileUtil.CompressData(mem.ToArray())); - //Update resource table - // filePath is a key not an actual path so we cannot use Path.Combine - resource_table.SetResource($"BancMapUnit/{mAreaName}.bcett.byml", decomp_size); + //Update resource table + // filePath is a key not an actual path so we cannot use Path.Combine + resource_table.SetResource($"BancMapUnit/{mAreaName}.bcett.byml", decomp_size); + } + catch(IOException e) + { + //Likely due to the course being open in the game, caught to prevent crash + //TODO: notify the user + } } public string GetName()