Verify sizes on load

This commit is contained in:
Kurt
2020-04-15 10:14:48 -07:00
parent 1af352dae5
commit 14bbc73481
2 changed files with 34 additions and 1 deletions

View File

@@ -57,5 +57,27 @@ public void ChangeIdentity(byte[] original, byte[] updated)
foreach (var pair in Players.SelectMany(z => z))
pair.Data.ReplaceOccurrences(original, updated);
}
public bool ValidateSizes()
{
var info = Main.Info.GetKnownRevisionIndex();
if (info < 0)
return false;
var sizes = RevisionChecker.SizeInfo[info];
if (Main.Data.Length != sizes.Main)
return false;
foreach (var p in Players)
{
if (p.Personal.Data.Length != sizes.Personal)
return false;
if (p.Photo.Data.Length != sizes.PhotoStudioIsland)
return false;
if (p.PostBox.Data.Length != sizes.PostBox)
return false;
if (p.Profile.Data.Length != sizes.Profile)
return false;
}
return true;
}
}
}

View File

@@ -27,7 +27,18 @@ public Main()
Open(args[i]);
}
private static void Open(HorizonSave file) => new Editor(file).Show();
private static void Open(HorizonSave file)
{
bool sized = file.ValidateSizes();
if (!sized)
{
const string sizeBad = "Save file sizes appear to be incorrect.";
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, sizeBad, "Continue?") != DialogResult.Yes)
return;
}
new Editor(file).Show();
}
private void Main_DragEnter(object sender, DragEventArgs e)
{