From c6d261bc89079dd3de9860289c372f18bfeeb839 Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Tue, 3 Sep 2024 12:08:35 +0200
Subject: [PATCH] Ask for live scripts only once

---
 scripts/Common/Scripts/Operations.ps1 | 51 +++++++++++++++------------
 1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/scripts/Common/Scripts/Operations.ps1 b/scripts/Common/Scripts/Operations.ps1
index 77a77d5c..04e70834 100644
--- a/scripts/Common/Scripts/Operations.ps1
+++ b/scripts/Common/Scripts/Operations.ps1
@@ -104,36 +104,41 @@ $null = New-Module {
                         }
 
                         if ($env:DEBUG) {
-                            if (
-                                (Get-Item $env:INSTALLER_SCRIPT).IsReadOnly -and
-                                (Test-Qemu) -and
-                                ($Host.UI.PromptForChoice(
+                            $liveScriptOption = "LiveScripts";
+
+                            if (($null -eq (Get-SetupOption $liveScriptOption)) -and (Test-Qemu)) {
+                                $result = $Host.UI.PromptForChoice(
                                     "Confirm",
                                     "Do you wish to swap to live scripts?",
                                     [ChoiceDescription[]]@(
                                         [ChoiceDescription]::new("&No", "Use scripts stored in the virtual machine"),
                                         [ChoiceDescription]::new("&Yes", "Use live scripts stored on the host")),
-                                    0) -eq 1)) {
-                                Install-ChocoPackage winfsp qemu-guest-agent;
-                                Get-Service VirtioFsSvc | Start-Service -PassThru | Set-Service -StartupType Automatic;
+                                    0);
 
-                                while (-not (Test-Path Z:\)) {
-                                    Start-Sleep 0.1;
+                                Set-SetupOption $liveScriptOption $result;
+
+                                if ($result -eq 1) {
+                                    Install-ChocoPackage winfsp qemu-guest-agent;
+                                    Get-Service VirtioFsSvc | Start-Service -PassThru | Set-Service -StartupType Automatic;
+
+                                    while (-not (Test-Path Z:\)) {
+                                        Start-Sleep 0.1;
+                                    }
+
+                                    foreach ($name in @("CONFIG_MODULE", "INSTALLER_SCRIPT")) {
+                                        $variable = Get-Item "Env:\$name";
+
+                                        $path = Join-Path `
+                                            "Z:\Repositories\PortValhalla" `
+                                            ([System.IO.Path]::GetRelativePath("$PSScriptRoot/../../..", $variable.Value));
+
+                                        Set-Item "Env:\$name" $path;
+                                        Write-Host "The new value of ``$name`` is ``$path``";
+                                    }
+
+                                    Restart-Intermediate;
+                                    exit;
                                 }
-
-                                foreach ($name in @("CONFIG_MODULE", "INSTALLER_SCRIPT")) {
-                                    $variable = Get-Item "Env:\$name";
-
-                                    $path = Join-Path `
-                                        "Z:\Repositories\PortValhalla" `
-                                        ([System.IO.Path]::GetRelativePath("$PSScriptRoot/../../..", $variable.Value));
-
-                                    Set-Item "Env:\$name" $path;
-                                    Write-Host "The new value of ``$name`` is ``$path``";
-                                }
-
-                                Restart-Intermediate;
-                                exit;
                             }
                         }