From 7aff1e4cb053394db57c2814d5fe1e6493e0cc75 Mon Sep 17 00:00:00 2001 From: watcherhd Date: Sat, 26 Nov 2011 14:19:43 +0000 Subject: Project folders rename part 2 git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@214 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb --- Dbx_tree/Logger.cpp | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 Dbx_tree/Logger.cpp (limited to 'Dbx_tree/Logger.cpp') diff --git a/Dbx_tree/Logger.cpp b/Dbx_tree/Logger.cpp new file mode 100644 index 0000000..551824d --- /dev/null +++ b/Dbx_tree/Logger.cpp @@ -0,0 +1,124 @@ +/* + +dbx_tree: tree database driver for Miranda IM + +Copyright 2007-2010 Michael "Protogenes" Kunz, + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "Logger.h" +#include + +CLogger CLogger::_Instance; + +CLogger::CLogger() + : m_Length(0), + m_Level(logNOTICE) +{ + +} + +CLogger::~CLogger() +{ + for (std::vector::iterator it = m_Messages.begin(); it != m_Messages.end(); ++it) + delete [] *it; +} + +void CLogger::Append(const TCHAR * File, const TCHAR * Function, const int Line, DWORD SysState, TLevel Level, const TCHAR * Message, ...) +{ + if (m_Level < Level) + m_Level = Level; + + time_t rawtime = time(NULL); + tm timeinfo; + TCHAR timebuf[80]; + localtime_s(&timeinfo, &rawtime); + size_t len = _tcsftime(timebuf, sizeof(timebuf) / sizeof(*timebuf), _T("%c"), &timeinfo); + + TCHAR msgbuf[4096]; + va_list va; + va_start(va, Message); + len += _vstprintf_s(msgbuf, Message, va); + va_end(va); + + TCHAR * message; + if (SysState) + { + TCHAR syserror[2048]; + len += FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, SysState, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), syserror, 2048, NULL); + + len += /*_tcslen(File) + 10 +*/ _tcslen(Function) + 32 + 12 + 1; + + message = new TCHAR[len]; + m_Length += _stprintf_s(message, len, _T("[%s - %s]\n%s\n\nSystem Error Code: %d\n%s\n\n"), timebuf, /*File, Line, */ Function, msgbuf, SysState, syserror) + 1; + } else { + len += /*_tcslen(File) + 10 +*/ _tcslen(Function) + 12 + 1; + + message = new TCHAR[len]; + m_Length += _stprintf_s(message, len, _T("[%s - %s]\n%s\n\n"), timebuf, /*File, Line, */Function, msgbuf) + 1; + } + m_Messages.push_back(message); +} + +CLogger::TLevel CLogger::ShowMessage(TLevel CanAsyncTill) +{ + if (m_Messages.size() == 0) + return logNOTICE; + + TCHAR * msg = new TCHAR[m_Length]; + *msg = 0; + + for (std::vector::iterator it = m_Messages.begin(); it != m_Messages.end(); ++it) + { + _tcscat_s(msg, m_Length, *it); + delete [] *it; + } + m_Messages.clear(); + + if (m_Level <= CanAsyncTill) + { + MSGBOXPARAMS * p = new MSGBOXPARAMS; + p->cbSize = sizeof(*p); + p->hwndOwner = 0; + p->hInstance = NULL; + p->lpszText = msg; + p->lpszCaption = _T(gInternalNameLong); + p->dwStyle = MB_OK | (m_Level >= logERROR)?MB_ICONHAND:((m_Level == logWARNING)?MB_ICONWARNING:MB_ICONINFORMATION); + p->lpszIcon = NULL; + p->dwContextHelpId = 0; + p->lpfnMsgBoxCallback = NULL; + p->dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL); + + _beginthread(&CLogger::MessageBoxAsync, 0, p); + } else { + MessageBox(0, msg, _T(gInternalNameLong), MB_OK | (m_Level >= logERROR)?MB_ICONHAND:((m_Level == logWARNING)?MB_ICONWARNING:MB_ICONINFORMATION)); + delete [] msg; + } + + TLevel tmp = m_Level; + m_Level = logNOTICE; + return tmp; +} + +void CLogger::MessageBoxAsync(void * MsgBoxParams) +{ + MSGBOXPARAMS* p = reinterpret_cast(MsgBoxParams); + MessageBoxIndirect(p); + if (p->lpszText) + delete [] p->lpszText; + delete p; +} \ No newline at end of file -- cgit v1.2.3