@echo off
REM ===========================================================
REM  ARKA rates widget - install on the Windows desktop.
REM  Double-click this file. No admin rights needed.
REM
REM  It downloads the launcher, copies it into your own user
REM  folder, adds it to Startup, and brings the widget up glued
REM  to the desktop: no taskbar button, no Alt+Tab, and it
REM  cannot be minimized away. From then on the launcher keeps
REM  itself up to date (signed updates only).
REM
REM  Keep this file PURE ASCII: cmd.exe reads .cmd with the OEM
REM  codepage and any Persian text here would come out broken.
REM ===========================================================
setlocal
title ARKA rates widget - setup

set "SRC=https://arkabistoon.ir/widget-desktop.ps1"
REM A fresh file name every run, and never a variable called TMP. On 7 Mehr
REM 1405 a stale arka_widget_desktop.ps1 in TEMP had become unwritable: the
REM download failed silently, "if exist" still saw the old file, and
REM powershell then said "-File ... does not exist".
set "ARKA_PS=%TEMP%\arka_widget_%RANDOM%%RANDOM%.ps1"

echo.
echo   ARKA rates widget - setup
echo   -------------------------
echo   downloading the launcher...

powershell -NoProfile -ExecutionPolicy Bypass -Command ^
 "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;" ^
 "try{Invoke-WebRequest -UseBasicParsing '%SRC%' -OutFile '%ARKA_PS%'}catch{Write-Host ('  '+$_.Exception.Message);exit 1}"
if errorlevel 1 goto :failed
if not exist "%ARKA_PS%" goto :failed

echo   installing...
powershell -NoProfile -ExecutionPolicy Bypass -File "%ARKA_PS%" -Install
if errorlevel 1 goto :failed

del "%ARKA_PS%" >nul 2>&1
echo.
echo   Done. The widget is on your desktop and will come back
echo   every time you log on.
echo.
pause
exit /b 0

:failed
del "%ARKA_PS%" >nul 2>&1
echo.
echo   Setup failed. Check that you can open this address in a
echo   browser:
echo     %SRC%
echo.
pause
exit /b 1
