annotate Log.cpp @ 2287:4e3236a4ea63

GenerateItemsInChest cleaned up a bit, unified the two switches
author Grumpy7
date Sat, 15 Mar 2014 23:42:51 +0100
parents aff7a7b072b7
children f4af3b203f65
rev   line source
2253
aff7a7b072b7 adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents: 1578
diff changeset
1 #define _CRT_SECURE_NO_WARNINGS
0
Ritor1
parents:
diff changeset
2 #include "Log.h"
Ritor1
parents:
diff changeset
3
Ritor1
parents:
diff changeset
4 #include <stdio.h>
Ritor1
parents:
diff changeset
5 #include <windows.h>
1481
0356a84be1cf uses std funcs instead
Beri Levi berilevi@gmail.com
parents: 1297
diff changeset
6
0
Ritor1
parents:
diff changeset
7 HANDLE hStdOut = nullptr;
Ritor1
parents:
diff changeset
8
Ritor1
parents:
diff changeset
9
Ritor1
parents:
diff changeset
10 void Log::Initialize()
Ritor1
parents:
diff changeset
11 {
Ritor1
parents:
diff changeset
12 if (AllocConsole())
Ritor1
parents:
diff changeset
13 hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
Ritor1
parents:
diff changeset
14 }
Ritor1
parents:
diff changeset
15
Ritor1
parents:
diff changeset
16
Ritor1
parents:
diff changeset
17 void Log::Warning(const wchar_t *pFormat, ...)
Ritor1
parents:
diff changeset
18 {
Ritor1
parents:
diff changeset
19 if (!hStdOut)
Ritor1
parents:
diff changeset
20 return;
Ritor1
parents:
diff changeset
21
Ritor1
parents:
diff changeset
22 va_list args;
1566
1e5086f7d401 undoing 1481
Grumpy7
parents: 1481
diff changeset
23 wchar_t pMsg[8192];
0
Ritor1
parents:
diff changeset
24
Ritor1
parents:
diff changeset
25 va_start(args, pFormat);
1566
1e5086f7d401 undoing 1481
Grumpy7
parents: 1481
diff changeset
26 vswprintf_s(pMsg, 8192, pFormat, args);
0
Ritor1
parents:
diff changeset
27 va_end(args);
Ritor1
parents:
diff changeset
28
1566
1e5086f7d401 undoing 1481
Grumpy7
parents: 1481
diff changeset
29 DWORD w;
1578
56cc81b1ed49 workaround for crash on startup
Beri Levi berilevi@gmail.com
parents: 1566
diff changeset
30 WriteConsoleW(hStdOut, pMsg, lstrlenW(pMsg), &w, nullptr);
56cc81b1ed49 workaround for crash on startup
Beri Levi berilevi@gmail.com
parents: 1566
diff changeset
31 WriteConsoleW(hStdOut, L"\r\n", 2, &w, nullptr);
0
Ritor1
parents:
diff changeset
32 }
1297
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
33 //----- (004BE386) --------------------------------------------------------
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
34 void __fastcall log_error(const char *pMessage)
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
35 {
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
36 const char *v1; // edi@1
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
37 FILE *f; // eax@1
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
38 FILE *v3; // esi@1
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
39
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
40 v1 = pMessage;
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
41 f = fopen("errorlog.txt", "a");
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
42 v3 = f;
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
43 if ( f )
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
44 {
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
45 fprintf(f, "%s\n", v1);
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
46 fclose(v3);
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
47 fflush(v3);
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
48 }
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
49 }