Added log error dialog
This commit is contained in:
parent
b61f21f346
commit
aa5453b84a
|
@ -5,6 +5,7 @@
|
||||||
namespace Log
|
namespace Log
|
||||||
{
|
{
|
||||||
|
|
||||||
|
TStringList ErrorLog;
|
||||||
static const TString gskLogFilename = "primeworldeditor.log";
|
static const TString gskLogFilename = "primeworldeditor.log";
|
||||||
|
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
|
@ -12,7 +13,7 @@ static const TString gskLogFilename = "primeworldeditor.log";
|
||||||
FILE *gpLogFile = fopen(*gskLogFilename, "w");
|
FILE *gpLogFile = fopen(*gskLogFilename, "w");
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
|
||||||
void Write(const TString& message)
|
void Write(const TString& rkMessage)
|
||||||
{
|
{
|
||||||
if (gpLogFile)
|
if (gpLogFile)
|
||||||
{
|
{
|
||||||
|
@ -25,51 +26,65 @@ void Write(const TString& message)
|
||||||
char Buffer[80];
|
char Buffer[80];
|
||||||
strftime(Buffer, 80, "[%H:%M:%S]", &pTimeInfo);
|
strftime(Buffer, 80, "[%H:%M:%S]", &pTimeInfo);
|
||||||
|
|
||||||
fprintf(gpLogFile, "%s %s\n", Buffer, *message);
|
fprintf(gpLogFile, "%s %s\n", Buffer, *rkMessage);
|
||||||
fflush(gpLogFile);
|
fflush(gpLogFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Error(const TString& message)
|
void Error(const TString& rkMessage)
|
||||||
{
|
{
|
||||||
Write("ERROR: " + message);
|
TString FullMessage = "ERROR: " + rkMessage;
|
||||||
std::cout << "ERROR: " << message << "\n";
|
Write(FullMessage);
|
||||||
|
ErrorLog.push_back(FullMessage);
|
||||||
|
std::cout << FullMessage << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Warning(const TString& message)
|
void Warning(const TString& rkMessage)
|
||||||
{
|
{
|
||||||
Write("Warning: " + message);
|
TString FullMessage = "Warning: " + rkMessage;
|
||||||
std::cout << "Warning: " << message << "\n";
|
Write(FullMessage);
|
||||||
|
ErrorLog.push_back(FullMessage);
|
||||||
|
std::cout << FullMessage << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWrite(const TString& filename, const TString& message)
|
void FileWrite(const TString& rkFilename, const TString& rkMessage)
|
||||||
{
|
{
|
||||||
Write(filename + " : " + message);
|
Write(rkFilename + " : " + rkMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWrite(const TString& filename, unsigned long offset, const TString& message)
|
void FileWrite(const TString& rkFilename, u32 Offset, const TString& rkMessage)
|
||||||
{
|
{
|
||||||
Write(filename + " : " + TString::HexString(offset) + " - " + message);
|
Write(rkFilename + " : " + TString::HexString(Offset) + " - " + rkMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileError(const TString& filename, const TString& message)
|
void FileError(const TString& rkFilename, const TString& rkMessage)
|
||||||
{
|
{
|
||||||
Error(filename + " : " + message);
|
Error(rkFilename + " : " + rkMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileError(const TString& filename, unsigned long offset, const TString& message)
|
void FileError(const TString& rkFilename, u32 Offset, const TString& rkMessage)
|
||||||
{
|
{
|
||||||
Error(filename + " : " + TString::HexString(offset) + " - " + message);
|
Error(rkFilename + " : " + TString::HexString(Offset) + " - " + rkMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWarning(const TString& filename, const TString& message)
|
void FileWarning(const TString& rkFilename, const TString& rkMessage)
|
||||||
{
|
{
|
||||||
Warning(filename + " : " + message);
|
Warning(rkFilename + " : " + rkMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWarning(const TString& filename, unsigned long offset, const TString& message)
|
void FileWarning(const TString& rkFilename, u32 Offset, const TString& rkMessage)
|
||||||
{
|
{
|
||||||
Warning(filename + " : " + TString::HexString(offset) + " - " + message);
|
Warning(rkFilename + " : " + TString::HexString(Offset) + " - " + rkMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
const TStringList& GetErrorLog()
|
||||||
|
{
|
||||||
|
return ErrorLog;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearErrorLog()
|
||||||
|
{
|
||||||
|
ErrorLog.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,17 @@
|
||||||
namespace Log
|
namespace Log
|
||||||
{
|
{
|
||||||
|
|
||||||
void Write(const TString& message);
|
void Write(const TString& rkMessage);
|
||||||
void Error(const TString& message);
|
void Error(const TString& rkMessage);
|
||||||
void Warning(const TString& message);
|
void Warning(const TString& rkMessage);
|
||||||
void FileWrite(const TString& filename, const TString& message);
|
void FileWrite(const TString& rkFilename, const TString& rkMessage);
|
||||||
void FileWrite(const TString& filename, unsigned long offset, const TString& message);
|
void FileWrite(const TString& rkFilename, unsigned long Offset, const TString& rkMessage);
|
||||||
void FileError(const TString& filename, const TString& message);
|
void FileError(const TString& rkFilename, const TString& rkMessage);
|
||||||
void FileError(const TString& filename, unsigned long offset, const TString& message);
|
void FileError(const TString& rkFilename, unsigned long Offset, const TString& rkMessage);
|
||||||
void FileWarning(const TString& filename, const TString& message);
|
void FileWarning(const TString& rkFilename, const TString& rkMessage);
|
||||||
void FileWarning(const TString& filename, unsigned long offset, const TString& message);
|
void FileWarning(const TString& rkFilename, unsigned long Offset, const TString& rkMessage);
|
||||||
|
const TStringList& GetErrorLog();
|
||||||
|
void ClearErrorLog();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
#include "CErrorLogDialog.h"
|
||||||
|
#include "ui_CErrorLogDialog.h"
|
||||||
|
#include "UICommon.h"
|
||||||
|
#include <Core/Log.h>
|
||||||
|
|
||||||
|
CErrorLogDialog::CErrorLogDialog(QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
ui(new Ui::CErrorLogDialog)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
connect(ui->CloseButton, SIGNAL(clicked()), this, SLOT(close()));
|
||||||
|
}
|
||||||
|
|
||||||
|
CErrorLogDialog::~CErrorLogDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CErrorLogDialog::GatherErrors()
|
||||||
|
{
|
||||||
|
const TStringList& rkErrors = Log::GetErrorLog();
|
||||||
|
if (rkErrors.empty()) return false;
|
||||||
|
|
||||||
|
QString DialogString;
|
||||||
|
|
||||||
|
for (auto it = rkErrors.begin(); it != rkErrors.end(); it++)
|
||||||
|
{
|
||||||
|
QString Error = TO_QSTRING(*it);
|
||||||
|
QString LineColor;
|
||||||
|
|
||||||
|
if (Error.startsWith("ERROR: "))
|
||||||
|
LineColor = "#ff0000";
|
||||||
|
else if (Error.startsWith("Warning: "))
|
||||||
|
LineColor = "#ff8000";
|
||||||
|
|
||||||
|
QString FullLine = Error;
|
||||||
|
|
||||||
|
if (!LineColor.isEmpty())
|
||||||
|
{
|
||||||
|
FullLine.prepend(QString("<font color=\"%1\">").arg(LineColor));
|
||||||
|
FullLine.append("</font>");
|
||||||
|
}
|
||||||
|
FullLine.append("<br />");
|
||||||
|
|
||||||
|
DialogString += FullLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->ErrorLogTextEdit->setText(DialogString);
|
||||||
|
Log::ClearErrorLog();
|
||||||
|
return true;
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef CERRORLOGDIALOG_H
|
||||||
|
#define CERRORLOGDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class CErrorLogDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CErrorLogDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit CErrorLogDialog(QWidget *parent = 0);
|
||||||
|
~CErrorLogDialog();
|
||||||
|
bool GatherErrors();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::CErrorLogDialog *ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CERRORLOGDIALOG_H
|
|
@ -0,0 +1,49 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>CErrorLogDialog</class>
|
||||||
|
<widget class="QDialog" name="CErrorLogDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>662</width>
|
||||||
|
<height>402</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Errors</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>The following errors were encountered while loading the area:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTextEdit" name="ErrorLogTextEdit">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="html">
|
||||||
|
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||||
|
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||||
|
p, li { white-space: pre-wrap; }
|
||||||
|
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
||||||
|
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="CloseButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Close</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -1,5 +1,6 @@
|
||||||
#include "CStartWindow.h"
|
#include "CStartWindow.h"
|
||||||
#include "ui_CStartWindow.h"
|
#include "ui_CStartWindow.h"
|
||||||
|
#include "CErrorLogDialog.h"
|
||||||
#include "UICommon.h"
|
#include "UICommon.h"
|
||||||
|
|
||||||
#include "Editor/ModelEditor/CModelEditorWindow.h"
|
#include "Editor/ModelEditor/CModelEditorWindow.h"
|
||||||
|
@ -169,6 +170,13 @@ void CStartWindow::on_LaunchWorldEditorButton_clicked()
|
||||||
mpWorldEditor->SetArea(mpWorld, pArea);
|
mpWorldEditor->SetArea(mpWorld, pArea);
|
||||||
mpWorldEditor->setWindowModality(Qt::WindowModal);
|
mpWorldEditor->setWindowModality(Qt::WindowModal);
|
||||||
mpWorldEditor->showMaximized();
|
mpWorldEditor->showMaximized();
|
||||||
|
|
||||||
|
// Display errors
|
||||||
|
CErrorLogDialog ErrorDialog(mpWorldEditor);
|
||||||
|
bool HasErrors = ErrorDialog.GatherErrors();
|
||||||
|
|
||||||
|
if (HasErrors)
|
||||||
|
ErrorDialog.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
gResCache.Clean();
|
gResCache.Clean();
|
||||||
|
|
|
@ -124,7 +124,8 @@ HEADERS += \
|
||||||
CStartWindow.h \
|
CStartWindow.h \
|
||||||
INodeEditor.h \
|
INodeEditor.h \
|
||||||
TestDialog.h \
|
TestDialog.h \
|
||||||
UICommon.h
|
UICommon.h \
|
||||||
|
CErrorLogDialog.h
|
||||||
|
|
||||||
# Source Files
|
# Source Files
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
@ -169,7 +170,8 @@ SOURCES += \
|
||||||
INodeEditor.cpp \
|
INodeEditor.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
TestDialog.cpp \
|
TestDialog.cpp \
|
||||||
UICommon.cpp
|
UICommon.cpp \
|
||||||
|
CErrorLogDialog.cpp
|
||||||
|
|
||||||
# UI Files
|
# UI Files
|
||||||
FORMS += \
|
FORMS += \
|
||||||
|
@ -183,4 +185,5 @@ FORMS += \
|
||||||
WorldEditor/CWorldEditor.ui \
|
WorldEditor/CWorldEditor.ui \
|
||||||
WorldEditor/WCreateTab.ui \
|
WorldEditor/WCreateTab.ui \
|
||||||
WorldEditor/WInstancesTab.ui \
|
WorldEditor/WInstancesTab.ui \
|
||||||
WorldEditor/WModifyTab.ui
|
WorldEditor/WModifyTab.ui \
|
||||||
|
CErrorLogDialog.ui
|
||||||
|
|
Loading…
Reference in New Issue