@echo off
title IND Global - BioTime 9.5 Wireless Auto-Sync Setup
echo ============================================================
echo   IND Global - Linking Local BioTime 9.5 (127.0.0.1:85)
echo   to Cloud Hub (31.97.111.155:8098)
echo ============================================================
echo.

powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "$dir = Join-Path $env:LOCALAPPDATA 'IndGlobalBioTimeSync'; New-Item -ItemType Directory -Force -Path $dir | Out-Null;" ^
  "$scriptPath = Join-Path $dir 'sync.ps1';" ^
  "Invoke-WebRequest -Uri 'http://31.97.111.155:8098/download/sync.ps1' -UseBasicParsing -OutFile $scriptPath;" ^
  "$runnerPath = Join-Path $dir 'loop.ps1';" ^
  "$loopCode = 'while ($true) { try { & "' + $scriptPath + '" } catch {} Start-Sleep -Seconds 20 }';" ^
  "Set-Content -Path $runnerPath -Value $loopCode -Encoding UTF8;" ^
  "Write-Host 'Syncing latest punches into local BioTime (127.0.0.1:85)...' -ForegroundColor Cyan;" ^
  "& $scriptPath;" ^
  "$startupDir = [Environment]::GetFolderPath('Startup');" ^
  "$vbsPath = Join-Path $startupDir 'IndGlobalBioTimeAutoSync.vbs';" ^
  "$vbs = 'Set ws = CreateObject("Wscript.Shell")' + [Environment]::NewLine + 'ws.Run "powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File ""' + $runnerPath + '""", 0, False';" ^
  "Set-Content -Path $vbsPath -Value $vbs -Encoding ASCII;" ^
  "Start-Process wscript.exe -ArgumentList ('"' + $vbsPath + '"');" ^
  "Write-Host ''; Write-Host 'SUCCESS! BioTime 9.5 (127.0.0.1:85) is now linked wirelessly 24/7!' -ForegroundColor Green;"

echo.
echo Done! Open http://127.0.0.1:85 - all punches now arrive automatically over Wi-Fi without any LAN cable!
pause
