From fbe76102e941b9f1edaf236788e42678f05fdf9a Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:08:06 +0200 Subject: 3.9 --- shared/global_func.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 shared/global_func.cpp (limited to 'shared/global_func.cpp') diff --git a/shared/global_func.cpp b/shared/global_func.cpp new file mode 100644 index 00000000..d1ab9d2c --- /dev/null +++ b/shared/global_func.cpp @@ -0,0 +1,93 @@ +// ************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) 2008-2010 ZenJu (zhnmju123 AT gmx.de) * +// ************************************************************************** +// +#include "global_func.h" +#include +#include +#include +#include "system_constants.h" + + +size_t common::getDigitCount(size_t number) //count number of digits +{ + return number == 0 ? 1 : static_cast(::log10(static_cast(number))) + 1; +} + + +//############################################################################ +Performance::Performance() : + resultWasShown(false), + timer(new wxStopWatch) +{ + timer->Start(); +} + + +Performance::~Performance() +{ + //keep non-inline destructor for std::auto_ptr to work with forward declaration + + if (!resultWasShown) + showResult(); +} + + +void Performance::showResult() +{ + resultWasShown = true; + wxMessageBox(wxLongLong(timer->Time()).ToString() + wxT(" ms")); + timer->Start(); //reset timer +} + + +//############################################################################ +DebugLog::DebugLog() : + lineCount(0), + logFile(NULL) +{ + logFile = new wxFile; + logfileName = assembleFileName(); + logFile->Open(logfileName.c_str(), wxFile::write); +} + + +DebugLog::~DebugLog() +{ + delete logFile; //automatically closes file handle +} + + +wxString DebugLog::assembleFileName() +{ + wxString tmp = wxDateTime::Now().FormatISOTime(); + tmp.Replace(wxT(":"), wxEmptyString); + return wxString(wxT("DEBUG_")) + wxDateTime::Now().FormatISODate() + wxChar('_') + tmp + wxT(".log"); +} + + +void DebugLog::write(const wxString& logText) +{ + ++lineCount; + if (lineCount % 50000 == 0) //prevent logfile from becoming too big + { + logFile->Close(); + wxRemoveFile(logfileName); + + logfileName = assembleFileName(); + logFile->Open(logfileName.c_str(), wxFile::write); + } + + logFile->Write(wxString(wxT("[")) + wxDateTime::Now().FormatTime() + wxT("] ")); + logFile->Write(logText + common::LINE_BREAK); +} + +//DebugLog logDebugInfo; + + +wxString getCodeLocation(const wxString file, const int line) +{ + return wxString(file).AfterLast(common::FILE_NAME_SEPARATOR) + wxT(", LINE ") + wxLongLong(line).ToString() + wxT(" | "); +} -- cgit