summaryrefslogtreecommitdiffstats
path: root/depends/util/src
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-09-09 23:53:33 +0200
committerPetr Mrázek <peterix@gmail.com>2015-09-09 23:53:33 +0200
commita1fd50e920eba0f198b898e5df4ff5f60424d355 (patch)
tree6b2a3e0ec704d5edfec221c84ca1571376df9c1e /depends/util/src
parent51070a13f711e53835f9aadc220c8177440590d9 (diff)
downloadMultiMC-a1fd50e920eba0f198b898e5df4ff5f60424d355.tar
MultiMC-a1fd50e920eba0f198b898e5df4ff5f60424d355.tar.gz
MultiMC-a1fd50e920eba0f198b898e5df4ff5f60424d355.tar.lz
MultiMC-a1fd50e920eba0f198b898e5df4ff5f60424d355.tar.xz
MultiMC-a1fd50e920eba0f198b898e5df4ff5f60424d355.zip
GH-1227: World import using drag and drop - zip files and folders
Diffstat (limited to 'depends/util/src')
-rw-r--r--depends/util/src/pathutils.cpp25
1 files changed, 19 insertions, 6 deletions
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