@echo off
setlocal
chcp 65001 >nul

set "INSTALL_DIR=%LOCALAPPDATA%\Tugsscript"
set "BIN_DIR=%USERPROFILE%\.local\bin"

if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%"
if not exist "%INSTALL_DIR%\examples" mkdir "%INSTALL_DIR%\examples"
if not exist "%BIN_DIR%" mkdir "%BIN_DIR%"

xcopy /E /I /Y "%~dp0runtime\python" "%INSTALL_DIR%\python" >nul
copy /Y "%~dp0runtime\codely.py" "%INSTALL_DIR%\codely.py" >nul
copy /Y "%~dp0runtime\shell.py" "%INSTALL_DIR%\shell.py" >nul
copy /Y "%~dp0runtime\examples\demo.tugs" "%INSTALL_DIR%\examples\demo.tugs" >nul
copy /Y "%~dp0runtime\examples\code1.tugs" "%INSTALL_DIR%\examples\code1.tugs" >nul
copy /Y "%~dp0tugs.cmd" "%BIN_DIR%\tugs.cmd" >nul

powershell -NoProfile -ExecutionPolicy Bypass -Command "$bin = '%BIN_DIR%'; $path = [Environment]::GetEnvironmentVariable('Path', 'User'); if (($path -split ';') -notcontains $bin) { $newPath = (($path + ';' + $bin).Trim(';')); [Environment]::SetEnvironmentVariable('Path', $newPath, 'User') }"

echo Tugsscript суулгалаа: %INSTALL_DIR%
echo Command launcher: %BIN_DIR%\tugs.cmd
echo.
echo PATH шинэчлэгдлээ. Шинэ terminal нээгээд:
echo   tugs "%INSTALL_DIR%\examples\demo.tugs"
