From 1c29cdd89c22ff7abe9269e80b21c9177c2693d7 Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Thu, 1 Aug 2024 23:34:35 +0200
Subject: [PATCH] Fix installer script structure

---
 scripts/Windows/Scripts/Software.ps1       | 81 +++++++++++-----------
 scripts/Windows/Software/winget/Manage.ps1 | 14 +++-
 2 files changed, 52 insertions(+), 43 deletions(-)

diff --git a/scripts/Windows/Scripts/Software.ps1 b/scripts/Windows/Scripts/Software.ps1
index 5811b4e1..b10321f2 100644
--- a/scripts/Windows/Scripts/Software.ps1
+++ b/scripts/Windows/Scripts/Software.ps1
@@ -1,50 +1,50 @@
 . "$PSScriptRoot/Config.ps1";
 . "$PSScriptRoot/../Types/InstallerAction.ps1";
 
+<#
+    .SYNOPSIS
+    Gets the name of the software.
+#>
+function Get-SoftwareName {
+    $path = ${Function:Install-Software}.File;
+
+    if ($path -ne "$PSCommandPath") {
+        Split-Path -Leaf (Split-Path -Parent $path);
+    } else {
+        $null;
+    }
+}
+
+<#
+    .SYNOPSIS
+    Installs the software.
+#>
+function Install-Software { }
+
+<#
+    .SYNOPSIS
+    Configures the system for the software.
+#>
+function Set-SoftwareConfiguration { }
+
+<#
+    .SYNOPSIS
+    Configures a user for the software.
+
+    .PARAMETER Name
+    The name of the user to configure.
+#>
+function Set-SoftwareUserConfiguration {
+    param(
+        [Parameter(Mandatory = $true)]
+        [string] $Name
+    )
+}
+
 $null = New-Module {
     . "$PSScriptRoot/../Types/InstallerAction.ps1";
     $userArgument = "name";
 
-    <#
-        .SYNOPSIS
-        Gets the name of the software.
-    #>
-    function Get-SoftwareName {
-        $path = ${Function:Install-Software}.File;
-
-        if ($path -ne "$PSCommandPath") {
-            Split-Path -Leaf (Split-Path -Parent $path);
-        } else {
-            $null;
-        }
-    }
-
-    <#
-        .SYNOPSIS
-        Installs the software.
-    #>
-    function Install-Software { }
-
-    <#
-        .SYNOPSIS
-        Configures the system for the software.
-    #>
-    function Set-SoftwareConfiguration { }
-
-    <#
-        .SYNOPSIS
-        Configures a user for the software.
-
-        .PARAMETER Name
-        The name of the user to configure.
-    #>
-    function Set-SoftwareUserConfiguration {
-        param(
-            [Parameter(Mandatory = $true)]
-            [string] $Name
-        )
-    }
-
     function Start-SoftwareInstaller {
         param(
             [InstallerAction] $Action,
@@ -68,7 +68,6 @@ $null = New-Module {
 
             foreach ($user in Get-Users) {
                 $Arguments.Add($userArgument, $user);
-
                 Start-SoftwareInstaller -Action ([InstallerAction]::ConfigureUser) @Arguments;
             }
         } elseif ($action -eq ([InstallerAction]::ConfigureUser)) {
diff --git a/scripts/Windows/Software/winget/Manage.ps1 b/scripts/Windows/Software/winget/Manage.ps1
index 734f4583..f45094e4 100644
--- a/scripts/Windows/Software/winget/Manage.ps1
+++ b/scripts/Windows/Software/winget/Manage.ps1
@@ -1,9 +1,19 @@
 param(
-    [string] $Action = ([InstallerAction]::Install),
+    $Action,
     [hashtable] $Arguments
 )
 
 . "$PSScriptRoot/../../Scripts/Software.ps1";
+. "$PSScriptRoot/../../Types/InstallerAction.ps1";
+
+function Install-Winget {
+    param(
+        [InstallerAction] $Action = [InstallerAction]::Install,
+        [hashtable] $Arguments
+    )
+
+    Start-SoftwareInstaller -Action $Action -Arguments $Arguments;
+}
 
 function Install-Software {
     $xamlDownloadLink = "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx";
@@ -17,4 +27,4 @@ function Install-Software {
     Remove-Item $file;
 }
 
-Start-SoftwareInstaller -Action $Action -Arguments $Arguments;
+Install-Winget @PSBoundParameters;