@echo off
rem {{ app_display }} {{ app_version }} -- self-contained bundle launcher.
rem
rem Generated by ariza for {{ platform }}. Everything this script needs is
rem inside the directory above it; nothing outside the bundle is read, and
rem nothing is installed.

setlocal enableextensions

rem %~dp0 is this script's directory with a trailing backslash, already
rem resolved, so the bundle root is one level up.
for %%I in ("%~dp0..") do set "BUNDLE_ROOT=%%~fI"

set "ARIZA_RAKU=%BUNDLE_ROOT%\rakudo\bin\raku.exe"
if not exist "%ARIZA_RAKU%" (
    echo {{ app_display }}: this bundle is incomplete - no interpreter at "%ARIZA_RAKU%" 1>&2
    echo   Unpack the whole archive and run this script from inside it. 1>&2
    exit /b 1
)

rem The bundle is the only module repository.
set "RAKULIB=inst#%BUNDLE_ROOT%\site"
set "PERL6LIB="
set "NOTCURSES_NATIVE_DATA_DIR=%BUNDLE_ROOT%\native"
{%- if sqlcipher %}
set "PATH=%BUNDLE_ROOT%\{{ sqlcipher_dir_win }};%PATH%"
set "DBIISH_SQLCIPHER_LIB=%BUNDLE_ROOT%\{{ sqlcipher_lib_win }}"
{%- endif %}

set "ARIZA_STATE_DIR=%LOCALAPPDATA%\{{ app_exec }}"
if not exist "%ARIZA_STATE_DIR%\.first-run" (
    echo {{ app_display }}: first launch can take a few seconds. Later ones are instant. 1>&2
    if not exist "%ARIZA_STATE_DIR%" mkdir "%ARIZA_STATE_DIR%" 2>nul
    if exist "%ARIZA_STATE_DIR%" type nul >"%ARIZA_STATE_DIR%\.first-run" 2>nul
)

"%ARIZA_RAKU%" "%BUNDLE_ROOT%\{{ target_win }}" %*
exit /b %ERRORLEVEL%
