From 0a5c50a4468e9ccdd720e859703dca85d40ba032 Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Sun, 18 Jun 2023 20:11:49 +0200
Subject: [PATCH] Allow setup without backup archive

---
 scripts/Windows/OS/Manage.ps1 | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/scripts/Windows/OS/Manage.ps1 b/scripts/Windows/OS/Manage.ps1
index f80428d4..ee54b39d 100644
--- a/scripts/Windows/OS/Manage.ps1
+++ b/scripts/Windows/OS/Manage.ps1
@@ -34,7 +34,7 @@ function Invoke-WindowsRestore([Context] $context) {
     {
         $backupPath = Read-Host -Prompt "Please enter the path to the archive load the backup from.";
 
-        if (-not (Test-Path -PathType Leaf $backupPath))
+        if (-not $backupPath -or (-not (Test-Path -PathType Leaf $backupPath)))
         {
             Write-Host "No file could be found at the specified path.";
             return Read-Path;
@@ -45,6 +45,15 @@ function Invoke-WindowsRestore([Context] $context) {
     $context = [Context]::new();
     $context.BackupName ??= "PortValhalla";
     $context.RootDir = $context.GetTempDirectory();
-    $context.Restore($backupPath, $context.BackupRoot());
+
+    if (-not $backupPath)
+    {
+        New-Item -ItemType Directory "$backupPath";
+    }
+    else
+    {
+        $context.Restore($backupPath, $context.BackupRoot());
+    }
+
     Remove-Item -Recurse $context.RootDir;
 }