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 *****************************************************************/
30 /* GLOBALS ******************************************************************/
32 HANDLE hLogFile
= NULL
;
35 /* FUNCTIONS ****************************************************************/
38 InitializeSetupActionLog (BOOL bDeleteOldLogFile
)
40 WCHAR szFileName
[MAX_PATH
];
42 GetWindowsDirectoryW(szFileName
, MAX_PATH
);
44 if (szFileName
[wcslen(szFileName
)] != L
'\\')
54 if (bDeleteOldLogFile
)
56 SetFileAttributesW(szFileName
, FILE_ATTRIBUTE_NORMAL
);
57 DeleteFileW(szFileName
);
60 hLogFile
= CreateFileW(szFileName
,
61 GENERIC_READ
| GENERIC_WRITE
,
62 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
65 FILE_ATTRIBUTE_NORMAL
,
67 if (hLogFile
== INVALID_HANDLE_VALUE
)
78 TerminateSetupActionLog(VOID
)
82 CloseHandle (hLogFile
);
89 SYSSETUP_LogItem(IN
const LPSTR lpFileName
,
90 IN DWORD dwLineNumber
,
92 IN LPWSTR lpMessageText
)
94 LPCSTR lpSeverityString
;
95 LPSTR lpMessageString
;
96 DWORD dwMessageLength
;
101 /* Get the severity code string */
104 case SYSSETUP_SEVERITY_INFORMATION
:
105 lpSeverityString
= "Information : ";
108 case SYSSETUP_SEVERITY_WARNING
:
109 lpSeverityString
= "Warning : ";
112 case SYSSETUP_SEVERITY_ERROR
:
113 lpSeverityString
= "Error : ";
116 case SYSSETUP_SEVERITY_FATAL_ERROR
:
117 lpSeverityString
= "Fatal error : ";
121 lpSeverityString
= "Unknown : ";
125 /* Get length of the converted ansi string */
126 dwMessageLength
= wcslen(lpMessageText
) * sizeof(WCHAR
);
127 RtlUnicodeToMultiByteSize(&dwMessageSize
,
131 /* Allocate message string buffer */
132 lpMessageString
= (LPSTR
) HeapAlloc(GetProcessHeap(),
135 if (!lpMessageString
)
138 /* Convert unicode to ansi */
139 RtlUnicodeToMultiByteN(lpMessageString
,
145 /* Set file pointer to the end of the file */
146 SetFilePointer(hLogFile
,
151 /* Write file name */
159 WriteFile(hLogFile
, ",", 1, &dwWritten
, NULL
);
161 /* Write line number */
162 snprintf(Buffer
, sizeof(Buffer
), "%lu", dwLineNumber
);
170 WriteFile(hLogFile
, ",", 1, &dwWritten
, NULL
);
172 /* Write severity code */
175 strlen(lpSeverityString
),
179 /* Write message string */
187 WriteFile(hLogFile
, "\r\n", 2, &dwWritten
, NULL
);
189 HeapFree(GetProcessHeap(),