@echo off
setlocal EnableExtensions EnableDelayedExpansion
set "MINIKE_INSTALL_MODE=app"
chcp 65001 >nul 2>&1
title Mike IA Local - Instalador Minike
color 0B

set "CORE_URL=https://minike.com.br/local-ai/mike-local-ai-minike.ps1"
set "CORE_SHA256_URL=https://minike.com.br/local-ai/mike-local-ai-minike.ps1.sha256"
set "CORE_SHA256_FALLBACK=50541F6FB080CBC3F533560EF5C94715CCD3D50650D2F5C96DFF1FEAE3369F88"
set "HELP_URL=https://minike.com.br/local-ai/"
set "HUB_URL=https://minike.com.br/local-ai/hub.php"
set "BUNDLE_URL=https://minike.com.br/local-ai/install-bundle.ps1"
set "BUNDLE_FILE=%TEMP%\mike-install-bundle.ps1"
set "CORE_FILE=%TEMP%\mike-local-ai-minike.ps1"
set "HASH_FILE=%TEMP%\mike-local-ai-minike.ps1.sha256"
set "VALIDATE_ONLY=0"
set "INSTALL_MODE=%MINIKE_INSTALL_MODE%"
if not defined INSTALL_MODE set "INSTALL_MODE=app"
set "SECONDARY_PRESET=%MINIKE_SECONDARY_PRESET%"
if not defined SECONDARY_PRESET set "SECONDARY_PRESET=creator"
set "SKIP_SECONDARY_MODELS=%MINIKE_SKIP_SECONDARY_MODELS%"
if not defined SKIP_SECONDARY_MODELS set "SKIP_SECONDARY_MODELS=0"
set "BUNDLE_PRESET=%MINIKE_BUNDLE_PRESET%"
if not defined BUNDLE_PRESET set "BUNDLE_PRESET=standard"
set "PREINSTALL_AGENTS=%MINIKE_PREINSTALL_AGENTS%"
if not defined PREINSTALL_AGENTS set "PREINSTALL_AGENTS=ready"
set "BUNDLE_DOWNLOADED=0"
set "BUNDLED_DIR=%~dp0"
set "BUNDLED_CORE=%BUNDLED_DIR%mike-local-ai-minike.ps1"
set "BUNDLED_HASH=%BUNDLED_DIR%mike-local-ai-minike.ps1.sha256"
set "BUNDLED_BUNDLE=%BUNDLED_DIR%install-bundle.ps1"
if not "%MINIKE_STABLE_INSTALLER%"=="1" (
  set "STABLE_DIR=%TEMP%\MINIKE-Installer"
  if not exist "!STABLE_DIR!" mkdir "!STABLE_DIR!" >nul 2>&1
  if not exist "!STABLE_DIR!\webview2-sdk" mkdir "!STABLE_DIR!\webview2-sdk" >nul 2>&1
  for %%F in (
    instalar-mike-windows.cmd
    mike-local-ai-minike.ps1
    mike-local-ai-minike.ps1.sha256
    mike-ui.html
    mike-conpty-terminal.cs
    mike-webview2-host.cs
    comfyui-mike-agent.ps1
    mike-compute-tray-agent.ps1
    mike-mouse-idle-agent.ps1
    install-mike-exo-cluster.ps1
    exo-wsl-setup.sh
    start-mike-exo-wsl.cmd
    install-mike-llamacpp-rpc.ps1
    conectar-cluster.ps1
    conectar-cluster.cmd
    install-bundle.ps1
    install-comfyui-mike.ps1
    install-comfyui-portable.ps1
    install-mike-secondary-engines.ps1
    install-mike-ollama-agents.ps1
    install-mike-heavy-models.ps1
    install-airllm-mike.ps1
    install-mike-multimedia-skills.ps1
    install-mike-video-engine.ps1
    install-mike-code-agent.ps1
    install-mike-piper-embeddings.ps1
    mike-secondary-models.json
    mike-secondary-engines-agent.ps1
  ) do if exist "%~dp0%%F" copy /Y "%~dp0%%F" "!STABLE_DIR!\%%F" >nul 2>&1
  for %%F in (
    Microsoft.Web.WebView2.Core.dll
    Microsoft.Web.WebView2.WinForms.dll
    WebView2Loader.dll
  ) do (
    if exist "%~dp0webview2-sdk\%%F" (
      copy /Y "%~dp0webview2-sdk\%%F" "!STABLE_DIR!\webview2-sdk\%%F" >nul 2>&1
    ) else if exist "%~dp0%%F" (
      copy /Y "%~dp0%%F" "!STABLE_DIR!\webview2-sdk\%%F" >nul 2>&1
    )
  )
  set "MINIKE_STABLE_INSTALLER=1"
  call "!STABLE_DIR!\instalar-mike-windows.cmd" %*
  exit /b !ERRORLEVEL!
)
call :parse_args %*

rem ============================================================
rem  Auto-elevacao: tudo automatico, SEM botao direito / SEM clique extra.
rem  Um unico "Sim" no UAC e o resto roda sozinho (pagefile, instalacoes,
rem  reinicio). Evita que usuarios leigos travem por falta de permissao.
rem ============================================================
if "%VALIDATE_ONLY%"=="1" goto after_elevation
net session >nul 2>&1
if not errorlevel 1 goto after_elevation
echo.
echo   Para instalar TUDO automaticamente, a Mike precisa de permissao de administrador.
echo   Vai abrir uma janela do Windows: clique SIM. Depois e tudo sozinho.
echo.
set "RELAUNCH_ARGS=%*"
if defined RELAUNCH_ARGS (
  powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -ArgumentList '%*' -Verb RunAs" >nul 2>&1
) else (
  powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -Verb RunAs" >nul 2>&1
)
exit /b
:after_elevation

call :banner
call :stage 5 "Verificando o Windows e os recursos basicos"

where powershell.exe >nul 2>&1
if errorlevel 1 (
  call :action "PowerShell nao foi encontrado neste Windows." "Instale o Windows Management Framework 5.1 ou atualize o Windows."
  exit /b 10
)

for /f "tokens=1,2,3" %%A in ('powershell.exe -NoProfile -Command "$v=[Environment]::OSVersion.Version; Write-Output ($v.Major.ToString()+' '+$v.Minor.ToString()+' '+$v.Build.ToString())"') do (
  set "WIN_MAJOR=%%A"
  set "WIN_MINOR=%%B"
  set "WIN_BUILD=%%C"
)
for /f %%A in ('powershell.exe -NoProfile -Command "$PSVersionTable.PSVersion.Major"') do set "PS_MAJOR=%%A"

if not defined WIN_MAJOR (
  call :action "Nao foi possivel identificar a versao do Windows." "Abra o suporte Minike para verificacao manual."
  start "" "%HELP_URL%"
  exit /b 11
)

echo.
echo   Windows detectado: %WIN_MAJOR%.%WIN_MINOR% build %WIN_BUILD%
echo   PowerShell detectado: %PS_MAJOR%
echo   Modo de uso escolhido: %INSTALL_MODE%
echo   Bundle preset: %BUNDLE_PRESET%
echo   Motores secundarios: %SECONDARY_PRESET%
echo   Agentes Ollama: %PREINSTALL_AGENTS%
echo.

if "%VALIDATE_ONLY%"=="1" (
  call :stage 100 "Validacao do CMD concluida"
  echo   Nenhuma instalacao ou download foi executado.
  exit /b 0
)

if %PS_MAJOR% LSS 5 (
  call :action "PowerShell antigo detectado." "A Mike precisa do PowerShell 5.1. Atualize o Windows Management Framework."
  start "" "https://learn.microsoft.com/powershell/scripting/windows-powershell/wmf/setup/install-configure"
  exit /b 12
)

set "LEGACY=0"
if %WIN_MAJOR% LSS 10 set "LEGACY=1"
if %WIN_MAJOR% EQU 10 if %WIN_BUILD% LSS 19045 set "LEGACY=1"

if "%LEGACY%"=="1" (
  call :stage 15 "Modo de compatibilidade para Windows antigo"
  echo.
  echo   O Ollama oficial exige Windows 10 22H2 ou mais novo.
  echo   Windows 7 e 8 nao recebem instalacao automatica do motor moderno.
  echo.
  where ollama.exe >nul 2>&1
  if errorlevel 1 (
    call :action "Motor local compativel nao encontrado." "Atualize para Windows 10 22H2/11. Enquanto isso, use o modo online Minike."
    start "" "%HELP_URL%"
    pause
    exit /b 20
  )
  echo   Um Ollama existente foi encontrado. A Mike tentara reutiliza-lo sem instalar dependencias.
  set "CORE_ARGS=-SkipDependencies"
  rem Windows 7/8/8.1 e Windows 10 antigo nao tem mais suporte do WebView2 (nem Electron/Tauri
  rem tem, desde 2023) - a janela nativa nunca e tentada aqui, cai sempre no navegador de sempre.
  if /I "%INSTALL_MODE%"=="desktop" set "INSTALL_MODE=app"
) else (
  set "CORE_ARGS="
)

if /I "%INSTALL_MODE%"=="desktop" (
  call :stage 18 "Verificando componente de janela nativa (WebView2)"
  powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
    "$k='{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}';$p=@();$p+=('HKLM:\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\'+$k);$p+=('HKLM:\SOFTWARE\Microsoft\EdgeUpdate\Clients\'+$k);$p+=('HKCU:\SOFTWARE\Microsoft\EdgeUpdate\Clients\'+$k);foreach($r in $p){if(Test-Path $r){$pv=(Get-ItemProperty -Path $r -Name pv -ErrorAction SilentlyContinue).pv;if($pv){exit 0}}};exit 1"
  if errorlevel 1 (
    echo   Componente WebView2 nao encontrado. Baixando o instalador oficial da Microsoft...
    del /q "%TEMP%\MicrosoftEdgeWebview2Setup.exe" >nul 2>&1
    powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
      "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; try{(New-Object Net.WebClient).DownloadFile('https://go.microsoft.com/fwlink/p/?LinkId=2124703','%TEMP%\MicrosoftEdgeWebview2Setup.exe')}catch{}"
    set "WEBVIEW2_SIGNED=0"
    if exist "%TEMP%\MicrosoftEdgeWebview2Setup.exe" (
      powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
        "$s=Get-AuthenticodeSignature -LiteralPath \"$env:TEMP\MicrosoftEdgeWebview2Setup.exe\"; if($s.Status -eq 'Valid' -and $s.SignerCertificate.Subject -match 'O=Microsoft Corporation'){exit 0}else{exit 1}"
      if not errorlevel 1 set "WEBVIEW2_SIGNED=1"
    )
    if "%WEBVIEW2_SIGNED%"=="1" (
      "%TEMP%\MicrosoftEdgeWebview2Setup.exe" /silent /install
      echo   Componente WebView2 instalado.
    ) else (
      echo   Nao foi possivel baixar/validar o WebView2 Runtime agora; a Mike vai abrir no navegador desta vez.
      del /q "%TEMP%\MicrosoftEdgeWebview2Setup.exe" >nul 2>&1
      set "INSTALL_MODE=app"
    )
  ) else (
    echo   Componente WebView2 ja estava presente neste PC.
  )
)

call :stage 22 "Preparando o instalador do bundle (Ollama + SD + exo)"
if exist "%BUNDLED_BUNDLE%" (
  set "BUNDLE_FILE=%BUNDLED_BUNDLE%"
  set "BUNDLE_DOWNLOADED=1"
  echo   Usando bundle embutido no instalador.
) else (
  del /q "%BUNDLE_FILE%" >nul 2>&1
  powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
    "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; (New-Object Net.WebClient).DownloadFile('%BUNDLE_URL%','%BUNDLE_FILE%')" >nul 2>&1
  if exist "%BUNDLE_FILE%" set "BUNDLE_DOWNLOADED=1"
)

call :stage 25 "Preparando o nucleo seguro da Mike"
if exist "%BUNDLED_CORE%" (
  set "CORE_FILE=%BUNDLED_CORE%"
  echo   Usando nucleo embutido no instalador.
) else (
  del /q "%CORE_FILE%" >nul 2>&1
  powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
    "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; (New-Object Net.WebClient).DownloadFile('%CORE_URL%','%CORE_FILE%')" >nul 2>&1
)

if not exist "%CORE_FILE%" (
  where certutil.exe >nul 2>&1
  if not errorlevel 1 certutil.exe -urlcache -split -f "%CORE_URL%" "%CORE_FILE%" >nul 2>&1
)

if not exist "%CORE_FILE%" (
  call :action "Falha ao baixar os arquivos da Mike." "Confira a internet, antivirus ou proxy e tente novamente."
  start "" "%HELP_URL%"
  pause
  exit /b 30
)

call :stage 28 "Buscando a assinatura publica do nucleo"
if exist "%BUNDLED_HASH%" (
  set "HASH_FILE=%BUNDLED_HASH%"
) else (
  del /q "%HASH_FILE%" >nul 2>&1
  powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
    "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; try{(New-Object Net.WebClient).DownloadFile('%CORE_SHA256_URL%','%HASH_FILE%')}catch{}" >nul 2>&1
)
if exist "%HASH_FILE%" (
  set /p "RAW_HASH_LINE="<"%HASH_FILE%"
)
set "EXPECTED_HASH="
if defined RAW_HASH_LINE (
  for /f "tokens=1" %%H in ("!RAW_HASH_LINE!") do set "EXPECTED_HASH=%%H"
)
if not defined EXPECTED_HASH set "EXPECTED_HASH=%CORE_SHA256_FALLBACK%"

call :stage 30 "Conferindo a integridade do nucleo"
for /f %%H in ('powershell.exe -NoProfile -Command "$s=[IO.File]::OpenRead('%CORE_FILE%');try{$h=[Security.Cryptography.SHA256]::Create();([BitConverter]::ToString($h.ComputeHash($s))).Replace('-','')}finally{$s.Dispose()}"') do set "DOWNLOADED_SHA256=%%H"
if /I not "%DOWNLOADED_SHA256%"=="%EXPECTED_HASH%" (
  del /q "%CORE_FILE%" >nul 2>&1
  del /q "%HASH_FILE%" >nul 2>&1
  call :action "O arquivo baixado nao passou na verificacao de seguranca." "Nao execute o instalador. Tente novamente mais tarde ou fale com o suporte Minike."
  start "" "%HELP_URL%"
  pause
  exit /b 31
)
if not "%HASH_FILE%"=="%BUNDLED_HASH%" del /q "%HASH_FILE%" >nul 2>&1

call :stage 32 "Baixando dependencias (Ollama / Stable Diffusion / exo)"
if "%BUNDLE_DOWNLOADED%"=="1" (
  powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%BUNDLE_FILE%" -BundlePreset "%BUNDLE_PRESET%" -Mode "%INSTALL_MODE%" -PreinstallAgents "%PREINSTALL_AGENTS%"
  if errorlevel 1 (
    call :action "O instalador do bundle parou com erro." "Siga as mensagens acima. O monstro ainda sera iniciado, mas sem Ollama/SD/exo."
  ) else (
    call :stage 32 "Bundle de dependencias concluido"
  )
) else (
  echo   (bundle nao baixado; seguindo apenas com o monstro)
  echo.
)

REM -- Preset cluster: instala tambem o agente de doacao automatica da rede --
if /I "%BUNDLE_PRESET%"=="cluster" (
  call :stage 33 "Instalando agente de rede automatica (30 min parado = 100%% do PC para a rede)"
  set "MINIKE_LOCAL_DIR=%LOCALAPPDATA%\MINIKE-Local-AI"
  if not exist "!MINIKE_LOCAL_DIR!" mkdir "!MINIKE_LOCAL_DIR!" >nul 2>&1
  set "COMPUTE_AGENT=!MINIKE_LOCAL_DIR!\mike-compute-tray-agent.ps1"
  set "IDLE_FILE=!MINIKE_LOCAL_DIR!\mike-mouse-idle-agent.ps1"
  set "EXO_INSTALLER=%TEMP%\install-mike-exo-cluster.ps1"
  if exist "%BUNDLED_DIR%mike-compute-tray-agent.ps1" copy /Y "%BUNDLED_DIR%mike-compute-tray-agent.ps1" "!COMPUTE_AGENT!" >nul 2>&1
  if exist "%BUNDLED_DIR%mike-mouse-idle-agent.ps1" copy /Y "%BUNDLED_DIR%mike-mouse-idle-agent.ps1" "!IDLE_FILE!" >nul 2>&1
  if exist "%BUNDLED_DIR%install-mike-exo-cluster.ps1" copy /Y "%BUNDLED_DIR%install-mike-exo-cluster.ps1" "%EXO_INSTALLER%" >nul 2>&1
  powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
    "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; if(-not (Test-Path -LiteralPath '!COMPUTE_AGENT!')){try{(New-Object Net.WebClient).DownloadFile('https://minike.com.br/local-ai/mike-compute-tray-agent.ps1','!COMPUTE_AGENT!')}catch{}}; if(-not (Test-Path -LiteralPath '!IDLE_FILE!')){try{(New-Object Net.WebClient).DownloadFile('https://minike.com.br/local-ai/mike-mouse-idle-agent.ps1','!IDLE_FILE!')}catch{}}; if(-not (Test-Path -LiteralPath '%EXO_INSTALLER%')){try{(New-Object Net.WebClient).DownloadFile('https://minike.com.br/local-ai/install-mike-exo-cluster.ps1','%EXO_INSTALLER%')}catch{}}"
  if exist "%EXO_INSTALLER%" (
    powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%EXO_INSTALLER%"
  ) else (
    call :action "Instalador do cluster exo nao baixou." "Sera possivel rodar depois pelo painel local-ai/hub.php."
  )
  if exist "!COMPUTE_AGENT!" (
    powershell.exe -NoProfile -ExecutionPolicy Bypass -File "!COMPUTE_AGENT!" -InstallTask -IdleThresholdMinutes 30 -ActivePercent 50 -IdlePercent 100
    start "" powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "!COMPUTE_AGENT!" -IdleThresholdMinutes 30 -ActivePercent 50 -IdlePercent 100
    call :stage 34 "Agente de rede instalado: ativo usa ate 50%%; parado 30 min libera 100%%."
  ) else if exist "!IDLE_FILE!" (
    powershell.exe -NoProfile -ExecutionPolicy Bypass -File "!IDLE_FILE!" --install-task
    start "" powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "!IDLE_FILE!" -IdleThresholdMinutes 30
    call :stage 34 "Fallback Mouse Idle Agent instalado e agendado para iniciar em todo logon."
  ) else (
    call :action "Agente de rede automatica nao baixou." "Voce podera instalar depois via local-ai/hub.php."
  )
)

call :stage 35 "Iniciando instalacao visivel"
echo   A proxima tela mostra cada etapa, percentual, modelo escolhido e qualquer acao necessaria.
echo.

set "SECONDARY_ARGS=-SecondaryEnginesPreset %SECONDARY_PRESET%"
if "%SKIP_SECONDARY_MODELS%"=="1" set "SECONDARY_ARGS=%SECONDARY_ARGS% -SkipSecondaryModelDownloads"
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%CORE_FILE%" %CORE_ARGS% -InstallMode "%INSTALL_MODE%" %SECONDARY_ARGS%
set "RESULT=%ERRORLEVEL%"

if not "%RESULT%"=="0" (
  color 0C
  call :action "A instalacao parou com o codigo %RESULT%." "Leia a mensagem acima. O log fica em %%LOCALAPPDATA%%\MINIKE-Local-AI\install.log."
  start "" "%HELP_URL%"
  pause
  exit /b %RESULT%
)

color 0A
call :stage 100 "Mike IA Local instalada"
echo.
echo   A interface local foi aberta no modo: %INSTALL_MODE%.
echo   Atalho: Mike IA Local - Minike
echo   Suporte e instalador: %HELP_URL%
echo.

rem -- Reinicio automatico SO se algum instalador precisou ativar memoria virtual --
if exist "%LOCALAPPDATA%\MINIKE-Local-AI\.needs-reboot" (
  del /q "%LOCALAPPDATA%\MINIKE-Local-AI\.needs-reboot" >nul 2>&1
  color 0E
  echo   ============================================================
  echo   Foi preciso ativar a memoria virtual para gerar imagens neste PC.
  echo   O computador vai REINICIAR sozinho em 60 segundos para concluir.
  echo   Salve o que estiver aberto. Depois de reiniciar, a Mike abre pronta.
  echo   ============================================================
  echo.
  shutdown /r /t 60 /c "Mike: reiniciando para ativar a memoria virtual e concluir a instalacao."
  timeout /t 8 /nobreak >nul
  exit /b 0
)
echo   Fechando automaticamente em alguns segundos...
timeout /t 8 /nobreak >nul
exit /b 0

:parse_args
if "%~1"=="" goto :parse_done
if /I "%~1"=="--validate" (
  set "VALIDATE_ONLY=1"
  shift
  goto :parse_args
)
if /I "%~1"=="--mode" (
  set "INSTALL_MODE=%~2"
  shift
  shift
  goto :parse_args
)
if /I "%~1"=="--classic" set "INSTALL_MODE=classic"
if /I "%~1"=="--app" set "INSTALL_MODE=app"
if /I "%~1"=="--pwa" set "INSTALL_MODE=pwa"
if /I "%~1"=="--desktop" set "INSTALL_MODE=desktop"
if /I "%~1"=="--secondary" (
  set "SECONDARY_PRESET=%~2"
  shift
  shift
  goto :parse_args
)
if /I "%~1"=="--no-secondary" set "SECONDARY_PRESET=disabled"
if /I "%~1"=="--editors-secondary" set "SECONDARY_PRESET=editors"
if /I "%~1"=="--creator-secondary" set "SECONDARY_PRESET=creator"
if /I "%~1"=="--full-secondary" set "SECONDARY_PRESET=full"
if /I "%~1"=="--skip-secondary-models" set "SKIP_SECONDARY_MODELS=1"
if /I "%~1"=="--bundle" (
  set "BUNDLE_PRESET=%~2"
  shift
  shift
  goto :parse_args
)
if /I "%~1"=="--bundle-lite" set "BUNDLE_PRESET=lite"
if /I "%~1"=="--bundle-standard" set "BUNDLE_PRESET=standard"
if /I "%~1"=="--bundle-full" set "BUNDLE_PRESET=full"
if /I "%~1"=="--bundle-cluster" set "BUNDLE_PRESET=cluster"
if /I "%~1"=="--no-bundle" set "BUNDLE_PRESET=none"
if /I "%~1"=="--agents" (
  set "PREINSTALL_AGENTS=%~2"
  shift
  shift
  goto :parse_args
)
if /I "%~1"=="--preinstall-agents" (
  set "PREINSTALL_AGENTS=%~2"
  shift
  shift
  goto :parse_args
)
if /I "%~1"=="--no-agents" set "PREINSTALL_AGENTS=none"
if /I "%~1"=="--agents-ready" set "PREINSTALL_AGENTS=ready"
if /I "%~1"=="--agents-all" set "PREINSTALL_AGENTS=all"
shift
goto :parse_args
:parse_done
if /I "%INSTALL_MODE%"=="browser" set "INSTALL_MODE=classic"
if /I not "%INSTALL_MODE%"=="classic" if /I not "%INSTALL_MODE%"=="app" if /I not "%INSTALL_MODE%"=="pwa" if /I not "%INSTALL_MODE%"=="desktop" set "INSTALL_MODE=app"
if /I not "%SECONDARY_PRESET%"=="disabled" if /I not "%SECONDARY_PRESET%"=="editors" if /I not "%SECONDARY_PRESET%"=="creator" if /I not "%SECONDARY_PRESET%"=="full" set "SECONDARY_PRESET=editors"
if /I "%BUNDLE_PRESET%"=="none" goto :parse_skip_bundle
if /I not "%BUNDLE_PRESET%"=="lite" if /I not "%BUNDLE_PRESET%"=="standard" if /I not "%BUNDLE_PRESET%"=="full" if /I not "%BUNDLE_PRESET%"=="cluster" set "BUNDLE_PRESET=standard"
:parse_skip_bundle
if /I not "%PREINSTALL_AGENTS%"=="none" if /I not "%PREINSTALL_AGENTS%"=="ready" if /I not "%PREINSTALL_AGENTS%"=="all" set "PREINSTALL_AGENTS=ready"
exit /b 0

:banner
cls
echo ================================================================
echo                    MIKE IA LOCAL - MINIKE
echo ================================================================
echo   Verificador e instalador para Windows 7, 8, 10 e 11
echo   O sistema detecta compatibilidade antes de alterar o computador.
echo ================================================================
echo.
exit /b 0
:stage
echo [%~1%%] %~2
exit /b 0

:action
color 0E
echo.
echo ================================================================
echo   ACAO NECESSARIA
echo ================================================================
echo   %~1
echo   %~2
echo ================================================================
echo.
exit /b 0
