-
Notifications
You must be signed in to change notification settings - Fork 18
/
Resolve-XMLDependencies.ps1
65 lines (58 loc) · 2.63 KB
/
Resolve-XMLDependencies.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function Resolve-XMLDependencies {
Param (
[Parameter( Mandatory = $true )]
[ValidateNotNullOrEmpty()]
$XMLIN,
[Parameter( Mandatory = $true )]
[string]$PackagePath,
[switch]$TreatUnsupportedAsPassed,
[switch]$FailInboxDrivers,
[switch]$ParentNodeIsAnd
)
$XMLTreeDepth++
[DependencyParserState]$ParserState = 0
$i = 0
foreach ($XMLTREE in $XMLIN) {
$i++
Write-Debug "$('- ' * $XMLTreeDepth )|> Node: $($XMLTREE.SchemaInfo.Name)"
if ($XMLTREE.SchemaInfo.Name -eq 'Not') {
$ParserState = $ParserState -bxor 1
Write-Debug "$('- ' * $XMLTreeDepth)Switched state to: $ParserState"
}
$Result = if ($XMLTREE.SchemaInfo.Name -like "_*") {
switch (Test-MachineSatisfiesDependency -Dependency $XMLTREE -PackagePath $PackagePath -DebugIndent $XMLTreeDepth -FailInboxDrivers:$FailInboxDrivers) {
0 {
$true
}
-1 {
$false
}
-2 {
Write-Debug "$('- ' * $XMLTreeDepth)Something unsupported encountered in: $($XMLTREE.SchemaInfo.Name)"
if ($TreatUnsupportedAsPassed) { $true } else { $false }
}
}
} else {
$SubtreeResults = Resolve-XMLDependencies -XMLIN $XMLTREE.ChildNodes -PackagePath $PackagePath -TreatUnsupportedAsPassed:$TreatUnsupportedAsPassed -FailInboxDrivers:$FailInboxDrivers -ParentNodeIsAnd:($XMLTREE.SchemaInfo.Name -eq 'And')
switch ($XMLTREE.SchemaInfo.Name) {
'And' {
Write-Debug "$('- ' * $XMLTreeDepth)Tree was AND: Results: $subtreeresults"
if ($subtreeresults -contains $false) { $false } else { $true }
}
default {
Write-Debug "$('- ' * $XMLTreeDepth)Tree was OR: Results: $subtreeresults"
if ($subtreeresults -contains $true ) { $true } else { $false }
}
}
}
Write-Debug "$('- ' * $XMLTreeDepth)< Returning $($Result -bxor $ParserState) from node $($XMLTREE.SchemaInfo.Name)"
$Result -bxor $ParserState
if ($ParentNodeIsAnd -and $i -ne $XMLIN.Count -and -not ($Result -bxor $ParserState)) {
Write-Debug "$('- ' * $XMLTreeDepth)Quitting AND evaluation early because we already got one FALSE."
$ParserState = 0 # DO_HAVE
break;
}
$ParserState = 0 # DO_HAVE
}
$XMLTreeDepth--
}