Proxy/FRPPanel.ps1

$BaseDir = Split-Path -Path $PSScriptRoot -Parent
. (Join-Path $baseDir 'Generic' 'Github.ps1')

<#
.SYNOPSIS
    Downloads the latest release of frp-panel and renames the executable to frpp.exe.
.PARAMETER DestinationPath
    The folder where frpp.exe will be saved.
#>

function Install-FrpPanel {
    [CmdletBinding(SupportsShouldProcess=$true)]
    param(
        [Parameter(Mandatory)]
        [string] $DestinationPath
    )

    $owner = 'VaalaCat'
    $repo = 'frp-panel'
    $pattern = '*.exe'

    if ($PSCmdlet.ShouldProcess("frp-panel from $owner/$repo", "Download and install latest release")) {
        Write-Verbose "Getting the URL for the latest exe..."
        $downloadUrl = Get-GitHubLatestReleaseAssetUrl -Owner $owner -Repo $repo -AssetNamePattern $pattern

        if (-not (Test-Path $DestinationPath)) {
            Write-Verbose "Creating directory $DestinationPath..."
            New-Item -ItemType Directory -Path $DestinationPath -Force | Out-Null
        }

        $targetExe = Join-Path $DestinationPath 'frpp.exe'

        Write-Verbose "Downloading and saving as frpp.exe..."
        Invoke-WebRequest -Uri $downloadUrl -OutFile $targetExe -UseBasicParsing -ErrorAction Stop

        if (-not (Test-Path $targetExe)) {
            Write-Warning "Antivirus might have removed frpp.exe. Permission to use the file may be required."
            Pause
        }
    }
}