diff --git a/CHANGELOG.md b/CHANGELOG.md index 24ee8ef13..1264ef870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## [Unreleased](https://github.com/LostArtefacts/TR-Rando/compare/V1.9.1...master) - xxxx-xx-xx +- improved data integrity checks when opening a folder and prior to randomization (#719) ## [V1.9.1](https://github.com/LostArtefacts/TR-Rando/compare/V1.9.0...V1.9.1) - 2024-06-23 - fixed a missing reference related to Willard, which would cause enemy randomization to fail if he was selected (#712) diff --git a/Deps/TRGE.Coord.dll b/Deps/TRGE.Coord.dll index 15df017f9..4e4e8d50b 100644 Binary files a/Deps/TRGE.Coord.dll and b/Deps/TRGE.Coord.dll differ diff --git a/Deps/TRGE.Core.dll b/Deps/TRGE.Core.dll index 89e7c6486..0ecb673df 100644 Binary files a/Deps/TRGE.Core.dll and b/Deps/TRGE.Core.dll differ diff --git a/TRRandomizerCore/Helpers/ChecksumTester.cs b/TRRandomizerCore/Helpers/ChecksumTester.cs index aa51039a4..6a5259f25 100644 --- a/TRRandomizerCore/Helpers/ChecksumTester.cs +++ b/TRRandomizerCore/Helpers/ChecksumTester.cs @@ -111,6 +111,7 @@ public bool Test(string file) "1e7d0d88ff9d569e22982af761bb006b", // FLOATING.TR2 (Multipatch/EPC) "fd8c45efc3f5e690edd0796d350a28ba", // XIAN.TR2 "b56c04ea52227eb7fdebd0665b45357a", // HOUSE.TR2 + "2241125203a4af81fc4889ed844d5b22", // HOUSE.TR2 (rando-generated for texture optimisation) "04ad2f33e48081a6b27a7f0ebf90968d", // LEVEL1.TR2 "d9b53b88dd70eec1e4b31182f3286bf5", // LEVEL2.TR2 "ca4294e3bd8835ebf06e114b479a22c2", // LEVEL3.TR2 diff --git a/TRRandomizerCore/TRRandomizerController.cs b/TRRandomizerCore/TRRandomizerController.cs index deb7cac5a..a26874913 100644 --- a/TRRandomizerCore/TRRandomizerController.cs +++ b/TRRandomizerCore/TRRandomizerController.cs @@ -20,10 +20,11 @@ public class TRRandomizerController internal AbstractTRScriptEditor ScriptEditor => _editor.ScriptEditor; internal RandomizerSettings LevelRandomizer => (_editor.LevelEditor as ISettingsProvider).Settings; - internal TRRandomizerController(string directoryPath, bool performChecksumTest) + internal TRRandomizerController(string directoryPath) { - // If there is a checksum mismatch, we will just ignore the previous backup and open the folder afresh - _editor = TRCoord.Instance.Open(directoryPath, TRScriptOpenOption.DiscardBackup, performChecksumTest ? TRBackupChecksumOption.PerformCheck : TRBackupChecksumOption.IgnoreIssues); + // If there is a script checksum mismatch, we will just ignore the previous backup and open the folder afresh. If the + // data files fail the checksum test, the folder cannot be opened. + _editor = TRCoord.Instance.Open(directoryPath, TRScriptOpenOption.DiscardBackup, TRBackupChecksumOption.PerformCheck); _editor.SaveProgressChanged += Editor_SaveProgressChanged; _editor.RestoreProgressChanged += Editor_RestoreProgressChanged; StoreExternalOrganisations(); diff --git a/TRRandomizerCore/TRRandomizerCoord.cs b/TRRandomizerCore/TRRandomizerCoord.cs index 813a7b563..f6e5bc428 100644 --- a/TRRandomizerCore/TRRandomizerCoord.cs +++ b/TRRandomizerCore/TRRandomizerCoord.cs @@ -68,10 +68,10 @@ public void Initialise(string applicationID, string version, string taggedVersio TRCoord.Instance.BackupProgressChanged += TRCoord_BackupProgressChanged; } - public TRRandomizerController Open(string directoryPath, bool performChecksumTest) + public TRRandomizerController Open(string directoryPath) { _openEventArgs = new(); - return new(directoryPath, performChecksumTest); + return new(directoryPath); } public static void ClearHistory() @@ -79,6 +79,11 @@ public static void ClearHistory() TRCoord.Instance.ClearHistory(); } + public static void CheckBackupIntegrity() + { + TRCoord.Instance.CheckBackupIntegrity(); + } + public static void ClearCurrentBackup() { TRCoord.Instance.ClearCurrentBackup(); diff --git a/TRRandomizerView/Controls/EditorControl.xaml.cs b/TRRandomizerView/Controls/EditorControl.xaml.cs index 4ae1b273f..1bf938091 100644 --- a/TRRandomizerView/Controls/EditorControl.xaml.cs +++ b/TRRandomizerView/Controls/EditorControl.xaml.cs @@ -7,6 +7,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Threading; +using TRGE.Core; using TRRandomizerCore; using TRRandomizerView.Events; using TRRandomizerView.Model; @@ -88,6 +89,7 @@ private void FireEditorStateChanged() { EditorStateChanged?.Invoke(this, new EditorEventArgs { + IsLoaded = Controller != null, IsDirty = _dirty, CanExport = Controller != null && Controller.IsExportPossible, ReloadRequested = _reloadRequested @@ -158,6 +160,23 @@ public bool Randomize() return false; } + try + { + TRRandomizerCoord.CheckBackupIntegrity(); + } + catch (ChecksumMismatchException) + { + MessageWindow.ShowError("Game backup data integrity check failed. Randomization cannot be performed as the game data files in the backup directory are not original." + + "\n\nPlease uninstall the game and remove any external mods you may have applied.\n\nOnce complete, reinstall the game afresh, and open the data folder again in the randomizer to proceed.", + "https://github.com/LostArtefacts/TR-Rando/blob/master/USING.md#troubleshooting"); + + if (DeleteBackupImpl()) + { + Unload(); + } + return false; + } + if (_options.DevelopmentMode) { if (!MessageWindow.ShowConfirm("Development mode is switched on and so the generated level files will not be playable.\n\nDo you wish to continue?")) @@ -284,23 +303,26 @@ public void RestoreDefaults() public bool DeleteBackup() { - if (MessageWindow.ShowConfirm("The files that were backed up when this folder was first opened will be deleted and the editor will be closed.\n\nDo you wish to proceed?")) + return MessageWindow.ShowConfirm("The files that were backed up when this folder was first opened will be deleted and the editor will be closed.\n\nDo you wish to proceed?") + && DeleteBackupImpl(); + } + + private bool DeleteBackupImpl() + { + try { - try - { - _showExternalModPrompt = false; - TRRandomizerCoord.ClearCurrentBackup(); - _dirty = false; - return true; - } - catch (Exception e) - { - MessageWindow.ShowException(e); - } - finally - { - _showExternalModPrompt = true; - } + _showExternalModPrompt = false; + TRRandomizerCoord.ClearCurrentBackup(); + _dirty = false; + return true; + } + catch (Exception e) + { + MessageWindow.ShowException(e); + } + finally + { + _showExternalModPrompt = true; } return false; diff --git a/TRRandomizerView/Controls/FolderLoadControl.xaml.cs b/TRRandomizerView/Controls/FolderLoadControl.xaml.cs index e5eeb261b..4a8775c38 100644 --- a/TRRandomizerView/Controls/FolderLoadControl.xaml.cs +++ b/TRRandomizerView/Controls/FolderLoadControl.xaml.cs @@ -93,9 +93,9 @@ public void OpenDataFolder(RecentFolder folder) OpenDataFolder(folder.FolderPath); } - public void OpenDataFolder(string folderPath, bool performChecksumTest = true) + public void OpenDataFolder(string folderPath) { - OpenProgressWindow opw = new(folderPath, performChecksumTest); + OpenProgressWindow opw = new(folderPath); try { if (opw.ShowDialog() ?? false) @@ -109,12 +109,9 @@ public void OpenDataFolder(string folderPath, bool performChecksumTest = true) } catch (ChecksumMismatchException) { - if (!MessageWindow.ShowConfirm(folderPath + "\n\nGame data integrity check failed. Randomization may not perform as expected as the game data files in the chosen directory are not original." + - "\n\nThe recommended action is for you to re-install the game. Once complete, open the data folder again in the randomizer to proceed." + - "\n\nDo you want to cancel the current operation and take the recommended action?")) - { - OpenDataFolder(folderPath, false); - } + MessageWindow.ShowError(folderPath + "\n\nGame data integrity check failed. Randomization cannot be performed as the game data files in the chosen directory are not original." + + "\n\nPlease uninstall the game and remove any external mods you may have applied.\n\nOnce complete, reinstall the game afresh, and open the data folder again in the randomizer to proceed.", + "https://github.com/LostArtefacts/TR-Rando/blob/master/USING.md#troubleshooting"); } catch (Exception e) { diff --git a/TRRandomizerView/Events/EditorEventArgs.cs b/TRRandomizerView/Events/EditorEventArgs.cs index ee929a2c9..ff0962e47 100644 --- a/TRRandomizerView/Events/EditorEventArgs.cs +++ b/TRRandomizerView/Events/EditorEventArgs.cs @@ -4,6 +4,7 @@ namespace TRRandomizerView.Events; public class EditorEventArgs : EventArgs { + public bool IsLoaded { get; set; } public bool IsDirty { get; set; } public bool CanExport { get; set; } public bool ReloadRequested { get; set; } diff --git a/TRRandomizerView/Windows/MainWindow.xaml.cs b/TRRandomizerView/Windows/MainWindow.xaml.cs index 7bd2ecd9a..d71116329 100644 --- a/TRRandomizerView/Windows/MainWindow.xaml.cs +++ b/TRRandomizerView/Windows/MainWindow.xaml.cs @@ -244,7 +244,11 @@ private void EditorControl_EditorStateChanged(object sender, EditorEventArgs e) IsEditorDirty = e.IsDirty; EditorCanExport = e.CanExport; _developmentModeMenuItem.IsChecked = _editorControl.DevelopmentMode; - if (e.ReloadRequested) + if (!e.IsLoaded) + { + IsEditorActive = false; + } + else if (e.ReloadRequested) { _editorControl.Unload(); IsEditorActive = false; diff --git a/TRRandomizerView/Windows/MessageWindow.xaml b/TRRandomizerView/Windows/MessageWindow.xaml index f628c07f6..4a400d04c 100644 --- a/TRRandomizerView/Windows/MessageWindow.xaml +++ b/TRRandomizerView/Windows/MessageWindow.xaml @@ -50,12 +50,20 @@ -