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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS system libraries
23 * PURPOSE: Log file functions
24 * FILE: lib/syssetup/logfile.c
25 * PROGRAMER: Eric Kohl
28 /* INCLUDES *****************************************************************/
38 /* GLOBALS ******************************************************************/
40 HANDLE hLogFile
= NULL
;
43 /* FUNCTIONS ****************************************************************/
46 InitializeSetupActionLog (BOOL bDeleteOldLogFile
)
48 WCHAR szFileName
[MAX_PATH
];
50 GetWindowsDirectoryW (szFileName
,
53 if (szFileName
[wcslen (szFileName
)] != L
'\\')
63 if (bDeleteOldLogFile
!= FALSE
)
65 SetFileAttributesW (szFileName
,
66 FILE_ATTRIBUTE_NORMAL
);
67 DeleteFileW (szFileName
);
70 hLogFile
= CreateFileW (szFileName
,
71 GENERIC_READ
| GENERIC_WRITE
,
72 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
75 FILE_ATTRIBUTE_NORMAL
,
77 if (hLogFile
== INVALID_HANDLE_VALUE
)
88 TerminateSetupActionLog (VOID
)
92 CloseHandle (hLogFile
);
99 LogItem (DWORD dwSeverity
,
100 LPWSTR lpMessageText
)
102 LPSTR lpNewLine
= "\r\n";
103 LPSTR lpSeverityString
;
104 LPSTR lpMessageString
;
105 DWORD dwMessageLength
;
109 /* Get the severity code string */
112 case SYSSETUP_SEVERITY_INFORMATION
:
113 lpSeverityString
= "Information : ";
116 case SYSSETUP_SEVERITY_WARNING
:
117 lpSeverityString
= "Warning : ";
120 case SYSSETUP_SEVERITY_ERROR
:
121 lpSeverityString
= "Error : ";
124 case SYSSETUP_SEVERITY_FATAL_ERROR
:
125 lpSeverityString
= "Fatal error : ";
129 lpSeverityString
= "Unknown : ";
133 /* Get length of the converted ansi string */
134 dwMessageLength
= wcslen(lpMessageText
) * sizeof(WCHAR
);
135 RtlUnicodeToMultiByteSize (&dwMessageSize
,
139 /* Allocate message string buffer */
140 lpMessageString
= (LPSTR
) HeapAlloc (GetProcessHeap (),
143 if (lpMessageString
== NULL
)
148 /* Convert unicode to ansi */
149 RtlUnicodeToMultiByteN (lpMessageString
,
155 /* Set file pointer to the end of the file */
156 SetFilePointer (hLogFile
,
161 /* Write severity code */
164 strlen (lpSeverityString
),
168 /* Write message string */
182 HeapFree (GetProcessHeap (),