mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-06 09:39:49 +00:00
Implemented a simple logger
This commit is contained in:
parent
eb04fa85b7
commit
10d2ca82f7
@ -19,7 +19,6 @@ Wizard::ExistingInstallationPage::ExistingInstallationPage(MainWizard *wizard) :
|
|||||||
installationsList->addItem(mEmptyItem);
|
installationsList->addItem(mEmptyItem);
|
||||||
mEmptyItem->setHidden(true);
|
mEmptyItem->setHidden(true);
|
||||||
|
|
||||||
|
|
||||||
connect(installationsList, SIGNAL(currentTextChanged(QString)),
|
connect(installationsList, SIGNAL(currentTextChanged(QString)),
|
||||||
this, SLOT(textChanged(QString)));
|
this, SLOT(textChanged(QString)));
|
||||||
|
|
||||||
|
@ -80,6 +80,9 @@ void Wizard::InstallationPage::startInstallation()
|
|||||||
connect(mUnshield, SIGNAL(textChanged(QString)),
|
connect(mUnshield, SIGNAL(textChanged(QString)),
|
||||||
logTextEdit, SLOT(appendPlainText(QString)), Qt::QueuedConnection);
|
logTextEdit, SLOT(appendPlainText(QString)), Qt::QueuedConnection);
|
||||||
|
|
||||||
|
connect(mUnshield, SIGNAL(textChanged(QString)),
|
||||||
|
mWizard, SLOT(addLogText(QString)), Qt::QueuedConnection);
|
||||||
|
|
||||||
connect(mUnshield, SIGNAL(progressChanged(int)),
|
connect(mUnshield, SIGNAL(progressChanged(int)),
|
||||||
installProgressBar, SLOT(setValue(int)), Qt::QueuedConnection);
|
installProgressBar, SLOT(setValue(int)), Qt::QueuedConnection);
|
||||||
|
|
||||||
@ -153,6 +156,8 @@ void Wizard::InstallationPage::showFileDialog(Wizard::Component component)
|
|||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
logTextEdit->appendHtml(tr("<p><br/><span style=\"color:red;\"> \
|
logTextEdit->appendHtml(tr("<p><br/><span style=\"color:red;\"> \
|
||||||
<b>Error: The installation was aborted by the user</b></p>"));
|
<b>Error: The installation was aborted by the user</b></p>"));
|
||||||
|
|
||||||
|
mWizard->addLogText(QLatin1String("Error: The installation was aborted by the user"));
|
||||||
mWizard->mError = true;
|
mWizard->mError = true;
|
||||||
|
|
||||||
emit completeChanged();
|
emit completeChanged();
|
||||||
@ -185,6 +190,10 @@ void Wizard::InstallationPage::installationError(const QString &text, const QStr
|
|||||||
logTextEdit->appendHtml(tr("<p><span style=\"color:red;\"> \
|
logTextEdit->appendHtml(tr("<p><span style=\"color:red;\"> \
|
||||||
<b>%1</b></p>").arg(details));
|
<b>%1</b></p>").arg(details));
|
||||||
|
|
||||||
|
mWizard->addLogText(QLatin1String("Error: ") + text);
|
||||||
|
mWizard->addLogText(details);
|
||||||
|
|
||||||
|
mWizard->mError = true;
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
msgBox.setWindowTitle(tr("An error occurred"));
|
msgBox.setWindowTitle(tr("An error occurred"));
|
||||||
msgBox.setIcon(QMessageBox::Critical);
|
msgBox.setIcon(QMessageBox::Critical);
|
||||||
@ -196,7 +205,7 @@ void Wizard::InstallationPage::installationError(const QString &text, const QStr
|
|||||||
msgBox.setDetailedText(details);
|
msgBox.setDetailedText(details);
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
|
|
||||||
mWizard->mError = true;
|
|
||||||
emit completeChanged();
|
emit completeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <QTime>
|
||||||
|
#include <QDateTime>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
@ -40,11 +42,53 @@ Wizard::MainWizard::MainWizard(QWidget *parent) :
|
|||||||
|
|
||||||
setDefaultProperty("ComponentListWidget", "mCheckedItems", "checkedItemsChanged");
|
setDefaultProperty("ComponentListWidget", "mCheckedItems", "checkedItemsChanged");
|
||||||
|
|
||||||
|
setupLog();
|
||||||
setupGameSettings();
|
setupGameSettings();
|
||||||
setupInstallations();
|
setupInstallations();
|
||||||
setupPages();
|
setupPages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Wizard::MainWizard::setupLog()
|
||||||
|
{
|
||||||
|
QString logPath(QString::fromUtf8(mCfgMgr.getLogPath().string().c_str()));
|
||||||
|
logPath.append(QLatin1String("wizard.log"));
|
||||||
|
|
||||||
|
QString message(tr("<html><head/><body><p><b>Could not open %1 for writing</b></p> \
|
||||||
|
<p>Please make sure you have the right permissions \
|
||||||
|
and try again.</p></body></html>"));
|
||||||
|
|
||||||
|
QFile *file = new QFile(logPath);
|
||||||
|
|
||||||
|
if (!file->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) {
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setWindowTitle(tr("Error opening Wizard log file"));
|
||||||
|
msgBox.setIcon(QMessageBox::Critical);
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
|
msgBox.setText(message.arg(file->fileName()));
|
||||||
|
msgBox.exec();
|
||||||
|
return qApp->quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << logPath;
|
||||||
|
|
||||||
|
mLog = new QTextStream(file);
|
||||||
|
mLog->setCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
|
//addLogText(QLatin1String("test test 123 test"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wizard::MainWizard::addLogText(const QString &text)
|
||||||
|
{
|
||||||
|
|
||||||
|
qDebug() << "AddLogText called! " << text;
|
||||||
|
if (!text.isEmpty()) {
|
||||||
|
qDebug() << "logging " << text;
|
||||||
|
*mLog << text << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// file.close();
|
||||||
|
}
|
||||||
|
|
||||||
void Wizard::MainWizard::setupGameSettings()
|
void Wizard::MainWizard::setupGameSettings()
|
||||||
{
|
{
|
||||||
QString userPath(QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()));
|
QString userPath(QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()));
|
||||||
|
@ -46,8 +46,12 @@ namespace Wizard
|
|||||||
|
|
||||||
bool mError;
|
bool mError;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void addLogText(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void setupLog();
|
||||||
void setupGameSettings();
|
void setupGameSettings();
|
||||||
void setupInstallations();
|
void setupInstallations();
|
||||||
void setupPages();
|
void setupPages();
|
||||||
@ -56,6 +60,8 @@ namespace Wizard
|
|||||||
|
|
||||||
Config::GameSettings mGameSettings;
|
Config::GameSettings mGameSettings;
|
||||||
|
|
||||||
|
QTextStream *mLog;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void accept();
|
void accept();
|
||||||
void reject();
|
void reject();
|
||||||
|
@ -153,37 +153,39 @@ void Wizard::UnshieldWorker::setIniCodec(QTextCodec *codec)
|
|||||||
mIniCodec = codec;
|
mIniCodec = codec;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wizard::UnshieldWorker::setupSettings()
|
bool Wizard::UnshieldWorker::setupSettings()
|
||||||
{
|
{
|
||||||
// Create Morrowind.ini settings map
|
// Create Morrowind.ini settings map
|
||||||
if (getIniPath().isEmpty())
|
if (getIniPath().isEmpty())
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
QFile file(getIniPath());
|
QFile file(getIniPath());
|
||||||
|
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
emit error(tr("Failed to open Morrowind configuration file!"),
|
emit error(tr("Failed to open Morrowind configuration file!"),
|
||||||
tr("Opening %1 failed: %2.").arg(getIniPath(), file.errorString()));
|
tr("Opening %1 failed: %2.").arg(getIniPath(), file.errorString()));
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextStream stream(&file);
|
QTextStream stream(&file);
|
||||||
stream.setCodec(mIniCodec);
|
stream.setCodec(mIniCodec);
|
||||||
|
|
||||||
mIniSettings.readFile(stream);
|
mIniSettings.readFile(stream);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wizard::UnshieldWorker::writeSettings()
|
bool Wizard::UnshieldWorker::writeSettings()
|
||||||
{
|
{
|
||||||
if (getIniPath().isEmpty())
|
if (getIniPath().isEmpty())
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
QFile file(getIniPath());
|
QFile file(getIniPath());
|
||||||
|
|
||||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
||||||
emit error(tr("Failed to open Morrowind configuration file!"),
|
emit error(tr("Failed to open Morrowind configuration file!"),
|
||||||
tr("Opening %1 failed: %2.").arg(getIniPath(), file.errorString()));
|
tr("Opening %1 failed: %2.").arg(getIniPath(), file.errorString()));
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextStream stream(&file);
|
QTextStream stream(&file);
|
||||||
@ -192,7 +194,10 @@ void Wizard::UnshieldWorker::writeSettings()
|
|||||||
if (!mIniSettings.writeFile(getIniPath(), stream)) {
|
if (!mIniSettings.writeFile(getIniPath(), stream)) {
|
||||||
emit error(tr("Failed to write Morrowind configuration file!"),
|
emit error(tr("Failed to write Morrowind configuration file!"),
|
||||||
tr("Writing to %1 failed: %2.").arg(getIniPath(), file.errorString()));
|
tr("Writing to %1 failed: %2.").arg(getIniPath(), file.errorString()));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wizard::UnshieldWorker::removeDirectory(const QString &dirName)
|
bool Wizard::UnshieldWorker::removeDirectory(const QString &dirName)
|
||||||
@ -383,7 +388,8 @@ void Wizard::UnshieldWorker::extract()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write the settings to the Morrowind config file
|
// Write the settings to the Morrowind config file
|
||||||
writeSettings();
|
if (!writeSettings())
|
||||||
|
return false;
|
||||||
|
|
||||||
// Remove the temporary directory
|
// Remove the temporary directory
|
||||||
removeDirectory(getPath() + QDir::separator() + QLatin1String("extract-temp"));
|
removeDirectory(getPath() + QDir::separator() + QLatin1String("extract-temp"));
|
||||||
@ -626,7 +632,9 @@ bool Wizard::UnshieldWorker::installComponent(Component component, const QString
|
|||||||
|
|
||||||
// Setup Morrowind configuration
|
// Setup Morrowind configuration
|
||||||
setIniPath(getPath() + QDir::separator() + QLatin1String("Morrowind.ini"));
|
setIniPath(getPath() + QDir::separator() + QLatin1String("Morrowind.ini"));
|
||||||
setupSettings();
|
|
||||||
|
if (!setupSettings())
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component == Wizard::Component_Tribunal)
|
if (component == Wizard::Component_Tribunal)
|
||||||
|
@ -42,11 +42,11 @@ namespace Wizard
|
|||||||
|
|
||||||
void setIniCodec(QTextCodec *codec);
|
void setIniCodec(QTextCodec *codec);
|
||||||
|
|
||||||
void setupSettings();
|
bool setupSettings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void writeSettings();
|
bool writeSettings();
|
||||||
|
|
||||||
bool getInstallComponent(Component component);
|
bool getInstallComponent(Component component);
|
||||||
|
|
||||||
@ -114,7 +114,6 @@ namespace Wizard
|
|||||||
void requestFileDialog(Wizard::Component component);
|
void requestFileDialog(Wizard::Component component);
|
||||||
|
|
||||||
void textChanged(const QString &text);
|
void textChanged(const QString &text);
|
||||||
void logTextChanged(const QString &text);
|
|
||||||
|
|
||||||
void error(const QString &text, const QString &details);
|
void error(const QString &text, const QString &details);
|
||||||
void progressChanged(int progress);
|
void progressChanged(int progress);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user