21 #include <libsigrok/libsigrok.h>
23 #include <QtCore/QDebug>
24 #include <QtCore/QFile>
25 #include <QtCore/QStandardPaths>
34 if (res->type == SR_RESOURCE_FIRMWARE) {
35 auto path = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
36 QString::fromStdString(
"sigrok-firmware/" + name));
38 path = QString::fromStdString(
"assets:/sigrok-firmware/" + name);
40 std::unique_ptr<QFile> file {
new QFile{path}};
42 if (!file->open(QIODevice::ReadOnly))
43 throw sigrok::Error{SR_ERR};
45 const auto size = file->size();
47 throw sigrok::Error{SR_ERR};
50 res->handle = file.release();
52 qWarning() <<
"AndroidAssetReader: Unknown resource type" << res->type;
53 throw sigrok::Error{SR_ERR};
60 qCritical(
"AndroidAssetReader: Invalid handle");
61 throw sigrok::Error{SR_ERR_ARG};
63 const std::unique_ptr<QFile> file {
static_cast<QFile*
>(res->handle)};
64 res->handle =
nullptr;
72 qCritical(
"AndroidAssetReader: Invalid handle");
73 throw sigrok::Error{SR_ERR_ARG};
75 auto *
const file =
static_cast<QFile*
>(res->handle);
77 const auto n_read = file->read(static_cast<char*>(buf), count);
79 throw sigrok::Error{SR_ERR};
size_t read(const struct sr_resource *res, void *buf, size_t count) override
virtual ~AndroidAssetReader()
void close(struct sr_resource *res) override
void open(struct sr_resource *res, std::string name) override