Skip to content

Commit

Permalink
installer: overwrite all essential files
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 authored Aug 7, 2023
1 parent fe76ee3 commit 1c5b427
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 60 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
11 changes: 0 additions & 11 deletions tools/installer/Installer/Controls/InstallSettingsStepControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,6 @@
</TextBlock>
</CheckBox>

<CheckBox VerticalAlignment="Center" Margin="0,0,0,12" IsChecked="{Binding InstallSettings.OverwriteAllFiles}">
<TextBlock TextWrapping="Wrap">
Overwrite all existing files
<LineBreak />
<Run Style="{StaticResource small}">
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.
</Run>
</TextBlock>
</CheckBox>

<CheckBox VerticalAlignment="Center" Margin="0,0,0,12" IsChecked="{Binding InstallSettings.CreateDesktopShortcut}">
Create desktop shortcut
</CheckBox>
Expand Down
3 changes: 1 addition & 2 deletions tools/installer/Installer/Installers/BaseInstallSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public abstract Task CopyOriginalGameFiles(
string sourceDirectory,
string targetDirectory,
IProgress<InstallProgress> progress,
bool importSaves,
bool overwrite
bool importSaves
);

public abstract bool IsDownloadingMusicNeeded(string sourceDirectory);
Expand Down
5 changes: 2 additions & 3 deletions tools/installer/Installer/Installers/GOGInstallSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public override Task CopyOriginalGameFiles(
string sourceDirectory,
string targetDirectory,
IProgress<InstallProgress> progress,
bool importSaves,
bool overwrite
bool importSaves
)
{
var cuePath = Path.Combine(sourceDirectory, "game.dat");
Expand Down Expand Up @@ -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)!);

Expand Down
3 changes: 1 addition & 2 deletions tools/installer/Installer/Installers/IInstallSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public Task CopyOriginalGameFiles(
string sourceDirectory,
string targetDirectory,
IProgress<InstallProgress> progress,
bool importSaves,
bool overwrite
bool importSaves
);

bool IsDownloadingMusicNeeded(string sourceDirectory);
Expand Down
17 changes: 2 additions & 15 deletions tools/installer/Installer/Installers/InstallExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstallProgress> progress)
Expand All @@ -85,20 +85,7 @@ protected async Task CopyTomb1MainFiles(string targetDirectory, IProgress<Instal
throw new ApplicationException($"Could not open embedded ZIP.");
}

var alwaysOverwrite = new string[]
{
"Tomb1Main.exe",
};

await InstallUtils.ExtractZip(
stream,
targetDirectory,
progress,
overwriteCallback:
file =>
_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)
Expand Down
9 changes: 4 additions & 5 deletions tools/installer/Installer/Installers/InstallUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,20 @@ public static async Task<byte[]> DownloadFile(string url, IProgress<InstallProgr
public static async Task DownloadZip(
string url,
string targetDirectory,
IProgress<InstallProgress> progress,
Func<string, bool>? overwriteCallback = null
IProgress<InstallProgress> 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(
Stream stream,
string targetDirectory,
IProgress<InstallProgress> progress,
Func<string, bool>? filterCallback = null,
Func<string, bool>? overwriteCallback = null
bool overwrite = false
)
{
try
Expand All @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ public override async Task CopyOriginalGameFiles(
string sourceDirectory,
string targetDirectory,
IProgress<InstallProgress> progress,
bool importSaves,
bool overwrite
bool importSaves
)
{
var filterRegex = new Regex(importSaves ? @"(data|fmv|music|saves)[\\/]|save.*\.\d+" : @"(data|fmv|music)[\\/]", RegexOptions.IgnoreCase);
await InstallUtils.CopyDirectoryTree(
sourceDirectory,
targetDirectory,
progress,
file => filterRegex.IsMatch(file),
file => overwrite
file => filterRegex.IsMatch(file)
);
}

Expand Down
6 changes: 2 additions & 4 deletions tools/installer/Installer/Installers/TombATIInstallSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ public override async Task CopyOriginalGameFiles(
string sourceDirectory,
string targetDirectory,
IProgress<InstallProgress> progress,
bool importSaves,
bool overwrite
bool importSaves
)
{
var filterRegex = new Regex(importSaves ? @"(data|fmv|music)[\\/]|save.*\.\d+\b" : @"(data|fmv|music)[\\/]", RegexOptions.IgnoreCase);
await InstallUtils.CopyDirectoryTree(
sourceDirectory,
targetDirectory,
progress,
file => filterRegex.IsMatch(file),
file => overwrite
file => filterRegex.IsMatch(file)
);
}

Expand Down
14 changes: 0 additions & 14 deletions tools/installer/Installer/Models/InstallSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,6 @@ public bool IsDownloadingUnfinishedBusinessNeeded
}
}

public bool OverwriteAllFiles
{
get => _overwriteAllFiles;
set
{
if (value != _overwriteAllFiles)
{
_overwriteAllFiles = value;
NotifyPropertyChanged();
}
}
}

public string? SourceDirectory
{
get => _sourceDirectory;
Expand Down Expand Up @@ -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;
}

0 comments on commit 1c5b427

Please sign in to comment.