@echo off
chcp 65001 >nul
setlocal enableextensions enabledelayedexpansion
title Media Downloader

set "TOOL_DIR=%~dp0"
set "PYTHONW=%TOOL_DIR%python\pythonw.exe"
set "SERVER=%TOOL_DIR%server.py"
set "RUNNER=%TOOL_DIR%_run_service.ps1"

if not exist "!PYTHONW!" (
  echo [ERROR] !PYTHONW! not found.
  echo Please re-download and extract ALL files.
  pause
  exit /b 1
)

if not exist "!SERVER!" (
  echo [ERROR] !SERVER! not found.
  echo Please re-download and extract ALL files.
  pause
  exit /b 1
)

if not exist "!RUNNER!" (
  echo [ERROR] !RUNNER! not found.
  echo Please re-download and extract ALL files.
  pause
  exit /b 1
)

rem Launch via runner script so cmd never re-parses the resolved path
rem (avoids "was unexpected at this time" when the install path contains spaces or parentheses).
powershell -NoProfile -ExecutionPolicy Bypass -File "!RUNNER!" -Python "!PYTHONW!" -Server "!SERVER!"
exit /b 0
