@echo off
setlocal
rem Opens the browser's installation screen. Installation requires user approval.
rem Does not create fake app shortcuts, install software, or change security settings.
set "ROKACH_CHECK="
if /I "%~1"=="--check-chrome" set "ROKACH_CHECK=1"
if /I "%~1"=="--check-chrome" goto chrome
if /I "%~1"=="--check-edge" set "ROKACH_CHECK=1"
if /I "%~1"=="--check-edge" goto edge
echo AR - Rokach by orAIta - DEV pilot installation
echo.
echo Choose your browser. It will ask you to confirm the app installation.
choice /C CE /N /M "[C] Google Chrome   [E] Microsoft Edge: "
if errorlevel 255 goto cancelled
if errorlevel 2 goto edge
if errorlevel 1 goto chrome
goto cancelled
:chrome
set "ROKACH_BROWSER=chrome"
set "ROKACH_EXE=%ProgramFiles%\Google\Chrome\Application\chrome.exe"
if exist "%ROKACH_EXE%" goto ready
set "ROKACH_EXE=%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe"
if exist "%ROKACH_EXE%" goto ready
set "ROKACH_EXE=%LocalAppData%\Google\Chrome\Application\chrome.exe"
if exist "%ROKACH_EXE%" goto ready
goto missing
:edge
set "ROKACH_BROWSER=edge"
set "ROKACH_EXE=%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe"
if exist "%ROKACH_EXE%" goto ready
set "ROKACH_EXE=%ProgramFiles%\Microsoft\Edge\Application\msedge.exe"
if exist "%ROKACH_EXE%" goto ready
set "ROKACH_EXE=%LocalAppData%\Microsoft\Edge\Application\msedge.exe"
if exist "%ROKACH_EXE%" goto ready
goto missing
:ready
set "ROKACH_URL=https://erp-dev.oraita.ai/pilot/install.html?setup=windows&browser=%ROKACH_BROWSER%&v=3"
if defined ROKACH_CHECK goto checked
start "" "%ROKACH_EXE%" --new-window "%ROKACH_URL%"
if errorlevel 1 goto failed
exit /b 0
:checked
echo Browser: %ROKACH_BROWSER%
echo Executable: %ROKACH_EXE%
echo URL: "%ROKACH_URL%"
exit /b 0
:missing
echo The selected browser was not found. No application was installed.
echo Install Chrome from google.com/chrome or Edge from microsoft.com/edge.
echo Then run this file again.
if not defined ROKACH_CHECK pause
exit /b 1
:failed
echo Unable to open the browser. No application was installed.
pause
exit /b 1
:cancelled
exit /b 1
