# check if folder exists
if (Test-Path -Path "C:\Program Files (x86)\ISL Online" )
{
    # remove ISL Online binaries

    # check if uninstaller exists
    $uninstaller = Get-ChildItem -Path "C:\Program Files (x86)\ISL Online" -Filter "unins*.exe" -ErrorAction SilentlyContinue
    if ($uninstaller)
    {
        # run uninstaller
        & $uninstaller /SILENT
    }
    Remove-Item -Recurse -Force "C:\Program Files (x86)\ISL Online" -Confirm:$false -ErrorAction SilentlyContinue
}

# cleand up registry
Remove-Item -Path "HKLM:\SOFTWARE\WOW6432Node\ISL Online" -Force -Confirm:$false -ErrorAction SilentlyContinue
Remove-Item -Path "HKCU:\SOFTWARE\ISL Online" -Force -Confirm:$false -ErrorAction SilentlyContinue
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
Remove-Item -Path "HKU:\S-1-5-18\Software\ISL Online" -Force -Confirm:$false -ErrorAction SilentlyContinue

$tpath = $(Join-Path -Path $env:ProgramData -ChildPath "isl")

if (!(Test-Path -Path $tpath -ErrorAction SilentlyContinue)) {
    New-Item -Path $tpath -ItemType Directory -Force | Out-Null
}
$lfile = $(Join-Path -Path $env:ProgramData -ChildPath "isl\setup.log")
Start-Transcript $lfile -Force

# copy uninstall script
Copy-Item "uninstall.ps1" "$tpath\uninstall.ps1"

#get current installer
$downloadURL = "https://isl.mhcsoftware.de/download/ISLAlwaysOn?cmdline=%2FVERYSILENT+grant_password+%22H%26K%23q_%40y%25oYuNwHyKO%2ACF%29A60Q%21AUP%3B4%3DSo%2B%25b%5E3%22+password+%22H%26K%23q_%40y%25oYuNwHyKO%2ACF%29A60Q%21AUP%3B4%3DSo%2B%25b%5E3%22+push_upgrade+true+ignore_system_account+grant_silent+%22zeJxtzkFOAzEMQFGZLtggFpyAE1RObCf2DdhwCMdJOiPRgpipkDgEZ6bs2X7pS28CvPq%2bL6tvzy%2fj8j0e4RTzAOv2djwvsb3P%2fcs%2fx7GPJzit%2fQCjEqtUpBkmY8w5GTEbOfWUoo7kLQm1qOKcqMYcTMMrupJy0UghXqhTncUtmypWLNrwVkSleXHJ0XNmTMTBQQ3F1VV6ab3VjKZTuJgWTFh%2b4AOAmQ6wwb%2fmK8B5uYPrHz2bJWNjvK0PcA%2b%2fN2FDMA%3d%3d%22"
Invoke-WebRequest  $downloadURL -outfile "$tpath\isl.exe"

# execute installer
start-process "$tpath\isl.exe" -ArgumentList "/SILENT" -wait -PassThru -NoNewWindow

# cleanup
Remove-Item "$tpath\isl.exe" -Force -Confirm:$false

# boost https
New-Item -Path "HKLM:\SOFTWARE\WOW6432Node\ISL Online\AutoTransport\Connect options" -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\ISL Online\AutoTransport\Connect options" -Name "boost" -Value "wininet-https" -PropertyType STRING -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\ISL Online\AutoTransport\Connect options" -Name "https" -Value "1" -PropertyType STRING -Force

Stop-Transcript