QzTools: Fix ensureUniqueFileName when file has no suffix

Closes #1706
remotes/origin/falkon
David Rosca 11 years ago
parent 800cc14dcd
commit ffcf137967
  1. 15
      src/lib/tools/qztools.cpp

@ -223,22 +223,23 @@ QString QzTools::ensureUniqueFilename(const QString &name, const QString &append
return name;
}
QString tmpFileName = name;
QString tmpPath = name;
int i = 1;
while (QFile::exists(tmpFileName)) {
tmpFileName = name;
int index = tmpFileName.lastIndexOf(QLatin1Char('.'));
while (QFile::exists(tmpPath)) {
tmpPath = name;
int fileNameIndex = tmpPath.lastIndexOf(QL1C('/'));
int index = tmpPath.lastIndexOf(QL1C('.'), fileNameIndex);
QString appendString = appendFormat.arg(i);
if (index == -1) {
tmpFileName.append(appendString);
tmpPath.append(appendString);
}
else {
tmpFileName = tmpFileName.left(index) + appendString + tmpFileName.mid(index);
tmpPath = tmpPath.left(index) + appendString + tmpPath.mid(index);
}
i++;
}
return tmpFileName;
return tmpPath;
}
QString QzTools::getFileNameFromUrl(const QUrl &url)

Loading…
Cancel
Save