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 *****************************************************************/
29 #define WIN32_NO_STATUS
31 #define NTOS_MODE_USER
32 #include <ndk/ntndk.h>
34 #include <syssetup/syssetup.h>
37 /* GLOBALS ******************************************************************/
39 HANDLE hLogFile
= NULL
;
42 /* FUNCTIONS ****************************************************************/
45 InitializeSetupActionLog (BOOL bDeleteOldLogFile
)
47 WCHAR szFileName
[MAX_PATH
];
49 GetWindowsDirectoryW (szFileName
,
52 if (szFileName
[wcslen (szFileName
)] != L
'\\')
62 if (bDeleteOldLogFile
!= FALSE
)
64 SetFileAttributesW (szFileName
,
65 FILE_ATTRIBUTE_NORMAL
);
66 DeleteFileW (szFileName
);
69 hLogFile
= CreateFileW (szFileName
,
70 GENERIC_READ
| GENERIC_WRITE
,
71 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
74 FILE_ATTRIBUTE_NORMAL
,
76 if (hLogFile
== INVALID_HANDLE_VALUE
)
87 TerminateSetupActionLog (VOID
)
91 CloseHandle (hLogFile
);
98 LogItem (DWORD dwSeverity
,
101 LPSTR lpNewLine
= "\r\n";
102 LPSTR lpSeverityString
;
103 LPSTR lpMessageString
;
104 DWORD dwMessageLength
;
108 /* Get the severity code string */
111 case SYSSETUP_SEVERITY_INFORMATION
:
112 lpSeverityString
= "Information : ";
115 case SYSSETUP_SEVERITY_WARNING
:
116 lpSeverityString
= "Warning : ";
119 case SYSSETUP_SEVERITY_ERROR
:
120 lpSeverityString
= "Error : ";
123 case SYSSETUP_SEVERITY_FATAL_ERROR
:
124 lpSeverityString
= "Fatal error : ";
128 lpSeverityString
= "Unknown : ";
132 /* Get length of the converted ansi string */
133 dwMessageLength
= wcslen(lpMessageText
) * sizeof(WCHAR
);
134 RtlUnicodeToMultiByteSize (&dwMessageSize
,
138 /* Allocate message string buffer */
139 lpMessageString
= (LPSTR
) HeapAlloc (GetProcessHeap (),
142 if (lpMessageString
== NULL
)
147 /* Convert unicode to ansi */
148 RtlUnicodeToMultiByteN (lpMessageString
,
154 /* Set file pointer to the end of the file */
155 SetFilePointer (hLogFile
,
160 /* Write severity code */
163 strlen (lpSeverityString
),
167 /* Write message string */
181 HeapFree (GetProcessHeap (),