ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

logfile.c
Go to the documentation of this file.
00001 /*
00002  *  ReactOS kernel
00003  *  Copyright (C) 2003 ReactOS Team
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License along
00016  *  with this program; if not, write to the Free Software Foundation, Inc.,
00017  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 /*
00020  * COPYRIGHT:         See COPYING in the top level directory
00021  * PROJECT:           ReactOS system libraries
00022  * PURPOSE:           Log file functions
00023  * FILE:              lib/syssetup/logfile.c
00024  * PROGRAMER:         Eric Kohl
00025  */
00026 
00027 /* INCLUDES *****************************************************************/
00028 #include "precomp.h"
00029 
00030 /* GLOBALS ******************************************************************/
00031 
00032 HANDLE hLogFile = NULL;
00033 
00034 
00035 /* FUNCTIONS ****************************************************************/
00036 
00037 BOOL WINAPI
00038 InitializeSetupActionLog (BOOL bDeleteOldLogFile)
00039 {
00040     WCHAR szFileName[MAX_PATH];
00041 
00042     GetWindowsDirectoryW(szFileName, MAX_PATH);
00043 
00044     if (szFileName[wcslen(szFileName)] != L'\\')
00045     {
00046         wcsncat(szFileName,
00047                 L"\\",
00048                 MAX_PATH);
00049     }
00050     wcsncat(szFileName,
00051             L"setuplog.txt",
00052             MAX_PATH);
00053 
00054     if (bDeleteOldLogFile)
00055     {
00056         SetFileAttributesW(szFileName, FILE_ATTRIBUTE_NORMAL);
00057         DeleteFileW(szFileName);
00058     }
00059 
00060     hLogFile = CreateFileW(szFileName,
00061                            GENERIC_READ | GENERIC_WRITE,
00062                            FILE_SHARE_READ | FILE_SHARE_WRITE,
00063                            NULL,
00064                            OPEN_ALWAYS,
00065                            FILE_ATTRIBUTE_NORMAL,
00066                            NULL);
00067     if (hLogFile == INVALID_HANDLE_VALUE)
00068     {
00069         hLogFile = NULL;
00070         return FALSE;
00071     }
00072 
00073     return TRUE;
00074 }
00075 
00076 
00077 VOID WINAPI
00078 TerminateSetupActionLog(VOID)
00079 {
00080     if (hLogFile != NULL)
00081     {
00082         CloseHandle (hLogFile);
00083         hLogFile = NULL;
00084     }
00085 }
00086 
00087 
00088 BOOL WINAPI
00089 SYSSETUP_LogItem(IN const LPSTR lpFileName,
00090                  IN DWORD dwLineNumber,
00091                  IN DWORD dwSeverity,
00092                  IN LPWSTR lpMessageText)
00093 {
00094     LPCSTR lpSeverityString;
00095     LPSTR lpMessageString;
00096     DWORD dwMessageLength;
00097     DWORD dwMessageSize;
00098     DWORD dwWritten;
00099     CHAR Buffer[6];
00100 
00101     /* Get the severity code string */
00102     switch (dwSeverity)
00103     {
00104         case SYSSETUP_SEVERITY_INFORMATION:
00105             lpSeverityString = "Information : ";
00106             break;
00107 
00108         case SYSSETUP_SEVERITY_WARNING:
00109             lpSeverityString = "Warning : ";
00110             break;
00111 
00112         case SYSSETUP_SEVERITY_ERROR:
00113             lpSeverityString = "Error : ";
00114             break;
00115 
00116         case SYSSETUP_SEVERITY_FATAL_ERROR:
00117             lpSeverityString = "Fatal error : ";
00118             break;
00119 
00120         default:
00121             lpSeverityString = "Unknown : ";
00122             break;
00123     }
00124 
00125     /* Get length of the converted ansi string */
00126     dwMessageLength = wcslen(lpMessageText) * sizeof(WCHAR);
00127     RtlUnicodeToMultiByteSize(&dwMessageSize,
00128                               lpMessageText,
00129                               dwMessageLength);
00130 
00131     /* Allocate message string buffer */
00132     lpMessageString = (LPSTR) HeapAlloc(GetProcessHeap(),
00133                                         HEAP_ZERO_MEMORY,
00134                                         dwMessageSize);
00135     if (!lpMessageString)
00136         return FALSE;
00137 
00138     /* Convert unicode to ansi */
00139     RtlUnicodeToMultiByteN(lpMessageString,
00140                            dwMessageSize,
00141                            NULL,
00142                            lpMessageText,
00143                            dwMessageLength);
00144 
00145     /* Set file pointer to the end of the file */
00146     SetFilePointer(hLogFile,
00147                    0,
00148                    NULL,
00149                    FILE_END);
00150 
00151     /* Write file name */
00152     WriteFile(hLogFile,
00153               lpFileName,
00154               strlen(lpFileName),
00155               &dwWritten,
00156               NULL);
00157 
00158     /* Write comma */
00159     WriteFile(hLogFile, ",", 1, &dwWritten, NULL);
00160 
00161     /* Write line number */
00162     snprintf(Buffer, sizeof(Buffer), "%lu", dwLineNumber);
00163     WriteFile(hLogFile,
00164               Buffer,
00165               strlen(Buffer),
00166               &dwWritten,
00167               NULL);
00168 
00169     /* Write comma */
00170     WriteFile(hLogFile, ",", 1, &dwWritten, NULL);
00171 
00172     /* Write severity code */
00173     WriteFile(hLogFile,
00174               lpSeverityString,
00175               strlen(lpSeverityString),
00176               &dwWritten,
00177               NULL);
00178 
00179     /* Write message string */
00180     WriteFile(hLogFile,
00181               lpMessageString,
00182               dwMessageSize,
00183               &dwWritten,
00184               NULL);
00185 
00186     /* Write newline */
00187     WriteFile(hLogFile, "\r\n", 2, &dwWritten, NULL);
00188 
00189     HeapFree(GetProcessHeap(),
00190              0,
00191              lpMessageString);
00192 
00193     return TRUE;
00194 }
00195 
00196 /* EOF */

Generated on Sat May 26 2012 04:25:09 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.