June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,88 @@
Function Read-ConfigurationFile {
[CmdletBinding()]
[OutputType([Collections.Specialized.OrderedDictionary])]
Param (
[Parameter(
Mandatory=$true,
Position=0
)
]
[Alias('LiteralPath')]
[ValidateScript({
Test-Path -LiteralPath $PSItem -PathType 'Leaf'
})
]
[String]
$_LiteralPath
)
Begin {
Function Houdini-Value ([String]$_Text) {
$__Aux = $_Text.Trim()
If ($__Aux.Length -eq 0) {
$__Aux = $true
} ElseIf ($__Aux.Contains(',')) {
$__Aux = $__Aux.Split(',') |
ForEach-Object {
If ($PSItem.Trim().Length -ne 0) {
$PSItem.Trim()
}
}
}
Return $__Aux
}
}
Process {
$__Configuration = [Ordered]@{}
# Config equivalent pattern
# Select-String -Pattern '^\s*[^\s;#=]+.*\s*$' -LiteralPath '.\filename.cfg'
Switch -Regex -File $_LiteralPath {
'^\s*[;#=]|^\s*$' {
Write-Verbose -Message "v$(' '*20)ignored"
Write-Verbose -Message $Matches[0]
Continue
}
'^([^=]+)=(.*)$' {
Write-Verbose -Message '↓← ← ← ← ← ← ← ← ← ← equal pattern'
Write-Verbose -Message $Matches[0]
$__Name,$__Value = $Matches[1..2]
$__Configuration[$__Name.Trim()] = Houdini-Value($__Value)
Continue
}
'^\s*([^\s;#=]+)(.*)(\s*)$' {
Write-Verbose -Message '↓← ← ← ← ← ← ← ← ← ← space or tab pattern or only name'
Write-Verbose -Message $Matches[0]
$__Name,$__Value = $Matches[1..2]
$__Configuration[$__Name.Trim()] = Houdini-Value($__Value)
Continue
}
}
Return $__Configuration
}
}
Function Show-Value ([Collections.Specialized.OrderedDictionary]$_Dictionary, $_Index, $_SubIndex) {
$__Aux = $_Index + ' = '
If ($_Dictionary[$_Index] -eq $null) {
$__Aux += $false
} ElseIf ($_Dictionary[$_Index].Count -gt 1) {
If ($_SubIndex -eq $null) {
$__Aux += $_Dictionary[$_Index] -join ','
} Else {
$__Aux = $_Index + '(' + $_SubIndex + ') = '
If ($_Dictionary[$_Index][$_SubIndex] -eq $null) {
$__Aux += $false
} Else {
$__Aux += $_Dictionary[$_Index][$_SubIndex]
}
}
} Else {
$__Aux += $_Dictionary[$_Index]
}
Return $__Aux
}

View file

@ -0,0 +1 @@
$Configuration = Read-ConfigurationFile -LiteralPath '.\config.cfg'

View file

@ -0,0 +1 @@
$Configuration

View file

@ -0,0 +1,8 @@
Show-Value $Configuration 'fullname'
Show-Value $Configuration 'favouritefruit'
Show-Value $Configuration 'needspeeling'
Show-Value $Configuration 'seedsremoved'
Show-Value $Configuration 'otherfamily'
Show-Value $Configuration 'otherfamily' 0
Show-Value $Configuration 'otherfamily' 1
Show-Value $Configuration 'otherfamily' 2

View file

@ -0,0 +1,45 @@
'$Configuration[''fullname'']'
$Configuration['fullname']
'$Configuration.''fullname'''
$Configuration.'fullname'
'$Configuration.Item(''fullname'')'
$Configuration.Item('fullname')
'$Configuration[0]'
$Configuration[0]
'$Configuration.Item(0)'
$Configuration.Item(0)
' '
'=== $Configuration[''otherfamily''] ==='
$Configuration['otherfamily']
'=== $Configuration[''otherfamily''][0] ==='
$Configuration['otherfamily'][0]
'=== $Configuration[''otherfamily''][1] ==='
$Configuration['otherfamily'][1]
' '
'=== $Configuration.''otherfamily'' ==='
$Configuration.'otherfamily'
'=== $Configuration.''otherfamily''[0] ==='
$Configuration.'otherfamily'[0]
'=== $Configuration.''otherfamily''[1] ==='
$Configuration.'otherfamily'[1]
' '
'=== $Configuration.Item(''otherfamily'') ==='
$Configuration.Item('otherfamily')
'=== $Configuration.Item(''otherfamily'')[0] ==='
$Configuration.Item('otherfamily')[0]
'=== $Configuration.Item(''otherfamily'')[1] ==='
$Configuration.Item('otherfamily')[1]
' '
'=== $Configuration[3] ==='
$Configuration[3]
'=== $Configuration[3][0] ==='
$Configuration[3][0]
'=== $Configuration[3][1] ==='
$Configuration[3][1]
' '
'=== $Configuration.Item(3) ==='
$Configuration.Item(3)
'=== $Configuration.Item(3).Item(0) ==='
$Configuration.Item(3).Item(0)
'=== $Configuration.Item(3).Item(1) ==='
$Configuration.Item(3).Item(1)