diff options
| author | Tomasz Sterna <tomek@xiaoka.com> | 2015-01-11 01:46:51 +0100 |
|---|---|---|
| committer | Tomasz Sterna <tomek@xiaoka.com> | 2015-01-11 01:46:51 +0100 |
| commit | 9e301eebd4e74e17a103c3d9fb59144f27525d4a (patch) | |
| tree | 4659462e804cdd233187008eca9aca1479ff1c82 | |
| parent | 1ec7ec1bda20f0c037b4d2fa834f4acf0d35e9d3 (diff) | |
Implemented support for unzipped .pbw bundlesRELEASE_0.13.js2
| -rw-r--r-- | app/qml/pages/InstallAppDialog.qml | 2 | ||||
| -rw-r--r-- | daemon/appinfo.cpp | 64 | ||||
| -rw-r--r-- | daemon/appinfo.h | 5 | ||||
| -rw-r--r-- | daemon/appmanager.cpp | 3 | ||||
| -rw-r--r-- | daemon/bankmanager.cpp | 11 | ||||
| -rw-r--r-- | rpm/pebble.spec | 2 | ||||
| -rw-r--r-- | rpm/pebble.yaml | 2 |
7 files changed, 50 insertions, 39 deletions
diff --git a/app/qml/pages/InstallAppDialog.qml b/app/qml/pages/InstallAppDialog.qml index 1510c57..debb48f 100644 --- a/app/qml/pages/InstallAppDialog.qml +++ b/app/qml/pages/InstallAppDialog.qml @@ -22,7 +22,7 @@ Dialog { delegate: ListItem { id: appDelegate - contentHeight: Theme.itemSizeSmall + contentHeight: modelData.isLocal ? Theme.itemSizeSmall : 0 visible: modelData.isLocal diff --git a/daemon/appinfo.cpp b/daemon/appinfo.cpp index f4a32c3..91ce0be 100644 --- a/daemon/appinfo.cpp +++ b/daemon/appinfo.cpp @@ -7,6 +7,7 @@ #include "appinfo.h" #include "unpacker.h" #include "stm32crc.h" +#include <quazip/quazipfile.h> namespace { struct ResourceEntry { @@ -155,8 +156,8 @@ bool AppInfo::hasMenuIcon() const QImage AppInfo::getMenuIconImage() const { if (hasMenuIcon()) { - QByteArray data = extractFromResourcePack( - QDir(d->path).filePath("app_resources.pbpack"), d->menuIconResource); + QScopedPointer<QIODevice> imageRes(openFile(AppInfo::RESOURCES)); + QByteArray data = extractFromResourcePack(imageRes.data(), d->menuIconResource); if (!data.isEmpty()) { return decodeResourceImage(data); } @@ -179,15 +180,11 @@ QString AppInfo::getJSApp() const { if (!isValid() || !isLocal()) return QString(); - QScopedPointer<QIODevice> appJS(openFile(AppInfo::APPJS)); + QScopedPointer<QIODevice> appJS(openFile(AppInfo::APPJS, QIODevice::Text)); if (!appJS) { qCWarning(l) << "cannot find app" << d->path << "app.js"; return QString(); } - if (!appJS->open(QIODevice::ReadOnly | QIODevice::Text)) { - qCWarning(l) << "cannot open app" << d->path << "app.js" << appJS->errorString(); - return QString(); - } return QString::fromUtf8(appJS->readAll()); @@ -205,15 +202,11 @@ AppInfo AppInfo::fromPath(const QString &path) info.d->path = path; - QScopedPointer<QIODevice> appInfoJSON(info.openFile(AppInfo::INFO)); + QScopedPointer<QIODevice> appInfoJSON(info.openFile(AppInfo::INFO, QIODevice::Text)); if (!appInfoJSON) { qCWarning(l) << "cannot find app" << path << "info json"; return AppInfo(); } - if (!appInfoJSON->open(QIODevice::ReadOnly | QIODevice::Text)) { - qCWarning(l) << "cannot open app" << path << "info json" << appInfoJSON->errorString(); - return AppInfo(); - } QJsonParseError parseError; QJsonDocument doc = QJsonDocument::fromJson(appInfoJSON->readAll(), &parseError); @@ -221,6 +214,7 @@ AppInfo AppInfo::fromPath(const QString &path) qCWarning(l) << "cannot parse app" << path << "info json" << parseError.errorString(); return AppInfo(); } + appInfoJSON->close(); const QJsonObject root = doc.object(); info.d->uuid = QUuid(root["uuid"].toString()); @@ -232,7 +226,8 @@ AppInfo AppInfo::fromPath(const QString &path) const QJsonObject watchapp = root["watchapp"].toObject(); info.d->watchface = watchapp["watchface"].toBool(); - info.d->jskit = appPath.exists("pebble-js-app.js"); + + info.d->jskit = info.fileExists(AppInfo::APPJS); if (root.contains("capabilities")) { const QJsonArray capabilities = root["capabilities"].toArray(); @@ -299,22 +294,22 @@ AppInfo AppInfo::fromSlot(const BankManager::SlotInfo &slot) return info; } -QByteArray AppInfo::extractFromResourcePack(const QString &file, int wanted_id) const +QByteArray AppInfo::extractFromResourcePack(QIODevice *dev, int wanted_id) const { - QFile f(file); - if (!f.open(QIODevice::ReadOnly)) { - qCWarning(l) << "cannot open resource file" << f.fileName(); + if (!dev) { + qCWarning(l) << "requested resource" << wanted_id + << "from NULL resource file"; return QByteArray(); } - QByteArray data = f.readAll(); + QByteArray data = dev->readAll(); Unpacker u(data); int num_files = u.readLE<quint32>(); u.readLE<quint32>(); // crc for entire file u.readLE<quint32>(); // timestamp - qCDebug(l) << "reading" << num_files << "resources from" << file; + qCDebug(l) << "reading" << num_files << "resources"; QList<ResourceEntry> table; @@ -348,7 +343,7 @@ QByteArray AppInfo::extractFromResourcePack(const QString &file, int wanted_id) crc.addData(res); if (crc.result() != e.crc) { - qCWarning(l) << "CRC failure in resource" << e.index << "on file" << file; + qCWarning(l) << "CRC failure in resource" << e.index << "on file" << res; return QByteArray(); } @@ -373,7 +368,7 @@ QImage AppInfo::decodeResourceImage(const QByteArray &data) const return img; } -QIODevice *AppInfo::openFile(enum AppInfo::File file) const +QIODevice *AppInfo::openFile(enum AppInfo::File file, QIODevice::OpenMode mode) const { QString fileName; switch (file) { @@ -391,10 +386,29 @@ QIODevice *AppInfo::openFile(enum AppInfo::File file) const break; } - QDir appDir(d->path); - if (appDir.exists(fileName)) { - return new QFile(appDir.absoluteFilePath(fileName)); + QIODevice *dev = 0; + QFileInfo appPath(d->path); + if (appPath.isDir()) { + QDir appDir(d->path); + if (appDir.exists(fileName)) { + dev = new QFile(appDir.absoluteFilePath(fileName)); + } + } else if (appPath.isFile()) { + dev = new QuaZipFile(d->path, fileName); } - return 0; + if (dev && !dev->open(QIODevice::ReadOnly | mode)) { + delete dev; + return 0; + } + + return dev; +} + +bool AppInfo::fileExists(enum AppInfo::File file) const +{ + QIODevice *dev = openFile(file); + bool exists = dev && dev->isOpen(); + delete dev; + return exists; } diff --git a/daemon/appinfo.h b/daemon/appinfo.h index 2991345..849e09e 100644 --- a/daemon/appinfo.h +++ b/daemon/appinfo.h @@ -77,12 +77,13 @@ public: QByteArray getMenuIconPng() const; QString getJSApp() const; - QIODevice *openFile(enum File) const; + QIODevice *openFile(enum File, QIODevice::OpenMode = 0) const; + bool fileExists(enum File) const; void setInvalid(); protected: - QByteArray extractFromResourcePack(const QString &file, int id) const; + QByteArray extractFromResourcePack(QIODevice *dev, int id) const; QImage decodeResourceImage(const QByteArray &data) const; private: diff --git a/daemon/appmanager.cpp b/daemon/appmanager.cpp index c50a7e0..7249961 100644 --- a/daemon/appmanager.cpp +++ b/daemon/appmanager.cpp @@ -72,6 +72,7 @@ void AppManager::rescan() _watcher->addPath(dir.absolutePath()); qCDebug(l) << "scanning dir" << dir.absolutePath(); QStringList entries = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable | QDir::Executable); + entries << dir.entryList(QStringList("*.pbw"), QDir::Files | QDir::Readable); qCDebug(l) << "scanning dir results" << entries; Q_FOREACH(const QString &path, entries) { QString appPath = dir.absoluteFilePath(path); @@ -79,6 +80,8 @@ void AppManager::rescan() if (dir.exists(path + "/appinfo.json")) { _watcher->addPath(appPath + "/appinfo.json"); scanApp(appPath); + } else if (QFileInfo(appPath).isFile()) { + scanApp(appPath); } } } diff --git a/daemon/bankmanager.cpp b/daemon/bankmanager.cpp index 69e6821..86577e6 100644 --- a/daemon/bankmanager.cpp +++ b/daemon/bankmanager.cpp @@ -81,9 +81,8 @@ bool BankManager::uploadApp(const QUuid &uuid, int slot) qCDebug(l) << "about to install app" << info.shortName() << "into slot" << slot; QSharedPointer<QIODevice> binaryFile(info.openFile(AppInfo::BINARY)); - if (!binaryFile->open(QIODevice::ReadOnly)) { - qCWarning(l) << "failed to open" << info.shortName() - << "AppInfo::BINARY" << binaryFile->errorString(); + if (!binaryFile) { + qCWarning(l) << "failed to open" << info.shortName() << "AppInfo::BINARY"; return false; } @@ -101,12 +100,6 @@ bool BankManager::uploadApp(const QUuid &uuid, int slot) // Proceed to upload the resource file QSharedPointer<QIODevice> resourceFile(info.openFile(AppInfo::RESOURCES)); if (resourceFile) { - if (!resourceFile->open(QIODevice::ReadOnly)) { - qCWarning(l) << "failed to open" << info.shortName() - << "AppInfo::RESOURCES" << resourceFile->errorString(); - _refresh->start(); - return; - } upload->uploadAppResources(slot, resourceFile.data(), [this, resourceFile, slot]() { qCDebug(l) << "app resources upload succesful"; diff --git a/rpm/pebble.spec b/rpm/pebble.spec index b22c351..3f45127 100644 --- a/rpm/pebble.spec +++ b/rpm/pebble.spec @@ -13,7 +13,7 @@ Name: pebble %{!?qtc_make:%define qtc_make make} %{?qtc_builddir:%define _builddir %qtc_builddir} Summary: Support for Pebble watch in SailfishOS -Version: 0.13.js1 +Version: 0.13.js2 Release: 1 Group: Qt/Qt License: GPL3 diff --git a/rpm/pebble.yaml b/rpm/pebble.yaml index f9adf09..6228174 100644 --- a/rpm/pebble.yaml +++ b/rpm/pebble.yaml @@ -1,6 +1,6 @@ Name: pebble Summary: Support for Pebble watch in SailfishOS -Version: 0.13.js1 +Version: 0.13.js2 Release: 1 Group: Qt/Qt URL: http://getpebble.com/ |
