diff --git a/openbr/plugins/gallery/binary.cpp b/openbr/plugins/gallery/binary.cpp index b83184c..b92c4d0 100644 --- a/openbr/plugins/gallery/binary.cpp +++ b/openbr/plugins/gallery/binary.cpp @@ -16,6 +16,7 @@ #include #include +#include #ifdef _WIN32 #include @@ -272,7 +273,8 @@ class utGallery : public BinaryGallery t.append(cv::Mat(1, dataSize, CV_8UC1, dataStart).clone() /* We don't want a shallow copy! */); } else { if (!gallery.atEnd()) - qFatal("Failed to read universal template header!"); + qWarning("Failed to read universal template header!"); + gallery.close(); } return t; } @@ -284,7 +286,10 @@ class utGallery : public BinaryGallery qFatal("Expected 16-byte ImageID, got: %d bytes.", imageID.size()); const int32_t algorithmID = (t.isEmpty() || t.file.fte) ? 0 : t.file.get("AlgorithmID"); - const QByteArray url = t.file.get("URL", t.file.name).toLatin1(); + + // QUrl::fromUserInput provides some nice functionality in terms of completing URLs + // e.g. C:/test.jpg -> file://C:/test.jpg and google.com/image.jpg -> http://google.com/image.jpg + const QByteArray url = QUrl::fromUserInput(t.file.get("URL", t.file.name)).toEncoded(); int32_t x = 0, y = 0; uint32_t width = 0, height = 0; diff --git a/openbr/plugins/gallery/empty.cpp b/openbr/plugins/gallery/empty.cpp index 56f5548..a361e3e 100644 --- a/openbr/plugins/gallery/empty.cpp +++ b/openbr/plugins/gallery/empty.cpp @@ -40,7 +40,12 @@ class EmptyGallery : public Gallery { QDir dir(file.name); QtUtils::touchDir(dir); - gallerySize = dir.count(); + QDirIterator it(dir.absolutePath(), QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); + gallerySize = 0; + while (it.hasNext()) { + it.next(); + gallerySize++; + } } TemplateList readBlock(bool *done) diff --git a/openbr/plugins/io/download.cpp b/openbr/plugins/io/download.cpp index 712a813..1d3dd87 100644 --- a/openbr/plugins/io/download.cpp +++ b/openbr/plugins/io/download.cpp @@ -57,7 +57,12 @@ private: if (!url.contains("://")) url = "file://" + url; dst.file.set("URL", url); - if (url.startsWith("file://")) + + static const QRegularExpression regExp("file:///[A-Z]:/"); + + if (url.contains(regExp)) + url = url.mid(8); + else if (url.startsWith("file://")) url = url.mid(7); QIODevice *device = NULL;