Sync with trunk r63502.
[reactos.git] / base / system / userinit / userinit.c
index 81027d4..717b818 100644 (file)
  * PROGRAMMERS: Thomas Weidenmueller (w3seek@users.sourceforge.net)
  *              HervĂ© Poussineau (hpoussin@reactos.org)
  */
-#include <windows.h>
-#include <cfgmgr32.h>
+
+#define WIN32_NO_STATUS
+#define _INC_WINDOWS
+#define COM_NO_WINDOWS_H
+#include <stdarg.h>
+#include <windef.h>
+#include <winbase.h>
+#include <winreg.h>
+#include <wingdi.h>
+#include <wincon.h>
+#include <shellapi.h>
 #include <regstr.h>
 #include <shlobj.h>
 #include <shlwapi.h>
-#include "resource.h"
+#include <undocuser.h>
 #include <wine/debug.h>
-#include <win32k/ntusrtyp.h>
+
+#include "resource.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(userinit);
 
@@ -114,7 +124,7 @@ BOOL IsConsoleShell(VOID)
         goto cleanup;
     }
 
-    /* Check for CONSOLE in SystemStartOptions */
+    /* Check for CONSOLE switch in SystemStartOptions */
     CurrentOption = SystemStartOptions;
     while (CurrentOption)
     {
@@ -217,7 +227,7 @@ StartAutoApplications(
     {
         if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (findData.nFileSizeHigh || findData.nFileSizeLow))
         {
-            memset(&ExecInfo, 0x0, sizeof(SHELLEXECUTEINFOW));
+            ZeroMemory(&ExecInfo, sizeof(SHELLEXECUTEINFOW));
             ExecInfo.cbSize = sizeof(ExecInfo);
             wcscpy(&szPath[len+1], findData.cFileName);
             ExecInfo.lpVerb = L"open";
@@ -241,9 +251,11 @@ TryToStartShell(
 
     TRACE("(%s)\n", debugstr_w(Shell));
 
-    ZeroMemory(&si, sizeof(STARTUPINFO));
-    si.cb = sizeof(STARTUPINFO);
-    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
+    ZeroMemory(&si, sizeof(si));
+    si.cb = sizeof(si);
+    si.dwFlags = STARTF_USESHOWWINDOW;
+    si.wShowWindow = SW_SHOWNORMAL;
+    ZeroMemory(&pi, sizeof(pi));
 
     ExpandEnvironmentStrings(Shell, ExpandedShell, MAX_PATH);
 
@@ -274,9 +286,70 @@ VOID StartShell(VOID)
 {
     WCHAR Shell[MAX_PATH];
     TCHAR szMsg[RC_STRING_MAX_SIZE];
+    DWORD Type, Size;
+    DWORD Value = 0;
+    LONG rc;
+    HKEY hKey;
 
     TRACE("()\n");
 
+    /* Safe Mode shell run */
+    rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+                       L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Option",
+                       0, KEY_QUERY_VALUE, &hKey);
+    if(rc == ERROR_SUCCESS)
+    {
+        Size = sizeof(Value);
+        rc = RegQueryValueExW(hKey, L"UseAlternateShell", NULL,
+                              &Type, (LPBYTE)&Value, &Size);
+        if(rc == ERROR_SUCCESS)
+        {
+            RegCloseKey(hKey);
+            if(Type == REG_DWORD)
+            {
+                if(Value)
+                {
+                    /* Safe Mode Alternate Shell required */
+                    rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+                                       L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot",
+                                       0, KEY_READ, &hKey);
+                    if(rc == ERROR_SUCCESS)
+                    {
+                        Size = MAX_PATH * sizeof(WCHAR);
+                        rc = RegQueryValueExW(hKey, L"AlternateShell", NULL,
+                                              &Type, (LPBYTE)Shell, &Size);
+                        if(rc == ERROR_SUCCESS)
+                        {
+                            RegCloseKey(hKey);
+                            if ((Type == REG_SZ) || (Type == REG_EXPAND_SZ))
+                            {
+                                TRACE("Key located - %s\n", debugstr_w(Shell));
+                                /* Try to run alternate shell */
+                                if (TryToStartShell(Shell))
+                                {
+                                    TRACE("Alternate shell started (Safe Mode)\n");
+                                    return;
+                                }
+                            }
+                            else
+                            {
+                                WARN("Wrong type %lu (expected %u or %u)\n",
+                                     Type, REG_SZ, REG_EXPAND_SZ);
+                            }
+                        }
+                        else
+                        {
+                            WARN("Alternate shell in Safe Mode required but not specified.");
+                        }
+                    }
+                }
+            }
+            else
+            {
+                WARN("Wrong type %lu (expected %u)\n", Type, REG_DWORD);
+            }
+        }
+    }
     /* Try to run shell in user key */
     if (GetShell(Shell, HKEY_CURRENT_USER) && TryToStartShell(Shell))
     {
@@ -357,11 +430,9 @@ COLORREF StrToColorref(
 
     TRACE("(%s)\n", debugstr_w(lpszCol));
 
-    rgb[0] = StrToIntW(lpszCol);
-    lpszCol = StrChrW(lpszCol, L' ') + 1;
-    rgb[1] = StrToIntW(lpszCol);
-    lpszCol = StrChrW(lpszCol, L' ') + 1;
-    rgb[2] = StrToIntW(lpszCol);
+    rgb[0] = (BYTE)wcstoul(lpszCol, &lpszCol, 10);
+    rgb[1] = (BYTE)wcstoul(lpszCol, &lpszCol, 10);
+    rgb[2] = (BYTE)wcstoul(lpszCol, &lpszCol, 10);
     return RGB(rgb[0], rgb[1], rgb[2]);
 }
 
@@ -370,7 +441,7 @@ VOID SetUserSysColors(VOID)
 {
     HKEY hKey;
     INT i;
-    WCHAR szColor[20];
+    WCHAR szColor[25];
     DWORD Type, Size;
     COLORREF crColor;
     LONG rc;
@@ -401,11 +472,6 @@ VOID SetUserSysColors(VOID)
     RegCloseKey(hKey);
 }
 
-DWORD
-WINAPI
-UpdatePerUserSystemParameters(DWORD dw1, BOOL bEnable);
-
-
 static
 VOID SetUserWallpaper(VOID)
 {