[SYSETUP]

- Implement pSetupDebugPrint and modify the LogItem macro accordingly.
- Add some log messages to the setup wizard.

svn path=/trunk/; revision=70474
This commit is contained in:
Eric Kohl 2015-12-31 22:17:45 +00:00
parent fa4dd77466
commit 93c88d5c67
5 changed files with 107 additions and 122 deletions

View file

@ -64,7 +64,7 @@ FatalError(char *pszFmt,...)
vsprintf(szBuffer, pszFmt, ap); vsprintf(szBuffer, pszFmt, ap);
va_end(ap); va_end(ap);
LogItem(SYSSETUP_SEVERITY_FATAL_ERROR, L"Failed"); LogItem(NULL, L"Failed");
strcat(szBuffer, "\nRebooting now!"); strcat(szBuffer, "\nRebooting now!");
MessageBoxA(NULL, MessageBoxA(NULL,
@ -1097,7 +1097,7 @@ InstallReactOS(HINSTANCE hInstance)
BOOL ret; BOOL ret;
InitializeSetupActionLog(FALSE); InitializeSetupActionLog(FALSE);
LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS"); LogItem(NULL, L"Installing ReactOS");
if (!InitializeProfiles()) if (!InitializeProfiles())
{ {
@ -1194,7 +1194,7 @@ InstallReactOS(HINSTANCE hInstance)
CloseHandle(hHotkeyThread); CloseHandle(hHotkeyThread);
} }
LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS done"); LogItem(NULL, L"Installing ReactOS done");
TerminateSetupActionLog(); TerminateSetupActionLog();
if (AdminInfo.Name != NULL) if (AdminInfo.Name != NULL)

View file

@ -27,11 +27,15 @@
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
#include "precomp.h" #include "precomp.h"
#include <stdarg.h>
/* GLOBALS ******************************************************************/ /* GLOBALS ******************************************************************/
HANDLE hLogFile = NULL; HANDLE hLogFile = NULL;
#define FORMAT_BUFFER_SIZE 512
#define LINE_BUFFER_SIZE 1024
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
BOOL WINAPI BOOL WINAPI
@ -85,64 +89,84 @@ TerminateSetupActionLog(VOID)
} }
BOOL WINAPI VOID
SYSSETUP_LogItem(IN const LPSTR lpFileName, CDECL
IN DWORD dwLineNumber, pSetupDebugPrint(
IN DWORD dwSeverity, IN PCWSTR pszFileName,
IN LPWSTR lpMessageText) IN INT nLineNumber,
IN PCWSTR pszTag,
IN PCWSTR pszMessage,
...)
{ {
LPCSTR lpSeverityString; PWSTR pszFormatBuffer = NULL;
LPSTR lpMessageString; PWSTR pszLineBuffer = NULL;
DWORD dwMessageLength; PSTR pszOutputBuffer = NULL;
DWORD dwMessageSize; ULONG ulLineSize, ulOutputSize;
DWORD dwWritten; DWORD dwWritten;
CHAR Buffer[6];
CHAR TimeBuffer[30];
SYSTEMTIME stTime; SYSTEMTIME stTime;
va_list args;
/* Get the severity code string */ if (hLogFile == NULL)
switch (dwSeverity) return;
GetLocalTime(&stTime);
if (pszMessage)
{ {
case SYSSETUP_SEVERITY_INFORMATION: pszFormatBuffer = HeapAlloc(GetProcessHeap(),
lpSeverityString = "Information : "; HEAP_ZERO_MEMORY,
break; FORMAT_BUFFER_SIZE * sizeof(WCHAR));
if (pszFormatBuffer == NULL)
goto done;
case SYSSETUP_SEVERITY_WARNING: va_start(args, pszMessage);
lpSeverityString = "Warning : "; vsnwprintf(pszFormatBuffer,
break; FORMAT_BUFFER_SIZE,
pszMessage,
case SYSSETUP_SEVERITY_ERROR: args);
lpSeverityString = "Error : "; va_end(args);
break;
case SYSSETUP_SEVERITY_FATAL_ERROR:
lpSeverityString = "Fatal error : ";
break;
default:
lpSeverityString = "Unknown : ";
break;
} }
pszLineBuffer = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
LINE_BUFFER_SIZE * sizeof(WCHAR));
if (pszLineBuffer == NULL)
goto done;
_snwprintf(pszLineBuffer,
LINE_BUFFER_SIZE,
L"%02d/%02d/%04d %02d:%02d:%02d.%03d, %s, %d, %s, %s\r\n",
stTime.wMonth,
stTime.wDay,
stTime.wYear,
stTime.wHour,
stTime.wMinute,
stTime.wSecond,
stTime.wMilliseconds,
pszFileName ? pszFileName : L"",
nLineNumber,
pszTag ? pszTag : L"",
pszFormatBuffer ? pszFormatBuffer : L"");
/* Get length of the converted ansi string */ /* Get length of the converted ansi string */
dwMessageLength = wcslen(lpMessageText) * sizeof(WCHAR); ulLineSize = wcslen(pszLineBuffer) * sizeof(WCHAR);
RtlUnicodeToMultiByteSize(&dwMessageSize, RtlUnicodeToMultiByteSize(&ulOutputSize,
lpMessageText, pszLineBuffer,
dwMessageLength); ulLineSize);
/* Allocate message string buffer */ /* Allocate message string buffer */
lpMessageString = (LPSTR) HeapAlloc(GetProcessHeap(), pszOutputBuffer = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
dwMessageSize); ulOutputSize);
if (!lpMessageString) if (pszOutputBuffer == NULL)
return FALSE; goto done;
/* Convert unicode to ansi */ /* Convert unicode to ansi */
RtlUnicodeToMultiByteN(lpMessageString, RtlUnicodeToMultiByteN(pszOutputBuffer,
dwMessageSize, ulOutputSize,
NULL, NULL,
lpMessageText, pszLineBuffer,
dwMessageLength); ulLineSize);
/* Set file pointer to the end of the file */ /* Set file pointer to the end of the file */
SetFilePointer(hLogFile, SetFilePointer(hLogFile,
@ -150,71 +174,21 @@ SYSSETUP_LogItem(IN const LPSTR lpFileName,
NULL, NULL,
FILE_END); FILE_END);
/* Write Time/Date */
GetLocalTime(&stTime);
snprintf(TimeBuffer, sizeof(TimeBuffer),
"%02d/%02d/%02d %02d:%02d:%02d.%03d",
stTime.wMonth,
stTime.wDay,
stTime.wYear,
stTime.wHour,
stTime.wMinute,
stTime.wSecond,
stTime.wMilliseconds);
WriteFile(hLogFile, WriteFile(hLogFile,
TimeBuffer, pszOutputBuffer,
strlen(TimeBuffer), ulOutputSize,
&dwWritten, &dwWritten,
NULL); NULL);
/* Write comma */ done:
WriteFile(hLogFile, ",", 1, &dwWritten, NULL); if (pszOutputBuffer)
HeapFree(GetProcessHeap(), 0, pszOutputBuffer);
/* Write file name */ if (pszLineBuffer)
WriteFile(hLogFile, HeapFree(GetProcessHeap(), 0, pszLineBuffer);
lpFileName,
strlen(lpFileName),
&dwWritten,
NULL);
/* Write comma */ if (pszFormatBuffer)
WriteFile(hLogFile, ",", 1, &dwWritten, NULL); HeapFree(GetProcessHeap(), 0, pszFormatBuffer);
/* Write line number */
snprintf(Buffer, sizeof(Buffer), "%lu", dwLineNumber);
WriteFile(hLogFile,
Buffer,
strlen(Buffer),
&dwWritten,
NULL);
/* Write comma */
WriteFile(hLogFile, ",", 1, &dwWritten, NULL);
/* Write severity code */
WriteFile(hLogFile,
lpSeverityString,
strlen(lpSeverityString),
&dwWritten,
NULL);
/* Write message string */
WriteFile(hLogFile,
lpMessageString,
dwMessageSize,
&dwWritten,
NULL);
/* Write newline */
WriteFile(hLogFile, "\r\n", 2, &dwWritten, NULL);
HeapFree(GetProcessHeap(),
0,
lpMessageString);
return TRUE;
} }
/* EOF */ /* EOF */

View file

@ -83,5 +83,5 @@
@ stub UpgradePrinters @ stub UpgradePrinters
@ stub ViewSetupActionLog @ stub ViewSetupActionLog
@ stdcall VolumeClassInstaller(long ptr ptr) @ stdcall VolumeClassInstaller(long ptr ptr)
@ stub pSetupDebugPrint @ varargs pSetupDebugPrint(wstr long wstr wstr)
@ stub pSetuplogSfcError @ stub pSetuplogSfcError

View file

@ -266,6 +266,7 @@ WelcomeDlgProc(HWND hwndDlg,
switch (lpnm->code) switch (lpnm->code)
{ {
case PSN_SETACTIVE: case PSN_SETACTIVE:
LogItem(L"BEGIN", L"WelcomePage");
/* Enable the Next button */ /* Enable the Next button */
PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT); PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
if (pSetupData->UnattendSetup) if (pSetupData->UnattendSetup)
@ -275,6 +276,10 @@ WelcomeDlgProc(HWND hwndDlg,
} }
break; break;
case PSN_WIZNEXT:
LogItem(L"END", L"WelcomePage");
break;
case PSN_WIZBACK: case PSN_WIZBACK:
pSetupData->UnattendSetup = FALSE; pSetupData->UnattendSetup = FALSE;
break; break;
@ -2302,7 +2307,7 @@ GetRosInstallCD(WCHAR *pwszPath, DWORD cchPathMax)
if (cchDrives == 0 || cchDrives >= _countof(wszDrives)) if (cchDrives == 0 || cchDrives >= _countof(wszDrives))
{ {
/* buffer too small or failure */ /* buffer too small or failure */
LogItem(SYSSETUP_SEVERITY_INFORMATION, L"GetLogicalDriveStringsW failed"); LogItem(NULL, L"GetLogicalDriveStringsW failed");
return FALSE; return FALSE;
} }
@ -2312,7 +2317,7 @@ GetRosInstallCD(WCHAR *pwszPath, DWORD cchPathMax)
{ {
WCHAR wszBuf[MAX_PATH]; WCHAR wszBuf[MAX_PATH];
wsprintf(wszBuf, L"%sreactos\\system32\\ntoskrnl.exe", pwszDrive); wsprintf(wszBuf, L"%sreactos\\system32\\ntoskrnl.exe", pwszDrive);
LogItem(SYSSETUP_SEVERITY_INFORMATION, wszBuf); LogItem(NULL, wszBuf);
if (GetFileAttributesW(wszBuf) != INVALID_FILE_ATTRIBUTES) if (GetFileAttributesW(wszBuf) != INVALID_FILE_ATTRIBUTES)
{ {
/* the file exists, so this is the right drive */ /* the file exists, so this is the right drive */
@ -2372,12 +2377,15 @@ InstallWizard(VOID)
MSG msg; MSG msg;
PSETUPDATA pSetupData = NULL; PSETUPDATA pSetupData = NULL;
LogItem(L"BEGIN_SECTION", L"InstallWizard");
/* Allocate setup data */ /* Allocate setup data */
pSetupData = HeapAlloc(GetProcessHeap(), pSetupData = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
sizeof(SETUPDATA)); sizeof(SETUPDATA));
if (pSetupData == NULL) if (pSetupData == NULL)
{ {
LogItem(NULL, L"SetupData allocation failed!");
MessageBoxW(NULL, MessageBoxW(NULL,
L"Setup failed to allocate global data!", L"Setup failed to allocate global data!",
L"ReactOS Setup", L"ReactOS Setup",
@ -2487,6 +2495,8 @@ InstallWizard(VOID)
DeleteObject(pSetupData->hTitleFont); DeleteObject(pSetupData->hTitleFont);
HeapFree(GetProcessHeap(), 0, pSetupData); HeapFree(GetProcessHeap(), 0, pSetupData);
LogItem(L"END_SECTION", L"InstallWizard");
} }
/* EOF */ /* EOF */

View file

@ -31,26 +31,27 @@ InstallReactOS (HINSTANCE hInstance);
/* Log File APIs */ /* Log File APIs */
#define SYSSETUP_SEVERITY_INFORMATION 0
#define SYSSETUP_SEVERITY_WARNING 1
#define SYSSETUP_SEVERITY_ERROR 2
#define SYSSETUP_SEVERITY_FATAL_ERROR 3
BOOL WINAPI BOOL WINAPI
InitializeSetupActionLog(IN BOOL bDeleteOldLogFile); InitializeSetupActionLog(IN BOOL bDeleteOldLogFile);
VOID WINAPI VOID WINAPI
TerminateSetupActionLog(VOID); TerminateSetupActionLog(VOID);
BOOL WINAPI VOID
SYSSETUP_LogItem(IN const LPSTR lpFileName, CDECL
IN DWORD dwLineNumber, pSetupDebugPrint(
IN DWORD dwSeverity, IN PCWSTR pszFileName,
IN LPWSTR lpMessageText); IN INT nLineNumber,
IN PCWSTR pszTag,
IN PCWSTR pszMessage,
...);
#define LogItem(dwSeverity, lpMessageText) \ #define __WFILE__ TOWL1(__FILE__)
SYSSETUP_LogItem(__FILE__, __LINE__, dwSeverity, lpMessageText) #define TOWL1(p) TOWL2(p)
#define TOWL2(p) L##p
#define LogItem(lpTag, lpMessageText...) \
pSetupDebugPrint(__WFILE__, __LINE__, lpTag, lpMessageText)
#endif /* __SYSSETUP_H_INCLUDED__ */ #endif /* __SYSSETUP_H_INCLUDED__ */