Improve temporary download directory robustness

This commit is contained in:
David Rowe 2016-12-07 11:55:17 +13:00
parent eafd51ba9e
commit 186d3f18ef

View file

@ -5488,20 +5488,25 @@ void Application::addAssetToWorldFromURLRequestFinished() {
if (result == ResourceRequest::Success) {
qInfo(interfaceapp) << "Downloaded asset from" << url;
QTemporaryDir temporaryDir;
temporaryDir.setAutoRemove(false);
QString temporaryDirPath = temporaryDir.path();
QString filename = url.section("filename=", 1, 1);
QString downloadPath = temporaryDirPath + "/" + filename;
qInfo() << "Download path:" << downloadPath;
if (temporaryDir.isValid()) {
QString temporaryDirPath = temporaryDir.path();
QString filename = url.section("filename=", 1, 1);
QString downloadPath = temporaryDirPath + "/" + filename;
qInfo() << "Download path:" << downloadPath;
QFile tempFile(downloadPath);
if (tempFile.open(QIODevice::WriteOnly)) {
tempFile.write(request->getData());
qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true);
QFile tempFile(downloadPath);
if (tempFile.open(QIODevice::WriteOnly)) {
tempFile.write(request->getData());
qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true);
} else {
QString errorInfo = "Couldn't open temporary file for download";
qWarning(interfaceapp) << errorInfo;
addAssetToWorldError(errorInfo);
}
} else {
QString errorInfo = "Couldn't open temporary file for writing";
QString errorInfo = "Couldn't create temporary directory for download";
qWarning(interfaceapp) << errorInfo;
addAssetToWorldError(errorInfo);
}