@echo off
setlocal enabledelayedexpansion

set "EXE=%~1"
if "%EXE%"=="" set "EXE=%~dp0..\anothereditor.exe"
for %%I in ("%EXE%") do set "EXE=%%~fI"

if not exist "%EXE%" (
  echo AnotherEditor executable not found: "%EXE%"
  echo Usage: install_windows_open_with.cmd C:\Path\To\anothereditor.exe
  exit /b 1
)

set "TMPREG=%TEMP%\anothereditor-open-with.reg"
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "$template = Get-Content -Raw 'packaging/windows/anothereditor-open-with.reg.in';" ^
  "$escaped = '%EXE%'.Replace('\', '\\');" ^
  "$template.Replace('@EXECUTABLE@', $escaped) | Set-Content -Encoding Unicode '%TMPREG%'"

reg import "%TMPREG%"
del "%TMPREG%" >nul 2>nul
echo Installed AnotherEditor Open With integration for the current user.
