From 5b8f4c7c4081e41e2d96fd315dd94d6b20514c40 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Mon, 29 Feb 2016 17:23:16 +0100 Subject: [PATCH] Store epoch in ChangesAvailableSince To compute a correct date if updates are available less than 7 days before the end of the month --- softwares/FWSUpdates/bin/chkupd.bat | 6 ++++-- softwares/FWSUpdates/bin/now.vbs | 1 + softwares/FWSUpdates/bin/sync.bat | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 softwares/FWSUpdates/bin/now.vbs diff --git a/softwares/FWSUpdates/bin/chkupd.bat b/softwares/FWSUpdates/bin/chkupd.bat index bd66e79..50b4da3 100644 --- a/softwares/FWSUpdates/bin/chkupd.bat +++ b/softwares/FWSUpdates/bin/chkupd.bat @@ -68,7 +68,7 @@ IF %CHANGES% LSS 1 IF %ADMIN% NEQ 1 ( goto :EOF ) -SET /A NOW=%DATE:~-4%%DATE:~3,2%%DATE:~0,2% +FOR /F "delims=" %%A in ('cscript /nologo %~dp0\now.vbs') DO SET /A NOW=%%A SET /A SINCE=%NOW% reg query "HKLM\Software\FWS\Updates" /v ChangesAvailableSince 1>NUL 2>NUL IF %ERRORLEVEL% EQU 0 FOR /F "tokens=3 delims= " %%A IN ('reg query "HKLM\Software\FWS\Updates" /v ChangesAvailableSince') DO SET /A SINCE=%%A @@ -83,9 +83,11 @@ IF %CHANGES% EQU 1 ( ) REM Compute how many days left we can delay updates -SET /A MAX=%SINCE%+%MAX_REPORT% +SET /A MAX=%SINCE%+%MAX_REPORT%*86400 SET /A AGE=%NOW%-%SINCE% +SET /A AGE=%AGE%/86400 SET /A REMAINING=%MAX%-%NOW% +SET /A REMAINING=%REMAINING%/86400 REM Non admin on RDP shouldn't see updates notif IF %ADMIN% NEQ 1 IF NOT "%SESSIONNAME%" == "Console" goto :EOF diff --git a/softwares/FWSUpdates/bin/now.vbs b/softwares/FWSUpdates/bin/now.vbs new file mode 100644 index 0000000..f5e1ae7 --- /dev/null +++ b/softwares/FWSUpdates/bin/now.vbs @@ -0,0 +1 @@ +WScript.Echo DateDiff("s", "01/01/1970 00:00:00", Now()) \ No newline at end of file diff --git a/softwares/FWSUpdates/bin/sync.bat b/softwares/FWSUpdates/bin/sync.bat index b3516f9..5633555 100644 --- a/softwares/FWSUpdates/bin/sync.bat +++ b/softwares/FWSUpdates/bin/sync.bat @@ -151,7 +151,7 @@ FOR /F "tokens=2 delims= " %%A IN ('cscript %SystemDrive%\FWSUpdates\repository\ SET /A CHANGES=!CHANGES!+1 ) echo %DATE% %TIME% - Found %CHANGES% changes >> %SystemDrive%\FWSUpdates\status\sync_log.txt -SET NOW=%DATE:~-4%%DATE:~3,2%%DATE:~0,2% +FOR /F "delims=" %%A in ('cscript /nologo %~dp0\now.vbs') DO SET /A NOW=%%A reg add "HKLM\Software\FWS\Updates" /v PendingChanges /t REG_DWORD /d %CHANGES% /f reg add "HKLM\Software\FWS\Updates" /v PendingChangesList /t REG_SZ /d "%LIST%" /f @@ -161,7 +161,7 @@ IF %CHANGES% GTR 0 ( IF ERRORLEVEL 1 ( reg add "HKLM\Software\FWS\Updates" /v ChangesAvailableSince /t REG_DWORD /d %NOW% /f SET /A SINCE=%NOW% - SET /A MAX=%SINCE%+%MAX_REPORT% + SET /A MAX=%SINCE%+%MAX_REPORT%*86400 ) ELSE ( FOR /F %%A IN ('reg query "HKLM\Software\FWS\Updates" /v ChangesAvailableSince') DO SET /A SINCE=%%A SET /A MAX=%SINCE%+%MAX_REPORT%