| 98 | } |
| 99 | |
| 100 | static bool cp_rf(const QString &what, const QString &where) |
| 101 | { |
| 102 | QFileInfo whatFi(what); |
| 103 | QFileInfo whereFi = QFileInfo(where); |
| 104 | |
| 105 | if (!whatFi.exists()) { |
| 106 | qDebug() << what << "does not exist" << Q_FUNC_INFO; |
| 107 | return false; |
| 108 | } else if (whatFi.isFile()) { |
| 109 | QString whereDir = where.section("/", 0, -2, QString::SectionSkipEmpty | QString::SectionIncludeLeadingSep); |
| 110 | QString newFilePath = where; |
| 111 | if (!whereFi.exists()) { |
| 112 | QDir().mkpath(whereDir); |
| 113 | } else if (whereFi.isDir()) { |
| 114 | newFilePath = whereDir + "/" + whatFi.fileName(); |
| 115 | } |
| 116 | if (QFile::exists(newFilePath)) { |
| 117 | QFile::remove(newFilePath); |
| 118 | } |
| 119 | if (!QFile::copy(what, newFilePath)) { |
| 120 | qDebug() << "can't copy" << what << "to" << where << Q_FUNC_INFO; |
| 121 | return false; |
| 122 | } |
| 123 | return true; |
| 124 | } else if (whatFi.isDir()) { |
| 125 | |
| 126 | if (whereFi.isFile() && whereFi.fileName().toLower() == whatFi.fileName().toLower()) { |
| 127 | qDebug() << "can't copy dir" << what << "to file" << where << Q_FUNC_INFO; |
| 128 | return false; |
| 129 | } else if (whereFi.isDir()) { |
| 130 | rm_r(where); |
| 131 | } |
| 132 | |
| 133 | QDir().mkpath(where); |
| 134 | |
| 135 | QFileInfoList fList = QDir(what).entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot); |
| 136 | foreach (QFileInfo sub, fList) { |
| 137 | if (!cp_rf(sub.absoluteFilePath(), where + "/" + sub.fileName())) |
| 138 | return false; |
| 139 | } |
| 140 | return true; |
| 141 | } |
| 142 | return true; |
| 143 | } |
| 144 | |
| 145 | static QString thumbFileNameFrom(const QString &filePath) |
| 146 | { |