Refactor the installation loop architecture

This commit is contained in:
Manuel Thalmann 2024-07-31 16:25:32 +02:00
parent 73c0648611
commit 467ad0caab
2 changed files with 36 additions and 25 deletions

View file

@ -29,32 +29,38 @@ function Start-InstallationLoop {
. "$PSScriptRoot/../Scripts/SetupConfig.ps1"; . "$PSScriptRoot/../Scripts/SetupConfig.ps1";
while (-not (Get-IsFinished)) { while (-not (Get-IsFinished)) {
switch (Get-Stage) { if (-not (Get-Stage)) {
$null { Set-Stage [SetupStage]::Initialize;
if (-not ((Get-Command "choco") -and (Get-Command "refreshenv"))) { break;
Invoke-Hook "Install-Chocolatey" -Fallback { } elseif (Get-Stage -eq [SetupStage]::Initialize) {
# Install chocolatey if (-not ((Get-Command "choco") -and (Get-Command "refreshenv"))) {
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; Invoke-Hook "Install-Chocolatey" -Fallback {
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')); # Install chocolatey
Import-Module $env:ChocolateyInstall/helpers/chocolateyProfile.psm1; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
refreshenv; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'));
}; Import-Module $env:ChocolateyInstall/helpers/chocolateyProfile.psm1;
} refreshenv;
};
if (-not (Test-ChocoSoftware "powershell-core")) { }
Invoke-Hook "Install-PowerShellCore" -Fallback {
choco install -y powershell-core --install-arguments='"ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 REGISTER_MANIFEST=1 USER_MU=1 ENABLE_MU=1"'; if (-not (Test-ChocoSoftware "powershell-core")) {
}; Invoke-Hook "Install-PowerShellCore" -Fallback {
choco install -y powershell-core --install-arguments='"ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 REGISTER_MANIFEST=1 USER_MU=1 ENABLE_MU=1"';
Restart-Intermediate; };
return;
} Restart-Intermediate;
return;
if (Test-Path $env:PWSH_PATH) { }
Remove-Item -Recurse $env:PWSH_PATH;
} if (Test-Path $env:PWSH_PATH) {
Remove-Item -Recurse $env:PWSH_PATH;
}
} else {
switch (Get-Stage) {
$null {
}
Default {}
} }
Default {}
} }
} }
} }

View file

@ -2,6 +2,11 @@ using namespace Microsoft.Win32;
using namespace System.Security.AccessControl; using namespace System.Security.AccessControl;
using namespace System.Security.Principal; using namespace System.Security.Principal;
enum SetupStage {
Initialize = "init"
Install = "install"
}
$null = New-Module { $null = New-Module {
[string] $configRoot = "HKLM:\Software\PortValhalla"; [string] $configRoot = "HKLM:\Software\PortValhalla";
[string] $stageOption = "Stage"; [string] $stageOption = "Stage";