Commit e67bca8f authored by Stefano Crocco's avatar Stefano Crocco

Slightly simplify the algorithm to generate the blob file name

parent 93edffa8
...@@ -167,25 +167,27 @@ void WebEnginePartDownloadManager::openBlob(QWebEngineDownloadItem* it, WebEngin ...@@ -167,25 +167,27 @@ void WebEnginePartDownloadManager::openBlob(QWebEngineDownloadItem* it, WebEngin
QString WebEnginePartDownloadManager::generateBlobTempFileName(const QString& suggestedName, const QString& ext) const QString WebEnginePartDownloadManager::generateBlobTempFileName(const QString& suggestedName, const QString& ext) const
{ {
QDir tmpDir(m_tempDownloadDir.path()); QDir tmpDir(m_tempDownloadDir.path());
QString fileName; QString baseName(suggestedName);
QString actualExt = ext; QString actualExt(ext);
if (!suggestedName.isEmpty()) { if (!baseName.isEmpty()) {
fileName = tmpDir.filePath(suggestedName); QString givenExt = QFileInfo(baseName).completeSuffix();
QString givenExt = QFileInfo(fileName).completeSuffix();
if (!givenExt.isEmpty()) { if (!givenExt.isEmpty()) {
actualExt = givenExt; actualExt = givenExt;
//Remove the extension from fileName. The -1 is needed to also remove the dot //The +1 is for the dot
fileName = fileName.left(fileName.length() - givenExt.length() - 1); int extLength = givenExt.length() + 1;
//Remove the extension from baseName
baseName.remove(baseName.length() - extLength, extLength);
} }
} else { } else {
fileName = tmpDir.filePath(QString::number(QTime::currentTime().msecsSinceStartOfDay())); baseName = QString::number(QTime::currentTime().msecsSinceStartOfDay());
} }
QString completeName = fileName + "." + actualExt; baseName = tmpDir.filePath(baseName);
QString completeName = QString("%1.%2").arg(baseName, actualExt);
QString nameTemplate = "%1-%2.%3"; QString nameTemplate = "%1-%2.%3";
int i = 0; int i = 0;
while (tmpDir.exists(completeName)) { while (QFileInfo::exists(completeName)) {
++i; ++i;
completeName = nameTemplate.arg(fileName).arg(i).arg(actualExt); completeName = nameTemplate.arg(baseName).arg(i).arg(actualExt);
} }
return completeName; return completeName;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment