@echo off
title PrintBilling Terminal Update
setlocal
set "ZIP_URL=https://nevcdn.com/tools/quanlytiemin/PrintBilling_Update_1.0.19.zip"
set "ZIP_FILE=%TEMP%\PrintBilling_update.zip"
set "EXTRACT_DIR=%TEMP%\PrintBilling_update_files"
set "INSTALL_DIR=C:\Users\Public\PrintBilling"
set "OLD_DIR=%USERPROFILE%\PrintBilling"
color 0B
echo ============================================================
echo  PRINTBILLING TERMINAL UPDATE
echo  Website: https://nevcdn.com/
echo  Zalo ho tro: 0355557778
echo ============================================================
echo.
echo Default install folder: %INSTALL_DIR%
set /p CUSTOM_DIR=Install folder, Enter to use default: 
if not "%CUSTOM_DIR%"=="" set "INSTALL_DIR=%CUSTOM_DIR%"
echo Using install folder: %INSTALL_DIR%
echo.
echo Closing PrintBilling if running...
taskkill /IM PrintBilling.exe /F >nul 2>nul
if exist "%EXTRACT_DIR%" rmdir /s /q "%EXTRACT_DIR%"
mkdir "%EXTRACT_DIR%" >nul 2>nul
mkdir "%INSTALL_DIR%" >nul 2>nul
echo [25%%] Downloading update zip...
powershell -NoProfile -ExecutionPolicy Bypass -Command "Invoke-WebRequest -Uri %ZIP_URL% -OutFile %ZIP_FILE%"
if errorlevel 1 goto failed
echo [50%%] Extracting update...
powershell -NoProfile -ExecutionPolicy Bypass -Command "Expand-Archive -LiteralPath %ZIP_FILE% -DestinationPath %EXTRACT_DIR% -Force"
if errorlevel 1 goto failed
if not exist "%INSTALL_DIR%\print_billing.db" if exist "%OLD_DIR%\print_billing.db" copy /Y "%OLD_DIR%\print_billing.db" "%INSTALL_DIR%\print_billing.db" >nul
if not exist "%INSTALL_DIR%\.pbc" if exist "%OLD_DIR%\.pbc" copy /Y "%OLD_DIR%\.pbc" "%INSTALL_DIR%\.pbc" >nul
if not exist "%INSTALL_DIR%\.trial" if exist "%OLD_DIR%\.trial" copy /Y "%OLD_DIR%\.trial" "%INSTALL_DIR%\.trial" >nul
echo [75%%] Copying files...
xcopy /Y /E /I "%EXTRACT_DIR%\*" "%INSTALL_DIR%\" >nul
if errorlevel 1 goto failed
echo [100%%] Update completed.
echo Starting PrintBilling...
start "" "%INSTALL_DIR%\PrintBilling.exe"
timeout /t 2 /nobreak >nul
exit /b 0
:failed
echo.
echo Update failed. Please send this screen to support.
pause
