annotate Log.cpp @ 2465:b054ea5daf45

cleaning project part 3
author zipi
date Sun, 17 Aug 2014 20:23:06 +0100
parents f4af3b203f65
children
rev   line source
2415
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2253
diff changeset
1 #define _CRTDBG_MAP_ALLOC
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2253
diff changeset
2 #include <stdlib.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2253
diff changeset
3 #include <crtdbg.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2253
diff changeset
4
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
5 #define _CRT_SECURE_NO_WARNINGS
0
Ritor1
parents:
diff changeset
6 #include "Log.h"
Ritor1
parents:
diff changeset
7
Ritor1
parents:
diff changeset
8 #include <stdio.h>
Ritor1
parents:
diff changeset
9 #include <windows.h>
1481
0356a84be1cf uses std funcs instead
Beri Levi berilevi@gmail.com
parents: 1297
diff changeset
10
0
Ritor1
parents:
diff changeset
11 HANDLE hStdOut = nullptr;
Ritor1
parents:
diff changeset
12
Ritor1
parents:
diff changeset
13
Ritor1
parents:
diff changeset
14 void Log::Initialize()
Ritor1
parents:
diff changeset
15 {
Ritor1
parents:
diff changeset
16 if (AllocConsole())
Ritor1
parents:
diff changeset
17 hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
Ritor1
parents:
diff changeset
18 }
Ritor1
parents:
diff changeset
19
Ritor1
parents:
diff changeset
20
Ritor1
parents:
diff changeset
21 void Log::Warning(const wchar_t *pFormat, ...)
Ritor1
parents:
diff changeset
22 {
Ritor1
parents:
diff changeset
23 if (!hStdOut)
Ritor1
parents:
diff changeset
24 return;
Ritor1
parents:
diff changeset
25
Ritor1
parents:
diff changeset
26 va_list args;
1566
1e5086f7d401 undoing 1481
Grumpy7
parents: 1481
diff changeset
27 wchar_t pMsg[8192];
0
Ritor1
parents:
diff changeset
28
Ritor1
parents:
diff changeset
29 va_start(args, pFormat);
1566
1e5086f7d401 undoing 1481
Grumpy7
parents: 1481
diff changeset
30 vswprintf_s(pMsg, 8192, pFormat, args);
0
Ritor1
parents:
diff changeset
31 va_end(args);
Ritor1
parents:
diff changeset
32
1566
1e5086f7d401 undoing 1481
Grumpy7
parents: 1481
diff changeset
33 DWORD w;
1578
56cc81b1ed49 workaround for crash on startup
Beri Levi berilevi@gmail.com
parents: 1566
diff changeset
34 WriteConsoleW(hStdOut, pMsg, lstrlenW(pMsg), &w, nullptr);
56cc81b1ed49 workaround for crash on startup
Beri Levi berilevi@gmail.com
parents: 1566
diff changeset
35 WriteConsoleW(hStdOut, L"\r\n", 2, &w, nullptr);
0
Ritor1
parents:
diff changeset
36 }
1297
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
37 //----- (004BE386) --------------------------------------------------------
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
38 void __fastcall log_error(const char *pMessage)
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
39 {
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
40 const char *v1; // edi@1
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
41 FILE *f; // eax@1
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
42 FILE *v3; // esi@1
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
43
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
44 v1 = pMessage;
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
45 f = fopen("errorlog.txt", "a");
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
46 v3 = f;
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
47 if ( f )
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
48 {
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
49 fprintf(f, "%s\n", v1);
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
50 fclose(v3);
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
51 fflush(v3);
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
52 }
5450af4f57ef moving files mm7_x ending
Ritor1
parents: 0
diff changeset
53 }