annotate Engine/Log.cpp @ 2553:48708da03b7f

Party Creation UI logic separated from MainMenu
author a.parshin
date Wed, 13 May 2015 02:20:05 +0200
parents 68cdef6879a0
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 }