@echo off
setlocal

REM Ciphon for Excel - Windows installer.
REM
REM Served with a .cmd_ pseudo-extension, not .cmd: browsers flag a real .cmd download as a
REM dangerous executable, and Explorer hides the suffix of a .cmd.txt (forcing users to enable
REM "file name extensions" before the rename works). An unregistered extension like .cmd_ is
REM neither flagged nor hidden, so the tester just deletes the trailing underscore to get
REM install-windows.cmd, then double-clicks it.
REM
REM Downloads and runs install-windows.ps1, which registers the add-in under the current user.
REM No administrator rights are required.

set "URL=https://excel.ciphon.development.draftworx.com/install-windows.ps1"
set "INSTALLER=%TEMP%\ciphon-install.ps1"

echo.
echo  Installing Ciphon for Excel
echo  ---------------------------
echo.

powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "try { Invoke-WebRequest -Uri '%URL%' -OutFile '%INSTALLER%' -UseBasicParsing } catch { Write-Host $_.Exception.Message -ForegroundColor Red; exit 1 }"
if errorlevel 1 goto :fail

REM -File runs the script in its own scope, so its exit code reaches errorlevel here.
powershell -NoProfile -ExecutionPolicy Bypass -File "%INSTALLER%"
if errorlevel 1 goto :fail

del "%INSTALLER%" >nul 2>&1

echo.
echo  Done. Close Excel completely, reopen it, and look for Ciphon on the Home tab.
echo.
REM Without pause the window closes instantly on double-click and the message above is never read.
pause
exit /b 0

:fail
del "%INSTALLER%" >nul 2>&1
echo.
echo  Installation failed. Send the message above to your Ciphon contact.
echo.
pause
exit /b 1
