annotate Engine/Log.cpp @ 2499:68cdef6879a0

engine folder
author Ritor1
date Fri, 19 Sep 2014 02:57:42 +0600
parents
children
rev   line source
2499
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
1 #define _CRTDBG_MAP_ALLOC
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
2 #include <stdlib.h>
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
3 #include <crtdbg.h>
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
4
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
5 #define _CRT_SECURE_NO_WARNINGS
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
6 #include "Log.h"
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
7
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
8 #include <stdio.h>
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
9 #include <windows.h>
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
10
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
11 HANDLE hStdOut = nullptr;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
12
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
13
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
14 void Log::Initialize()
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
15 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
16 if (AllocConsole())
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
17 hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
18 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
19
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
20
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
21 void Log::Warning(const wchar_t *pFormat, ...)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
22 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
23 if (!hStdOut)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
24 return;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
25
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
26 va_list args;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
27 wchar_t pMsg[8192];
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
28
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
29 va_start(args, pFormat);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
30 vswprintf_s(pMsg, 8192, pFormat, args);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
31 va_end(args);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
32
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
33 DWORD w;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
34 WriteConsoleW(hStdOut, pMsg, lstrlenW(pMsg), &w, nullptr);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
35 WriteConsoleW(hStdOut, L"\r\n", 2, &w, nullptr);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
36 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
37 //----- (004BE386) --------------------------------------------------------
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
38 void __fastcall log_error(const char *pMessage)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
39 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
40 const char *v1; // edi@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
41 FILE *f; // eax@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
42 FILE *v3; // esi@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
43
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
44 v1 = pMessage;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
45 f = fopen("errorlog.txt", "a");
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
46 v3 = f;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
47 if ( f )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
48 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
49 fprintf(f, "%s\n", v1);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
50 fclose(v3);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
51 fflush(v3);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
52 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
53 }