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 const LPCSTR lpNewLine
= "\r\n";
95 LPCSTR lpSeverityString
;
96 LPSTR lpMessageString
;
97 DWORD dwMessageLength
;
102 /* Get the severity code string */
105 case SYSSETUP_SEVERITY_INFORMATION
:
106 lpSeverityString
= "Information : ";
109 case SYSSETUP_SEVERITY_WARNING
:
110 lpSeverityString
= "Warning : ";
113 case SYSSETUP_SEVERITY_ERROR
:
114 lpSeverityString
= "Error : ";
117 case SYSSETUP_SEVERITY_FATAL_ERROR
:
118 lpSeverityString
= "Fatal error : ";
122 lpSeverityString
= "Unknown : ";
126 /* Get length of the converted ansi string */
127 dwMessageLength
= wcslen(lpMessageText
) * sizeof(WCHAR
);
128 RtlUnicodeToMultiByteSize(&dwMessageSize
,
132 /* Allocate message string buffer */
133 lpMessageString
= (LPSTR
) HeapAlloc(GetProcessHeap(),
136 if (!lpMessageString
)
139 /* Convert unicode to ansi */
140 RtlUnicodeToMultiByteN(lpMessageString
,
146 /* Set file pointer to the end of the file */
147 SetFilePointer(hLogFile
,
152 /* Write file name */
160 WriteFile(hLogFile
, ",", 1, &dwWritten
, NULL
);
162 /* Write line number */
163 snprintf(Buffer
, sizeof(Buffer
), "%lu", dwLineNumber
);
171 WriteFile(hLogFile
, ",", 1, &dwWritten
, NULL
);
173 /* Write severity code */
176 strlen(lpSeverityString
),
180 /* Write message string */
194 HeapFree(GetProcessHeap(),