1
0
Fork 0

Log redirection (#849)

* Log redirection

* invalid handle is INVALID_HANDLE_VALUE not NULL

* Use cstdio

* fix issue with Unicode file name

* update icons

* update error message
This commit is contained in:
Torusrxxx 2016-07-17 10:52:29 +00:00 committed by Duncan Ogilvie
parent 135af2d543
commit a3cc839d42
6 changed files with 58 additions and 3 deletions

View File

@ -23,7 +23,7 @@ CPUMultiDump::CPUMultiDump(CPUDisassembly* disas, int nbCpuDumpTabs, QWidget* pa
mWatch = new WatchView(this);
//mMaxCPUDumpTabs++;
this->addTabEx(mWatch, DIcon("geolocation-goto.png"), tr("Watch ") + QString::number(1), QString("Watch 1"));
this->addTabEx(mWatch, DIcon("animal-dog.png"), tr("Watch ") + QString::number(1), QString("Watch 1"));
mWatch->loadColumnFromConfig("Watch1");
connect(this, SIGNAL(currentChanged(int)), this, SLOT(updateCurrentTabSlot(int)));

View File

@ -1,8 +1,9 @@
#include "LogView.h"
#include "Configuration.h"
#include "Bridge.h"
#include "BrowseDialog.h"
LogView::LogView(QWidget* parent) : QTextEdit(parent)
LogView::LogView(QWidget* parent) : QTextEdit(parent), logRedirection(NULL)
{
updateStyle();
this->setUndoRedoEnabled(false);
@ -17,6 +18,13 @@ LogView::LogView(QWidget* parent) : QTextEdit(parent)
setupContextMenu();
}
LogView::~LogView()
{
if(logRedirection != NULL)
fclose(logRedirection);
logRedirection = NULL;
}
void LogView::updateStyle()
{
setFont(ConfigFont("Log"));
@ -45,6 +53,9 @@ void LogView::setupContextMenu()
actionToggleLogging->setShortcutContext(Qt::WidgetShortcut);
connect(actionToggleLogging, SIGNAL(triggered()), this, SLOT(toggleLoggingSlot()));
this->addAction(actionToggleLogging);
actionRedirectLog = new QAction(tr("&Redirect Log..."), this);
connect(actionRedirectLog, SIGNAL(triggered()), this, SLOT(redirectLogSlot()));
this->addAction(actionRedirectLog);
refreshShortcutsSlot();
connect(Config(), SIGNAL(shortcutsUpdated()), this, SLOT(refreshShortcutsSlot()));
@ -68,12 +79,26 @@ void LogView::contextMenuEvent(QContextMenuEvent* event)
else
actionToggleLogging->setText(tr("Enable &Logging"));
wMenu.addAction(actionToggleLogging);
wMenu.addAction(actionRedirectLog);
wMenu.exec(event->globalPos());
}
void LogView::addMsgToLogSlot(QString msg)
{
// fix Unix-style line endings.
msg.replace(QString("\r\n"), QString("\n"));
msg.replace(QChar('\n'), QString("\r\n"));
// redirect the log
if(logRedirection != NULL)
{
if(!fwrite(msg.data_ptr()->data(), msg.size() * 2, 1, logRedirection))
{
fclose(logRedirection);
logRedirection = NULL;
msg += tr("fwrite() failed (GetLastError()= %1 ). Log redirection stopped.\r\n").arg(GetLastError());
}
}
if(!loggingEnabled)
return;
if(this->document()->characterCount() > 10000 * 100) //limit the log to ~100mb
@ -87,6 +112,29 @@ void LogView::clearLogSlot()
this->clear();
}
void LogView::redirectLogSlot()
{
if(logRedirection != NULL)
fclose(logRedirection);
logRedirection = NULL;
BrowseDialog browse(this, tr("Redirect log to file"), tr("Enter the file to which you want to redirect log messages."), tr("Log files(*.txt);;All files(*.*)"), QCoreApplication::applicationDirPath(), true);
if(browse.exec() == QDialog::Accepted)
{
logRedirection = _wfopen(browse.path.toStdWString().c_str(), L"ab");
if(logRedirection == NULL)
addMsgToLogSlot(tr("_wfopen() failed. Log will not be redirected to %1.\n").arg(browse.path));
else
{
if(ftell(logRedirection) == 0)
{
unsigned short BOM = 0xfeff;
fwrite(&BOM, 2, 1, logRedirection);
}
addMsgToLogSlot(tr("Log will be redirected to %1.\n").arg(browse.path));
}
}
}
void LogView::setLoggingEnabled(bool enabled)
{
loggingEnabled = enabled;

View File

@ -2,12 +2,14 @@
#define LOGVIEW_H
#include <QTextEdit>
#include <cstdio>
class LogView : public QTextEdit
{
Q_OBJECT
public:
explicit LogView(QWidget* parent = 0);
~LogView();
void setupContextMenu();
void contextMenuEvent(QContextMenuEvent* event);
@ -15,6 +17,7 @@ public slots:
void refreshShortcutsSlot();
void updateStyle();
void addMsgToLogSlot(QString msg);
void redirectLogSlot();
void setLoggingEnabled(bool enabled);
bool getLoggingEnabled();
@ -29,6 +32,9 @@ private:
QAction* actionClear;
QAction* actionSave;
QAction* actionToggleLogging;
QAction* actionRedirectLog;
FILE* logRedirection;
};
#endif // LOGVIEW_H

View File

@ -894,7 +894,7 @@
<action name="actionRtu">
<property name="icon">
<iconset resource="../../resource.qrc">
<normaloff>:/icons/images/recentfiles.png</normaloff>:/icons/images/recentfiles.png</iconset>
<normaloff>:/icons/images/runtouser.png</normaloff>:/icons/images/runtouser.png</iconset>
</property>
<property name="text">
<string>Run to &amp;user code</string>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -248,5 +248,6 @@
<file>images/runtouser.png</file>
<file>images/undo.png</file>
<file>images/binary_save.png</file>
<file>images/animal-dog.png</file>
</qresource>
</RCC>