mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 14:04:23 +00:00
Web UI: Cleaned up torrent upload code
Should also fix issues on Windows.
This commit is contained in:
parent
3d5487dfcb
commit
7bd8bb4880
@ -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());
|
||||||
|
tmpfile->close();
|
||||||
|
emit torrentReadyToBeDownloaded(tmpfile->fileName(), false, QString(), false);
|
||||||
|
delete tmpfile;
|
||||||
} 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;
|
||||||
}
|
}
|
||||||
tmpfile->close();
|
|
||||||
// Now temporary file is created but closed so that it can be used.
|
|
||||||
// write torrent to temporary file
|
|
||||||
QFile torrent(filePath);
|
|
||||||
if(torrent.open(QIODevice::WriteOnly)) {
|
|
||||||
torrent.write(torrentfile);
|
|
||||||
torrent.close();
|
|
||||||
} else {
|
|
||||||
std::cerr << "I/O Error: Could not create temporary file" << std::endl;
|
|
||||||
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…
x
Reference in New Issue
Block a user