Allow storing settings using the context
This commit is contained in:
parent
775f6a1c10
commit
5bbe1e3733
1 changed files with 29 additions and 1 deletions
|
@ -4,11 +4,17 @@ class Context {
|
||||||
[string]$BackupName;
|
[string]$BackupName;
|
||||||
[string]$UserName;
|
[string]$UserName;
|
||||||
[string]$AdminName = "Admin";
|
[string]$AdminName = "Admin";
|
||||||
|
[string]$ConfigRoot = "HKLM:\Software\PortValhalla";
|
||||||
[string]$RunOnceName = "PortValhalla";
|
[string]$RunOnceName = "PortValhalla";
|
||||||
|
|
||||||
|
[string] ProjectRoot() {
|
||||||
|
return Resolve-Path (Join-Path $PSScriptRoot ".." ".." "..");
|
||||||
|
}
|
||||||
|
|
||||||
[string] BackupRoot() {
|
[string] BackupRoot() {
|
||||||
if (-not $this.RootDir)
|
if (-not $this.RootDir)
|
||||||
{
|
{
|
||||||
return Join-Path $PSScriptRoot ".." ".." ".." "backup" $this.BackupName;
|
return Join-Path $this.ProjectRoot() $this.BackupName;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -16,6 +22,28 @@ class Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Microsoft.Win32.RegistryKey] EnsureConfigKey() {
|
||||||
|
if (-not (Test-Path $this.ConfigRoot)) {
|
||||||
|
New-Item $this.ConfigRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Get-Item $this.ConfigRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
[void] Set([string] $key, $value, [Microsoft.Win32.RegistryValueKind] $type) {
|
||||||
|
$configKey = $this.EnsureConfigKey();
|
||||||
|
$configKey.SetValue($key, $value, $type);
|
||||||
|
}
|
||||||
|
|
||||||
|
[object] Get([string] $key) {
|
||||||
|
$configKey = $this.EnsureConfigKey();
|
||||||
|
if ($configKey.GetValueNames().Contains($key)) {
|
||||||
|
return $configKey.GetValue($key);
|
||||||
|
} else {
|
||||||
|
return $null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[string] ArchivePath($name) {
|
[string] ArchivePath($name) {
|
||||||
return Join-Path $this.BackupRoot() "$name.7z";
|
return Join-Path $this.BackupRoot() "$name.7z";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue