Commit 980b6d04fc988098d4dd60722554b03d0f1bdbde
1 parent
a29b78a7
added support to preserve file paths when enrolling to a folder
Showing
5 changed files
with
23 additions
and
2 deletions
sdk/core/qtutils.cpp
| ... | ... | @@ -121,6 +121,15 @@ void QtUtils::writeFile(const QString &file, const QByteArray &data, int compres |
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | +void QtUtils::copyFile(const QString &src, const QString &dst) | |
| 125 | +{ | |
| 126 | + touchDir(QFileInfo(dst)); | |
| 127 | + if (!QFile::copy(src, dst)) { | |
| 128 | + if (QFileInfo(src).exists()) qFatal("Unable to copy %s to %s. Check file permissions.", qPrintable(src), qPrintable(dst)); | |
| 129 | + else qFatal("Unable to copy %s to %s. File does not exist.", qPrintable(src), qPrintable(dst)); | |
| 130 | + } | |
| 131 | +} | |
| 132 | + | |
| 124 | 133 | void QtUtils::touchDir(const QDir &dir) |
| 125 | 134 | { |
| 126 | 135 | if (dir.exists(".")) return; | ... | ... |
sdk/core/qtutils.h
| ... | ... | @@ -39,6 +39,7 @@ namespace QtUtils |
| 39 | 39 | void writeFile(const QString &file, const QStringList &lines); |
| 40 | 40 | void writeFile(const QString &file, const QString &data); |
| 41 | 41 | void writeFile(const QString &file, const QByteArray &data, int compression = 0); |
| 42 | + void copyFile(const QString &src, const QString &dst); | |
| 42 | 43 | |
| 43 | 44 | /**** Directory Utilities ****/ |
| 44 | 45 | void touchDir(const QDir &dir); | ... | ... |
sdk/openbr_plugin.cpp
| ... | ... | @@ -148,6 +148,14 @@ void File::set(const QString &key, const QVariant &value) |
| 148 | 148 | m_metadata.insert(key, value); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | +bool File::getBool(const QString &key) const | |
| 152 | +{ | |
| 153 | + if (!contains(key)) return false; | |
| 154 | + QVariant variant = value(key); | |
| 155 | + if (variant.isNull() || !variant.canConvert<bool>()) return true; | |
| 156 | + return variant.value<bool>(); | |
| 157 | +} | |
| 158 | + | |
| 151 | 159 | QString File::subject(int label) |
| 152 | 160 | { |
| 153 | 161 | return Globals->classes.key(label, QString::number(label)); | ... | ... |
sdk/openbr_plugin.h
| ... | ... | @@ -206,6 +206,9 @@ struct BR_EXPORT File |
| 206 | 206 | return variant.value<T>(); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | + /*!< \brief Specialization for boolean type. */ | |
| 210 | + bool getBool(const QString &key) const; | |
| 211 | + | |
| 209 | 212 | /*!< \brief Returns a value for the key, returning \em defaultValue if the key does not exist or can't be converted. */ |
| 210 | 213 | template <typename T> |
| 211 | 214 | T get(const QString &key, const T &defaultValue) const | ... | ... |
sdk/plugins/gallery.cpp
| ... | ... | @@ -127,10 +127,10 @@ class EmptyGallery : public Gallery |
| 127 | 127 | // Enrolling a null file is used as an idiom to initialize an algorithm |
| 128 | 128 | if (file.name.isEmpty()) return; |
| 129 | 129 | |
| 130 | - const QString destination = file.name + "/" + t.file.fileName(); | |
| 130 | + const QString destination = file.name + "/" + (file.getBool("preservePath") ? t.file.name : t.file.fileName()); | |
| 131 | 131 | QMutexLocker diskLocker(&diskLock); // Windows prefers to crash when writing to disk in parallel |
| 132 | 132 | if (t.isNull()) { |
| 133 | - QFile::copy(t.file.resolved(), destination); | |
| 133 | + QtUtils::copyFile(t.file.resolved(), destination); | |
| 134 | 134 | } else { |
| 135 | 135 | QScopedPointer<Format> format(Factory<Format>::make(destination)); |
| 136 | 136 | format->write(t); | ... | ... |