Adjust the background icon size for high dpi monitors
[TortoiseGit.git] / src / Utils / DebugOutput.h
blobc455febbe4bbdacf57c8e8f9f41be9339f23c545
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009, 2011, 2013-2014 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
20 #include "registry.h"
23 class CTraceToOutputDebugString
25 public:
26 static CTraceToOutputDebugString& Instance()
28 if (!m_pInstance)
29 m_pInstance = new CTraceToOutputDebugString;
30 return *m_pInstance;
33 static bool Active()
35 return Instance().m_bActive;
38 // Non Unicode output helper
39 void operator()(PCSTR pszFormat, ...)
41 if (m_bActive)
43 va_list ptr;
44 va_start(ptr, pszFormat);
45 TraceV(pszFormat,ptr);
46 va_end(ptr);
50 // Unicode output helper
51 void operator()(PCWSTR pszFormat, ...)
53 if (m_bActive)
55 va_list ptr;
56 va_start(ptr, pszFormat);
57 TraceV(pszFormat,ptr);
58 va_end(ptr);
62 private:
63 CTraceToOutputDebugString()
64 : m_LastTick(GetTickCount64())
65 , m_bActive(!!CRegStdDWORD(L"Software\\TortoiseGit\\DebugOutputString", FALSE))
69 ~CTraceToOutputDebugString()
71 delete m_pInstance;
73 // prevent cloning
74 CTraceToOutputDebugString(const CTraceToOutputDebugString&);
75 CTraceToOutputDebugString& operator=(const CTraceToOutputDebugString&);
77 ULONGLONG m_LastTick;
78 bool m_bActive;
79 static CTraceToOutputDebugString * m_pInstance;
81 // Non Unicode output helper
82 void TraceV(PCSTR pszFormat, va_list args) const
84 // Format the output buffer
85 char szBuffer[1024];
86 _vsnprintf_s(szBuffer, _countof(szBuffer), _countof(szBuffer)-1, pszFormat, args);
87 OutputDebugStringA(szBuffer);
90 // Unicode output helper
91 void TraceV(PCWSTR pszFormat, va_list args) const
93 wchar_t szBuffer[1024];
94 _vsnwprintf_s(szBuffer, _countof(szBuffer), _countof(szBuffer)-1, pszFormat, args);
95 OutputDebugStringW(szBuffer);
98 bool IsActive()
100 #ifdef DEBUG
101 return true;
102 #else
103 if (GetTickCount64() - m_LastTick > 10000UL)
105 m_LastTick = GetTickCount64();
106 m_bActive = !!CRegStdDWORD(L"Software\\TortoiseGit\\DebugOutputString", FALSE);
108 return m_bActive;
109 #endif