@echo off
setlocal enabledelayedexpansion

title SecureLine App Installer

echo ==========================================
echo        SecureLine App Installer
echo ==========================================
echo.

REM ------------------------------------------
REM check adb available
REM ------------------------------------------

where adb >nul 2>nul

if %errorlevel% neq 0 (
    echo ERROR: adb not found in PATH
    echo Install Android platform-tools first
    exit /b 1
)

REM ------------------------------------------
REM check device connection
REM ------------------------------------------

for /f "skip=1 tokens=1" %%D in ('adb devices') do (
    if not "%%D"=="" (
        set DEVICE_FOUND=1
    )
)

if not defined DEVICE_FOUND (
    echo ERROR: no device detected
    echo.
    echo Make sure:
    echo - phone is connected
    echo - USB debugging is enabled
    echo - RSA fingerprint accepted
    exit /b 1
)

echo Device detected
echo.

REM ------------------------------------------
REM app list
REM ------------------------------------------

set APPS=^
WhatsApp.apk ^
Telegram.apk ^
Signal.apk ^
Molly.apk ^
ThreemaLibre.apk ^
Mullvad.apk ^
Simplex.apk ^
FDroid.apk ^
AuroraStore.apk ^
Briar.apk ^
Session.apk

REM ------------------------------------------
REM install apps
REM ------------------------------------------

set FAILCOUNT=0

for %%A in (%APPS%) do (

    if exist "%%A" (

        echo Installing %%A ...

        adb install -r "%%A" >nul

        if !errorlevel! neq 0 (
            echo FAILED: %%A
            set /a FAILCOUNT+=1
        ) else (
            echo OK: %%A
        )

    ) else (

        echo MISSING FILE: %%A
        set /a FAILCOUNT+=1

    )
)

echo.
echo ==========================================

if %FAILCOUNT% neq 0 (

    echo Completed with %FAILCOUNT% issue(s)
    exit /b 2

) else (

    echo All apps installed successfully
    exit /b 0

)
