[WINLOGON] Fix shutdown timeout format string for long timeout
authorEric Kohl <eric.kohl@reactos.org>
Mon, 2 Apr 2018 16:52:47 +0000 (18:52 +0200)
committerEric Kohl <eric.kohl@reactos.org>
Mon, 2 Apr 2018 17:09:13 +0000 (19:09 +0200)
- Use the "%d days" format for timeouts longer than a day.
- Fail if timeout is 10 years or longer.
- TODO: Replace format strings by resources. German WinXP uses "%d days" instead of "%d Tage". We can do better! ;-)

base/system/winlogon/shutdown.c

index d093686..42452ca 100644 (file)
@@ -16,6 +16,8 @@
 /* DEFINES *******************************************************************/
 
 #define SHUTDOWN_TIMER_ID 2000
+#define SECONDS_PER_DAY 86400
+#define SECONDS_PER_DECADE 315360000
 
 
 /* STRUCTS *******************************************************************/
@@ -46,16 +48,25 @@ OnTimer(
     HWND hwndDlg,
     PSYS_SHUTDOWN_PARAMS pShutdownParams)
 {
-    WCHAR szBuffer[10];
-    INT iSeconds, iMinutes, iHours;
+    WCHAR szBuffer[12];
+    INT iSeconds, iMinutes, iHours, iDays;
 
-    iSeconds = (INT)pShutdownParams->dwTimeout;
-    iHours = iSeconds / 3600;
-    iSeconds -= iHours * 3600;
-    iMinutes = iSeconds / 60;
-    iSeconds -= iMinutes * 60;
+    if (pShutdownParams->dwTimeout < SECONDS_PER_DAY)
+    {
+        iSeconds = (INT)pShutdownParams->dwTimeout;
+        iHours = iSeconds / 3600;
+        iSeconds -= iHours * 3600;
+        iMinutes = iSeconds / 60;
+        iSeconds -= iMinutes * 60;
+
+        swprintf(szBuffer, L"%02d:%02d:%02d", iHours, iMinutes, iSeconds);
+    }
+    else
+    {
+        iDays = (INT)(pShutdownParams->dwTimeout / SECONDS_PER_DAY);
+        swprintf(szBuffer, L"%d days", iDays);
+    }
 
-    swprintf(szBuffer, L"%02d:%02d:%02d", iHours, iMinutes, iSeconds);
     SetDlgItemTextW(hwndDlg, IDC_SYSSHUTDOWNTIMELEFT, szBuffer);
 
     if (pShutdownParams->dwTimeout == 0)
@@ -185,6 +196,10 @@ StartSystemShutdown(
 {
     HANDLE hThread;
 
+    /* Fail if the timeout is 10 years or more */
+    if (dwTimeout >= SECONDS_PER_DECADE)
+        return ERROR_INVALID_PARAMETER;
+
     if (_InterlockedCompareExchange8((volatile char*)&g_ShutdownParams.bShuttingDown, TRUE, FALSE) == TRUE)
         return ERROR_SHUTDOWN_IN_PROGRESS;