[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);
va_end(ap);
LogItem(SYSSETUP_SEVERITY_FATAL_ERROR, L"Failed");
LogItem(NULL, L"Failed");
strcat(szBuffer, "\nRebooting now!");
MessageBoxA(NULL,
@ -1097,7 +1097,7 @@ InstallReactOS(HINSTANCE hInstance)
BOOL ret;
InitializeSetupActionLog(FALSE);
LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS");
LogItem(NULL, L"Installing ReactOS");
if (!InitializeProfiles())
{
@ -1194,7 +1194,7 @@ InstallReactOS(HINSTANCE hInstance)
CloseHandle(hHotkeyThread);
}
LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS done");
LogItem(NULL, L"Installing ReactOS done");
TerminateSetupActionLog();
if (AdminInfo.Name != NULL)

View file

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

View file

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

View file

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

View file

@ -31,26 +31,27 @@ InstallReactOS (HINSTANCE hInstance);
/* 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
InitializeSetupActionLog(IN BOOL bDeleteOldLogFile);
VOID WINAPI
TerminateSetupActionLog(VOID);
BOOL WINAPI
SYSSETUP_LogItem(IN const LPSTR lpFileName,
IN DWORD dwLineNumber,
IN DWORD dwSeverity,
IN LPWSTR lpMessageText);
VOID
CDECL
pSetupDebugPrint(
IN PCWSTR pszFileName,
IN INT nLineNumber,
IN PCWSTR pszTag,
IN PCWSTR pszMessage,
...);
#define LogItem(dwSeverity, lpMessageText) \
SYSSETUP_LogItem(__FILE__, __LINE__, dwSeverity, lpMessageText)
#define __WFILE__ TOWL1(__FILE__)
#define TOWL1(p) TOWL2(p)
#define TOWL2(p) L##p
#define LogItem(lpTag, lpMessageText...) \
pSetupDebugPrint(__WFILE__, __LINE__, lpTag, lpMessageText)
#endif /* __SYSSETUP_H_INCLUDED__ */