From b7a0fd4bbe478916d7794f00b2241a81eb3c1c2d Mon Sep 17 00:00:00 2001 From: Steve Streeting Date: Tue, 6 Oct 2020 15:22:33 +0100 Subject: [PATCH] Generalise the finding of sets of files --- inc/filetools.ps1 | 25 +++++++++++++++++++++++++ ue4-package.ps1 | 12 ++---------- 2 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 inc/filetools.ps1 diff --git a/inc/filetools.ps1 b/inc/filetools.ps1 new file mode 100644 index 0000000..8b83e9d --- /dev/null +++ b/inc/filetools.ps1 @@ -0,0 +1,25 @@ +function Find-File-Set { + param ( + [string]$startDir, + [string]$pattern, + [bool]$includeByDefault, + [array]$includeBaseNames, + [array]$excludeBaseNames + ) + + $set = [System.Collections.Generic.HashSet[string]]::New() + Get-ChildItem -Path $startDir -Filter $pattern -Recurse | ForEach-Object { + if ($includeByDefault) { + if ($excludeBaseNames -notcontains $_.BaseName) { + $set.Add($_.BaseName) > $null + } + } else { + if ($includeBaseNames -contains $_.BaseName) { + $set.Add($_.BaseName) > $null + } + } + } + + return $set + +} \ No newline at end of file diff --git a/ue4-package.ps1 b/ue4-package.ps1 index e4c1ff0..66c54ce 100644 --- a/ue4-package.ps1 +++ b/ue4-package.ps1 @@ -28,6 +28,7 @@ param ( . $PSScriptRoot\inc\uproject.ps1 . $PSScriptRoot\inc\ueinstall.ps1 . $PSScriptRoot\inc\ueeditor.ps1 +. $PSScriptRoot\inc\filetools.ps1 function Write-Usage { @@ -139,16 +140,7 @@ try { Write-Warning "Unknown variant(s) ignored: $($unmatchedVariants -join ", ")" } - $maps = [System.Collections.Generic.HashSet[string]]::New() - if ($config.CookAllMaps) { - Get-ChildItem -Path $(Join-Path $src "Content") -Filter *.umap -Recurse | ForEach-Object { - if ($config.MapsExcluded -notcontains $_.BaseName) { - $maps.Add($_.BaseName) - } - } - } elseif ($config.MapsIncluded) { - $config.MapsIncluded | ForEach-Object { $maps.Add($_) } - } + $maps = Find-File-Set -startDir:$(Join-Path $src "Content") -pattern:*.umap -includeByDefault:$config.CookAllMaps -includeBaseNames:$config.MapsIncluded -excludeBaseNames:$config.MapsExcluded Write-Output "" Write-Output "Project File : $projfile"