Class/TerrafunConfig.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 |
class TerrafunConfig { # Properties [String]$DesiredVersion [String]$LastUpdateCheck [string[]]$AvailableVersions # Constructor TerrafunConfig () { $this.LastUpdateCheck = Get-Date -format s "0001-01-01" } [Void] Read() { $UserProfile = (Get-Item ~).FullName $WorkingDir = Join-Path -Path $UserProfile -ChildPath ".terrafun" $ConfigPath = Join-Path -Path $WorkingDir -ChildPath "config.json" Write-Debug ("reading config {0}" -f $ConfigPath) New-Item -ItemType Directory -Path $WorkingDir -Force -ErrorAction SilentlyContinue | Out-Null if (Test-Path $ConfigPath){ $Config = Get-Content -Path $ConfigPath | ConvertFrom-Json $this.DesiredVersion = $Config.DesiredVersion $this.LastUpdateCheck = Get-Date -Format s $Config.LastUpdateCheck $this.AvailableVersions = $Config.AvailableVersions } } [Void] Save() { $UserProfile = (Get-Item ~).FullName $WorkingDir = Join-Path -Path $UserProfile -ChildPath ".terrafun" $ConfigPath = Join-Path -Path $WorkingDir -ChildPath "config.json" Write-Debug ("writing config {0}" -f $ConfigPath) $this | ConvertTo-Json | Out-File -FilePath $ConfigPath } } |