Generalise the finding of sets of files

This commit is contained in:
Steve Streeting 2020-10-06 15:22:33 +01:00
parent 8328051da8
commit b7a0fd4bbe
2 changed files with 27 additions and 10 deletions

25
inc/filetools.ps1 Normal file
View File

@ -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
}

View File

@ -28,6 +28,7 @@ param (
. $PSScriptRoot\inc\uproject.ps1 . $PSScriptRoot\inc\uproject.ps1
. $PSScriptRoot\inc\ueinstall.ps1 . $PSScriptRoot\inc\ueinstall.ps1
. $PSScriptRoot\inc\ueeditor.ps1 . $PSScriptRoot\inc\ueeditor.ps1
. $PSScriptRoot\inc\filetools.ps1
function Write-Usage { function Write-Usage {
@ -139,16 +140,7 @@ try {
Write-Warning "Unknown variant(s) ignored: $($unmatchedVariants -join ", ")" Write-Warning "Unknown variant(s) ignored: $($unmatchedVariants -join ", ")"
} }
$maps = [System.Collections.Generic.HashSet[string]]::New() $maps = Find-File-Set -startDir:$(Join-Path $src "Content") -pattern:*.umap -includeByDefault:$config.CookAllMaps -includeBaseNames:$config.MapsIncluded -excludeBaseNames:$config.MapsExcluded
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($_) }
}
Write-Output "" Write-Output ""
Write-Output "Project File : $projfile" Write-Output "Project File : $projfile"