From 51dab92826ae091032c4350164d3ce6daf3e1b3c Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Mon, 13 Mar 2023 03:22:50 +1000 Subject: [PATCH] Improve error message shown for malformed `.bk2`/`.tasproj` of course I didn't test it --- .../movie/bk2/Bk2Movie.IO.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs index 305dc4a1ee..eaa65c0655 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs @@ -37,17 +37,19 @@ namespace BizHawk.Client.Common return false; } - using var bl = ZipStateLoader.LoadAndDetect(Filename, true); - if (bl == null) + try { - return false; + using var bl = ZipStateLoader.LoadAndDetect(Filename, true); + if (bl is null) return false; + ClearBeforeLoad(); + LoadFields(bl, preload); + Changes = false; + return true; + } + catch (InvalidDataException e) when (e.StackTrace.Contains("ZipArchive.ReadEndOfCentralDirectory")) + { + throw new Exception("Archive appears to be corrupt. Make a backup, then try to repair it with e.g. 7-Zip.", e); } - - ClearBeforeLoad(); - LoadFields(bl, preload); - - Changes = false; - return true; } public bool PreLoadHeaderAndLength() => Load(true);