diff options
author | Frerich Raabe <raabe@froglogic.com> | 2015-11-23 23:58:06 +0100 |
---|---|---|
committer | Katja Marttila <katja.marttila@theqtcompany.com> | 2016-02-15 05:48:59 +0000 |
commit | c790c068031edd8cd620d9195bda36ba8b5bb489 (patch) | |
tree | 3e47d86a8c89752c3b2229905f02b23732514773 /src/libs/installer/utils.cpp | |
parent | dd24111989653ec43275cc1992e633b5ec46612b (diff) |
Factored QFile usage out of VerboseWriter::flush()
This introduces a new 'VerboseWriterOutput' interface which can be
reimplemented to perform writing the installation log file by different
means. For now, there's just a standard QFile-based implementation. The
plan is to use this facility for implementing log writing via
RemoteFileEngine.
Change-Id: I89d91a4c7a146401ca96f27b25c49558099c5bb7
Reviewed-by: Katja Marttila <katja.marttila@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/utils.cpp')
-rw-r--r-- | src/libs/installer/utils.cpp | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/src/libs/installer/utils.cpp b/src/libs/installer/utils.cpp index 7e563a284..a802eac6b 100644 --- a/src/libs/installer/utils.cpp +++ b/src/libs/installer/utils.cpp @@ -219,11 +219,13 @@ QInstaller::VerboseWriter::VerboseWriter() QInstaller::VerboseWriter::~VerboseWriter() { - if (preFileBuffer.isOpen()) - (void)flush(); + if (preFileBuffer.isOpen()) { + PlainVerboseWriterOutput output; + (void)flush(&output); + } } -bool QInstaller::VerboseWriter::flush() +bool QInstaller::VerboseWriter::flush(VerboseWriterOutput *output) { stream.flush(); if (logFileName.isEmpty()) // binarycreator @@ -234,15 +236,18 @@ bool QInstaller::VerboseWriter::flush() if (!QFileInfo(logFileName).absoluteDir().exists()) return true; - QFile output(logFileName); - if (output.open(QIODevice::ReadWrite | QIODevice::Append | QIODevice::Text)) { - QString logInfo; - logInfo += QLatin1String("************************************* Invoked: "); - logInfo += currentDateTimeAsString; - logInfo += QLatin1String("\n"); - output.write(logInfo.toLocal8Bit()); - output.write(preFileBuffer.data()); - output.close(); + QString logInfo; + logInfo += QLatin1String("************************************* Invoked: "); + logInfo += currentDateTimeAsString; + logInfo += QLatin1String("\n"); + + QBuffer buffer; + buffer.open(QIODevice::WriteOnly); + buffer.write(logInfo.toLocal8Bit()); + buffer.write(preFileBuffer.data()); + buffer.close(); + + if (output->write(logFileName, QIODevice::ReadWrite | QIODevice::Append | QIODevice::Text, buffer.data())) { preFileBuffer.close(); stream.setDevice(0); return true; @@ -268,6 +273,20 @@ void QInstaller::VerboseWriter::appendLine(const QString &msg) stream << msg << endl; } +QInstaller::VerboseWriterOutput::~VerboseWriterOutput() +{ +} + +bool QInstaller::PlainVerboseWriterOutput::write(const QString &fileName, QIODevice::OpenMode openMode, const QByteArray &data) +{ + QFile output(fileName); + if (output.open(openMode)) { + output.write(data); + return true; + } + return false; +} + #ifdef Q_OS_WIN // taken from qcoreapplication_p.h template<typename Char> |