Store installation context in a separate parameter

This commit is contained in:
Manuel Thalmann 2024-09-29 17:12:44 +02:00
parent 42322c7428
commit 9d24859ecf
4 changed files with 26 additions and 22 deletions

View file

@ -15,7 +15,8 @@ $null = New-Module {
[scriptblock] $UserBackup = $null, [scriptblock] $UserBackup = $null,
[scriptblock] $UserConfigurator = $null, [scriptblock] $UserConfigurator = $null,
[Nullable[InstallerAction]] $Action, [Nullable[InstallerAction]] $Action,
[hashtable] $Arguments [hashtable] $Arguments,
[hashtable] $Context
) )
[InstallerAction] $Action = & { [InstallerAction] $Action = & {
@ -35,7 +36,8 @@ $null = New-Module {
param( param(
[string] $Name, [string] $Name,
[InstallerAction] $Action, [InstallerAction] $Action,
[hashtable] $Arguments [hashtable] $Arguments,
[hashtable] $Context
) )
[string] $DisplayName = $null; [string] $DisplayName = $null;
@ -47,11 +49,13 @@ $null = New-Module {
} }
$Arguments ??= @{ }; $Arguments ??= @{ };
$Context ??= @{ };
$argumentList = @{ $argumentList = @{
name = $Name; name = $Name;
installer = $installHandler; installer = $installHandler;
arguments = $Arguments; arguments = $Arguments;
context = $Context;
}; };
switch ($Action) { switch ($Action) {
@ -105,7 +109,7 @@ $null = New-Module {
} }
}; };
& $installHandler -Name $Name -Action $Action -Arguments $Arguments; & $installHandler -Name $Name -Action $Action -Arguments $Arguments -Context $Context;
}; };
} }
} }

View file

@ -24,16 +24,16 @@ $null = New-Module {
) )
@{ @{
arguments = @{ context = @{
name = $Name; name = $Name;
nativeOnly = $NativeOnly; nativeOnly = $NativeOnly;
}; };
installer = { installer = {
param( param(
[hashtable] $Arguments [hashtable] $Context
) )
$env:PENDING_MODULE_NAME = $Arguments.Name; $env:PENDING_MODULE_NAME = $Context.Name;
$installAction = { $installAction = {
$module = $env:PENDING_MODULE_NAME; $module = $env:PENDING_MODULE_NAME;
@ -43,7 +43,7 @@ $null = New-Module {
} }
}; };
if (-not $Arguments.NativeOnly) { if (-not $Context.NativeOnly) {
& $installAction -AcceptLicense; & $installAction -AcceptLicense;
} }
@ -56,10 +56,10 @@ $null = New-Module {
configurator = ($NoProfile.IsPresent) ? { } : { configurator = ($NoProfile.IsPresent) ? { } : {
param( param(
[hashtable] $Arguments [hashtable] $Context
) )
$name = $Arguments.Name; $name = $Context.Name;
Add-PowerShellProfileStatement ` Add-PowerShellProfileStatement `
-System ` -System `

View file

@ -12,22 +12,22 @@ foreach ($key in $PSBoundParameters.Keys) {
$parameters.Add($key, $PSBoundParameters.TryGetValue($key)); $parameters.Add($key, $PSBoundParameters.TryGetValue($key));
} }
$arguments = $parameters.arguments; $context = $parameters.context;
$arguments.Add("Installer", $parameters.installer); $context.Add("Installer", $parameters.installer);
Start-SoftwareInstaller @parameters -Installer { Start-SoftwareInstaller @parameters -Installer {
param( param(
[hashtable] $Arguments [hashtable] $Context
) )
$providerName = "NuGet"; $providerName = "NuGet";
$module = $Arguments.Name; $module = $Context.Name;
if ({ $null = powershell -c "Get-PackageProvider -ListAvailable $providerName"; $? }) { if ({ $null = powershell -c "Get-PackageProvider -ListAvailable $providerName"; $? }) {
$null = powershell -c "Install-PackageProvider -Force $providerName"; $null = powershell -c "Install-PackageProvider -Force $providerName";
} }
& $Arguments.Installer @PSBoundParameters; & $Context.Installer @PSBoundParameters;
if (-not (& { powershell -NoProfile -Command "Import-Module $module; exit ([bool]`$Error)" 2> $null; $?; })) { if (-not (& { powershell -NoProfile -Command "Import-Module $module; exit ([bool]`$Error)" 2> $null; $?; })) {
$feature = "NetFx3"; $feature = "NetFx3";

View file

@ -19,14 +19,14 @@ function Get-TMForeverInstallerComponents {
) )
@{ @{
arguments = @{ context = @{
iconName = $IconName; iconName = $IconName;
userDirectory = $UserDirectory; userDirectory = $UserDirectory;
installer = $Installer; installer = $Installer;
}; };
installer = { installer = {
param([hashtable] $Arguments) param([hashtable] $Context)
$iconName = $Arguments.IconName; $iconName = $Context.IconName;
foreach ($feature in @("DirectPlay", "NetFx3")) { foreach ($feature in @("DirectPlay", "NetFx3")) {
if ((Get-WindowsOptionalFeature -Online -FeatureName $feature).State -ne "Enabled") { if ((Get-WindowsOptionalFeature -Online -FeatureName $feature).State -ne "Enabled") {
@ -35,16 +35,16 @@ function Get-TMForeverInstallerComponents {
} }
} }
& $Arguments.Installer; & $Context.Installer;
Remove-DesktopIcon "*$iconName*"; Remove-DesktopIcon "*$iconName*";
}; };
userBackup = { userBackup = {
param( param(
[string] $Name, [string] $Name,
[hashtable] $Arguments [hashtable] $Context
) )
Add-BackupArtifacts -User $Arguments.Name -Source $Arguments.UserDirectory -Path "$Name" ` Add-BackupArtifacts -User $Context.Name -Source $Context.UserDirectory -Path "$Name" `
-Include @( -Include @(
"ChallengeMusics", "ChallengeMusics",
"MediaTracker", "MediaTracker",
@ -58,10 +58,10 @@ function Get-TMForeverInstallerComponents {
userConfigurator = { userConfigurator = {
param( param(
[string] $Name, [string] $Name,
[hashtable] $Arguments [hashtable] $Context
) )
$user = $Arguments.Name; $user = $Context.Name;
Expand-BackupArtifacts -User $user -Path "$Name" -Target $path; Expand-BackupArtifacts -User $user -Path "$Name" -Target $path;
}; };
}; };