From 5ae07886c8b24fbce3ef7ba21239f969b55169c7 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Mon, 23 Sep 2024 02:10:42 +0200 Subject: [PATCH] Make software name available in scripts --- scripts/Common/Scripts/Software.ps1 | 28 +++++++++++-------- scripts/Common/Software/Oh My Posh/Manage.ps1 | 4 ++- scripts/Common/Software/aliae/Main.ps1 | 3 +- scripts/Common/Software/zoxide/Main.ps1 | 6 ++-- scripts/Windows/Software/LGHub/Manage.ps1 | 6 ++-- .../Windows/Software/ManiaPlanet/Manage.ps1 | 6 ++-- scripts/Windows/Software/PuTTY/Manage.ps1 | 16 ++++++++--- scripts/Windows/Software/RetroArch/Manage.ps1 | 7 +++-- .../TrackMania Nations Forever/Manage.ps1 | 18 ++++++++---- .../TrackMania United Forever/Manage.ps1 | 16 ++++++++--- .../Windows/Software/VisualStudio/Manage.ps1 | 11 ++++++-- .../Windows/Software/chocolatey/Manage.ps1 | 3 +- scripts/Windows/Software/osu!/Manage.ps1 | 20 +++++++++---- scripts/Windows/Software/osu!lazer/Manage.ps1 | 15 ++++++++-- scripts/Windows/Software/reWASD/Manage.ps1 | 7 +++-- 15 files changed, 116 insertions(+), 50 deletions(-) diff --git a/scripts/Common/Scripts/Software.ps1 b/scripts/Common/Scripts/Software.ps1 index 4c55f4ce..f8e68bfb 100644 --- a/scripts/Common/Scripts/Software.ps1 +++ b/scripts/Common/Scripts/Software.ps1 @@ -317,21 +317,25 @@ $null = New-Module { } Start-Operation { - if ($null -ne $Name) { - $Name = "``$Name``"; - } else { - $Name = "unknown software"; - } - $installHandler = { param( + [string] $Name, [InstallerAction] $Action, [hashtable] $Arguments ) + [string] $DisplayName = $null; + + if ($null -ne $Name) { + $DisplayName = "``$Name``"; + } else { + $DisplayName = "unknown software"; + } + $Arguments ??= @{ }; $argumentList = @{ + name = $Name; installer = $installHandler; arguments = $Arguments; }; @@ -339,13 +343,13 @@ $null = New-Module { switch ($Action) { ([InstallerAction]::Backup) { if ($Backup) { - Write-Host "Backing up $Name…"; + Write-Host "Backing up $DisplayName…"; & $Backup @argumentList; } } ([InstallerAction]::Install) { if ($Installer) { - Write-Host "Installing $Name…"; + Write-Host "Installing $DisplayName…"; & $Installer @argumentList; } @@ -357,7 +361,7 @@ $null = New-Module { } ([InstallerAction]::Configure) { if ($Configurator) { - Write-Host "Configuring $Name…"; + Write-Host "Configuring $DisplayName…"; & $Configurator @argumentList; } } @@ -372,13 +376,13 @@ $null = New-Module { switch ($_) { ([InstallerAction]::BackupUser) { if ($UserBackup) { - Write-Host "Backing up $Name for user ``$user``…"; + Write-Host "Backing up $DisplayName for user ``$user``…"; & $UserBackup @argumentList; } } ([InstallerAction]::ConfigureUser) { if ($UserConfigurator) { - Write-Host "Configuring $Name for user ``$user``…"; + Write-Host "Configuring $DisplayName for user ``$user``…"; & $UserConfigurator @argumentList; } } @@ -387,7 +391,7 @@ $null = New-Module { } }; - & $installHandler -Action $Action -Arguments $Arguments; + & $installHandler -Name $Name -Action $Action -Arguments $Arguments; }; } } diff --git a/scripts/Common/Software/Oh My Posh/Manage.ps1 b/scripts/Common/Software/Oh My Posh/Manage.ps1 index b6060705..e568d600 100644 --- a/scripts/Common/Software/Oh My Posh/Manage.ps1 +++ b/scripts/Common/Software/Oh My Posh/Manage.ps1 @@ -10,9 +10,11 @@ param ( Start-SoftwareInstaller @PSBoundParameters ` -Configurator { + param([string] $Name) + Add-PowerShellProfileStatement ` -System ` - -Category "oh-my-posh" ` + -Category "$Name" ` -Script ( @( "# Oh My Posh!", diff --git a/scripts/Common/Software/aliae/Main.ps1 b/scripts/Common/Software/aliae/Main.ps1 index 1daf726a..11de350e 100644 --- a/scripts/Common/Software/aliae/Main.ps1 +++ b/scripts/Common/Software/aliae/Main.ps1 @@ -9,6 +9,7 @@ param( Start-SoftwareInstaller @PSBoundParameters ` -Configurator { + param([string] $Name) . "$PSScriptRoot/Constants.ps1"; $pathExpression = Get-GlobalConfigExpression; $path = Get-GlobalConfigPath; @@ -17,7 +18,7 @@ Start-SoftwareInstaller @PSBoundParameters ` Add-PowerShellProfileStatement ` -System ` - -Category "aliae" ` + -Category $Name ` -Script ( @( { diff --git a/scripts/Common/Software/zoxide/Main.ps1 b/scripts/Common/Software/zoxide/Main.ps1 index ce91049f..f3e7bcdd 100644 --- a/scripts/Common/Software/zoxide/Main.ps1 +++ b/scripts/Common/Software/zoxide/Main.ps1 @@ -8,12 +8,14 @@ param( Start-SoftwareInstaller @PSBoundParameters ` -Configurator { + param([string] $Name) + Add-PowerShellProfileStatement ` -System ` - -Category "zoxide" ` + -Category "$Name" ` -Script ( @( - "# zoxide", + "# $Name", (Get-ScriptInitializer "zoxide init powershell | Out-String") ) -join [System.Environment]::NewLine); }; diff --git a/scripts/Windows/Software/LGHub/Manage.ps1 b/scripts/Windows/Software/LGHub/Manage.ps1 index ee840bed..07403926 100644 --- a/scripts/Windows/Software/LGHub/Manage.ps1 +++ b/scripts/Windows/Software/LGHub/Manage.ps1 @@ -63,21 +63,23 @@ param( } ` -UserBackup { param( + [string] $Name, [hashtable] $Arguments ) Edit-LGHubConfig { - Add-BackupArtifacts -User $Arguments.Name -Source $configPath -Path "LGHub" ` + Add-BackupArtifacts -User $Arguments.Name -Source $configPath -Path "$Name" ` -Include @("settings.db", "icon_cache") }; } ` -UserConfigurator { param( + [string] $Name, [hashtable] $Arguments ) Edit-LGHubConfig { - Expand-BackupArtifacts -User $Arguments.Name -Path "LGHub" -Target $configPath; + Expand-BackupArtifacts -User $Arguments.Name -Path "$Name" -Target $configPath; }; }; } $PSBoundParameters; diff --git a/scripts/Windows/Software/ManiaPlanet/Manage.ps1 b/scripts/Windows/Software/ManiaPlanet/Manage.ps1 index 571fcdf4..ccb93b76 100644 --- a/scripts/Windows/Software/ManiaPlanet/Manage.ps1 +++ b/scripts/Windows/Software/ManiaPlanet/Manage.ps1 @@ -17,10 +17,11 @@ param( } ` -UserBackup { param( + [string] $Name, [hashtable] $Arguments ) - Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "ManiaPlanet" ` + Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "$Name" ` -Include @( "Actions", "Blocks", @@ -36,9 +37,10 @@ param( } ` -UserConfigurator { param( + [string] $Name, [hashtable] $Arguments ) - Expand-BackupArtifacts -User $Arguments.Name -Path "ManiaPlanet" -Target $path; + Expand-BackupArtifacts -User $Arguments.Name -Path "$Name" -Target $path; }; } $PSBoundParameters; diff --git a/scripts/Windows/Software/PuTTY/Manage.ps1 b/scripts/Windows/Software/PuTTY/Manage.ps1 index 17dd3045..a957cedc 100644 --- a/scripts/Windows/Software/PuTTY/Manage.ps1 +++ b/scripts/Windows/Software/PuTTY/Manage.ps1 @@ -14,18 +14,26 @@ Start-SoftwareInstaller @PSBoundParameters ` Install-ChocoPackage putty; } ` -UserBackup { - param([hashtable] $Arguments) + param( + [string] $Name, + [hashtable] $Arguments + ) + $dir = New-TemporaryDirectory; $fileName = Join-Path "$dir" PuTTY.reg; & reg export "HKCU\Software\SimonTatham\PuTTY" $fileName /y; - Add-BackupArtifacts -User $Arguments.Name -Source $fileName -Path "PuTTY/PuTTY.reg"; + Add-BackupArtifacts -User $Arguments.Name -Source $fileName -Path "$Name/$Name.reg"; Remove-Item -Recurse -Force $dir; } ` -UserConfigurator { - param([hashtable] $Arguments) + param( + [string] $Name, + [hashtable] $Arguments + ) + $dir = New-TemporaryDirectory; $fileName = Join-Path "$dir" PuTTY.reg; - Expand-BackupArtifacts -User $Arguments.Name -Path "PuTTY/PuTTY.reg" -Target $fileName; + Expand-BackupArtifacts -User $Arguments.Name -Path "$Name/$Name.reg" -Target $fileName; & reg import $fileName; Remove-Item -Recurse -Force $dir; }; diff --git a/scripts/Windows/Software/RetroArch/Manage.ps1 b/scripts/Windows/Software/RetroArch/Manage.ps1 index 4838ed92..6a94e002 100644 --- a/scripts/Windows/Software/RetroArch/Manage.ps1 +++ b/scripts/Windows/Software/RetroArch/Manage.ps1 @@ -12,7 +12,9 @@ param( Start-SoftwareInstaller @Parameters ` -Backup { - Add-BackupArtifacts -Path "RetroArch" -Source $path ` + param([string] $Name) + + Add-BackupArtifacts -Path "$Name" -Source $path ` -Include @( "config", "cores", @@ -29,7 +31,8 @@ param( Install-ChocoPackage retroarch; } ` -Configurator { + param([string] $Name) Add-StartMenuIcon "RetroArch" "C:\tools\RetroArch-Win64\retroarch.exe"; - Expand-BackupArtifacts -Path "RetroArch" -Target $path; + Expand-BackupArtifacts -Path "$Name" -Target $path; }; } $PSBoundParameters; diff --git a/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1 b/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1 index 956ea038..df75d5cc 100644 --- a/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1 +++ b/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1 @@ -23,10 +23,14 @@ param( Remove-DesktopIcon "*TmNationsForever*"; } ` -UserBackup { - param([hashtable] $Arguments) + param( + [string] $Name, + [hashtable] $Arguments + ) + $name = $Arguments.Name; - Add-BackupArtifacts -User $name -Source $path -Path "TmNationsForever" ` + Add-BackupArtifacts -User $name -Source $path -Path "$Name" ` -Include @( "ChallengeMusics", "MediaTracker", @@ -38,8 +42,12 @@ param( ); } ` -UserConfigurator { - param([hashtable] $Arguments) - $name = $Arguments.Name; - Expand-BackupArtifacts -User $name -Path "TmNationsForever" -Target $path; + param( + [string] $Name, + [hashtable] $Arguments + ) + + $user = $Arguments.Name; + Expand-BackupArtifacts -User $user -Path "$Name" -Target $path; }; } $PSBoundParameters; diff --git a/scripts/Windows/Software/TrackMania United Forever/Manage.ps1 b/scripts/Windows/Software/TrackMania United Forever/Manage.ps1 index edd78c69..6b2459ce 100644 --- a/scripts/Windows/Software/TrackMania United Forever/Manage.ps1 +++ b/scripts/Windows/Software/TrackMania United Forever/Manage.ps1 @@ -35,8 +35,12 @@ param( Remove-Item -Recurse $dir; } ` -UserBackup { - param([hashtable] $Arguments) - Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "TmUnitedForever" ` + param( + [string] $Name, + [hashtable] $Arguments + ) + + Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "$Name" ` -Include @( "ChallengeMusics", "MediaTracker", @@ -47,7 +51,11 @@ param( ); } ` -UserConfigurator { - param([hashtable] $Arguments) - Expand-BackupArtifacts -User $Arguments.Name -Path "TmUnitedForever" -Target $path; + param( + [string] $Name, + [hashtable] $Arguments + ) + + Expand-BackupArtifacts -User $Arguments.Name -Path "$Name" -Target $path; }; } $PSBoundParameters; diff --git a/scripts/Windows/Software/VisualStudio/Manage.ps1 b/scripts/Windows/Software/VisualStudio/Manage.ps1 index 0779d0da..d430c02f 100644 --- a/scripts/Windows/Software/VisualStudio/Manage.ps1 +++ b/scripts/Windows/Software/VisualStudio/Manage.ps1 @@ -36,14 +36,17 @@ param( #> function Get-ConfigPath { param( + [string] $Name, [string] $PackageName ) - return Join-Path "Visual Studio" "$PackageName.vsconfig"; + return Join-Path "$Name" "$PackageName.vsconfig"; } Start-SoftwareInstaller @parameters ` -Backup { + param([string] $Name) + foreach ($version in $versions) { if (Test-ChocoPackage $version[0]) { Write-Host "Backing up ``$($version[0])…"; @@ -58,17 +61,19 @@ param( "--quiet" ); - Add-BackupArtifacts -Source $configFile -Path (Get-ConfigPath $version[0]); + Add-BackupArtifacts -Source $configFile -Path (Get-ConfigPath $Name $version[0]); Remove-Item $configFile; } } } ` -Installer { + param([string] $Name) + foreach ($version in $versions) { $packageName = $version[0]; $file = New-TemporaryFile; Remove-Item $file; - Expand-BackupArtifacts -Path (Get-ConfigPath $packageName) -Target $file; + Expand-BackupArtifacts -Path (Get-ConfigPath $Name $packageName) -Target $file; if (Test-Path $file) { Write-Host "Restoring ``$packageName``…"; diff --git a/scripts/Windows/Software/chocolatey/Manage.ps1 b/scripts/Windows/Software/chocolatey/Manage.ps1 index 768e6051..f12957ac 100644 --- a/scripts/Windows/Software/chocolatey/Manage.ps1 +++ b/scripts/Windows/Software/chocolatey/Manage.ps1 @@ -10,6 +10,7 @@ param( Start-SoftwareInstaller @PSBoundParameters ` -Configurator { + param([string] $Name) [string] $backup = $null; $nativeProfile = powershell -c '$PROFILE'; @@ -23,7 +24,7 @@ Start-SoftwareInstaller @PSBoundParameters ` Add-PowerShellProfileStatement ` -DefaultUser ` - -Category "chocolatey" ` + -Category "$Name" ` -Script (Get-Content $nativeProfile | Out-String) ` -Append; diff --git a/scripts/Windows/Software/osu!/Manage.ps1 b/scripts/Windows/Software/osu!/Manage.ps1 index 3024a636..f5db941b 100644 --- a/scripts/Windows/Software/osu!/Manage.ps1 +++ b/scripts/Windows/Software/osu!/Manage.ps1 @@ -20,7 +20,9 @@ param( Remove-DesktopIcon "*osu*"; } ` -Backup { - Add-BackupArtifacts -Source (& $getInstallPath) -Path "osu!" ` + param([string] $Name) + + Add-BackupArtifacts -Source (& $getInstallPath) -Path "$Name" ` -Include @( "Screenshots", "Skins", @@ -30,16 +32,22 @@ param( ); } ` -Configurator { - Expand-BackupArtifacts -Path "osu!" -Target (& $getInstallPath); + param([string] $Name) + + Expand-BackupArtifacts -Path "$Name" -Target (& $getInstallPath); } ` -UserBackup { - param([hashtable] $Arguments) - $name = $Arguments.Name; - Add-BackupArtifacts -Source "$(& $getInstallPath)/osu!.$name.cfg" -User $name -Path "osu!/osu!.cfg"; + param( + [string] $Name, + [hashtable] $Arguments + ) + + $user = $Arguments.Name; + Add-BackupArtifacts -Source "$(& $getInstallPath)/osu!.$user.cfg" -User $user -Path "$Name/osu!.cfg"; } ` -UserConfigurator { param([hashtable] $Arguments) $name = $Arguments.Name; - Expand-BackupArtifacts -User $name -Path "osu!/osu!.cfg" -Target "$(& $getInstallPath)/osu!.$name.cfg"; + Expand-BackupArtifacts -User $name -Path "$Name/osu!.cfg" -Target "$(& $getInstallPath)/osu!.$name.cfg"; }; } $PSBoundParameters; diff --git a/scripts/Windows/Software/osu!lazer/Manage.ps1 b/scripts/Windows/Software/osu!lazer/Manage.ps1 index d2f7a727..b6f8556d 100644 --- a/scripts/Windows/Software/osu!lazer/Manage.ps1 +++ b/scripts/Windows/Software/osu!lazer/Manage.ps1 @@ -12,8 +12,12 @@ param( Start-SoftwareInstaller @Parameters ` -UserBackup { - param([hashtable] $Arguments) - Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "osu!lazer" ` + param( + [string] $Name, + [hashtable] $Arguments + ) + + Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "$Name" ` -Include @( "files", "rulesets", @@ -24,6 +28,11 @@ param( ); } ` -UserConfigurator { + param( + [string] $Name, + [hashtable] $Arguments + ) + $file = "osu!lazer.exe"; $processName = "osu!"; $dir = New-TemporaryDirectory; @@ -42,6 +51,6 @@ param( Remove-Item -Recurse $dir; Remove-DesktopIcon "*osu*"; - Expand-BackupArtifacts -User $Arguments.Name -Path "osu!lazer" -Target $path; + Expand-BackupArtifacts -User $Arguments.Name -Path "$Name" -Target $path; }; } $PSBoundParameters; diff --git a/scripts/Windows/Software/reWASD/Manage.ps1 b/scripts/Windows/Software/reWASD/Manage.ps1 index d17dad37..7781f411 100644 --- a/scripts/Windows/Software/reWASD/Manage.ps1 +++ b/scripts/Windows/Software/reWASD/Manage.ps1 @@ -14,7 +14,9 @@ param( Start-SoftwareInstaller @Parameters ` -Backup { - Add-BackupArtifacts -Path "reWASD" -Source $path ` + param([string] $Name) + + Add-BackupArtifacts -Path "$Name" -Source $path ` -Exclude @( "Logs", "Presets", @@ -40,6 +42,7 @@ param( Remove-DesktopIcon "*reWASD*"; } ` -Configurator { - Expand-BackupArtifacts -Path "reWASD" -Target $path; + param([string] $Name) + Expand-BackupArtifacts -Path "$Name" -Target $path; }; } $PSBoundParameters;