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 *****************************************************************/
28 #define WIN32_NO_STATUS
30 #define NTOS_MODE_USER
31 #include <ndk/ntndk.h>
33 #include <syssetup/syssetup.h>
35 /* GLOBALS ******************************************************************/
37 HANDLE hLogFile
= NULL
;
40 /* FUNCTIONS ****************************************************************/
43 InitializeSetupActionLog (BOOL bDeleteOldLogFile
)
45 WCHAR szFileName
[MAX_PATH
];
47 GetWindowsDirectoryW(szFileName
, MAX_PATH
);
49 if (szFileName
[wcslen(szFileName
)] != L
'\\')
59 if (bDeleteOldLogFile
)
61 SetFileAttributesW(szFileName
, FILE_ATTRIBUTE_NORMAL
);
62 DeleteFileW(szFileName
);
65 hLogFile
= CreateFileW(szFileName
,
66 GENERIC_READ
| GENERIC_WRITE
,
67 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
70 FILE_ATTRIBUTE_NORMAL
,
72 if (hLogFile
== INVALID_HANDLE_VALUE
)
83 TerminateSetupActionLog(VOID
)
87 CloseHandle (hLogFile
);
94 SYSSETUP_LogItem(IN
const LPSTR lpFileName
,
95 IN DWORD dwLineNumber
,
97 IN LPWSTR lpMessageText
)
99 const LPCSTR lpNewLine
= "\r\n";
100 LPCSTR lpSeverityString
;
101 LPSTR lpMessageString
;
102 DWORD dwMessageLength
;
107 /* Get the severity code string */
110 case SYSSETUP_SEVERITY_INFORMATION
:
111 lpSeverityString
= "Information : ";
114 case SYSSETUP_SEVERITY_WARNING
:
115 lpSeverityString
= "Warning : ";
118 case SYSSETUP_SEVERITY_ERROR
:
119 lpSeverityString
= "Error : ";
122 case SYSSETUP_SEVERITY_FATAL_ERROR
:
123 lpSeverityString
= "Fatal error : ";
127 lpSeverityString
= "Unknown : ";
131 /* Get length of the converted ansi string */
132 dwMessageLength
= wcslen(lpMessageText
) * sizeof(WCHAR
);
133 RtlUnicodeToMultiByteSize(&dwMessageSize
,
137 /* Allocate message string buffer */
138 lpMessageString
= (LPSTR
) HeapAlloc(GetProcessHeap(),
141 if (!lpMessageString
)
144 /* Convert unicode to ansi */
145 RtlUnicodeToMultiByteN(lpMessageString
,
151 /* Set file pointer to the end of the file */
152 SetFilePointer(hLogFile
,
157 /* Write file name */
165 WriteFile(hLogFile
, ",", 1, &dwWritten
, NULL
);
167 /* Write line number */
168 snprintf(Buffer
, sizeof(Buffer
), "%lu", dwLineNumber
);
176 WriteFile(hLogFile
, ",", 1, &dwWritten
, NULL
);
178 /* Write severity code */
181 strlen(lpSeverityString
),
185 /* Write message string */
199 HeapFree(GetProcessHeap(),