From 1c5b427a2e596f8b77c172f20661e1816e2917bf Mon Sep 17 00:00:00 2001 From: lahm86 <33758420+lahm86@users.noreply.github.com> Date: Mon, 7 Aug 2023 14:26:05 +0100 Subject: [PATCH] installer: overwrite all essential files Resolves #904. --- CHANGELOG.md | 1 + .../Controls/InstallSettingsStepControl.xaml | 11 ----------- .../Installer/Installers/BaseInstallSource.cs | 3 +-- .../Installer/Installers/GOGInstallSource.cs | 5 ++--- .../Installer/Installers/IInstallSource.cs | 3 +-- .../Installer/Installers/InstallExecutor.cs | 17 ++--------------- .../Installer/Installers/InstallUtils.cs | 9 ++++----- .../Installers/Tomb1MainInstallSource.cs | 6 ++---- .../Installers/TombATIInstallSource.cs | 6 ++---- .../Installer/Models/InstallSettings.cs | 14 -------------- 10 files changed, 15 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1a9c9f7c..3ac15cf03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## [Unreleased](https://github.com/rr-/Tomb1Main/compare/stable...develop) - ××××-××-×× - added the current music track and timestamp to the savegame so they now persist on load (#419) +- changed the installer to always overwrite all essential files such as the gameflow and injections (#904) - fixed Natla's gun moving while she is in her semi death state (#878) - fixed an error message from showing on exiting the game when the gym level is not present in the gameflow (#899) - fixed the bear pat attack so it does not miss Lara (#450) diff --git a/tools/installer/Installer/Controls/InstallSettingsStepControl.xaml b/tools/installer/Installer/Controls/InstallSettingsStepControl.xaml index 4c8c8848c..cfa46db40 100644 --- a/tools/installer/Installer/Controls/InstallSettingsStepControl.xaml +++ b/tools/installer/Installer/Controls/InstallSettingsStepControl.xaml @@ -122,17 +122,6 @@ - - - Overwrite all existing files - - - Overwrites any files such as level data, music files and existing user settings. - If this option is off, only overwrites Tomb1Main.exe in order to update the game. - - - - Create desktop shortcut diff --git a/tools/installer/Installer/Installers/BaseInstallSource.cs b/tools/installer/Installer/Installers/BaseInstallSource.cs index 42dd260c3..bdbf5a9e4 100644 --- a/tools/installer/Installer/Installers/BaseInstallSource.cs +++ b/tools/installer/Installer/Installers/BaseInstallSource.cs @@ -32,8 +32,7 @@ public abstract Task CopyOriginalGameFiles( string sourceDirectory, string targetDirectory, IProgress progress, - bool importSaves, - bool overwrite + bool importSaves ); public abstract bool IsDownloadingMusicNeeded(string sourceDirectory); diff --git a/tools/installer/Installer/Installers/GOGInstallSource.cs b/tools/installer/Installer/Installers/GOGInstallSource.cs index 1b726e7be..07b1d1ec1 100644 --- a/tools/installer/Installer/Installers/GOGInstallSource.cs +++ b/tools/installer/Installer/Installers/GOGInstallSource.cs @@ -38,8 +38,7 @@ public override Task CopyOriginalGameFiles( string sourceDirectory, string targetDirectory, IProgress progress, - bool importSaves, - bool overwrite + bool importSaves ) { var cuePath = Path.Combine(sourceDirectory, "game.dat"); @@ -86,7 +85,7 @@ bool overwrite foreach (var path in filesToExtract) { var targetPath = Path.Combine(targetDirectory, path); - if (!File.Exists(targetPath) || overwrite) + if (!File.Exists(targetPath)) { Directory.CreateDirectory(Path.GetDirectoryName(targetPath)!); diff --git a/tools/installer/Installer/Installers/IInstallSource.cs b/tools/installer/Installer/Installers/IInstallSource.cs index a1ca0f23a..a40afaea4 100644 --- a/tools/installer/Installer/Installers/IInstallSource.cs +++ b/tools/installer/Installer/Installers/IInstallSource.cs @@ -18,8 +18,7 @@ public Task CopyOriginalGameFiles( string sourceDirectory, string targetDirectory, IProgress progress, - bool importSaves, - bool overwrite + bool importSaves ); bool IsDownloadingMusicNeeded(string sourceDirectory); diff --git a/tools/installer/Installer/Installers/InstallExecutor.cs b/tools/installer/Installer/Installers/InstallExecutor.cs index 4506f9c65..2dd1c8e6d 100644 --- a/tools/installer/Installer/Installers/InstallExecutor.cs +++ b/tools/installer/Installer/Installers/InstallExecutor.cs @@ -59,7 +59,7 @@ protected async Task CopyOriginalGameFiles(string sourceDirectory, string target { throw new NullReferenceException(); } - await _settings.InstallSource.CopyOriginalGameFiles(sourceDirectory, targetDirectory, progress, _settings.ImportSaves, _settings.OverwriteAllFiles); + await _settings.InstallSource.CopyOriginalGameFiles(sourceDirectory, targetDirectory, progress, _settings.ImportSaves); } protected async Task CopyTomb1MainFiles(string targetDirectory, IProgress progress) @@ -85,20 +85,7 @@ protected async Task CopyTomb1MainFiles(string targetDirectory, IProgress - _settings.OverwriteAllFiles - || alwaysOverwrite.Any(otherFile => string.Equals(Path.GetFileName(file), otherFile, StringComparison.CurrentCultureIgnoreCase)) - ); + await InstallUtils.ExtractZip(stream, targetDirectory, progress, overwrite: true); } protected void CreateDesktopShortcut(string targetDirectory) diff --git a/tools/installer/Installer/Installers/InstallUtils.cs b/tools/installer/Installer/Installers/InstallUtils.cs index 3134f961a..25caaa734 100644 --- a/tools/installer/Installer/Installers/InstallUtils.cs +++ b/tools/installer/Installer/Installers/InstallUtils.cs @@ -89,13 +89,12 @@ public static async Task DownloadFile(string url, IProgress progress, - Func? overwriteCallback = null + IProgress progress ) { var response = await DownloadFile(url, progress); using var stream = new MemoryStream(response); - await ExtractZip(stream, targetDirectory, progress, overwriteCallback); + await ExtractZip(stream, targetDirectory, progress); } public static async Task ExtractZip( @@ -103,7 +102,7 @@ public static async Task ExtractZip( string targetDirectory, IProgress progress, Func? filterCallback = null, - Func? overwriteCallback = null + bool overwrite = false ) { try @@ -129,7 +128,7 @@ public static async Task ExtractZip( targetDirectory, new Regex(@"[\\/]").Replace(entry.FullName, Path.DirectorySeparatorChar.ToString())); - if (!File.Exists(targetPath) || (overwriteCallback is not null && overwriteCallback(entry.FullName))) + if (!File.Exists(targetPath) || overwrite) { progress.Report(new InstallProgress { diff --git a/tools/installer/Installer/Installers/Tomb1MainInstallSource.cs b/tools/installer/Installer/Installers/Tomb1MainInstallSource.cs index 30e28da8a..580c9bc99 100644 --- a/tools/installer/Installer/Installers/Tomb1MainInstallSource.cs +++ b/tools/installer/Installer/Installers/Tomb1MainInstallSource.cs @@ -37,8 +37,7 @@ public override async Task CopyOriginalGameFiles( string sourceDirectory, string targetDirectory, IProgress progress, - bool importSaves, - bool overwrite + bool importSaves ) { var filterRegex = new Regex(importSaves ? @"(data|fmv|music|saves)[\\/]|save.*\.\d+" : @"(data|fmv|music)[\\/]", RegexOptions.IgnoreCase); @@ -46,8 +45,7 @@ await InstallUtils.CopyDirectoryTree( sourceDirectory, targetDirectory, progress, - file => filterRegex.IsMatch(file), - file => overwrite + file => filterRegex.IsMatch(file) ); } diff --git a/tools/installer/Installer/Installers/TombATIInstallSource.cs b/tools/installer/Installer/Installers/TombATIInstallSource.cs index d1bcbfc50..f668465bb 100644 --- a/tools/installer/Installer/Installers/TombATIInstallSource.cs +++ b/tools/installer/Installer/Installers/TombATIInstallSource.cs @@ -31,8 +31,7 @@ public override async Task CopyOriginalGameFiles( string sourceDirectory, string targetDirectory, IProgress progress, - bool importSaves, - bool overwrite + bool importSaves ) { var filterRegex = new Regex(importSaves ? @"(data|fmv|music)[\\/]|save.*\.\d+\b" : @"(data|fmv|music)[\\/]", RegexOptions.IgnoreCase); @@ -40,8 +39,7 @@ await InstallUtils.CopyDirectoryTree( sourceDirectory, targetDirectory, progress, - file => filterRegex.IsMatch(file), - file => overwrite + file => filterRegex.IsMatch(file) ); } diff --git a/tools/installer/Installer/Models/InstallSettings.cs b/tools/installer/Installer/Models/InstallSettings.cs index 8fedfe86c..97b8088c4 100644 --- a/tools/installer/Installer/Models/InstallSettings.cs +++ b/tools/installer/Installer/Models/InstallSettings.cs @@ -89,19 +89,6 @@ public bool IsDownloadingUnfinishedBusinessNeeded } } - public bool OverwriteAllFiles - { - get => _overwriteAllFiles; - set - { - if (value != _overwriteAllFiles) - { - _overwriteAllFiles = value; - NotifyPropertyChanged(); - } - } - } - public string? SourceDirectory { get => _sourceDirectory; @@ -133,7 +120,6 @@ public string? TargetDirectory private bool _downloadUnfinishedBusiness; private bool _importSaves; private IInstallSource? _installSource; - private bool _overwriteAllFiles = false; private string? _sourceDirectory; private string? _targetDirectory; }