@echo off
REM Pipsity Connector installer for MetaTrader 5 (Windows).
REM Downloads PipsityConnector.ex5 and puts it in every MT5 on this PC.
REM It changes nothing else. Safe to run again (updates the connector).
title Pipsity Connector installer
echo.
echo   Pipsity Connector for MetaTrader 5
echo   ----------------------------------
echo.
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "$ErrorActionPreference='Stop';" ^
  "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;" ^
  "$tmp=Join-Path $env:TEMP 'PipsityConnector.ex5';" ^
  "try { Invoke-WebRequest -UseBasicParsing 'https://tj-mt5.pipsity.workers.dev/dl/PipsityConnector.ex5' -OutFile $tmp } catch { Write-Host '  Could not download the connector. Check your internet / VPN and run this again.'; exit 1 };" ^
  "$dirs=@(Get-ChildItem -Directory (Join-Path $env:APPDATA 'MetaQuotes\Terminal') -ErrorAction SilentlyContinue | ForEach-Object { Join-Path $_.FullName 'MQL5\Experts' } | Where-Object { Test-Path $_ });" ^
  "if($dirs.Count -eq 0){ Write-Host '  No MetaTrader 5 found. Open MetaTrader 5 once, close it, and run this again.'; Write-Host '  (Or in MetaTrader: File > Open Data Folder > MQL5 > Experts, and copy the file there.)'; exit 1 };" ^
  "foreach($d in $dirs){ Copy-Item $tmp (Join-Path $d 'PipsityConnector.ex5') -Force; Write-Host ('  Installed in: ' + $d) };" ^
  "Write-Host '';" ^
  "Write-Host '  Done! Now:';" ^
  "Write-Host '   1. Restart MetaTrader 5 (or right-click Expert Advisors in the Navigator > Refresh).';" ^
  "Write-Host '   2. Drag PipsityConnector from the Navigator onto any one chart and click OK.';" ^
  "Write-Host '   3. Type the code it shows into the journal (menu > Auto-sync MetaTrader).'"
echo.
pause
