@echo off
setlocal EnableExtensions
if /I not "%~1"=="/elevated" (
  net session >nul 2>&1
  if errorlevel 1 (
    powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -ArgumentList '/elevated' -Verb RunAs"
    exit /b
  )
)
set "ROOT=%~dp0.."
if defined ProgramFiles(x86) (set "PF=%ProgramFiles(x86)%") else (set "PF=%ProgramFiles%")
set "TARGET=%PF%\K-Diagnostics\Virtual Tester VCI Bridge"
if not exist "%ROOT%\dist\windows-x86\KDX.VciClient.exe" (
  echo ERROR: KDX.VciClient.exe was not found.
  pause
  exit /b 2
)
mkdir "%TARGET%" 2>nul
copy /y "%ROOT%\dist\windows-x86\KDX.VciClient.exe" "%TARGET%\KDX.VciClient.exe" >nul
call "%ROOT%\windows\CONFIGURE_SDCONNECT_IPS.bat" >nul
powershell -NoProfile -ExecutionPolicy Bypass -Command "$w=New-Object -ComObject WScript.Shell; $s=$w.CreateShortcut([Environment]::GetFolderPath('CommonPrograms')+'\K-Diagnostics Virtual Tester VCI Bridge.lnk'); $s.TargetPath='%TARGET%\KDX.VciClient.exe'; $s.WorkingDirectory='%TARGET%'; $s.Save(); $d=$w.CreateShortcut([Environment]::GetFolderPath('CommonDesktopDirectory')+'\K-Diagnostics Virtual Tester VCI Bridge.lnk'); $d.TargetPath='%TARGET%\KDX.VciClient.exe'; $d.WorkingDirectory='%TARGET%'; $d.Save()"
echo.
echo Installed native 32-bit client to:
echo %TARGET%
echo.
echo It installs one GUI app: KDX.VciClient.exe.
echo It runs on 32-bit and 64-bit Windows. It scans only the 32-bit J2534 registry view.
echo SDconnect LAN 172.29.127.122 and Wi-Fi 192.168.2.199 are configured.
pause
