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