@echo off
setlocal EnableExtensions
title Raids Timer helper
cd /d "%~dp0"

REM Drop the internet "blocked" mark so Windows does not treat these files as unsafe.
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem -LiteralPath '%~dp0' -File -ErrorAction SilentlyContinue | Where-Object { $_.Name -match '(?i)^(pc-banner|Open-Raids-Timer-BlueStacks|RaidsTimer-helper)' } | ForEach-Object { Unblock-File -LiteralPath $_.FullName -ErrorAction SilentlyContinue; Remove-Item -LiteralPath $_.FullName -Stream Zone.Identifier -Force -ErrorAction SilentlyContinue }" >nul 2>&1

echo Raids Timer helper
echo Starting helper 1.0.200 (not an old Downloads copy).
echo.

set "STARTPS=%~dp0pc-banner-start.ps1"
set "INST=%APPDATA%\RaidsTimer\pc-banner.ps1"
set "ALIVE=%APPDATA%\RaidsTimer\helper-alive.txt"
set "READY=%APPDATA%\RaidsTimer\helper-ready.txt"
if exist "%ALIVE%" del /q "%ALIVE%" >nul 2>&1
if exist "%READY%" del /q "%READY%" >nul 2>&1

if exist "%STARTPS%" (
  powershell.exe -NoProfile -STA -ExecutionPolicy Bypass -File "%STARTPS%"
) else (
  echo Using the installed helper in AppData.
  if not exist "%INST%" (
    echo Missing helper. Download pc-banner.ps1 and pc-banner.cmd from the website into the same folder.
    echo.
    pause
    exit /b 1
  )
  start "RaidsTimerHelper" powershell.exe -NoProfile -STA -ExecutionPolicy Bypass -WindowStyle Hidden -File "%INST%" -OpenFarm
)

set /a N=0
:wait
timeout /t 1 /nobreak >nul
set /a N+=1
if exist "%ALIVE%" goto started
if exist "%READY%" goto started
if %N% LSS 20 goto wait

echo.
echo Windows closed the helper or blocked it.
echo.
echo Fix:
echo  1. Right-click every pc-banner.ps1 - Properties - tick Unblock - Apply
echo  2. Use the Desktop shortcut Raids Timer Chat
echo.
pause
exit /b 1

:started
echo Helper is running. The Auto Farm window title should say 1.0.200.
timeout /t 5 /nobreak >nul
exit /b 0
