# FuckCapsLock Installer
# Run as Administrator: right-click -> Run with PowerShell (Run as Administrator)

$ErrorActionPreference = "Stop"
$DestDir = "$env:ProgramFiles\FuckCapsLock"
$ExeName = "fuckcapslock.exe"
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
$RegName = "FuckCapsLock"

# Source exe: assume script is in the repo root, exe is in out/
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$SourceExe = Join-Path $ScriptDir "out" $ExeName

if (-not (Test-Path $SourceExe)) {
    Write-Error "Could not find $SourceExe — make sure this script is run from the repo root."
    exit 1
}

# Require admin
$IsAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $IsAdmin) {
    Write-Error "This script must be run as Administrator."
    exit 1
}

# Create destination directory
if (-not (Test-Path $DestDir)) {
    New-Item -ItemType Directory -Path $DestDir -Force | Out-Null
}

# Copy exe
Copy-Item -Path $SourceExe -Destination (Join-Path $DestDir $ExeName) -Force
Write-Host "Copied $ExeName to $DestDir"

# Set registry auto-start (HKLM = all users, starts before user logon)
$ExePath = Join-Path $DestDir $ExeName
Set-ItemProperty -Path $RegPath -Name $RegName -Value $ExePath
Write-Host "Registry auto-start set: $RegPath\$RegName = $ExePath"

# Launch
Start-Process -FilePath $ExePath
Write-Host "FuckCapsLock launched."
Write-Host ""
Write-Host "Done. Caps Lock is now permanently disabled until you right-click"
Write-Host "the tray icon and select Exit."
