History

Improve temporary download directory robustness

David Rowe committed 9 years ago

Commit 186d3f11 parent eafd51b1 file · +16 −11Browse files

Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all

Unified · Split

interface/src/Application.cpp+16−11
@@ -5488,20 +5488,25 @@ void Application::addAssetToWorldFromURLRequestFinished() { · 5487 unmodified lines
54885488
54895489 if (result == ResourceRequest::Success) {
54905490 qInfo(interfaceapp) << "Downloaded asset from" << url;
5491−
54925491 QTemporaryDir temporaryDir;
54935492 temporaryDir.setAutoRemove(false);
5494− QString temporaryDirPath = temporaryDir.path();
5495− QString filename = url.section("filename=", 1, 1);
5496− QString downloadPath = temporaryDirPath + "/" + filename;
5497− qInfo() << "Download path:" << downloadPath;
5498−
5499− QFile tempFile(downloadPath);
5500− if (tempFile.open(QIODevice::WriteOnly)) {
5501− tempFile.write(request->getData());
5502− qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true);
5493+ if (temporaryDir.isValid()) {
5494+ QString temporaryDirPath = temporaryDir.path();
5495+ QString filename = url.section("filename=", 1, 1);
5496+ QString downloadPath = temporaryDirPath + "/" + filename;
5497+ qInfo() << "Download path:" << downloadPath;
5498+
5499+ QFile tempFile(downloadPath);
5500+ if (tempFile.open(QIODevice::WriteOnly)) {
5501+ tempFile.write(request->getData());
5502+ qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true);
5503+ } else {
5504+ QString errorInfo = "Couldn't open temporary file for download";
5505+ qWarning(interfaceapp) << errorInfo;
5506+ addAssetToWorldError(errorInfo);
5507+ }
55035508 } else {
5504− QString errorInfo = "Couldn't open temporary file for writing";
5509+ QString errorInfo = "Couldn't create temporary directory for download";
55055510 qWarning(interfaceapp) << errorInfo;
55065511 addAssetToWorldError(errorInfo);
55075512 }