summaryrefslogtreecommitdiff
path: root/library/globalFunctions.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 16:54:32 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 16:54:32 +0200
commitcbb59ba3fb48fb87065469eaa1b4a34a18851b9e (patch)
tree6f43ab99e0f22a33fccb941ab0441d1bee38adf9 /library/globalFunctions.cpp
parent1.11 (diff)
downloadFreeFileSync-cbb59ba3fb48fb87065469eaa1b4a34a18851b9e.tar.gz
FreeFileSync-cbb59ba3fb48fb87065469eaa1b4a34a18851b9e.tar.bz2
FreeFileSync-cbb59ba3fb48fb87065469eaa1b4a34a18851b9e.zip
1.12
Diffstat (limited to 'library/globalFunctions.cpp')
-rw-r--r--library/globalFunctions.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/library/globalFunctions.cpp b/library/globalFunctions.cpp
index 67b56819..07c34af0 100644
--- a/library/globalFunctions.cpp
+++ b/library/globalFunctions.cpp
@@ -1,5 +1,8 @@
#include "globalFunctions.h"
#include "resources.h"
+#include <wx/msgdlg.h>
+#include <wx/file.h>
+
inline
int globalFunctions::round(const double d)
@@ -123,3 +126,76 @@ void globalFunctions::writeInt(wxOutputStream& stream, const int number)
const char* buffer = reinterpret_cast<const char*>(&number);
stream.Write(buffer, sizeof(int));
}
+
+
+//############################################################################
+Performance::Performance() :
+ resultWasShown(false)
+{
+ timer.Start();
+}
+
+
+Performance::~Performance()
+{
+ if (!resultWasShown)
+ showResult();
+}
+
+
+void Performance::showResult()
+{
+ resultWasShown = true;
+ wxMessageBox(globalFunctions::numberToWxString(unsigned(timer.Time())) + 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 % 10000 == 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 + wxChar('\n'));
+}
+
+//DebugLog logDebugInfo;
+
+
+wxString getCodeLocation(const wxString file, const int line)
+{
+ return wxString(file).AfterLast(GlobalResources::fileNameSeparator) + wxT(", LINE ") + globalFunctions::numberToWxString(line) + wxT(" | ");
+}
bgstack15