Improve error message shown for malformed `.bk2`/`.tasproj`

of course I didn't test it
This commit is contained in:
YoshiRulz 2023-03-13 03:22:50 +10:00
parent 5be9e03a30
commit 51dab92826
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 11 additions and 9 deletions

View File

@ -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);