public/Utils/Update-Xray.ps1

using module '..\..\modules\Enums.psm1'
using module '..\..\modules\Session.psd1'

function Update-Xray(){
    [CmdletBinding()]
    param(
        [switch] $settings,
        [switch] $removeOldVersions,
        [switch] $listInstallations
    )

    #$session = [Session]::getCurrent()

    if ($settings){
        Write-Host $LocalizedData.LoadingCurrentSettingsMessage
        $settingsFile = [Config]::Load()
        Write-Debug "Settings: $($settingsFile.autoUpdate)"

        if ($settingsFile.autoUpdate.settings) {
            Write-Host $LocalizedData.DownloadingNewSettingsMessage

            $newSettings = [Config]::DownloadSettings($settingsFile.autoUpdate.settings)
            Write-Host $LocalizedData.SucessfullyDownloadedAndSavedMessage
        }
        else {
            Write-Error $LocalizedData.NoSettingsFileOrNoAutoUpdateError
        }
        if ($newSettings) {
            if ($session){
                $session.config.Reload()
                Write-Host $LocalizedData.ReloadingNewSettingsMessage
            }
        }
    }

    $moduleName = 'SportsbookXray'
    if ($module){ Update-Module -Name $moduleName }

    if ($listInstallations){
        Get-InstalledModule -Name $moduleName -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
    }

    if ($removeOldVersions){
        $latest = Get-InstalledModule -Name $moduleName -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
        Get-InstalledModule $moduleName -AllVersions | Where-Object { $_.Version -ne $latest.Version } | Uninstall-Module
    }
}