Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/plugin/PluginDebug.cpp

Issue 6288156869525504: Issue #276 - eliminate CString from GetDataPath (Closed)
Patch Set: Created July 30, 2014, 8:59 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/plugin/PluginSettings.h » ('j') | src/plugin/PluginSettings.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include "PluginDebug.h" 3 #include "PluginDebug.h"
4 #include "PluginMutex.h" 4 #include "PluginMutex.h"
5 #include "PluginSettings.h" 5 #include "PluginSettings.h"
6 6
7 7
8 class CPluginDebugLock : public CPluginMutex 8 class CPluginDebugLock : public CPluginMutex
9 { 9 {
10 10
(...skipping 25 matching lines...) Expand all
36 CONSOLE("%s", CT2A(text.GetString(), CP_UTF8)); 36 CONSOLE("%s", CT2A(text.GetString(), CP_UTF8));
37 #endif 37 #endif
38 38
39 if (CPluginSettings::HasInstance()) 39 if (CPluginSettings::HasInstance())
40 { 40 {
41 #ifdef ENABLE_DEBUG_SPLIT_FILE 41 #ifdef ENABLE_DEBUG_SPLIT_FILE
42 CPluginSettings* settings = CPluginSettings::GetInstance(); 42 CPluginSettings* settings = CPluginSettings::GetInstance();
43 43
44 bool isWorkingThread = settings->IsWorkingThread(dwThreadId); 44 bool isWorkingThread = settings->IsWorkingThread(dwThreadId);
45 45
46 CString processor; 46 std::wstring processor;
47 wchar_t tmp[10]; 47 wchar_t tmp[10];
48 _itow_s(::GetCurrentProcessId(), tmp, 10); 48 _itow_s(::GetCurrentProcessId(), tmp, 10);
49 if (isWorkingThread) 49 if (isWorkingThread)
50 processor = L"tab" + CString(tmp) + L"_thread"; 50 processor = L"tab" + std::wstring(tmp) + L"_thread";
51 else 51 else
52 processor = L"tab" + CString(tmp) + L"_ui"; 52 processor = L"tab" + std::wstring(tmp) + L"_ui";
53 #else 53 #else
54 if (dwProcessId == 0) 54 if (dwProcessId == 0)
55 { 55 {
56 dwProcessId = ::GetCurrentProcessId(); 56 dwProcessId = ::GetCurrentProcessId();
57 } 57 }
58 if (dwThreadId == 0) 58 if (dwThreadId == 0)
59 { 59 {
60 dwThreadId = ::GetCurrentThreadId(); 60 dwThreadId = ::GetCurrentThreadId();
61 } 61 }
62 62
63 CStringA processInfo; 63 CStringA processInfo;
64 processInfo.Format("%4.4u.%4.4u - ", dwProcessId, dwThreadId); 64 processInfo.Format("%4.4u.%4.4u - ", dwProcessId, dwThreadId);
65 #endif 65 #endif
66 SYSTEMTIME st; 66 SYSTEMTIME st;
67 ::GetSystemTime(&st); 67 ::GetSystemTime(&st);
68 68
69 CStringA sysTime; 69 CStringA sysTime;
70 sysTime.Format("%2.2d:%2.2d:%2.2d.%3.3d - ", st.wHour, st.wMinute, st.wSecon d, st.wMilliseconds); 70 sysTime.Format("%2.2d:%2.2d:%2.2d.%3.3d - ", st.wHour, st.wMinute, st.wSecon d, st.wMilliseconds);
71 71
72 CPluginDebugLock lock; 72 CPluginDebugLock lock;
73 if (lock.IsLocked()) 73 if (lock.IsLocked())
74 { 74 {
75 std::ofstream debugFile; 75 std::ofstream debugFile;
76 76
77 #ifdef ENABLE_DEBUG_SPLIT_FILE 77 #ifdef ENABLE_DEBUG_SPLIT_FILE
78 debugFile.open(CPluginSettings::GetDataPath(L"debug_" + processor + L".txt "), std::ios::app); 78 debugFile.open(GetDataPath(L"debug_" + processor + L".txt"), std::ios::app );
79 #else 79 #else
80 debugFile.open(CPluginSettings::GetDataPath(L"debug.txt"), std::ios::app); 80 debugFile.open(GetDataPath(L"debug.txt"), std::ios::app);
81 #endif 81 #endif
82 int pos = 0; 82 int pos = 0;
83 CStringA line = text.Tokenize(L"\n\r", pos); 83 CStringA line = text.Tokenize(L"\n\r", pos);
84 84
85 while (pos >= 0) 85 while (pos >= 0)
86 { 86 {
87 debugFile.write(sysTime.GetBuffer(), sysTime.GetLength()); 87 debugFile.write(sysTime.GetBuffer(), sysTime.GetLength());
88 #ifndef ENABLE_DEBUG_SPLIT_FILE 88 #ifndef ENABLE_DEBUG_SPLIT_FILE
89 debugFile.write(processInfo.GetBuffer(), processInfo.GetLength()); 89 debugFile.write(processInfo.GetBuffer(), processInfo.GetLength());
90 #endif 90 #endif
91 debugFile.write(line.GetBuffer(), line.GetLength()); 91 debugFile.write(line.GetBuffer(), line.GetLength());
92 debugFile.write("\n", 1); 92 debugFile.write("\n", 1);
93 93
94 line = text.Tokenize(L"\n\r", pos); 94 line = text.Tokenize(L"\n\r", pos);
95 } 95 }
96 96
97 debugFile.flush(); 97 debugFile.flush();
98 } 98 }
99 } 99 }
100 } 100 }
101 101
102 void CPluginDebug::DebugClear() 102 void CPluginDebug::DebugClear()
103 { 103 {
104 CPluginDebugLock lock; 104 CPluginDebugLock lock;
105 if (lock.IsLocked()) 105 if (lock.IsLocked())
106 { 106 {
107 ::DeleteFile(CPluginSettings::GetDataPath(L"debug.txt")); 107 DeleteFileW(GetDataPath(L"debug.txt").c_str());
108 ::DeleteFile(CPluginSettings::GetDataPath(L"debug_main_ui.txt")); 108 DeleteFileW(GetDataPath(L"debug_main_ui.txt").c_str());
109 ::DeleteFile(CPluginSettings::GetDataPath(L"debug_main_thread.txt")); 109 DeleteFileW(GetDataPath(L"debug_main_thread.txt").c_str());
110 110
111 for (int i = 1; i <= 10; i++) 111 for (int i = 1; i <= 10; i++)
112 { 112 {
113 CString x; 113 std::wstring x = std::to_wstring(i);
114 x.Format(L"%d", i); 114 DeleteFileW(GetDataPath(L"debug_tab" + x + L"_ui.txt").c_str());
115 115 DeleteFileW(GetDataPath(L"debug_tab" + x + L"_thread.txt").c_str());
116 ::DeleteFile(CPluginSettings::GetDataPath(L"debug_tab" + x + L"_ui.txt"));
117 ::DeleteFile(CPluginSettings::GetDataPath(L"debug_tab" + x + L"_thread.txt "));
118 } 116 }
119 } 117 }
120 } 118 }
121 119
122 #endif 120 #endif
123 121
124 #if (defined ENABLE_DEBUG_INFO || defined ENABLE_DEBUG_SELFTEST) 122 #if (defined ENABLE_DEBUG_INFO || defined ENABLE_DEBUG_SELFTEST)
125 123
126 void CPluginDebug::DebugError(const CString& error) 124 void CPluginDebug::DebugError(const CString& error)
127 { 125 {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 CStringA sysTime; 160 CStringA sysTime;
163 sysTime.Format("%2.2d:%2.2d:%2.2d.%3.3d - ", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); 161 sysTime.Format("%2.2d:%2.2d:%2.2d.%3.3d - ", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
164 162
165 CStringA textA = text; 163 CStringA textA = text;
166 164
167 CPluginDebugLock lock; 165 CPluginDebugLock lock;
168 if (lock.IsLocked()) 166 if (lock.IsLocked())
169 { 167 {
170 std::ofstream debugFile; 168 std::ofstream debugFile;
171 169
172 debugFile.open(CPluginSettings::GetDataPath("debug_result.txt"), std::ios::a pp); 170 debugFile.open(GetDataPath(L"debug_result.txt"), std::ios::app);
173 debugFile.write(sysTime.GetBuffer(), sysTime.GetLength()); 171 debugFile.write(sysTime.GetBuffer(), sysTime.GetLength());
174 debugFile.write(LPCSTR(textA), textA.GetLength()); 172 debugFile.write(LPCSTR(textA), textA.GetLength());
175 debugFile.write("\n", 1); 173 debugFile.write("\n", 1);
176 debugFile.flush(); 174 debugFile.flush();
177 } 175 }
178 } 176 }
179 177
180 void CPluginDebug::DebugResultDomain(const CString& domain) 178 void CPluginDebug::DebugResultDomain(const CString& domain)
181 { 179 {
182 DebugResult(L"================================================================ ================================================================================ ==========================================="); 180 DebugResult(L"================================================================ ================================================================================ ===========================================");
(...skipping 30 matching lines...) Expand all
213 211
214 DebugResult(blocking); 212 DebugResult(blocking);
215 } 213 }
216 214
217 215
218 void CPluginDebug::DebugResultClear() 216 void CPluginDebug::DebugResultClear()
219 { 217 {
220 CPluginDebugLock lock; 218 CPluginDebugLock lock;
221 if (lock.IsLocked()) 219 if (lock.IsLocked())
222 { 220 {
223 ::DeleteFile(CPluginSettings::GetDataPath("debug_result.txt")); 221 DeleteFileW(GetDataPath(L"debug_result.txt").c_str());
224 } 222 }
225 } 223 }
226 224
227 #endif // ENABLE_DEBUG_RESULT 225 #endif // ENABLE_DEBUG_RESULT
228 226
229 227
230 #ifdef ENABLE_DEBUG_RESULT_IGNORED 228 #ifdef ENABLE_DEBUG_RESULT_IGNORED
231 229
232 void CPluginDebug::DebugResultIgnoring(const CString& type, const CString& src, const CString& domain) 230 void CPluginDebug::DebugResultIgnoring(const CString& type, const CString& src, const CString& domain)
233 { 231 {
234 CString srcTrunc = src; 232 CString srcTrunc = src;
235 if (srcTrunc.GetLength() > 100) 233 if (srcTrunc.GetLength() > 100)
236 { 234 {
237 srcTrunc = src.Left(67) + L"..." + src.Right(30); 235 srcTrunc = src.Left(67) + L"..." + src.Right(30);
238 } 236 }
239 237
240 CString blocking; 238 CString blocking;
241 blocking.Format(L"Ignored %-12s %s %s", type, domain.IsEmpty()? L"-" : doma in, srcTrunc); 239 blocking.Format(L"Ignored %-12s %s %s", type, domain.IsEmpty()? L"-" : doma in, srcTrunc);
242 240
243 DebugResult(blocking); 241 DebugResult(blocking);
244 } 242 }
245 243
246 #endif // ENABLE_DEBUG_RESULT_IGNORED 244 #endif // ENABLE_DEBUG_RESULT_IGNORED
OLDNEW
« no previous file with comments | « no previous file | src/plugin/PluginSettings.h » ('j') | src/plugin/PluginSettings.h » ('J')

Powered by Google App Engine
This is Rietveld