Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 #include "stdafx.h" | |
2 | |
3 #include <fstream> | |
4 #include <stdio.h> | |
5 | |
6 #include "Debug.h" | |
7 #include "Utils.h" | |
8 | |
9 #ifdef _DEBUG | |
Felix Dahlke
2013/06/04 06:57:58
I assume this is something defined in the plugin?
Wladimir Palant
2013/06/04 09:33:59
No, this is defined by the compiler.
Felix Dahlke
2013/06/04 09:39:09
Hm, didn't know that one, seems to be MSVS only. B
| |
10 | |
11 namespace | |
12 { | |
13 class CriticalSection | |
14 { | |
15 public: | |
16 CriticalSection() | |
17 { | |
18 InitializeCriticalSection(§ion); | |
19 } | |
20 | |
21 ~CriticalSection() | |
Felix Dahlke
2013/06/04 06:57:58
Rule of Three again :P I suggest making copy const
| |
22 { | |
23 DeleteCriticalSection(§ion); | |
24 } | |
25 | |
26 class Lock | |
27 { | |
28 public: | |
29 Lock(CriticalSection& cs) | |
30 : section(&cs.section) | |
31 { | |
32 EnterCriticalSection(section); | |
33 } | |
34 | |
35 ~Lock() | |
Felix Dahlke
2013/06/04 06:57:58
Same as above, should have a private copy construc
| |
36 { | |
37 LeaveCriticalSection(section); | |
38 } | |
39 private: | |
40 LPCRITICAL_SECTION section; | |
41 }; | |
42 private: | |
43 CRITICAL_SECTION section; | |
44 }; | |
45 | |
46 static CriticalSection debugLock; | |
Felix Dahlke
2013/06/04 06:57:58
static in namespaces is deprecated in C++. Don't t
| |
47 } | |
48 | |
49 void Debug(const std::string& text) | |
50 { | |
51 SYSTEMTIME st; | |
52 ::GetSystemTime(&st); | |
53 | |
54 char timeBuf[14]; | |
55 _snprintf_s(timeBuf, _TRUNCATE, "%02i:%02i:%02i.%03i", st.wHour, st.wMinute, s t.wSecond, st.wMilliseconds); | |
56 | |
57 std::wstring filePath = GetAppDataPath() + L"\\debug_engine.txt"; | |
58 | |
59 CriticalSection::Lock lock(debugLock); | |
60 std::ofstream out(filePath, std::ios::app); | |
61 out << timeBuf << " - " << text << std::endl; | |
62 out.flush(); | |
63 } | |
64 | |
65 void DebugLastError(const std::string& message) | |
66 { | |
67 std::stringstream stream; | |
68 stream << message << " (Error code: " << GetLastError() << ")"; | |
69 Debug(stream.str()); | |
70 } | |
71 | |
72 void DebugException(const std::exception& exception) | |
73 { | |
74 Debug(std::string("An exception occurred: ") + exception.what()); | |
75 } | |
76 | |
77 #endif // _DEBUG | |
OLD | NEW |