add file and folder exclusions to copy task
This commit is contained in:
parent
227e68f8fd
commit
4508735c4f
@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using Serilog;
|
||||
@ -8,12 +9,18 @@ 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();
|
||||
@ -25,7 +32,7 @@ public static class FileHelper
|
||||
}
|
||||
}
|
||||
|
||||
private static Result IterateFiles(DirectoryInfo sourceDir, DirectoryInfo targetDir, Action<string, int> updateCallback = null)
|
||||
private static Result IterateFiles(DirectoryInfo sourceDir, DirectoryInfo targetDir, string[] exclusions, Action<string, int> 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<double> progress = null) =>
|
||||
CopyDirectoryWithProgress(sourceDir, targetDir, (msg, prog) => progress?.Report(prog));
|
||||
public static Result CopyDirectoryWithProgress(DirectoryInfo sourceDir, DirectoryInfo targetDir, IProgress<double> progress = null, string[] exclusions = null) =>
|
||||
CopyDirectoryWithProgress(sourceDir, targetDir, (msg, prog) => progress?.Report(prog), exclusions);
|
||||
|
||||
public static Result CopyDirectoryWithProgress(DirectoryInfo sourceDir, DirectoryInfo targetDir, Action<string, int> updateCallback = null)
|
||||
public static Result CopyDirectoryWithProgress(DirectoryInfo sourceDir, DirectoryInfo targetDir, Action<string, int> 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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user