Skip to content

Commit

Permalink
Prevent crash when attempting to save course while it is open elsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
TomatechGames committed Nov 6, 2023
1 parent 103816c commit 8313032
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
20 changes: 14 additions & 6 deletions Fushigi/course/CourseArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 10 additions & 2 deletions Fushigi/rstb/RSTB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,19 @@ public void Save()

var mem = new MemoryStream();
Write(mem);

File.WriteAllBytes(

try
{
File.WriteAllBytes(
Path.Combine(dir, "ResourceSizeTable.Product.100.rsizetable.zs"),
FileUtil.CompressData(mem.ToArray())
);
}
catch (IOException e)
{
//Likely due to the course being open in the game, caught to prevent crash
//TODO: notify the user
}
}

private void Read(Stream stream)
Expand Down

0 comments on commit 8313032

Please sign in to comment.