3 * Copyright (C) 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS system libraries
22 * PURPOSE: Log file functions
23 * FILE: lib/syssetup/logfile.c
24 * PROGRAMER: Eric Kohl
27 /* INCLUDES *****************************************************************/
32 /* GLOBALS ******************************************************************/
34 HANDLE hLogFile
= NULL
;
36 #define FORMAT_BUFFER_SIZE 512
37 #define LINE_BUFFER_SIZE 1024
39 /* FUNCTIONS ****************************************************************/
42 InitializeSetupActionLog (BOOL bDeleteOldLogFile
)
44 WCHAR szFileName
[MAX_PATH
];
46 GetWindowsDirectoryW(szFileName
, MAX_PATH
);
48 if (szFileName
[wcslen(szFileName
)] != L
'\\')
52 (sizeof(szFileName
) / sizeof(szFileName
[0])) - wcslen(szFileName
));
56 (sizeof(szFileName
) / sizeof(szFileName
[0])) - wcslen(szFileName
));
58 if (bDeleteOldLogFile
)
60 SetFileAttributesW(szFileName
, FILE_ATTRIBUTE_NORMAL
);
61 DeleteFileW(szFileName
);
64 hLogFile
= CreateFileW(szFileName
,
65 GENERIC_READ
| GENERIC_WRITE
,
66 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
69 FILE_ATTRIBUTE_NORMAL
,
71 if (hLogFile
== INVALID_HANDLE_VALUE
)
82 TerminateSetupActionLog(VOID
)
86 CloseHandle (hLogFile
);
95 IN PCWSTR pszFileName
,
101 PWSTR pszFormatBuffer
= NULL
;
102 PWSTR pszLineBuffer
= NULL
;
103 PSTR pszOutputBuffer
= NULL
;
104 ULONG ulLineSize
, ulOutputSize
;
109 if (hLogFile
== NULL
)
112 GetLocalTime(&stTime
);
116 pszFormatBuffer
= HeapAlloc(GetProcessHeap(),
118 FORMAT_BUFFER_SIZE
* sizeof(WCHAR
));
119 if (pszFormatBuffer
== NULL
)
122 va_start(args
, pszMessage
);
123 vsnwprintf(pszFormatBuffer
,
130 pszLineBuffer
= HeapAlloc(GetProcessHeap(),
132 LINE_BUFFER_SIZE
* sizeof(WCHAR
));
133 if (pszLineBuffer
== NULL
)
136 _snwprintf(pszLineBuffer
,
138 L
"%02d/%02d/%04d %02d:%02d:%02d.%03d, %s, %d, %s, %s\r\n",
145 stTime
.wMilliseconds
,
146 pszFileName
? pszFileName
: L
"",
148 pszTag
? pszTag
: L
"",
149 pszFormatBuffer
? pszFormatBuffer
: L
"");
151 /* Get length of the converted ansi string */
152 ulLineSize
= wcslen(pszLineBuffer
) * sizeof(WCHAR
);
153 RtlUnicodeToMultiByteSize(&ulOutputSize
,
157 /* Allocate message string buffer */
158 pszOutputBuffer
= HeapAlloc(GetProcessHeap(),
161 if (pszOutputBuffer
== NULL
)
164 /* Convert unicode to ansi */
165 RtlUnicodeToMultiByteN(pszOutputBuffer
,
171 /* Set file pointer to the end of the file */
172 SetFilePointer(hLogFile
,
185 HeapFree(GetProcessHeap(), 0, pszOutputBuffer
);
188 HeapFree(GetProcessHeap(), 0, pszLineBuffer
);
191 HeapFree(GetProcessHeap(), 0, pszFormatBuffer
);