Browse Source

Web UI: Cleaned up torrent upload code

Should also fix issues on Windows.
adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
7bd8bb4880
  1. 34
      src/webui/httpconnection.cpp

34
src/webui/httpconnection.cpp

@ -388,39 +388,23 @@ void HttpConnection::respondCommand(QString command)
} }
} }
} }
if(command == "upload") if(command == "upload") {
{
QByteArray torrentfile = parser.torrent();
// Get a unique filename // Get a unique filename
QString filePath;
// XXX: We need to use a QTemporaryFile pointer here // XXX: We need to use a QTemporaryFile pointer here
// and it fails on Windows // and it fails on Windows.
QTemporaryFile *tmpfile = new QTemporaryFile; // The file also needs to end with .torrent otherwise
tmpfile->setAutoRemove(false); // it fails to load on Windows.
QTemporaryFile *tmpfile = new QTemporaryFile (QDir::temp().absoluteFilePath("qBT-XXXXXX.torrent"));
if (tmpfile->open()) { if (tmpfile->open()) {
filePath = tmpfile->fileName(); tmpfile->write(parser.torrent());
} else {
std::cerr << "I/O Error: Could not create temporary file" << std::endl;
return;
}
tmpfile->close(); tmpfile->close();
// Now temporary file is created but closed so that it can be used. emit torrentReadyToBeDownloaded(tmpfile->fileName(), false, QString(), false);
// write torrent to temporary file delete tmpfile;
QFile torrent(filePath);
if(torrent.open(QIODevice::WriteOnly)) {
torrent.write(torrentfile);
torrent.close();
} else { } else {
std::cerr << "I/O Error: Could not create temporary file" << std::endl; std::cerr << "I/O Error: Could not create temporary file" << std::endl;
delete tmpfile;
return; return;
} }
#ifdef Q_WS_WIN
// Change extension to .torrent on Windows or loading will fail
QFile::rename(filePath, filePath+".torrent");
filePath += ".torrent";
#endif
emit torrentReadyToBeDownloaded(filePath, false, QString(), false);
delete tmpfile;
// Prepare response // Prepare response
generator.setStatusLine(200, "OK"); generator.setStatusLine(200, "OK");
generator.setContentTypeByExt("html"); generator.setContentTypeByExt("html");

Loading…
Cancel
Save