ReactOS  0.4.14-dev-49-gfb4591c
logfile.c File Reference
#include "precomp.h"
#include <stdarg.h>
Include dependency graph for logfile.c:

Go to the source code of this file.

Macros

#define FORMAT_BUFFER_SIZE   512
 
#define LINE_BUFFER_SIZE   1024
 

Functions

BOOL WINAPI InitializeSetupActionLog (BOOL bDeleteOldLogFile)
 
VOID WINAPI TerminateSetupActionLog (VOID)
 
VOID CDECL pSetupDebugPrint (IN PCWSTR pszFileName, IN INT nLineNumber, IN PCWSTR pszTag, IN PCWSTR pszMessage,...)
 

Variables

HANDLE hLogFile = NULL
 

Macro Definition Documentation

◆ FORMAT_BUFFER_SIZE

#define FORMAT_BUFFER_SIZE   512

Definition at line 36 of file logfile.c.

◆ LINE_BUFFER_SIZE

#define LINE_BUFFER_SIZE   1024

Definition at line 37 of file logfile.c.

Function Documentation

◆ InitializeSetupActionLog()

BOOL WINAPI InitializeSetupActionLog ( BOOL  bDeleteOldLogFile)

Definition at line 42 of file logfile.c.

43 {
44  WCHAR szFileName[MAX_PATH];
45 
46  GetWindowsDirectoryW(szFileName, MAX_PATH);
47 
48  if (szFileName[wcslen(szFileName)] != L'\\')
49  {
50  wcsncat(szFileName,
51  L"\\",
52  (sizeof(szFileName) / sizeof(szFileName[0])) - wcslen(szFileName));
53  }
54  wcsncat(szFileName,
55  L"setuplog.txt",
56  (sizeof(szFileName) / sizeof(szFileName[0])) - wcslen(szFileName));
57 
58  if (bDeleteOldLogFile)
59  {
61  DeleteFileW(szFileName);
62  }
63 
64  hLogFile = CreateFileW(szFileName,
67  NULL,
70  NULL);
72  {
73  hLogFile = NULL;
74  return FALSE;
75  }
76 
77  return TRUE;
78 }
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:944
#define TRUE
Definition: types.h:120
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2351
#define GENERIC_WRITE
Definition: nt_native.h:90
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
HANDLE hLogFile
Definition: logfile.c:34
#define OPEN_ALWAYS
Definition: disk.h:70
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:124
_CRTIMP wchar_t *__cdecl wcsncat(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#define CreateFileW
Definition: compat.h:400
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by InstallReactOS().

◆ pSetupDebugPrint()

VOID CDECL pSetupDebugPrint ( IN PCWSTR  pszFileName,
IN INT  nLineNumber,
IN PCWSTR  pszTag,
IN PCWSTR  pszMessage,
  ... 
)

Definition at line 94 of file logfile.c.

100 {
101  PWSTR pszFormatBuffer = NULL;
102  PWSTR pszLineBuffer = NULL;
103  PSTR pszOutputBuffer = NULL;
104  ULONG ulLineSize, ulOutputSize;
105  DWORD dwWritten;
106  SYSTEMTIME stTime;
107  va_list args;
108 
109  if (hLogFile == NULL)
110  return;
111 
112  GetLocalTime(&stTime);
113 
114  if (pszMessage)
115  {
116  pszFormatBuffer = HeapAlloc(GetProcessHeap(),
118  FORMAT_BUFFER_SIZE * sizeof(WCHAR));
119  if (pszFormatBuffer == NULL)
120  goto done;
121 
122  va_start(args, pszMessage);
123  vsnwprintf(pszFormatBuffer,
125  pszMessage,
126  args);
127  va_end(args);
128  }
129 
130  pszLineBuffer = HeapAlloc(GetProcessHeap(),
132  LINE_BUFFER_SIZE * sizeof(WCHAR));
133  if (pszLineBuffer == NULL)
134  goto done;
135 
136  _snwprintf(pszLineBuffer,
138  L"%02d/%02d/%04d %02d:%02d:%02d.%03d, %s, %d, %s, %s\r\n",
139  stTime.wMonth,
140  stTime.wDay,
141  stTime.wYear,
142  stTime.wHour,
143  stTime.wMinute,
144  stTime.wSecond,
145  stTime.wMilliseconds,
146  pszFileName ? pszFileName : L"",
147  nLineNumber,
148  pszTag ? pszTag : L"",
149  pszFormatBuffer ? pszFormatBuffer : L"");
150 
151  /* Get length of the converted ansi string */
152  ulLineSize = wcslen(pszLineBuffer) * sizeof(WCHAR);
153  RtlUnicodeToMultiByteSize(&ulOutputSize,
154  pszLineBuffer,
155  ulLineSize);
156 
157  /* Allocate message string buffer */
158  pszOutputBuffer = HeapAlloc(GetProcessHeap(),
160  ulOutputSize);
161  if (pszOutputBuffer == NULL)
162  goto done;
163 
164  /* Convert unicode to ansi */
165  RtlUnicodeToMultiByteN(pszOutputBuffer,
166  ulOutputSize,
167  NULL,
168  pszLineBuffer,
169  ulLineSize);
170 
171  /* Set file pointer to the end of the file */
173  0,
174  NULL,
175  FILE_END);
176 
178  pszOutputBuffer,
179  ulOutputSize,
180  &dwWritten,
181  NULL);
182 
183 done:
184  if (pszOutputBuffer)
185  HeapFree(GetProcessHeap(), 0, pszOutputBuffer);
186 
187  if (pszLineBuffer)
188  HeapFree(GetProcessHeap(), 0, pszLineBuffer);
189 
190  if (pszFormatBuffer)
191  HeapFree(GetProcessHeap(), 0, pszFormatBuffer);
192 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define LINE_BUFFER_SIZE
Definition: logfile.c:37
WORD wMonth
Definition: winbase.h:871
uint16_t * PWSTR
Definition: typedefs.h:54
NTSYSAPI NTSTATUS NTAPI RtlUnicodeToMultiByteSize(PULONG MbSize, PCWCH UnicodeString, ULONG UnicodeSize)
Definition: match.c:390
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
WORD wYear
Definition: winbase.h:870
#define va_end(ap)
Definition: acmsvcex.h:90
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:41
WORD wMinute
Definition: winbase.h:875
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:276
#define FORMAT_BUFFER_SIZE
Definition: logfile.c:36
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define FILE_END
Definition: winbase.h:114
__wchar_t WCHAR
Definition: xmlstorage.h:180
__CRT_INLINE int __cdecl vsnwprintf(wchar_t *s, size_t n, const wchar_t *format, va_list arg)
Definition: stdio.h:930
unsigned long DWORD
Definition: ntddk_ex.h:95
HANDLE hLogFile
Definition: logfile.c:34
WORD wSecond
Definition: winbase.h:876
WORD wMilliseconds
Definition: winbase.h:877
NTSYSAPI NTSTATUS NTAPI RtlUnicodeToMultiByteN(PCHAR MbString, ULONG MbSize, PULONG ResultSize, PCWCH UnicodeString, ULONG UnicodeSize)
static const WCHAR L[]
Definition: oid.c:1250
WORD wDay
Definition: winbase.h:873
signed char * PSTR
Definition: retypes.h:7
WORD wHour
Definition: winbase.h:874
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
unsigned int ULONG
Definition: retypes.h:1
#define args
Definition: format.c:66
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ TerminateSetupActionLog()

VOID WINAPI TerminateSetupActionLog ( VOID  )

Definition at line 82 of file logfile.c.

83 {
84  if (hLogFile != NULL)
85  {
87  hLogFile = NULL;
88  }
89 }
#define CloseHandle
Definition: compat.h:398
smooth NULL
Definition: ftsmooth.c:416
HANDLE hLogFile
Definition: logfile.c:34

Referenced by InstallReactOS().

Variable Documentation

◆ hLogFile

HANDLE hLogFile = NULL