From 4508735c4f03c87bc4c0723b1bbf9537a801deff Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Sat, 16 Sep 2023 16:10:40 -0400 Subject: [PATCH 1/4] add file and folder exclusions to copy task --- SPTInstaller/Helpers/FileHelper.cs | 35 ++++++++++++++----- .../Installer Tasks/CopyClientTask.cs | 4 ++- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/SPTInstaller/Helpers/FileHelper.cs b/SPTInstaller/Helpers/FileHelper.cs index f3513b6..55d5ea9 100644 --- a/SPTInstaller/Helpers/FileHelper.cs +++ b/SPTInstaller/Helpers/FileHelper.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Text.RegularExpressions; using Serilog; @@ -8,24 +9,30 @@ namespace SPTInstaller.Helpers; public static class FileHelper { - private static Result IterateDirectories(DirectoryInfo sourceDir, DirectoryInfo targetDir) + private static Result IterateDirectories(DirectoryInfo sourceDir, DirectoryInfo targetDir, string[] exclusions) { try { foreach (var dir in sourceDir.GetDirectories("*", SearchOption.AllDirectories)) { + if (exclusions.Contains(dir.FullName.Replace(sourceDir.FullName, ""))) + { + Log.Information($"Excluding Dir: {dir.FullName}"); + continue; + } + Directory.CreateDirectory(dir.FullName.Replace(sourceDir.FullName, targetDir.FullName)); } return Result.FromSuccess(); } - catch (Exception ex) + catch (Exception ex) { Log.Error(ex, "Error while creating directories"); return Result.FromError(ex.Message); } } - private static Result IterateFiles(DirectoryInfo sourceDir, DirectoryInfo targetDir, Action updateCallback = null) + private static Result IterateFiles(DirectoryInfo sourceDir, DirectoryInfo targetDir, string[] exclusions, Action updateCallback = null) { try { @@ -36,6 +43,16 @@ public static class FileHelper { updateCallback?.Invoke(file.Name, (int)Math.Floor(((double)processedFiles / totalFiles) * 100)); + foreach (var exclusion in exclusions) + { + var currentFileRelativePath = file.FullName.Replace(sourceDir.FullName, ""); + + if (currentFileRelativePath.StartsWith(exclusion) || currentFileRelativePath == exclusion) + { + continue; + } + } + File.Copy(file.FullName, file.FullName.Replace(sourceDir.FullName, targetDir.FullName), true); processedFiles++; } @@ -62,18 +79,18 @@ public static class FileHelper return path; } - public static Result CopyDirectoryWithProgress(DirectoryInfo sourceDir, DirectoryInfo targetDir, IProgress progress = null) => - CopyDirectoryWithProgress(sourceDir, targetDir, (msg, prog) => progress?.Report(prog)); + public static Result CopyDirectoryWithProgress(DirectoryInfo sourceDir, DirectoryInfo targetDir, IProgress progress = null, string[] exclusions = null) => + CopyDirectoryWithProgress(sourceDir, targetDir, (msg, prog) => progress?.Report(prog), exclusions); - public static Result CopyDirectoryWithProgress(DirectoryInfo sourceDir, DirectoryInfo targetDir, Action updateCallback = null) + public static Result CopyDirectoryWithProgress(DirectoryInfo sourceDir, DirectoryInfo targetDir, Action updateCallback = null, string[] exclusions = null) { try { - var iterateDirectoriesResult = IterateDirectories(sourceDir, targetDir); + var iterateDirectoriesResult = IterateDirectories(sourceDir, targetDir, exclusions ??= new string[0]); if(!iterateDirectoriesResult.Succeeded) return iterateDirectoriesResult; - var iterateFilesResult = IterateFiles(sourceDir, targetDir, updateCallback); + var iterateFilesResult = IterateFiles(sourceDir, targetDir, exclusions ??= new string[0], updateCallback); if (!iterateFilesResult.Succeeded) return iterateDirectoriesResult; diff --git a/SPTInstaller/Installer Tasks/CopyClientTask.cs b/SPTInstaller/Installer Tasks/CopyClientTask.cs index 646677a..7ab63c3 100644 --- a/SPTInstaller/Installer Tasks/CopyClientTask.cs +++ b/SPTInstaller/Installer Tasks/CopyClientTask.cs @@ -21,6 +21,8 @@ public class CopyClientTask : InstallerTaskBase var originalGameDirInfo = new DirectoryInfo(_data.OriginalGamePath); var targetInstallDirInfo = new DirectoryInfo(_data.TargetInstallPath); - return FileHelper.CopyDirectoryWithProgress(originalGameDirInfo, targetInstallDirInfo, (message, progress) => { SetStatus(null, message, progress, null, true); }); + var exclusions = new[] { "\\Logs" }; + + return FileHelper.CopyDirectoryWithProgress(originalGameDirInfo, targetInstallDirInfo, (message, progress) => { SetStatus(null, message, progress, null, true); }, exclusions); } } \ No newline at end of file From 987f62ed5f7e7a363b52b3e820e0495f68ec58b2 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Sat, 16 Sep 2023 16:11:02 -0400 Subject: [PATCH 2/4] fix cache info getting cut off --- SPTInstaller/Installer Tasks/CopyClientTask.cs | 1 + SPTInstaller/Views/MessageView.axaml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/SPTInstaller/Installer Tasks/CopyClientTask.cs b/SPTInstaller/Installer Tasks/CopyClientTask.cs index 7ab63c3..bdc91ae 100644 --- a/SPTInstaller/Installer Tasks/CopyClientTask.cs +++ b/SPTInstaller/Installer Tasks/CopyClientTask.cs @@ -21,6 +21,7 @@ public class CopyClientTask : InstallerTaskBase var originalGameDirInfo = new DirectoryInfo(_data.OriginalGamePath); var targetInstallDirInfo = new DirectoryInfo(_data.TargetInstallPath); + // relative path for exclusions var exclusions = new[] { "\\Logs" }; return FileHelper.CopyDirectoryWithProgress(originalGameDirInfo, targetInstallDirInfo, (message, progress) => { SetStatus(null, message, progress, null, true); }, exclusions); diff --git a/SPTInstaller/Views/MessageView.axaml b/SPTInstaller/Views/MessageView.axaml index 210c9ec..9335703 100644 --- a/SPTInstaller/Views/MessageView.axaml +++ b/SPTInstaller/Views/MessageView.axaml @@ -38,7 +38,7 @@ Padding="20 10" /> - From 85a562079cf414c6c388f614504c89b8ed269ab4 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Sat, 16 Sep 2023 16:49:24 -0400 Subject: [PATCH 3/4] move live install check to precheck viewmodel also deletes log file and doens't log anything at the message viewmodel so the log isn't in the live directory --- .../Installer Tasks/IntializationTask.cs | 5 ----- SPTInstaller/SPTInstaller.csproj | 4 ++-- SPTInstaller/ViewModels/MessageViewModel.cs | 6 +++-- SPTInstaller/ViewModels/PreChecksViewModel.cs | 22 +++++++++++++++++++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/SPTInstaller/Installer Tasks/IntializationTask.cs b/SPTInstaller/Installer Tasks/IntializationTask.cs index 5d9a163..b713465 100644 --- a/SPTInstaller/Installer Tasks/IntializationTask.cs +++ b/SPTInstaller/Installer Tasks/IntializationTask.cs @@ -34,11 +34,6 @@ public class InitializationTask : InstallerTaskBase return Result.FromError("Unable to find original EFT directory, please make sure EFT is installed. Please also run EFT once"); } - if (_data.OriginalGamePath == _data.TargetInstallPath) - { - return Result.FromError("Installer is located in EFT's original directory. Please move the installer to a seperate folder as per the guide"); - } - if (File.Exists(Path.Join(_data.TargetInstallPath, "EscapeFromTarkov.exe"))) { return Result.FromError("Installer is located in a folder that has existing game files. Please make sure the installer is in a fresh folder as per the guide"); diff --git a/SPTInstaller/SPTInstaller.csproj b/SPTInstaller/SPTInstaller.csproj index 263d4bf..b919a07 100644 --- a/SPTInstaller/SPTInstaller.csproj +++ b/SPTInstaller/SPTInstaller.csproj @@ -9,8 +9,8 @@ icon.ico Assets\icon.ico Debug;Release;TEST - 2.12 - 2.12 + 2.13 + 2.13 diff --git a/SPTInstaller/ViewModels/MessageViewModel.cs b/SPTInstaller/ViewModels/MessageViewModel.cs index 9d1b813..94f1acb 100644 --- a/SPTInstaller/ViewModels/MessageViewModel.cs +++ b/SPTInstaller/ViewModels/MessageViewModel.cs @@ -54,7 +54,7 @@ public class MessageViewModel : ViewModelBase } }); - public MessageViewModel(IScreen Host, IResult result, bool showCloseButton = true) : base(Host) + public MessageViewModel(IScreen Host, IResult result, bool showCloseButton = true, bool noLog = false) : base(Host) { ShowCloseButton = showCloseButton; Message = result.Message; @@ -75,6 +75,8 @@ public class MessageViewModel : ViewModelBase } HasErrors = true; - Log.Error(Message); + + if (!noLog) + Log.Error(Message); } } \ No newline at end of file diff --git a/SPTInstaller/ViewModels/PreChecksViewModel.cs b/SPTInstaller/ViewModels/PreChecksViewModel.cs index e0ff8ca..13aa088 100644 --- a/SPTInstaller/ViewModels/PreChecksViewModel.cs +++ b/SPTInstaller/ViewModels/PreChecksViewModel.cs @@ -2,6 +2,7 @@ using System.Reflection; using System.Threading.Tasks; using System.Windows.Input; +using Avalonia.Controls; using Avalonia.Threading; using DialogHostAvalonia; using ReactiveUI; @@ -78,6 +79,7 @@ public class PreChecksViewModel : ViewModelBase if (data.OriginalGamePath == null) { NavigateTo(new MessageViewModel(HostScreen, Result.FromError("Could not find EFT install.\n\nDo you own and have the game installed?"))); + return; } #endif @@ -86,6 +88,26 @@ public class PreChecksViewModel : ViewModelBase Log.Information($"Install Path: {FileHelper.GetRedactedPath(InstallPath)}"); + if (data.OriginalGamePath == data.TargetInstallPath) + { + Log.CloseAndFlush(); + + var logFiles = Directory.GetFiles(InstallPath, "spt-aki-installer_*.log"); + + // remove log file from original game path if they exist + foreach (var file in logFiles) + { + try + { + File.Delete(file); + } + catch { } + } + + NavigateTo(new MessageViewModel(HostScreen, Result.FromError("Installer is located in EFT's original directory. Please move the installer to a seperate folder as per the guide"), noLog: true)); + return; + } + Task.Run(async () => { if (FileHelper.CheckPathForProblemLocations(InstallPath)) From 57fdc83cb54d3584703fc0d7ed13a3b8038ede90 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Sat, 16 Sep 2023 18:12:24 -0400 Subject: [PATCH 4/4] fix exclusion checks --- SPTInstaller/Helpers/FileHelper.cs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/SPTInstaller/Helpers/FileHelper.cs b/SPTInstaller/Helpers/FileHelper.cs index 55d5ea9..787fd72 100644 --- a/SPTInstaller/Helpers/FileHelper.cs +++ b/SPTInstaller/Helpers/FileHelper.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Reflection; using System.Text.RegularExpressions; using Serilog; @@ -15,12 +14,22 @@ public static class FileHelper { foreach (var dir in sourceDir.GetDirectories("*", SearchOption.AllDirectories)) { - if (exclusions.Contains(dir.FullName.Replace(sourceDir.FullName, ""))) + var exclude = false; + + foreach (var exclusion in exclusions) { - Log.Information($"Excluding Dir: {dir.FullName}"); - continue; + var currentDirRelativePath = dir.FullName.Replace(sourceDir.FullName, ""); + + if (currentDirRelativePath.StartsWith(exclusion) || currentDirRelativePath == exclusion) + { + exclude = true; + break; + } } + if (exclude) + continue; + Directory.CreateDirectory(dir.FullName.Replace(sourceDir.FullName, targetDir.FullName)); } return Result.FromSuccess(); @@ -41,6 +50,8 @@ public static class FileHelper foreach (var file in sourceDir.GetFiles("*.*", SearchOption.AllDirectories)) { + var exclude = false; + updateCallback?.Invoke(file.Name, (int)Math.Floor(((double)processedFiles / totalFiles) * 100)); foreach (var exclusion in exclusions) @@ -49,10 +60,14 @@ public static class FileHelper if (currentFileRelativePath.StartsWith(exclusion) || currentFileRelativePath == exclusion) { - continue; + exclude = true; + break; } } + if (exclude) + continue; + File.Copy(file.FullName, file.FullName.Replace(sourceDir.FullName, targetDir.FullName), true); processedFiles++; }