Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,107 +0,0 @@
|
|||
function Update-ConfigurationFile
|
||||
{
|
||||
[CmdletBinding()]
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory=$false,
|
||||
Position=0)]
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]
|
||||
$Path = ".\config.txt",
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]
|
||||
$FavouriteFruit,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[int]
|
||||
$NumberOfBananas,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[int]
|
||||
$NumberOfStrawberries,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[ValidateSet("On", "Off")]
|
||||
[string]
|
||||
$NeedsPeeling,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[ValidateSet("On", "Off")]
|
||||
[string]
|
||||
$SeedsRemoved
|
||||
)
|
||||
|
||||
[string[]]$lines = Get-Content $Path
|
||||
|
||||
Clear-Content $Path
|
||||
|
||||
if (-not ($lines | Select-String -Pattern "^\s*NumberOfStrawberries" -Quiet))
|
||||
{
|
||||
"", "# How many strawberries we have", "NumberOfStrawberries 0" | ForEach-Object {$lines += $_}
|
||||
}
|
||||
|
||||
foreach ($line in $lines)
|
||||
{
|
||||
$line = $line -replace "^\s*","" ## Strip leading whitespace
|
||||
|
||||
if ($line -match "[;].*\s*") {continue} ## Strip semicolons
|
||||
|
||||
switch -Regex ($line)
|
||||
{
|
||||
"(^$)|(^#\s.*)" ## Blank line or comment
|
||||
{
|
||||
$line = $line
|
||||
}
|
||||
"^FavouriteFruit\s*.*" ## Parameter FavouriteFruit
|
||||
{
|
||||
if ($FavouriteFruit)
|
||||
{
|
||||
$line = "FAVOURITEFRUIT $FavouriteFruit"
|
||||
}
|
||||
}
|
||||
"^NumberOfBananas\s*.*" ## Parameter NumberOfBananas
|
||||
{
|
||||
if ($NumberOfBananas)
|
||||
{
|
||||
$line = "NUMBEROFBANANAS $NumberOfBananas"
|
||||
}
|
||||
}
|
||||
"^NumberOfStrawberries\s*.*" ## Parameter NumberOfStrawberries
|
||||
{
|
||||
if ($NumberOfStrawberries)
|
||||
{
|
||||
$line = "NUMBEROFSTRAWBERRIES $NumberOfStrawberries"
|
||||
}
|
||||
}
|
||||
".*NeedsPeeling\s*.*" ## Parameter NeedsPeeling
|
||||
{
|
||||
if ($NeedsPeeling -eq "On")
|
||||
{
|
||||
$line = "NEEDSPEELING"
|
||||
}
|
||||
elseif ($NeedsPeeling -eq "Off")
|
||||
{
|
||||
$line = "; NEEDSPEELING"
|
||||
}
|
||||
}
|
||||
".*SeedsRemoved\s*.*" ## Parameter SeedsRemoved
|
||||
{
|
||||
if ($SeedsRemoved -eq "On")
|
||||
{
|
||||
$line = "SEEDSREMOVED"
|
||||
}
|
||||
elseif ($SeedsRemoved -eq "Off")
|
||||
{
|
||||
$line = "; SEEDSREMOVED"
|
||||
}
|
||||
}
|
||||
Default ## Whatever...
|
||||
{
|
||||
$line = $line
|
||||
}
|
||||
}
|
||||
|
||||
Add-Content $Path -Value $line -Force
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
Update-ConfigurationFile -NumberOfStrawberries 62000 -NumberOfBananas 1024 -SeedsRemoved On -NeedsPeeling Off
|
||||
|
||||
Invoke-Item -Path ".\config.txt"
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
Set objFSO = CreateObject("Scripting.FileSystemObject")
|
||||
|
||||
'Paramater lookups
|
||||
Set objParamLookup = CreateObject("Scripting.Dictionary")
|
||||
With objParamLookup
|
||||
.Add "FAVOURITEFRUIT", "banana"
|
||||
.Add "NEEDSPEELING", ""
|
||||
.Add "SEEDSREMOVED", ""
|
||||
.Add "NUMBEROFBANANAS", "1024"
|
||||
.Add "NUMBEROFSTRAWBERRIES", "62000"
|
||||
End With
|
||||
|
||||
'Open the config file for reading.
|
||||
Set objInFile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) &_
|
||||
"\IN_config.txt",1)
|
||||
'Initialize output.
|
||||
Output = ""
|
||||
Isnumberofstrawberries = False
|
||||
With objInFile
|
||||
Do Until .AtEndOfStream
|
||||
line = .ReadLine
|
||||
If Left(line,1) = "#" Or line = "" Then
|
||||
Output = Output & line & vbCrLf
|
||||
ElseIf Left(line,1) = " " And InStr(line,"#") Then
|
||||
Output = Output & Mid(line,InStr(1,line,"#"),1000) & vbCrLf
|
||||
ElseIf Replace(Replace(line,";","")," ","") <> "" Then
|
||||
If InStr(1,line,"FAVOURITEFRUIT",1) Then
|
||||
Output = Output & "FAVOURITEFRUIT" & " " & objParamLookup.Item("FAVOURITEFRUIT") & vbCrLf
|
||||
ElseIf InStr(1,line,"NEEDSPEELING",1) Then
|
||||
Output = Output & "; " & "NEEDSPEELING" & vbCrLf
|
||||
ElseIf InStr(1,line,"SEEDSREMOVED",1) Then
|
||||
Output = Output & "SEEDSREMOVED" & vbCrLf
|
||||
ElseIf InStr(1,line,"NUMBEROFBANANAS",1) Then
|
||||
Output = Output & "NUMBEROFBANANAS" & " " & objParamLookup.Item("NUMBEROFBANANAS") & vbCrLf
|
||||
ElseIf InStr(1,line,"NUMBEROFSTRAWBERRIES",1) Then
|
||||
Output = Output & "NUMBEROFSTRAWBERRIES" & " " & objParamLookup.Item("NUMBEROFSTRAWBERRIES") & vbCrLf
|
||||
Isnumberofstrawberries = True
|
||||
End If
|
||||
End If
|
||||
Loop
|
||||
If Isnumberofstrawberries = False Then
|
||||
Output = Output & "NUMBEROFSTRAWBERRIES" & " " & objParamLookup.Item("NUMBEROFSTRAWBERRIES") & vbCrLf
|
||||
Isnumberofstrawberries = True
|
||||
End If
|
||||
.Close
|
||||
End With
|
||||
|
||||
'Create a new config file.
|
||||
Set objOutFile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) &_
|
||||
"\OUT_config.txt",2,True)
|
||||
With objOutFile
|
||||
.Write Output
|
||||
.Close
|
||||
End With
|
||||
|
||||
Set objFSO = Nothing
|
||||
Set objParamLookup = Nothing
|
||||
Loading…
Add table
Add a link
Reference in a new issue