summaryrefslogtreecommitdiff
path: root/DebugEngine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'DebugEngine.cpp')
-rw-r--r--DebugEngine.cpp108
1 files changed, 55 insertions, 53 deletions
diff --git a/DebugEngine.cpp b/DebugEngine.cpp
index 2cdfaab..2168210 100644
--- a/DebugEngine.cpp
+++ b/DebugEngine.cpp
@@ -7,11 +7,13 @@
#include <QMessageBox>
#include <QFileDialog>
#include <QLocalSocket>
-#include <QRegularExpression>
+#include <regex>
+#include <iostream>
#include "Variable.h"
#include "DebugEngine.h"
#include "ExtraSocket.h"
+#include "cpp11addition.h"
#ifdef WIN32
# define __func__ __FUNCTION__
@@ -29,7 +31,7 @@
/// \brief initiate the ultracopier event dispatcher and check if no other session is running
DebugEngine::DebugEngine()
{
- fileNameCleaner=QRegularExpression(QStringLiteral("\\.\\.?[/\\\\]([^/]+[/\\\\])?"));
+ //fileNameCleaner=std::regex("\\.\\.?[/\\\\]([^/]+[/\\\\])?");
quit=false;
QStringList ultracopierArguments=QCoreApplication::arguments();
if(ultracopierArguments.size()==2)
@@ -56,12 +58,8 @@ DebugEngine::DebugEngine()
debugHtmlContent+="td {white-space:nowrap;}";
debugHtmlContent+="</style>";
debugHtmlContent+="<title>";
- #ifdef ULTRACOPIER_MODE_SUPERCOPIER
- debugHtmlContent+="Supercopier";
- #else
debugHtmlContent+="Ultracopier";
- #endif
- debugHtmlContent+=" "+QString(ULTRACOPIER_VERSION)+" "+QString(ULTRACOPIER_PLATFORM_NAME)+", debug report</title>";
+ debugHtmlContent+=" "+std::string(ULTRACOPIER_VERSION)+" "+ULTRACOPIER_PLATFORM_NAME.toStdString()+", debug report</title>";
debugHtmlContent+="</head>";
debugHtmlContent+="<body>";
debugHtmlContent+="<table>";
@@ -85,14 +83,14 @@ DebugEngine::DebugEngine()
dir.cdUp();
dir.cdUp();
dir.cd("Data");
- logFile.setFileName(dir.absolutePath()+QDir::separator()+"log.html");
- lockFile.setFileName(dir.absolutePath()+QDir::separator()+"ultracopier.lock");
+ logFile.setFileName(dir.absolutePath()+FacilityEngine::separator()+"log.html");
+ lockFile.setFileName(dir.absolutePath()+FacilityEngine::separator()+"ultracopier.lock");
fileNameIsLoaded=true;
#else
//Load the ultracopier path
QDir dir(QCoreApplication::applicationDirPath());
- logFile.setFileName(dir.absolutePath()+QDir::separator()+"log.html");
- lockFile.setFileName(dir.absolutePath()+QDir::separator()+"ultracopier.lock");
+ logFile.setFileName(dir.absolutePath()+FacilityEngine::separator()+"log.html");
+ lockFile.setFileName(dir.absolutePath()+FacilityEngine::separator()+"ultracopier.lock");
fileNameIsLoaded=true;
#endif
#else
@@ -136,10 +134,10 @@ DebugEngine::DebugEngine()
//Ask to the user
QMessageBox::StandardButton reply = QMessageBox::question(NULL,"Save the previous report",
#ifdef ULTRACOPIER_MODE_SUPERCOPIER
- QString("Supercopier")+
+ QString("Supercopier")+
#else
- QString("Ultracopier")+
- #endif
+ QString("Ultracopier")+
+ #endif
" seam have crashed, do you want save the previous report for report it to the forum?",QMessageBox::Yes|QMessageBox::No,QMessageBox::No);
if(reply==QMessageBox::Yes)
saveBugReport();
@@ -165,7 +163,7 @@ DebugEngine::DebugEngine()
{
logFile.resize(0);
currentBackend=File;
- logFile.write(debugHtmlContent.toUtf8());
+ logFile.write(debugHtmlContent.data(),static_cast<qint64>(debugHtmlContent.size()));
}
}
}
@@ -178,7 +176,7 @@ DebugEngine::~DebugEngine()
{
removeTheLockFile();
//Finalize the log file
- logFile.write(endOfLogFile.toUtf8());
+ logFile.write(endOfLogFile.data(),static_cast<qint64>(endOfLogFile.size()));
logFile.close();
}
}
@@ -231,11 +229,11 @@ bool DebugEngine::removeTheLockFile()
return true;
}
-void DebugEngine::addDebugInformationStatic(const Ultracopier::DebugLevel &level,const QString& function,const QString& text,const QString& file,const int& ligne,const QString& location)
+void DebugEngine::addDebugInformationStatic(const Ultracopier::DebugLevel &level,const std::string& function,const std::string& text,const std::string& file,const int& ligne,const std::string& location)
{
if(DebugEngine::debugEngine==NULL)
{
- qWarning() << QStringLiteral("After close: ") << function << file << ligne;
+ std::cerr << "After close: " << function << file << ligne;
return;
}
DebugLevel_custom tempLevel=DebugLevel_custom_Information;
@@ -259,74 +257,77 @@ void DebugEngine::addDebugInformationStatic(const Ultracopier::DebugLevel &level
DebugEngine::debugEngine->addDebugInformation(tempLevel,function,text,file,ligne,location);
}
-void DebugEngine::addDebugNote(const QString& text)
+void DebugEngine::addDebugNote(const std::string& text)
{
if(DebugEngine::debugEngine==NULL)
return;
- DebugEngine::debugEngine->addDebugInformation(DebugLevel_custom_UserNote,QStringLiteral(""),text,QStringLiteral(""),-1,QStringLiteral("Core"));
+ DebugEngine::debugEngine->addDebugInformation(DebugLevel_custom_UserNote,"",text,"",-1,"Core");
}
/// \brief For add message info, this function is thread safe
-void DebugEngine::addDebugInformation(const DebugLevel_custom &level,const QString& function,const QString& text,QString file,const int& ligne,const QString& location)
+void DebugEngine::addDebugInformation(const DebugLevel_custom &level,const std::string& function,const std::string& text,std::string file,const int& ligne,const std::string& location)
{
if(DebugEngine::debugEngine==NULL)
{
- qWarning() << QStringLiteral("After close: ") << function << file << ligne;
+ std::cerr << "After close: " << function << file << ligne;
return;
}
//Remove the compiler extra patch generated
- file=file.remove(fileNameCleaner);
- QString addDebugInformation_lignestring=QString::number(ligne);
- QString addDebugInformation_fileString=file;
+ //file=file.remove(fileNameCleaner);don't clean, too many performance heart
+ std::string addDebugInformation_lignestring=std::to_string(ligne);
+ std::string addDebugInformation_fileString=file;
if(ligne!=-1)
- addDebugInformation_fileString+=QStringLiteral(":")+addDebugInformation_lignestring;
+ addDebugInformation_fileString+=":"+addDebugInformation_lignestring;
//Load the time from start
- QString addDebugInformation_time = QString::number(startTime.elapsed());
- QString addDebugInformation_htmlFormat;
+ std::string addDebugInformation_time = std::to_string(startTime.elapsed());
+ std::string addDebugInformation_htmlFormat;
bool important=true;
switch(level)
{
case DebugLevel_custom_Information:
- addDebugInformation_htmlFormat=QStringLiteral("<tr class=\"Information\"><td class=\"time\">")+addDebugInformation_time+QStringLiteral("</span></td><td>")+addDebugInformation_fileString+QStringLiteral("</td><td class=\"function\">")+function+QStringLiteral("()</td><td class=\"location\">")+location+QStringLiteral("</td><td>")+htmlEntities(text)+QStringLiteral("</td></tr>\n");
+ addDebugInformation_htmlFormat="<tr class=\"Information\"><td class=\"time\">";
break;
case DebugLevel_custom_Critical:
- addDebugInformation_htmlFormat=QStringLiteral("<tr class=\"Critical\"><td class=\"time\">")+addDebugInformation_time+QStringLiteral("</span></td><td>")+addDebugInformation_fileString+QStringLiteral("</td><td class=\"function\">")+function+QStringLiteral("()</td><td class=\"location\">")+location+QStringLiteral("</td><td>")+htmlEntities(text)+QStringLiteral("</td></tr>\n");
+ addDebugInformation_htmlFormat="<tr class=\"Critical\"><td class=\"time\">";
break;
case DebugLevel_custom_Warning:
- addDebugInformation_htmlFormat=QStringLiteral("<tr class=\"Warning\"><td class=\"time\">")+addDebugInformation_time+QStringLiteral("</span></td><td>")+addDebugInformation_fileString+QStringLiteral("</td><td class=\"function\">")+function+QStringLiteral("()</td><td class=\"location\">")+location+QStringLiteral("</td><td>")+htmlEntities(text)+QStringLiteral("</td></tr>\n");
+ addDebugInformation_htmlFormat="<tr class=\"Warning\"><td class=\"time\">";
break;
case DebugLevel_custom_Notice:
{
- addDebugInformation_htmlFormat=QStringLiteral("<tr class=\"Notice\"><td class=\"time\">")+addDebugInformation_time+QStringLiteral("</span></td><td>")+addDebugInformation_fileString+QStringLiteral("</td><td class=\"function\">")+function+QStringLiteral("()</td><td class=\"location\">")+location+QStringLiteral("</td><td>")+htmlEntities(text)+QStringLiteral("</td></tr>\n");
+ addDebugInformation_htmlFormat="<tr class=\"Notice\"><td class=\"time\">";
important=false;
}
break;
case DebugLevel_custom_UserNote:
- addDebugInformation_htmlFormat=QStringLiteral("<tr class=\"Note\"><td class=\"time\">")+addDebugInformation_time+QStringLiteral("</span></td><td>")+addDebugInformation_fileString+QStringLiteral("</td><td class=\"function\">")+function+QStringLiteral("()</td><td class=\"location\">")+location+QStringLiteral("</td><td>")+htmlEntities(text)+QStringLiteral("</td></tr>\n");
+ addDebugInformation_htmlFormat="<tr class=\"Note\"><td class=\"time\">";
break;
}
+ addDebugInformation_htmlFormat+=addDebugInformation_time+"</span></td><td>"+addDebugInformation_fileString+"</td><td class=\"function\">"+function+"()</td><td class=\"location\">"+location+"</td><td>"+htmlEntities(text)+"</td></tr>\n";
//To prevent access of string in multi-thread
{
//Show the text in console
- QString addDebugInformation_textFormat;
- addDebugInformation_textFormat = QStringLiteral("(")+addDebugInformation_time.rightJustified(8,' ')+QStringLiteral(") ");
- if(file!="" && ligne!=-1)
- addDebugInformation_textFormat += file+QStringLiteral(":")+addDebugInformation_lignestring+QStringLiteral(":");
- addDebugInformation_textFormat += function+QStringLiteral("(), (location: ")+location+QStringLiteral("): ")+text;
+ std::string addDebugInformation_textFormat;
+ if(addDebugInformation_time.size()<8)
+ addDebugInformation_time=std::string(8-addDebugInformation_time.size(),' ')+addDebugInformation_time;
+ addDebugInformation_textFormat = "("+addDebugInformation_time+") ";
+ if(!file.empty() && ligne!=-1)
+ addDebugInformation_textFormat += file+":"+addDebugInformation_lignestring+":";
+ addDebugInformation_textFormat += function+"(), (location: "+location+"): "+text;
QMutexLocker lock_mutex(&mutex);
if(currentBackend==File)
{
if(logFile.size()<ULTRACOPIER_DEBUG_MAX_ALL_SIZE*1024*1024 || (important && logFile.size()<ULTRACOPIER_DEBUG_MAX_IMPORTANT_SIZE*1024*1024))
{
- puts(qPrintable(addDebugInformation_textFormat));
- logFile.write(addDebugInformation_htmlFormat.toUtf8());
+ std::cout << addDebugInformation_textFormat << std::endl;
+ logFile.write(addDebugInformation_htmlFormat.data(),static_cast<qint64>(addDebugInformation_htmlFormat.size()));
}
}
else
{
if(debugHtmlContent.size()<ULTRACOPIER_DEBUG_MAX_ALL_SIZE*1024*1024 || (important && debugHtmlContent.size()<ULTRACOPIER_DEBUG_MAX_IMPORTANT_SIZE*1024*1024))
{
- puts(qPrintable(addDebugInformation_textFormat));
+ std::cout << addDebugInformation_textFormat << std::endl;
debugHtmlContent+=addDebugInformation_htmlFormat;
}
}
@@ -334,40 +335,41 @@ void DebugEngine::addDebugInformation(const DebugLevel_custom &level,const QStri
if(addDebugInformationCallNumber<ULTRACOPIER_DEBUG_MAX_GUI_LINE)
{
addDebugInformationCallNumber++;
- DebugModel::debugModel->addDebugInformation(startTime.elapsed(),level,function,text,file,ligne,location);
+ DebugModel::debugModel->addDebugInformation(startTime.elapsed(),level,function,text,file,static_cast<const unsigned int>(ligne),location);
}
}
}
/// \brief Get the html text info for re-show it
-QString DebugEngine::getTheDebugHtml()
+std::string DebugEngine::getTheDebugHtml()
{
if(currentBackend==File)
{
logFile.seek(0);
if(!logFile.isOpen())
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_custom_Warning,"The log file is not open");
- return QString().fromUtf8(logFile.readAll().data())+endOfLogFile;
+ const QByteArray &data=logFile.readAll();
+ return std::string(data.constData(),static_cast<size_t>(data.size()))+endOfLogFile;
}
else
return debugHtmlContent+endOfLogFile;
}
/// \brief Get the html end
-QString DebugEngine::getTheDebugEnd()
+std::string DebugEngine::getTheDebugEnd()
{
return endOfLogFile;
}
/// \brief Drop the html entities
-QString DebugEngine::htmlEntities(const QString &text)
+std::string DebugEngine::htmlEntities(const std::string &text)
{
- QString newText(text);
- newText.replace('&',"&amp;");
- newText.replace('"',"&quot;");
- newText.replace('\'',"&#039;");
- newText.replace('<',"&lt;");
- newText.replace('>',"&gt;");
+ std::string newText(text);
+ stringreplaceAll(newText,"&","&amp;");
+ /*stringreplaceAll(newText,"\"","&quot;");
+ stringreplaceAll(newText,"\\","&#039;");*/
+ stringreplaceAll(newText,"<","&lt;");
+ stringreplaceAll(newText,">","&gt;");
return newText;
}
@@ -380,7 +382,7 @@ DebugEngine::Backend DebugEngine::getCurrentBackend()
bool DebugEngine::tryConnect()
{
QLocalSocket localSocket;
- localSocket.connectToServer(ExtraSocket::pathSocket(ULTRACOPIER_SOCKETNAME),QIODevice::WriteOnly|QIODevice::Unbuffered);
+ localSocket.connectToServer(QString::fromStdString(ExtraSocket::pathSocket(ULTRACOPIER_SOCKETNAME)),QIODevice::WriteOnly|QIODevice::Unbuffered);
if(localSocket.waitForConnected(1000))
{
localSocket.disconnectFromServer();