@echo off
setlocal
rem Reference Verify - Word add-in installer (Windows, desktop Word).
rem Source and help: https://www.referenceverify.com/word-add-in
rem What it does: downloads manifest.xml into your user folder, registers it under Word's
rem developer add-ins key (HKCU) and opens a blank document once to activate the add-in.
rem No administrator rights needed; no system settings touched. To remove: uninstall.cmd

set "D=%LOCALAPPDATA%\ReferenceVerify"
set "BASE=https://referenceverify.com/word-add-in"
echo.
echo  Reference Verify - installing the Word add-in...
echo.
tasklist /FI "IMAGENAME eq WINWORD.EXE" 2>nul | find /I "WINWORD.EXE" >nul
if not errorlevel 1 (
  echo  Please close Word completely first, then run this file again.
  echo.
  pause
  exit /b 1
)
if not exist "%D%" mkdir "%D%"
curl -sSL -o "%D%\manifest.xml" "%BASE%/manifest.xml" || goto :err
curl -sSL -o "%D%\start.docx" "%BASE%/start.docx" || goto :err
reg add "HKCU\Software\Microsoft\Office\16.0\WEF\Developer" /v ReferenceVerify /t REG_SZ /d "%D%\manifest.xml" /f >nul || goto :err
rem Start menu shortcut: opening Word through this document activates the add-in for that session.
powershell -NoProfile -Command "$s=(New-Object -ComObject WScript.Shell).CreateShortcut([IO.Path]::Combine($env:APPDATA,'Microsoft\Windows\Start Menu\Programs\Reference Verify (Word).lnk')); $s.TargetPath='%D%\start.docx'; $s.Description='Opens Word with the Reference Verify add-in active'; $s.Save()" >nul 2>&1
echo  Installed. Word is opening; the "Check Bibliography" button is on the right of the Home ribbon.
echo.
echo  NOTE: the next time you start Word, click Add-ins on the Home ribbon and pick
echo  Reference Verify under "Developer Add-ins" (two clicks), or start Word from the
echo  "Reference Verify (Word)" Start menu shortcut.
echo  To remove: %BASE%/uninstall.cmd
start "" "%D%\start.docx"
ping -n 4 127.0.0.1 >nul
exit /b 0

:err
echo.
echo  Installation failed. Check your internet connection and try again.
echo  Help: %BASE%
pause
exit /b 1
