diff --git a/files/experimental/software-management-tool.bat b/files/experimental/software-management-tool.bat index ac153f8..7033506 100644 --- a/files/experimental/software-management-tool.bat +++ b/files/experimental/software-management-tool.bat @@ -14,7 +14,7 @@ echo. echo ======================================== echo. echo [1] Scan installed software -echo [2] Check and install updates +echo [2] Check for updates echo [3] Uninstall software echo [4] Full system report echo [0] Exit @@ -23,7 +23,7 @@ echo ======================================== set /p CHOICE="Select option: " if "%CHOICE%"=="1" goto SCAN_SOFTWARE -if "%CHOICE%"=="2" goto CHECK_AND_UPDATE +if "%CHOICE%"=="2" goto CHECK_UPDATES if "%CHOICE%"=="3" goto UNINSTALL_SOFTWARE if "%CHOICE%"=="4" goto FULL_REPORT if "%CHOICE%"=="0" goto EXIT @@ -153,14 +153,15 @@ del "%tempfile%" >nul 2>&1 pause goto MENU -:CHECK_AND_UPDATE +:CHECK_UPDATES cls echo ======================================== -echo Check and Install Updates +echo Check for Updates echo ======================================== echo. set "tempfile=%TEMP%\update_check_%RANDOM%.tmp" +set "updatelist=%TEMP%\update_programs_%RANDOM%.tmp" ( echo ======================================== @@ -182,7 +183,9 @@ if %errorlevel%==0 ( echo [AVAILABLE UPDATES] >> "%tempfile%" echo ---------------------------------------- >> "%tempfile%" - winget upgrade >> "%tempfile%" 2>&1 + REM Get list of upgradeable packages + winget upgrade > "%updatelist%" 2>&1 + type "%updatelist%" >> "%tempfile%" echo. >> "%tempfile%" echo ======================================== >> "%tempfile%" @@ -191,44 +194,178 @@ if %errorlevel%==0 ( echo Cannot check for updates automatically. >> "%tempfile%" echo. >> "%tempfile%" echo Please install Windows Package Manager or check manually. >> "%tempfile%" + echo ======================================== >> "%tempfile%" + + cls + type "%tempfile%" + echo. + + if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%tempfile%" "Update_Check" + + del "%tempfile%" >nul 2>&1 + del "%updatelist%" >nul 2>&1 + pause + goto MENU ) -echo ======================================== >> "%tempfile%" - cls type "%tempfile%" echo. -set "INSTALL_CHOICE=" -set /p INSTALL_CHOICE="Install available updates? (Y/N): " - -if /i "%INSTALL_CHOICE%"=="Y" ( - cls - echo ======================================== - echo Installing Updates - echo ======================================== - echo. - echo Choose update method: - echo [1] Update all programs - echo [2] Update specific programs - echo [0] Cancel - echo. - set /p UPDATE_METHOD="Select option: " - - if "!UPDATE_METHOD!"=="1" goto UPDATE_ALL_PROGRAMS - if "!UPDATE_METHOD!"=="2" goto UPDATE_SPECIFIC_PROGRAMS - if "!UPDATE_METHOD!"=="0" ( - if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%tempfile%" "Update_Check" - del "%tempfile%" >nul 2>&1 - pause - goto MENU - ) - goto CHECK_AND_UPDATE +REM Check if updates are available +findstr /C:"upgrades available" "%updatelist%" >nul 2>&1 +if %errorlevel%==0 ( + echo No updates available. + if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%tempfile%" "Update_Check" + del "%tempfile%" >nul 2>&1 + del "%updatelist%" >nul 2>&1 + pause + goto MENU ) -if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%tempfile%" "Update_Check" +echo ======================================== +set /p INSTALL_CHOICE="Install updates? (Y/N): " + +if /i not "%INSTALL_CHOICE%"=="Y" ( + if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%tempfile%" "Update_Check" + del "%tempfile%" >nul 2>&1 + del "%updatelist%" >nul 2>&1 + pause + goto MENU +) + +cls +echo ======================================== +echo Install Updates +echo ======================================== +echo. +echo [1] Update all programs +echo [2] Select specific programs +echo [0] Cancel +echo. +set /p UPDATE_METHOD="Select option: " + +if "%UPDATE_METHOD%"=="1" ( + del "%tempfile%" >nul 2>&1 + del "%updatelist%" >nul 2>&1 + goto UPDATE_ALL_PROGRAMS +) +if "%UPDATE_METHOD%"=="2" ( + goto SELECT_UPDATES +) +if "%UPDATE_METHOD%"=="0" ( + if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%tempfile%" "Update_Check" + del "%tempfile%" >nul 2>&1 + del "%updatelist%" >nul 2>&1 + pause + goto MENU +) del "%tempfile%" >nul 2>&1 +del "%updatelist%" >nul 2>&1 +goto CHECK_UPDATES + +:SELECT_UPDATES +cls +echo ======================================== +echo Select Programs to Update +echo ======================================== +echo. +echo Extracting available updates... +echo. + +set "pkglist=%TEMP%\packages_%RANDOM%.tmp" + +REM Extract package IDs from winget output +winget upgrade | findstr /V /C:"Name" /C:"---" /C:"upgrades available" | findstr /V "^$" > "%pkglist%" 2>nul + +REM Count available packages +set PKG_COUNT=0 +for /f "tokens=*" %%a in ('type "%pkglist%"') do set /a PKG_COUNT+=1 + +if %PKG_COUNT%==0 ( + echo No updatable packages found. + del "%pkglist%" >nul 2>&1 + del "%tempfile%" >nul 2>&1 + del "%updatelist%" >nul 2>&1 + pause + goto MENU +) + +REM Display packages with numbers +cls +echo ======================================== +echo Available Updates +echo ======================================== +echo. +echo Enter the numbers of programs to update (separated by spaces) +echo Example: 1 3 5 7 +echo. +echo ---------------------------------------- + +set INDEX=0 +for /f "tokens=1* delims= " %%a in ('type "%pkglist%"') do ( + set /a INDEX+=1 + set "PKG_!INDEX!=%%a" + echo [!INDEX!] %%a +) + +echo ---------------------------------------- +echo. +set /p SELECTIONS="Enter numbers (space-separated): " + +if "%SELECTIONS%"=="" ( + echo [ERROR] No selection made! + del "%pkglist%" >nul 2>&1 + del "%tempfile%" >nul 2>&1 + del "%updatelist%" >nul 2>&1 + pause + goto MENU +) + +cls +echo ======================================== +echo Installing Selected Updates +echo ======================================== +echo. + +set "logfile=%TEMP%\update_selected_%RANDOM%.log" + +( +echo ======================================== +echo SELECTED UPDATES INSTALLATION LOG +echo Date: %date% %time% +echo ======================================== +echo. +) > "%logfile%" + +REM Process selections +for %%S in (%SELECTIONS%) do ( + if defined PKG_%%S ( + echo ---------------------------------------- >> "%logfile%" + echo Updating: !PKG_%%S! >> "%logfile%" + echo ---------------------------------------- >> "%logfile%" + echo Updating: !PKG_%%S! + + winget upgrade --id "!PKG_%%S!" --accept-source-agreements --accept-package-agreements >> "%logfile%" 2>&1 + + echo. >> "%logfile%" + ) +) + +echo ======================================== >> "%logfile%" +echo Update process completed. >> "%logfile%" + +cls +type "%logfile%" +echo. + +if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%logfile%" "Update_Selected" + +del "%logfile%" >nul 2>&1 +del "%pkglist%" >nul 2>&1 +del "%tempfile%" >nul 2>&1 +del "%updatelist%" >nul 2>&1 pause goto MENU @@ -277,70 +414,6 @@ del "%logfile%" >nul 2>&1 pause goto MENU -:UPDATE_SPECIFIC_PROGRAMS -cls -echo ======================================== -echo Update Specific Programs -echo ======================================== -echo. -echo Enter program IDs or names separated by commas. -echo Example: Firefox, Chrome, VSCode -echo. -set /p PROGRAMS="Programs (comma-separated): " - -if "%PROGRAMS%"=="" ( - echo [ERROR] No programs specified! - pause - goto CHECK_AND_UPDATE -) - -echo. -echo Updating selected programs... -echo. - -set "logfile=%TEMP%\update_specific_%RANDOM%.log" - -( -echo ======================================== -echo SPECIFIC PROGRAM UPDATE LOG -echo Date: %date% %time% -echo ======================================== -echo. -echo Programs to update: %PROGRAMS% -echo. -) > "%logfile%" - -REM Process comma-separated list -set "PROGRAMS=%PROGRAMS:, =,%" -set "PROGRAMS=%PROGRAMS: ,=,%" - -for %%P in (%PROGRAMS%) do ( - echo ---------------------------------------- >> "%logfile%" - echo Updating: %%P >> "%logfile%" - echo ---------------------------------------- >> "%logfile%" - - where winget >nul 2>&1 - if !errorlevel!==0 ( - winget upgrade "%%P" --accept-source-agreements --accept-package-agreements >> "%logfile%" 2>&1 - ) else ( - echo [ERROR] Winget not available >> "%logfile%" - ) - echo. >> "%logfile%" -) - -echo ======================================== >> "%logfile%" -echo Update process completed. >> "%logfile%" - -cls -type "%logfile%" -echo. - -if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%logfile%" "Update_Specific" - -del "%logfile%" >nul 2>&1 -pause -goto MENU - :UNINSTALL_SOFTWARE cls echo ======================================== @@ -540,4 +613,4 @@ echo Thank you for using Software Management Tool echo ======================================== echo. timeout /t 2 >nul -exit +exit \ No newline at end of file