# RevitAI installer - copies the add-in into your Revit add-ins folder.
#
# HOW TO RUN (drafters):
#   1. Unzip this folder anywhere (e.g. your Downloads).
#   2. Right-click install.ps1  ->  "Run with PowerShell".
#      (If Windows blocks it, open PowerShell and run:
#         powershell -ExecutionPolicy Bypass -File .\install.ps1 )
#   3. Close Revit if it's open, then re-open it.
#   4. First launch shows a security prompt for an unsigned add-in -
#      click **Always Load**. You only do this once.
#
# The "AI Drafting" tab with the Auto Dimension button appears on the ribbon.

# This zip targets one Revit version; the build stamps it here.
$RevitVersion = "2025"

$ErrorActionPreference = "Stop"
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$dest = Join-Path $env:APPDATA "Autodesk\Revit\Addins\$RevitVersion"

Write-Host ""
Write-Host "RevitAI installer  ->  Revit $RevitVersion" -ForegroundColor Cyan
Write-Host ""

# Warn (don't fail) if Revit is running - the DLL is locked while it is.
if (Get-Process Revit -ErrorAction SilentlyContinue) {
    Write-Host "Revit is currently running. Please close it, then run this installer again." -ForegroundColor Yellow
    Read-Host "Press Enter to exit"
    exit 1
}

# Everything in this folder except the installer itself is payload.
$payload = Get-ChildItem -Path $here -File | Where-Object { $_.Name -ne "install.ps1" -and $_.Name -ne "README.txt" }

if (-not (Test-Path $dest)) {
    New-Item -ItemType Directory -Path $dest -Force | Out-Null
    Write-Host "Created $dest"
}

foreach ($f in $payload) {
    Copy-Item -Path $f.FullName -Destination (Join-Path $dest $f.Name) -Force
    Write-Host "  copied $($f.Name)"
}

Write-Host ""
Write-Host "Done. Installed to:" -ForegroundColor Green
Write-Host "  $dest"
Write-Host ""
Write-Host "Next: open Revit $RevitVersion. If prompted about an unsigned add-in," -ForegroundColor Green
Write-Host "click 'Always Load'. Look for the 'AI Drafting' tab on the ribbon." -ForegroundColor Green
Write-Host ""
Read-Host "Press Enter to close"

