PortValhalla/scripts/Windows/Scripts/SetupConfig.ps1

122 lines
2.7 KiB
PowerShell
Raw Normal View History

using namespace Microsoft.Win32;
using namespace System.Security.AccessControl;
using namespace System.Security.Principal;
$null = New-Module {
[string] $configRoot = "HKLM:\Software\PortValhalla";
[string] $stageOption = "Stage";
[string] $finishedOption = "Finished";
[RegistryKey] $key = $null;
<#
.SYNOPSIS
Gets the registry key containing options related to the setup.
#>
2024-07-31 13:52:23 +00:00
function Get-SetupConfigKey {
if (-not (Test-Path $configRoot)) {
$key = New-Item $configRoot;
$acl = Get-Acl $configRoot;
$acl.AddAccessRule(
[RegistryAccessRule]::new(
[SecurityIdentifier]::new([WellKnownSidType]::BuiltinUsersSid, $null),
[RegistryRights]::FullControl,
[InheritanceFlags]::ObjectInherit -bor [InheritanceFlags]::ContainerInherit,
[PropagationFlags]::None,
[AccessControlType]::Allow));
Set-Acl $configRoot $acl;
} else {
$key = Get-Item $configRoot;
}
return $key;
}
<#
.SYNOPSIS
Gets the value of an option related to the setup.
.PARAMETER Name
The name of the option value to get.
#>
2024-07-31 13:52:23 +00:00
function Get-SetupOption {
param(
[string] $Name
)
$key = Get-SetupConfigKey;
if ($key.GetValueNames().Contains($Name)) {
return $key.GetValue($Name);
} else {
return $null;
}
}
<#
.SYNOPSIS
Sets the value of an option related to the setup.
.PARAMETER Name
The name of the option to set.
.PARAMETER Value
The value to set the option to.
#>
2024-07-31 13:52:23 +00:00
function Set-SetupOption {
param(
[string] $Name,
$Value
)
if ($Value -is [string]) {
}
$key = Get-SetupConfigKey;
return $key.SetValue($Value);
}
<#
.SYNOPSIS
Gets the name of the current setup stage.
#>
2024-07-31 13:52:23 +00:00
function Get-Stage {
return Get-SetupOption $stageOption;
}
<#
.SYNOPSIS
Sets the current stage.
.PARAMETER Name
The name to set the current stage to.
#>
2024-07-31 13:52:23 +00:00
function Set-Stage {
param(
[string] $Name
)
$null = Set-SetupOption $stageOption $Name;
}
<#
.SYNOPSIS
Gets a value indicating whether the setup has finished.
#>
function Get-IsFinished {
return [bool] (Get-SetupOption $finishedOption);
}
<#
.SYNOPSIS
Sets a value indicating whether the setup has finished.
#>
function Set-IsFinished {
param(
$Value
)
}
}