summaryrefslogtreecommitdiffstats
path: root/private/sdktools/instaler/event.c
blob: 492504f63fb9c609a31964880e9d014daaee57f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*++

Copyright (c) 1992  Microsoft Corporation

Module Name:

    event.c

Abstract:

    Log formatted events to a file and possibly the console too

Author:

    Steve Wood (stevewo) 09-Aug-1994

Revision History:

--*/

#include "instaler.h"

VOID
CDECL
LogEvent(
    UINT MessageId,
    UINT NumberOfArguments,
    ...
    )
{
    va_list arglist;
    HMODULE ModuleHandle;
    DWORD Flags, Size;
    WCHAR MessageBuffer[ 512 ];
    PWSTR s;
    ULONG Args[ 24 ];
    PULONG p;

    va_start( arglist, NumberOfArguments );
    p = Args;
    while (NumberOfArguments--) {
        *p++ = va_arg( arglist, ULONG );
        }
    *p++ = ((GetTickCount() - StartProcessTickCount) / 1000);   // Seconds since the start
    *p++ = 0;
    va_end( arglist );

    Size = FormatMessageW( FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
                           (LPCVOID)InstalerModuleHandle,
                           MessageId,
                           0,
                           MessageBuffer,
                           sizeof( MessageBuffer ) / sizeof( WCHAR ),
                           (va_list *)Args
                         );
    if (Size != 0) {
        s = MessageBuffer;
        while (s = wcschr( s, L'\r' )) {
            if (s[1] == '\n') {
                wcscpy( s, s+1 );
                }
            else {
                s += 1;
                }
            }
        printf( "%ws", MessageBuffer );
        if (InstalerLogFile) {
            fprintf( InstalerLogFile, "%ws", MessageBuffer );
            }
        }
    else {
        printf( "INSTALER: Unable to get message text for %08x\n", MessageId );
        }

    return;
}