@echo off
setlocal
rem cadssistant for AutoCAD -- installer
rem Downloads the plug-in bundle from https://cadssistant.com and installs it
rem for the current Windows user. No admin rights needed.

set "DEST=%APPDATA%\Autodesk\ApplicationPlugins"
set "ZIP=%TEMP%\cadssistant.bundle.zip"

echo Installing cadssistant for AutoCAD from https://cadssistant.com ...
if not exist "%DEST%" mkdir "%DEST%"

curl -fsSL -o "%ZIP%" "https://cadssistant.com/cadssistant.bundle.zip"
if errorlevel 1 goto :fail

if exist "%DEST%\cadssistant.bundle" rmdir /s /q "%DEST%\cadssistant.bundle"
tar -xf "%ZIP%" -C "%DEST%"
if errorlevel 1 goto :fail
del "%ZIP%" >nul 2>nul

rem Clear any development-server override so the palette loads production.
reg delete "HKCU\Environment" /v CADSSISTANT_URL /f >nul 2>nul

echo.
echo Done. Installed to:
echo   %DEST%\cadssistant.bundle
echo.
echo Restart AutoCAD, then type CADSSISTANT to open the palette.
pause
exit /b 0

:fail
echo.
echo Something went wrong -- nothing was installed.
echo Manual install: download https://cadssistant.com/cadssistant.bundle.zip
echo and extract it into %DEST%\
pause
exit /b 1
