From 1e3fd33924bdce73d0155f93a732374319af042b Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 24 Sep 2024 18:15:06 +0200 Subject: [PATCH] Create universal TrackMania script --- scripts/Windows/Scripts/Deployment.ps1 | 4 +- .../TrackMania Nations Forever/Main.ps1 | 21 ++++++ .../TrackMania Nations Forever/Manage.ps1 | 54 --------------- .../TrackMania United Forever/Main.ps1 | 30 ++++++++ .../TrackMania United Forever/Manage.ps1 | 69 ++++++++++--------- 5 files changed, 91 insertions(+), 87 deletions(-) create mode 100644 scripts/Windows/Software/TrackMania Nations Forever/Main.ps1 delete mode 100644 scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1 create mode 100644 scripts/Windows/Software/TrackMania United Forever/Main.ps1 diff --git a/scripts/Windows/Scripts/Deployment.ps1 b/scripts/Windows/Scripts/Deployment.ps1 index dab15880..678b6875 100644 --- a/scripts/Windows/Scripts/Deployment.ps1 +++ b/scripts/Windows/Scripts/Deployment.ps1 @@ -291,8 +291,8 @@ function Deploy-SoftwareAction { Remove-DesktopIcon "EA.*"; } - & "$softwarePath/TrackMania Nations Forever/Manage.ps1" @arguments; - & "$softwarePath/TrackMania United Forever/Manage.ps1" @arguments; + & "$softwarePath/TrackMania Nations Forever/Main.ps1" @arguments; + & "$softwarePath/TrackMania United Forever/Main.ps1" @arguments; & "$softwarePath/ManiaPlanet/Manage.ps1" @arguments; & "$softwarePath/osu!/Manage.ps1" @arguments; & "$softwarePath/osu!lazer/Manage.ps1" @arguments; diff --git a/scripts/Windows/Software/TrackMania Nations Forever/Main.ps1 b/scripts/Windows/Software/TrackMania Nations Forever/Main.ps1 new file mode 100644 index 00000000..e35a7ec6 --- /dev/null +++ b/scripts/Windows/Software/TrackMania Nations Forever/Main.ps1 @@ -0,0 +1,21 @@ +param( + $Action, + [hashtable] $Arguments +) + +. "$PSScriptRoot/../TrackMania United Forever/Manage.ps1"; +. "$PSScriptRoot/../../Scripts/SoftwareManagement.ps1"; +. "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; + +$parameters = Get-TMForeverInstallerComponents ` + -IconName "TmNationsForever" ` + -UserDirectory "$HOME/Documents/TmForever" ` + -Installer { + Install-WingetPackage Nadeo.TrackManiaNationsForever; + }; + +foreach ($key in $PSBoundParameters.Keys) { + $parameters.Add($key, $PSBoundParameters[$key]); +} + +Start-SoftwareInstaller @parameters; diff --git a/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1 b/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1 deleted file mode 100644 index fbbb4e51..00000000 --- a/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1 +++ /dev/null @@ -1,54 +0,0 @@ -param( - $Action, - [hashtable] $Arguments -) - - -& { - param($Parameters) - . "$PSScriptRoot/../../Scripts/Restoration.ps1"; - . "$PSScriptRoot/../../Scripts/SoftwareManagement.ps1"; - . "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; - $path = "$HOME/Documents/TmForever"; - - Start-SoftwareInstaller @Parameters ` - -Installer { - foreach ($feature in @("DirectPlay", "NetFx3")) { - if ((Get-WindowsOptionalFeature -Online -FeatureName $feature).State -ne "Enabled") { - Write-Information "Enabling the ``$feature`` feature…"; - choco install --source windowsFeatures -y $feature; - } - } - - Install-WingetPackage Nadeo.TrackManiaNationsForever; - Remove-DesktopIcon "*TmNationsForever*"; - } ` - -UserBackup { - param( - [string] $Name, - [hashtable] $Arguments - ) - - $name = $Arguments.Name; - - Add-BackupArtifacts -User $name -Source $path -Path "$Name" ` - -Include @( - "ChallengeMusics", - "MediaTracker", - "MenuMusics", - "Painter", - "Scores", - "Skins", - "Tracks" - ); - } ` - -UserConfigurator { - 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/Main.ps1 b/scripts/Windows/Software/TrackMania United Forever/Main.ps1 new file mode 100644 index 00000000..da7e19ca --- /dev/null +++ b/scripts/Windows/Software/TrackMania United Forever/Main.ps1 @@ -0,0 +1,30 @@ +param( + $Action, + [hashtable] $Arguments +) + +. "$PSScriptRoot/Manage.ps1"; +. "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; + +$parameters = Get-TMForeverInstallerComponents ` + -IconName "TmUnitedForever" ` + -UserDirectory "$HOME/Documents/TrackMania" ` + -Installer { + $file = "TmUnitedForever.exe"; + $dir = New-TemporaryDirectory; + + $null = Push-Location $dir; + Write-Host "Downloading TrackMania United Forever…"; + Invoke-WebRequest "http://files.trackmaniaforever.com/tmunitedforever_setup.exe" -OutFile "$file"; + + Write-Host "Starting installation…"; + Start-Process -Wait -FilePath "$file" -ArgumentList "/Silent"; + $null = Pop-Location; + Remove-Item -Recurse $dir; + }; + +foreach ($key in $PSBoundParameters.Keys) { + $parameters.Add($key, $PSBoundParameters[$key]); +} + +Start-SoftwareInstaller @parameters; diff --git a/scripts/Windows/Software/TrackMania United Forever/Manage.ps1 b/scripts/Windows/Software/TrackMania United Forever/Manage.ps1 index 6b2459ce..64c4f3a0 100644 --- a/scripts/Windows/Software/TrackMania United Forever/Manage.ps1 +++ b/scripts/Windows/Software/TrackMania United Forever/Manage.ps1 @@ -1,20 +1,32 @@ -param( - $Action, - [hashtable] $Arguments -) +. "$PSScriptRoot/../../Scripts/Restoration.ps1"; +. "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; +<# + .SYNOPSIS + Generates the components for installing a TrackMania Forever game. -& { - param($Parameters) - . "$PSScriptRoot/../../Scripts/Restoration.ps1"; - . "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; - . "$PSScriptRoot/../../../Common/Scripts/System.ps1"; - $path = "$HOME/Documents/TrackMania"; + .PARAMETER Installer + The script to execute for installing the game. - Start-SoftwareInstaller @Parameters ` - -Installer { - $file = "TmUnitedForever.exe"; - $dir = New-TemporaryDirectory; + .PARAMETER UserDirectory + The directory containing the user data. +#> +function Get-TMForeverInstallerComponents { + param( + [string] $IconName, + [string] $UserDirectory, + [scriptblock] $Installer + ) + + @{ + arguments = @{ + iconName = $IconName; + userDirectory = $UserDirectory; + installer = $Installer; + }; + installer = { + param([hashtable] $Arguments) + $iconName = $Arguments.IconName; foreach ($feature in @("DirectPlay", "NetFx3")) { if ((Get-WindowsOptionalFeature -Online -FeatureName $feature).State -ne "Enabled") { @@ -23,39 +35,34 @@ param( } } - $null = Push-Location $dir; - Write-Host "Downloading TrackMania United Forever…"; - Invoke-WebRequest "http://files.trackmaniaforever.com/tmunitedforever_setup.exe" -OutFile "$file"; - - Write-Host "Starting installation…"; - Start-Process -Wait -FilePath $file -ArgumentList "/Silent"; - Remove-DesktopIcon "*TmUnitedForever*"; - $null = Pop-Location; - - Remove-Item -Recurse $dir; - } ` - -UserBackup { + & $Arguments.Installer; + Remove-DesktopIcon "*$iconName*"; + }; + userBackup = { param( [string] $Name, [hashtable] $Arguments ) - Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "$Name" ` + Add-BackupArtifacts -User $Arguments.Name -Source $Arguments.UserDirectory -Path "$Name" ` -Include @( "ChallengeMusics", "MediaTracker", "MenuMusics", + "Painter", "Scores", "Skins", "Tracks" ); - } ` - -UserConfigurator { + }; + userConfigurator = { param( [string] $Name, [hashtable] $Arguments ) - Expand-BackupArtifacts -User $Arguments.Name -Path "$Name" -Target $path; + $user = $Arguments.Name; + Expand-BackupArtifacts -User $user -Path "$Name" -Target $path; }; -} $PSBoundParameters; + }; +}