. "$PSScriptRoot/Manage.ps1";
. "$PSScriptRoot/../../../lib/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;
    };

Start-SoftwareInstaller @args @parameters;