@ECHO OFF
REM CHECKUPD.BAT - Check for available updates without applying them
REM Version: 1.4 - DOS 6.22 compatible (removed CALL :label subroutines)
REM Last modified: 2026-01-21

IF "%MACHINE%"=="" GOTO NO_MACHINE

REM Verify T: drive
IF NOT EXIST T:\*.* GOTO NO_T_DRIVE

ECHO.
ECHO ==============================================================
ECHO Update Check: %MACHINE%
ECHO ==============================================================
ECHO.

REM Initialize flags
SET COMMON=
SET MACHINEFILES=
SET SYSFILE=

REM Check COMMON batch files
ECHO (1/3) Checking T:\COMMON\ProdSW for batch file updates...

IF NOT EXIST T:\COMMON\ProdSW\*.* GOTO NO_COMMON

IF EXIST T:\COMMON\ProdSW\*.BAT SET COMMON=FOUND
IF "%COMMON%"=="" ECHO       No updates in COMMON
IF NOT "%COMMON%"=="" ECHO       Updates available in COMMON

ECHO.
GOTO CHECK_MACHINE

:NO_COMMON
ECHO       T:\COMMON\ProdSW not found
ECHO.

:CHECK_MACHINE
ECHO (2/3) Checking T:\%MACHINE%\ProdSW for machine-specific updates...

IF NOT EXIST T:\%MACHINE%\ProdSW\*.* GOTO NO_MACHINE_DIR

IF EXIST T:\%MACHINE%\ProdSW\*.* SET MACHINEFILES=FOUND
IF "%MACHINEFILES%"=="" ECHO       No updates for %MACHINE%
IF NOT "%MACHINEFILES%"=="" ECHO       Updates available for %MACHINE%

ECHO.
GOTO CHECK_SYSTEM

:NO_MACHINE_DIR
ECHO       T:\%MACHINE%\ProdSW not found
ECHO.

:CHECK_SYSTEM
ECHO (3/3) Checking T:\COMMON\DOS for system file updates...

IF NOT EXIST T:\COMMON\DOS\*.* GOTO NO_DOS_DIR

IF EXIST T:\COMMON\DOS\AUTOEXEC.NEW SET SYSFILE=FOUND
IF EXIST T:\COMMON\DOS\AUTOEXEC.NEW ECHO       AUTOEXEC.NEW found (reboot required)

IF EXIST T:\COMMON\DOS\CONFIG.NEW SET SYSFILE=FOUND
IF EXIST T:\COMMON\DOS\CONFIG.NEW ECHO       CONFIG.NEW found (reboot required)

IF "%SYSFILE%"=="" ECHO       No system file updates

ECHO.
GOTO SHOW_SUMMARY

:NO_DOS_DIR
ECHO       T:\COMMON\DOS not found
ECHO.

:SHOW_SUMMARY
SET HASUPDATES=
IF NOT "%COMMON%"=="" SET HASUPDATES=YES
IF NOT "%MACHINEFILES%"=="" SET HASUPDATES=YES
IF NOT "%SYSFILE%"=="" SET HASUPDATES=YES

ECHO ==============================================================
ECHO Update Summary
ECHO ==============================================================
ECHO.
IF NOT "%COMMON%"=="" ECHO   FOUND: Common batch files
IF "%COMMON%"=="" ECHO   OK: Common batch files
IF NOT "%MACHINEFILES%"=="" ECHO   FOUND: Machine-specific files
IF "%MACHINEFILES%"=="" ECHO   OK: Machine-specific files
IF NOT "%SYSFILE%"=="" ECHO   FOUND: System files
IF "%SYSFILE%"=="" ECHO   OK: System files
ECHO.

IF "%HASUPDATES%"=="" GOTO NO_UPDATES_AVAILABLE

ECHO Recommendation: Run NWTOC to install updates
ECHO.
IF NOT "%SYSFILE%"=="" ECHO WARNING: System file updates require reboot
IF NOT "%SYSFILE%"=="" ECHO.

GOTO CLEANUP

:NO_UPDATES_AVAILABLE
ECHO Status: All files are up to date
ECHO.
GOTO CLEANUP

:NO_MACHINE
ECHO.
ECHO ERROR: MACHINE variable not set
ECHO Set MACHINE in AUTOEXEC.BAT: SET MACHINE=TS-4R
ECHO.
PAUSE
GOTO CLEANUP

:NO_T_DRIVE
ECHO.
ECHO ERROR: T: drive not available
ECHO Run: C:\STARTNET.BAT
ECHO.
PAUSE
GOTO CLEANUP

:CLEANUP
SET COMMON=
SET MACHINEFILES=
SET SYSFILE=
SET HASUPDATES=
