diff --git a/SPTInstaller/Helpers/FileHelper.cs b/SPTInstaller/Helpers/FileHelper.cs index f3513b6..787fd72 100644 --- a/SPTInstaller/Helpers/FileHelper.cs +++ b/SPTInstaller/Helpers/FileHelper.cs @@ -8,24 +8,40 @@ 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)) { + var exclude = false; + + foreach (var exclusion in exclusions) + { + 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(); } - 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 { @@ -34,8 +50,24 @@ 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) + { + var currentFileRelativePath = file.FullName.Replace(sourceDir.FullName, ""); + + if (currentFileRelativePath.StartsWith(exclusion) || currentFileRelativePath == exclusion) + { + exclude = true; + break; + } + } + + if (exclude) + continue; + File.Copy(file.FullName, file.FullName.Replace(sourceDir.FullName, targetDir.FullName), true); processedFiles++; } @@ -62,18 +94,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..bdc91ae 100644 --- a/SPTInstaller/Installer Tasks/CopyClientTask.cs +++ b/SPTInstaller/Installer Tasks/CopyClientTask.cs @@ -21,6 +21,9 @@ 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); }); + // relative path for exclusions + var exclusions = new[] { "\\Logs" }; + + return FileHelper.CopyDirectoryWithProgress(originalGameDirInfo, targetInstallDirInfo, (message, progress) => { SetStatus(null, message, progress, null, true); }, exclusions); } } \ No newline at end of file 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)) 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" /> -