Commit 2ec427dc5ae6178f9281614403cd0029fc0e84a7
1 parent
429f944e
preliminary socket support
Showing
1 changed file
with
24 additions
and
16 deletions
sdk/core/qtutils.cpp
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | #include <QDebug> |
| 19 | 19 | #ifndef BR_EMBEDDED |
| 20 | 20 | #include <QDesktopServices> |
| 21 | +#include <QLocalSocket> | |
| 21 | 22 | #endif // BR_EMBEDDED |
| 22 | 23 | #include <QFile> |
| 23 | 24 | #include <QFileInfo> |
| ... | ... | @@ -92,30 +93,37 @@ void QtUtils::readFile(const QString &file, QByteArray &data, bool uncompress) |
| 92 | 93 | |
| 93 | 94 | void QtUtils::writeFile(const QString &file, const QStringList &lines) |
| 94 | 95 | { |
| 95 | - writeFile(file, lines.join("\n") + "\n"); | |
| 96 | + writeFile(file, lines.join("\n")); | |
| 96 | 97 | } |
| 97 | 98 | |
| 98 | 99 | void QtUtils::writeFile(const QString &file, const QString &data) |
| 99 | 100 | { |
| 100 | - if (QFileInfo(file).baseName() == "terminal") { | |
| 101 | - printf("%s", qPrintable(data)); | |
| 102 | - } else { | |
| 103 | - QFile f(file); | |
| 104 | - touchDir(f); | |
| 105 | - if (!f.open(QFile::WriteOnly)) qFatal("QtUtils::writeFile failed to open %s for writing.", qPrintable(file)); | |
| 106 | - f.write(qPrintable(data)); | |
| 107 | - f.close(); | |
| 108 | - } | |
| 101 | + writeFile(file, data.toLocal8Bit()); | |
| 109 | 102 | } |
| 110 | 103 | |
| 111 | 104 | void QtUtils::writeFile(const QString &file, const QByteArray &data, int compression) |
| 112 | 105 | { |
| 113 | - QFile f(file); | |
| 114 | - touchDir(f); | |
| 115 | - if (!f.open(QFile::WriteOnly)) qFatal("QtUtils::writeFile failed to open %s for writing.", qPrintable(file)); | |
| 116 | - if (compression == 0) f.write(data); | |
| 117 | - else f.write(qCompress(data, compression)); | |
| 118 | - f.close(); | |
| 106 | + const QString baseName = QFileInfo(file).baseName(); | |
| 107 | + const QByteArray contents = (compression == 0) ? data : qCompress(data, compression); | |
| 108 | + if (baseName == "terminal") { | |
| 109 | + printf("%s", qPrintable(contents)); | |
| 110 | + } | |
| 111 | +#ifndef BR_EMBEDDED | |
| 112 | + else if (baseName.endsWith("socket")) { | |
| 113 | + QLocalSocket socket; | |
| 114 | + socket.connectToServer(file, QLocalSocket::WriteOnly); | |
| 115 | + socket.write(data); | |
| 116 | + socket.close(); | |
| 117 | + } | |
| 118 | +#endif // BR_EMBEDDED | |
| 119 | + else { | |
| 120 | + QFile f(file); | |
| 121 | + touchDir(f); | |
| 122 | + if (!f.open(QFile::WriteOnly)) | |
| 123 | + qFatal("QtUtils::writeFile failed to open %s for writing.", qPrintable(file)); | |
| 124 | + f.write(contents); | |
| 125 | + f.close(); | |
| 126 | + } | |
| 119 | 127 | } |
| 120 | 128 | |
| 121 | 129 | void QtUtils::touchDir(const QDir &dir) | ... | ... |