From 875ac600df13c0b2a3abaa7da14fe3d6ac1eb7e4 Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Tue, 3 Sep 2024 12:02:09 +0200
Subject: [PATCH] Allow backing up TrackMania Forever

---
 .../TrackMania Nations Forever/Manage.ps1     | 48 ++++++++++----
 .../TrackMania United Forever/Manage.ps1      | 64 ++++++++++++-------
 2 files changed, 78 insertions(+), 34 deletions(-)

diff --git a/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1 b/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1
index e9b1fd2c..956ea038 100644
--- a/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1	
+++ b/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1	
@@ -3,19 +3,43 @@ param(
     [hashtable] $Arguments
 )
 
-. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
 
-Start-SoftwareInstaller @PSBoundParameters `
-    -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;
+& {
+    param($Parameters)
+    . "$PSScriptRoot/../../Scripts/Restoration.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*";
-    };
+            Install-WingetPackage Nadeo.TrackManiaNationsForever;
+            Remove-DesktopIcon "*TmNationsForever*";
+        } `
+        -UserBackup {
+            param([hashtable] $Arguments)
+            $name = $Arguments.Name;
 
-# ToDo: Add restoration
+            Add-BackupArtifacts -User $name -Source $path -Path "TmNationsForever" `
+                -Include @(
+                    "ChallengeMusics",
+                    "MediaTracker",
+                    "MenuMusics",
+                    "Painter",
+                    "Scores",
+                    "Skins",
+                    "Tracks"
+                );
+        } `
+        -UserConfigurator {
+            param([hashtable] $Arguments)
+            $name = $Arguments.Name;
+            Expand-BackupArtifacts -User $name -Path "TmNationsForever" -Target $path;
+        };
+} $PSBoundParameters;
diff --git a/scripts/Windows/Software/TrackMania United Forever/Manage.ps1 b/scripts/Windows/Software/TrackMania United Forever/Manage.ps1
index b15ea704..edd78c69 100644
--- a/scripts/Windows/Software/TrackMania United Forever/Manage.ps1	
+++ b/scripts/Windows/Software/TrackMania United Forever/Manage.ps1	
@@ -3,31 +3,51 @@ param(
     [hashtable] $Arguments
 )
 
-. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
-. "$PSScriptRoot/../../../Common/Scripts/System.ps1";
 
-Start-SoftwareInstaller @PSBoundParameters `
-    -Installer {
-        $file = "TmUnitedForever.exe";
-        $dir = New-TemporaryDirectory;
+& {
+    param($Parameters)
+    . "$PSScriptRoot/../../Scripts/Restoration.ps1";
+    . "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
+    . "$PSScriptRoot/../../../Common/Scripts/System.ps1";
+    $path = "$HOME/Documents/TrackMania";
 
-        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;
+    Start-SoftwareInstaller @Parameters `
+        -Installer {
+            $file = "TmUnitedForever.exe";
+            $dir = New-TemporaryDirectory;
+
+            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;
+                }
             }
-        }
 
-        $null = Push-Location $dir;
-        Write-Host "Downloading TrackMania United Forever…";
-        Invoke-WebRequest "http://files.trackmaniaforever.com/tmunitedforever_setup.exe" -OutFile "$file";
+            $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;
+            Write-Host "Starting installation…";
+            Start-Process -Wait -FilePath $file -ArgumentList "/Silent";
+            Remove-DesktopIcon "*TmUnitedForever*";
+            $null = Pop-Location;
 
-        Remove-Item -Recurse $dir;
-    };
-
-# ToDo: Add restoration
+            Remove-Item -Recurse $dir;
+        } `
+        -UserBackup {
+            param([hashtable] $Arguments)
+            Add-BackupArtifacts -User $Arguments.Name -Source $path -Path "TmUnitedForever" `
+                -Include @(
+                    "ChallengeMusics",
+                    "MediaTracker",
+                    "MenuMusics",
+                    "Scores",
+                    "Skins",
+                    "Tracks"
+                );
+        } `
+        -UserConfigurator {
+            param([hashtable] $Arguments)
+            Expand-BackupArtifacts -User $Arguments.Name -Path "TmUnitedForever" -Target $path;
+        };
+} $PSBoundParameters;