. "$PSScriptRoot/../../Scripts/Context.ps1";

$null = New-Module {
    $path = "$HOME/Documents/TmForever";
    $softwareName = "TmNationsForever";

    function Backup-TmNations([Context] $context) {
        Write-Host "Backing up TrackMania Nations Forever";
        $context.Backup($path, $context.SoftwareArchive($softwareName), @("-i@`"$PSScriptRoot/include.txt`""));
    }

    function Restore-TmNations([Context] $context) {
        $feature = "DirectPlay";
        Write-Host "Restoring TrackMania Nations Forever";

        if (-not (Get-WindowsOptionalFeature -Online -FeatureName $feature).State) {
            Write-Information "Enabling the ``$feature`` feature";
            Enable-WindowsOptionalFeature -Online -FeatureName $feature;
        }

        Write-Information "Installing TrackMania Nations Forever";
        winget install -e --id Nadeo.TrackManiaNationsForever;
        Write-Information "Removing Desktop Icon";
        Remove-Item "$env:PUBLIC\Desktop\*TmNationsForever*";
        Write-Information "Restoring Files";
        $context.Restore($context.SoftwareArchive($softwareName), $path);
    }
}