From a1fd50e920eba0f198b898e5df4ff5f60424d355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 9 Sep 2015 23:53:33 +0200 Subject: GH-1227: World import using drag and drop - zip files and folders --- depends/util/include/pathutils.h | 2 +- depends/util/src/pathutils.cpp | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'depends/util') diff --git a/depends/util/include/pathutils.h b/depends/util/include/pathutils.h index f31b96d1..82d55cd7 100644 --- a/depends/util/include/pathutils.h +++ b/depends/util/include/pathutils.h @@ -54,7 +54,7 @@ LIBUTIL_EXPORT bool ensureFolderPathExists(QString filenamepath); /** * Copy a folder recursively */ -LIBUTIL_EXPORT bool copyPath(QString src, QString dst, bool follow_symlinks = true); +LIBUTIL_EXPORT bool copyPath(const QString &src, const QString &dst, bool follow_symlinks = true); /** * Delete a folder recursively diff --git a/depends/util/src/pathutils.cpp b/depends/util/src/pathutils.cpp index ce9138be..35c7f901 100644 --- a/depends/util/src/pathutils.cpp +++ b/depends/util/src/pathutils.cpp @@ -81,16 +81,24 @@ QString RemoveInvalidFilenameChars(QString string, QChar replaceWith) QString DirNameFromString(QString string, QString inDir) { int num = 0; - QString dirName = RemoveInvalidFilenameChars(string, '-'); - while (QFileInfo(PathCombine(inDir, dirName)).exists()) + QString baseName = RemoveInvalidFilenameChars(string, '-'); + QString dirName; + do { - num++; - dirName = RemoveInvalidFilenameChars(dirName, '-') + QString::number(num); + if(num == 0) + { + dirName = baseName; + } + else + { + dirName = baseName + QString::number(num);; + } // If it's over 9000 if (num > 9000) return ""; - } + num++; + } while (QFileInfo(PathCombine(inDir, dirName)).exists()); return dirName; } @@ -112,7 +120,7 @@ bool ensureFolderPathExists(QString foldernamepath) return success; } -bool copyPath(QString src, QString dst, bool follow_symlinks) +bool copyPath(const QString &src, const QString &dst, bool follow_symlinks) { //NOTE always deep copy on windows. the alternatives are too messy. #if defined Q_OS_WIN32 @@ -127,21 +135,26 @@ bool copyPath(QString src, QString dst, bool follow_symlinks) bool OK = true; + qDebug() << "Looking at " << dir.absolutePath(); foreach(QString f, dir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System)) { QString inner_src = src + QDir::separator() + f; QString inner_dst = dst + QDir::separator() + f; + qDebug() << f << "translates to"<< inner_src << "to" << inner_dst; QFileInfo fileInfo(inner_src); if(!follow_symlinks && fileInfo.isSymLink()) { + qDebug() << "creating symlink" << inner_src << " - " << inner_dst; OK &= QFile::link(fileInfo.symLinkTarget(),inner_dst); } else if (fileInfo.isDir()) { + qDebug() << "recursing" << inner_src << " - " << inner_dst; OK &= copyPath(inner_src, inner_dst, follow_symlinks); } else if (fileInfo.isFile()) { + qDebug() << "copying file" << inner_src << " - " << inner_dst; OK &= QFile::copy(inner_src, inner_dst); } else -- cgit v1.2.3