Add traces

svn path=/trunk/; revision=31656
This commit is contained in:
Hervé Poussineau 2008-01-07 21:42:59 +00:00
parent 6345038990
commit aa482ff783
2 changed files with 124 additions and 37 deletions

View file

@ -29,6 +29,9 @@
#include <shlobj.h> #include <shlobj.h>
#include <shlwapi.h> #include <shlwapi.h>
#include "resource.h" #include "resource.h"
#include <wine/debug.h>
WINE_DEFAULT_DEBUG_CHANNEL(userinit);
#define CMP_MAGIC 0x01234567 #define CMP_MAGIC 0x01234567
@ -47,17 +50,29 @@ ReadRegSzKey(
DWORD cbData = 0; DWORD cbData = 0;
LPWSTR Value; LPWSTR Value;
TRACE("(%p, %s, %p)\n", hKey, debugstr_w(pszKey), pValue);
rc = RegQueryValueExW(hKey, pszKey, NULL, &dwType, NULL, &cbData); rc = RegQueryValueExW(hKey, pszKey, NULL, &dwType, NULL, &cbData);
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
{
WARN("RegQueryValueEx(%s) failed with error %lu\n", debugstr_w(pszKey), rc);
return rc; return rc;
}
if (dwType != REG_SZ) if (dwType != REG_SZ)
{
WARN("Wrong registry data type (%u vs %u)\n", dwType, REG_SZ);
return ERROR_FILE_NOT_FOUND; return ERROR_FILE_NOT_FOUND;
}
Value = (WCHAR*) HeapAlloc(GetProcessHeap(), 0, cbData + sizeof(WCHAR)); Value = (WCHAR*) HeapAlloc(GetProcessHeap(), 0, cbData + sizeof(WCHAR));
if (!Value) if (!Value)
{
WARN("No memory\n");
return ERROR_NOT_ENOUGH_MEMORY; return ERROR_NOT_ENOUGH_MEMORY;
}
rc = RegQueryValueExW(hKey, pszKey, NULL, NULL, (LPBYTE)Value, &cbData); rc = RegQueryValueExW(hKey, pszKey, NULL, NULL, (LPBYTE)Value, &cbData);
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
{ {
WARN("RegQueryValueEx(%s) failed with error %lu\n", debugstr_w(pszKey), rc);
HeapFree(GetProcessHeap(), 0, Value); HeapFree(GetProcessHeap(), 0, Value);
return rc; return rc;
} }
@ -77,16 +92,26 @@ BOOL IsConsoleShell(VOID)
LONG rc; LONG rc;
BOOL ret = FALSE; BOOL ret = FALSE;
TRACE("()\n");
rc = RegOpenKeyEx( rc = RegOpenKeyEx(
HKEY_LOCAL_MACHINE, HKEY_LOCAL_MACHINE,
REGSTR_PATH_CURRENT_CONTROL_SET, REGSTR_PATH_CURRENT_CONTROL_SET,
0, 0,
KEY_QUERY_VALUE, KEY_QUERY_VALUE,
&ControlKey); &ControlKey);
if (rc != ERROR_SUCCESS)
{
WARN("RegOpenKeyEx() failed with error %lu\n", rc);
goto cleanup;
}
rc = ReadRegSzKey(ControlKey, L"SystemStartOptions", &SystemStartOptions); rc = ReadRegSzKey(ControlKey, L"SystemStartOptions", &SystemStartOptions);
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
{
WARN("ReadRegSzKey() failed with error %lu\n", rc);
goto cleanup; goto cleanup;
}
/* Check for CONSOLE in SystemStartOptions */ /* Check for CONSOLE in SystemStartOptions */
CurrentOption = SystemStartOptions; CurrentOption = SystemStartOptions;
@ -97,6 +122,7 @@ BOOL IsConsoleShell(VOID)
*NextOption = L'\0'; *NextOption = L'\0';
if (wcsicmp(CurrentOption, L"CONSOLE") == 0) if (wcsicmp(CurrentOption, L"CONSOLE") == 0)
{ {
TRACE("Found 'CONSOLE' boot option\n");
ret = TRUE; ret = TRUE;
goto cleanup; goto cleanup;
} }
@ -120,26 +146,38 @@ BOOL GetShell(
WCHAR Shell[MAX_PATH]; WCHAR Shell[MAX_PATH];
BOOL Ret = FALSE; BOOL Ret = FALSE;
BOOL ConsoleShell = IsConsoleShell(); BOOL ConsoleShell = IsConsoleShell();
LONG rc;
if (RegOpenKeyEx(hRootKey, REGSTR_PATH_WINLOGON, TRACE("(%p, %p)\n", CommandLine, hRootKey);
0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
rc = RegOpenKeyEx(hRootKey, REGSTR_PATH_WINLOGON,
0, KEY_QUERY_VALUE, &hKey);
if (rc == ERROR_SUCCESS)
{ {
Size = MAX_PATH * sizeof(WCHAR); Size = MAX_PATH * sizeof(WCHAR);
if (RegQueryValueEx(hKey, rc = RegQueryValueEx(hKey,
ConsoleShell ? L"ConsoleShell" : L"Shell", ConsoleShell ? L"ConsoleShell" : L"Shell",
NULL, NULL,
&Type, &Type,
(LPBYTE)Shell, (LPBYTE)Shell,
&Size) == ERROR_SUCCESS) &Size);
if (rc == ERROR_SUCCESS)
{ {
if ((Type == REG_SZ) || (Type == REG_EXPAND_SZ)) if ((Type == REG_SZ) || (Type == REG_EXPAND_SZ))
{ {
TRACE("Found command line %s\n", debugstr_w(Shell));
wcscpy(CommandLine, Shell); wcscpy(CommandLine, Shell);
Ret = TRUE; Ret = TRUE;
} }
else
WARN("Wrong type %lu (expected %u or %u)\n", Type, REG_SZ, REG_EXPAND_SZ);
} }
else
WARN("RegQueryValueEx() failed with error %lu\n", rc);
RegCloseKey(hKey); RegCloseKey(hKey);
} }
else
WARN("RegOpenKeyEx() failed with error %lu\n", rc);
return Ret; return Ret;
} }
@ -155,10 +193,13 @@ StartAutoApplications(
SHELLEXECUTEINFOW ExecInfo; SHELLEXECUTEINFOW ExecInfo;
size_t len; size_t len;
TRACE("(%d)\n", clsid);
hResult = SHGetFolderPathW(NULL, clsid, NULL, SHGFP_TYPE_CURRENT, szPath); hResult = SHGetFolderPathW(NULL, clsid, NULL, SHGFP_TYPE_CURRENT, szPath);
len = wcslen(szPath); len = wcslen(szPath);
if (!SUCCEEDED(hResult) || len == 0) if (!SUCCEEDED(hResult) || len == 0)
{ {
WARN("SHGetFolderPath() failed with error %lu\n", GetLastError());
return; return;
} }
@ -166,6 +207,7 @@ StartAutoApplications(
hFind = FindFirstFileW(szPath, &findData); hFind = FindFirstFileW(szPath, &findData);
if (hFind == INVALID_HANDLE_VALUE) if (hFind == INVALID_HANDLE_VALUE)
{ {
WARN("FindFirstFile(%s) failed with error %lu\n", debugstr_w(szPath), GetLastError());
return; return;
} }
szPath[len] = L'\0'; szPath[len] = L'\0';
@ -179,6 +221,8 @@ StartAutoApplications(
ExecInfo.lpVerb = L"open"; ExecInfo.lpVerb = L"open";
ExecInfo.lpFile = findData.cFileName; ExecInfo.lpFile = findData.cFileName;
ExecInfo.lpDirectory = szPath; ExecInfo.lpDirectory = szPath;
TRACE("Executing %s in directory %s\n",
debugstr_w(findData.cFileName), debugstr_w(szPath));
ShellExecuteExW(&ExecInfo); ShellExecuteExW(&ExecInfo);
} }
} while (FindNextFileW(hFind, &findData)); } while (FindNextFileW(hFind, &findData));
@ -193,6 +237,8 @@ TryToStartShell(
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
WCHAR ExpandedShell[MAX_PATH]; WCHAR ExpandedShell[MAX_PATH];
TRACE("(%s)\n", debugstr_w(Shell));
ZeroMemory(&si, sizeof(STARTUPINFO)); ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO); si.cb = sizeof(STARTUPINFO);
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION)); ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
@ -210,6 +256,7 @@ TryToStartShell(
&si, &si,
&pi)) &pi))
{ {
WARN("CreateProcess() failed with error %lu\n", GetLastError());
return FALSE; return FALSE;
} }
@ -227,15 +274,19 @@ VOID StartShell(VOID)
WCHAR Shell[MAX_PATH]; WCHAR Shell[MAX_PATH];
TCHAR szMsg[RC_STRING_MAX_SIZE]; TCHAR szMsg[RC_STRING_MAX_SIZE];
TRACE("()\n");
/* Try to run shell in user key */ /* Try to run shell in user key */
if (GetShell(Shell, HKEY_CURRENT_USER) && TryToStartShell(Shell)) if (GetShell(Shell, HKEY_CURRENT_USER) && TryToStartShell(Shell))
{ {
TRACE("Failed to start a shell from HKEY_CURRENT_USER\n");
return; return;
} }
/* Try to run shell in local machine key */ /* Try to run shell in local machine key */
if (GetShell(Shell, HKEY_LOCAL_MACHINE) && TryToStartShell(Shell)) if (GetShell(Shell, HKEY_LOCAL_MACHINE) && TryToStartShell(Shell))
{ {
TRACE("Failed to start a shell from HKEY_LOCAL_MACHINE\n");
return; return;
} }
@ -256,12 +307,13 @@ VOID StartShell(VOID)
} }
if (!TryToStartShell(Shell)) if (!TryToStartShell(Shell))
{ {
WARN("Failed to start default shell %s\n", debugstr_w(Shell));
LoadString( GetModuleHandle(NULL), STRING_USERINIT_FAIL, szMsg, sizeof(szMsg) / sizeof(szMsg[0])); LoadString( GetModuleHandle(NULL), STRING_USERINIT_FAIL, szMsg, sizeof(szMsg) / sizeof(szMsg[0]));
MessageBox(0, szMsg, NULL, 0); MessageBox(0, szMsg, NULL, 0);
} }
} }
WCHAR g_RegColorNames[][32] = { const WCHAR g_RegColorNames[][32] = {
L"Scrollbar", /* 00 = COLOR_SCROLLBAR */ L"Scrollbar", /* 00 = COLOR_SCROLLBAR */
L"Background", /* 01 = COLOR_DESKTOP */ L"Background", /* 01 = COLOR_DESKTOP */
L"ActiveTitle", /* 02 = COLOR_ACTIVECAPTION */ L"ActiveTitle", /* 02 = COLOR_ACTIVECAPTION */
@ -302,6 +354,8 @@ COLORREF StrToColorref(
{ {
BYTE rgb[3]; BYTE rgb[3];
TRACE("(%s)\n", debugstr_w(lpszCol));
rgb[0] = StrToIntW(lpszCol); rgb[0] = StrToIntW(lpszCol);
lpszCol = StrChrW(lpszCol, L' ') + 1; lpszCol = StrChrW(lpszCol, L' ') + 1;
rgb[1] = StrToIntW(lpszCol); rgb[1] = StrToIntW(lpszCol);
@ -318,25 +372,32 @@ VOID SetUserSysColors(VOID)
WCHAR szColor[20]; WCHAR szColor[20];
DWORD Type, Size; DWORD Type, Size;
COLORREF crColor; COLORREF crColor;
LONG rc;
if (!RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_COLORS, TRACE("()\n");
0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
rc = RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_COLORS,
0, KEY_QUERY_VALUE, &hKey);
if (rc != ERROR_SUCCESS)
{ {
WARN("RegOpenKeyEx() failed with error %lu\n", rc);
return; return;
} }
for(i = 0; i < NUM_SYSCOLORS; i++) for(i = 0; i < NUM_SYSCOLORS; i++)
{ {
Size = sizeof(szColor); Size = sizeof(szColor);
if (RegQueryValueEx(hKey, g_RegColorNames[i], NULL, &Type, rc = RegQueryValueEx(hKey, g_RegColorNames[i], NULL, &Type,
(LPBYTE)szColor, &Size) == ERROR_SUCCESS && (LPBYTE)szColor, &Size);
Type == REG_SZ) if (rc == ERROR_SUCCESS && Type == REG_SZ)
{ {
crColor = StrToColorref(szColor); crColor = StrToColorref(szColor);
SetSysColors(1, &i, &crColor); SetSysColors(1, &i, &crColor);
} }
else
WARN("RegQueryValueEx(%s) failed with error %lu\n",
debugstr_w(g_RegColorNames[i]), rc);
} }
RegCloseKey(hKey); RegCloseKey(hKey);
return;
} }
static static
@ -347,17 +408,22 @@ VOID LoadUserFontSetting(
HKEY hKey; HKEY hKey;
LOGFONTW lfTemp; LOGFONTW lfTemp;
DWORD Type, Size; DWORD Type, Size;
INT error; LONG rc;
TRACE("(%s, %p)\n", debugstr_w(lpValueName), pFont);
Size = sizeof(LOGFONTW); Size = sizeof(LOGFONTW);
if (!RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_METRICS, rc = RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_METRICS,
0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) 0, KEY_QUERY_VALUE, &hKey);
if (rc != ERROR_SUCCESS)
{ {
WARN("RegOpenKeyEx() failed with error %lu\n", rc);
return; return;
} }
error = RegQueryValueEx(hKey, lpValueName, NULL, &Type, (LPBYTE)&lfTemp, &Size); rc = RegQueryValueEx(hKey, lpValueName, NULL, &Type, (LPBYTE)&lfTemp, &Size);
if ((error != ERROR_SUCCESS) || (Type != REG_BINARY)) if (rc != ERROR_SUCCESS || Type != REG_BINARY)
{ {
WARN("RegQueryValueEx() failed with error %lu\n", rc);
return; return;
} }
RegCloseKey(hKey); RegCloseKey(hKey);
@ -372,18 +438,23 @@ VOID LoadUserMetricSetting(
{ {
HKEY hKey; HKEY hKey;
DWORD Type, Size; DWORD Type, Size;
INT ret;
WCHAR strValue[8]; WCHAR strValue[8];
LONG rc;
TRACE("(%s, %p)\n", debugstr_w(lpValueName), pValue);
Size = sizeof(strValue); Size = sizeof(strValue);
if (!RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_METRICS, rc = RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_METRICS,
0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) 0, KEY_QUERY_VALUE, &hKey);
if (rc != ERROR_SUCCESS)
{ {
WARN("RegOpenKeyEx() failed with error %lu\n", rc);
return; return;
} }
ret = RegQueryValueEx(hKey, lpValueName, NULL, &Type, (LPBYTE)&strValue, &Size); rc = RegQueryValueEx(hKey, lpValueName, NULL, &Type, (LPBYTE)&strValue, &Size);
if ((ret != ERROR_SUCCESS) || (Type != REG_SZ)) if (rc != ERROR_SUCCESS || Type != REG_SZ)
{ {
WARN("RegQueryValueEx() failed with error %lu\n", rc);
return; return;
} }
RegCloseKey(hKey); RegCloseKey(hKey);
@ -396,6 +467,8 @@ VOID SetUserMetrics(VOID)
NONCLIENTMETRICSW ncmetrics; NONCLIENTMETRICSW ncmetrics;
MINIMIZEDMETRICS mmmetrics; MINIMIZEDMETRICS mmmetrics;
TRACE("()\n");
ncmetrics.cbSize = sizeof(NONCLIENTMETRICSW); ncmetrics.cbSize = sizeof(NONCLIENTMETRICSW);
mmmetrics.cbSize = sizeof(MINIMIZEDMETRICS); mmmetrics.cbSize = sizeof(MINIMIZEDMETRICS);
SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &ncmetrics, 0); SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &ncmetrics, 0);
@ -427,20 +500,25 @@ VOID SetUserWallpaper(VOID)
HKEY hKey; HKEY hKey;
DWORD Type, Size; DWORD Type, Size;
WCHAR szWallpaper[MAX_PATH + 1]; WCHAR szWallpaper[MAX_PATH + 1];
LONG rc;
if (RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_DESKTOP, TRACE("()\n");
0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
rc = RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_DESKTOP,
0, KEY_QUERY_VALUE, &hKey);
if (rc == ERROR_SUCCESS)
{ {
Size = sizeof(szWallpaper); Size = sizeof(szWallpaper);
if (RegQueryValueEx(hKey, rc = RegQueryValueEx(hKey,
L"Wallpaper", L"Wallpaper",
NULL, NULL,
&Type, &Type,
(LPBYTE)szWallpaper, (LPBYTE)szWallpaper,
&Size) == ERROR_SUCCESS && &Size);
Type == REG_SZ) if (rc == ERROR_SUCCESS && Type == REG_SZ)
{ {
ExpandEnvironmentStrings(szWallpaper, szWallpaper, MAX_PATH); ExpandEnvironmentStrings(szWallpaper, szWallpaper, MAX_PATH);
TRACE("Using wallpaper %s\n", debugstr_w(szWallpaper));
/* Load and change the wallpaper */ /* Load and change the wallpaper */
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, szWallpaper, SPIF_SENDCHANGE); SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, szWallpaper, SPIF_SENDCHANGE);
@ -448,15 +526,20 @@ VOID SetUserWallpaper(VOID)
else else
{ {
/* remove the wallpaper */ /* remove the wallpaper */
TRACE("No wallpaper set in registry (error %lu)\n", rc);
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, NULL, SPIF_SENDCHANGE); SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, NULL, SPIF_SENDCHANGE);
} }
RegCloseKey(hKey); RegCloseKey(hKey);
} }
else
WARN("RegOpenKeyEx() failed with error %lu\n", rc);
} }
static static
VOID SetUserSettings(VOID) VOID SetUserSettings(VOID)
{ {
TRACE("()\n");
SetUserSysColors(); SetUserSysColors();
SetUserMetrics(); SetUserMetrics();
SetUserWallpaper(); SetUserWallpaper();
@ -470,15 +553,21 @@ NotifyLogon(VOID)
HINSTANCE hModule; HINSTANCE hModule;
PCMP_REPORT_LOGON CMP_Report_LogOn; PCMP_REPORT_LOGON CMP_Report_LogOn;
TRACE("()\n");
hModule = LoadLibrary(L"setupapi.dll"); hModule = LoadLibrary(L"setupapi.dll");
if (hModule) if (hModule)
{ {
CMP_Report_LogOn = (PCMP_REPORT_LOGON)GetProcAddress(hModule, "CMP_Report_LogOn"); CMP_Report_LogOn = (PCMP_REPORT_LOGON)GetProcAddress(hModule, "CMP_Report_LogOn");
if (CMP_Report_LogOn) if (CMP_Report_LogOn)
CMP_Report_LogOn(CMP_MAGIC, GetCurrentProcessId()); CMP_Report_LogOn(CMP_MAGIC, GetCurrentProcessId());
else
WARN("GetProcAddress() failed\n");
FreeLibrary(hModule); FreeLibrary(hModule);
} }
else
WARN("LoadLibrary() failed with error %lu\n", GetLastError());
} }
#ifdef _MSC_VER #ifdef _MSC_VER

View file

@ -1,9 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd"> <!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
<module name="userinit" type="win32gui" installbase="system32" installname="userinit.exe"> <module name="userinit" type="win32gui" installbase="system32" installname="userinit.exe" unicode="yes">
<include base="userinit">.</include> <include base="userinit">.</include>
<define name="UNICODE" />
<define name="_UNICODE" />
<library>ntdll</library> <library>ntdll</library>
<library>kernel32</library> <library>kernel32</library>
<library>user32</library> <library>user32</library>