@echo off
:: ============================================================
::  Dark Desires — Installer
::  Double-click this file to install Dark Desires.
::
::  What it does:
::    1. Copies the app to %LOCALAPPDATA%\DarkDesires\
::    2. Creates a Desktop shortcut
::    3. Creates a Start Menu shortcut
::    4. Opens config.py in Notepad so you can add your API key
::
::  No admin rights required — installs for current user only.
:: ============================================================

setlocal enabledelayedexpansion

echo.
echo  ============================================================
echo   Dark Desires ^| Installer
echo   BlackBazaar.store
echo  ============================================================
echo.
echo  For adults 18+ only. All content is fictional.
echo.

:: ── Confirm age ───────────────────────────────────────────────
set /p AGE_CONFIRM="  I confirm I am 18 years of age or older [Y/N]: "
if /i not "%AGE_CONFIRM%"=="Y" (
    echo.
    echo  Installation cancelled.
    echo.
    pause & exit /b 0
)

echo.

:: ── Paths ─────────────────────────────────────────────────────
:: Install to user's local app data — no admin needed
set "INSTALL_DIR=%LOCALAPPDATA%\DarkDesires"
set "APP_EXE=%INSTALL_DIR%\DarkDesires.exe"
set "CONFIG=%INSTALL_DIR%\config.py"
set "DESKTOP_LNK=%USERPROFILE%\Desktop\Dark Desires.lnk"
set "START_DIR=%APPDATA%\Microsoft\Windows\Start Menu\Programs\Dark Desires"
set "START_LNK=%START_DIR%\Dark Desires.lnk"
set "UNINSTALL_LNK=%START_DIR%\Uninstall Dark Desires.lnk"

:: Source = DarkDesires folder sitting next to this bat file
set "SOURCE=%~dp0DarkDesires"

:: ── Validate source ───────────────────────────────────────────
if not exist "%SOURCE%\DarkDesires.exe" (
    echo  [ERROR] Cannot find DarkDesires folder next to this installer.
    echo  Make sure install.bat and the DarkDesires folder are in the same place.
    echo.
    pause & exit /b 1
)

:: ── Remove old install if present ────────────────────────────
if exist "%INSTALL_DIR%" (
    echo  [1/4] Removing previous installation...
    rmdir /s /q "%INSTALL_DIR%"
)

:: ── Copy app files ────────────────────────────────────────────
echo  [1/4] Installing to %INSTALL_DIR% ...
xcopy /e /i /q "%SOURCE%" "%INSTALL_DIR%" >nul
if errorlevel 1 (
    echo  [ERROR] Failed to copy files. Check you have write access to %LOCALAPPDATA%
    pause & exit /b 1
)

:: Ensure saves folder exists
if not exist "%INSTALL_DIR%\saves" mkdir "%INSTALL_DIR%\saves"

:: ── Desktop shortcut ──────────────────────────────────────────
echo  [2/4] Creating Desktop shortcut...
powershell -NoProfile -Command ^
  "$s=(New-Object -COM WScript.Shell).CreateShortcut('%DESKTOP_LNK%');" ^
  "$s.TargetPath='%APP_EXE%';" ^
  "$s.WorkingDirectory='%INSTALL_DIR%';" ^
  "$s.Description='Dark Desires - AI Adult Roleplay';" ^
  "$s.Save()"

:: ── Start Menu shortcut ───────────────────────────────────────
echo  [3/4] Creating Start Menu shortcuts...
if not exist "%START_DIR%" mkdir "%START_DIR%"

powershell -NoProfile -Command ^
  "$s=(New-Object -COM WScript.Shell).CreateShortcut('%START_LNK%');" ^
  "$s.TargetPath='%APP_EXE%';" ^
  "$s.WorkingDirectory='%INSTALL_DIR%';" ^
  "$s.Description='Dark Desires - AI Adult Roleplay';" ^
  "$s.Save()"

:: Uninstall shortcut in Start Menu
powershell -NoProfile -Command ^
  "$s=(New-Object -COM WScript.Shell).CreateShortcut('%UNINSTALL_LNK%');" ^
  "$s.TargetPath='%INSTALL_DIR%\uninstall.bat';" ^
  "$s.WorkingDirectory='%INSTALL_DIR%';" ^
  "$s.Description='Uninstall Dark Desires';" ^
  "$s.Save()"

:: ── Copy uninstall.bat into install dir ──────────────────────
if exist "%~dp0uninstall.bat" (
    copy /y "%~dp0uninstall.bat" "%INSTALL_DIR%\uninstall.bat" >nul
)

:: ── Open config.py for API key setup ─────────────────────────
echo  [4/4] Opening config.py for API key setup...
echo.
echo  ============================================================
echo   Installation complete!
echo.
echo   IMPORTANT — Final step:
echo   Notepad will now open config.py.
echo   Replace  YOUR_API_KEY_HERE  with your xAI Grok API key.
echo   Get a free key at:  https://console.x.ai
echo.
echo   After saving config.py, launch the app from your Desktop.
echo  ============================================================
echo.
pause

:: Open config in Notepad
start "" notepad "%CONFIG%"

:: Also launch the app
start "" "%APP_EXE%"
