@echo off
setlocal
title Install AI Usage for Cursor
echo AI Usage - Cursor installer
echo.
powershell.exe -NoLogo -NoProfile -Command "$ErrorActionPreference='Stop'; $package=$null; try { $cursor=@((Join-Path $env:LOCALAPPDATA 'Programs\cursor\resources\app\bin\cursor.cmd'),(Join-Path $env:ProgramFiles 'Cursor\resources\app\bin\cursor.cmd')) | Where-Object {Test-Path -LiteralPath $_} | Select-Object -First 1; if(!$cursor){$command=Get-Command cursor.cmd -ErrorAction SilentlyContinue; if($command){$cursor=$command.Source}}; if(!$cursor){throw 'Cursor was not found. Install Cursor from https://cursor.com/downloads, then open this installer again.'}; $package=Join-Path ([IO.Path]::GetTempPath()) ('ai-usage-'+[guid]::NewGuid().ToString('N')+'.vsix'); Write-Host 'Downloading AI Usage Cloud 0.2.18...'; [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -UseBasicParsing -Uri 'https://ai-usage-ttw.web.app/downloads/ai-usage-cloud-0.2.18.vsix' -OutFile $package; if((Get-FileHash -LiteralPath $package -Algorithm SHA256).Hash -ne '57da77c146b22bb87d38008dd3c4ca33d972636f318943b709d2f0bf2c52edd6'){throw 'The download could not be verified. Nothing was installed. Download the installer again from https://ai-usage-ttw.web.app/install.'}; Write-Host 'Installing in Cursor...'; & $cursor --install-extension $package; if($LASTEXITCODE -ne 0){throw 'Cursor could not finish the installation. See the message above, or use the manual installation steps on https://ai-usage-ttw.web.app/install.'}; Write-Host ''; Write-Host 'Installed! In Cursor, click AI Usage Cloud in the status bar.' -ForegroundColor Green; Write-Host 'If it is not visible, press Ctrl+Shift+P and run Developer: Reload Window.'; } catch {Write-Host ''; Write-Host $_.Exception.Message -ForegroundColor Red; exit 1} finally {if($package -and (Test-Path -LiteralPath $package)){Remove-Item -LiteralPath $package -Force}}"
set "install_result=%errorlevel%"
echo.
echo Press any key to close this window.
pause >nul
exit /b %install_result%
