Browse Source

Fix torrent loading problem from Web UI on Windows.

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
76ca967d70
  1. 5
      src/downloadthread.cpp
  2. 3
      src/qtlibtorrent/qbtsession.cpp
  3. 14
      src/webui/httpconnection.cpp

5
src/downloadthread.cpp

@ -86,9 +86,8 @@ void DownloadThread::processDlFinished(QNetworkReply* reply) {
// TODO: Support GZIP compression // TODO: Support GZIP compression
tmpfile->write(reply->readAll()); tmpfile->write(reply->readAll());
tmpfile->close(); tmpfile->close();
// XXX: For some reason, tmpfile has to be destroyed before // XXX: tmpfile needs to be deleted on Windows before using the file
// the signal is sent or the file stays locked on Windows // or it will complain that the file is used by another process.
// for some reason.
delete tmpfile; delete tmpfile;
// Send finished signal // Send finished signal
emit downloadFinished(url, filePath); emit downloadFinished(url, filePath);

3
src/qtlibtorrent/qbtsession.cpp

@ -989,9 +989,10 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
t = new torrent_info(path.toUtf8().constData()); t = new torrent_info(path.toUtf8().constData());
if(!t->is_valid()) if(!t->is_valid())
throw std::exception(); throw std::exception();
} catch(std::exception&) { } catch(std::exception& e) {
if(!from_url.isNull()) { if(!from_url.isNull()) {
addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(from_url), QString::fromUtf8("red")); addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(from_url), QString::fromUtf8("red"));
addConsoleMessage(QString::fromLocal8Bit(e.what()), "red");
//emit invalidTorrent(from_url); //emit invalidTorrent(from_url);
misc::safeRemove(path); misc::safeRemove(path);
}else{ }else{

14
src/webui/httpconnection.cpp

@ -430,16 +430,18 @@ void HttpConnection::respondCommand(const QString& command) {
if(command == "upload") { if(command == "upload") {
qDebug() << Q_FUNC_INFO << "upload"; qDebug() << Q_FUNC_INFO << "upload";
// Get a unique filename // Get a unique filename
// XXX: We need to use a QTemporaryFile pointer here
// and it fails on Windows.
// The file also needs to end with .torrent otherwise
// it fails to load on Windows.
QTemporaryFile *tmpfile = new QTemporaryFile (QDir::temp().absoluteFilePath("qBT-XXXXXX.torrent")); QTemporaryFile *tmpfile = new QTemporaryFile (QDir::temp().absoluteFilePath("qBT-XXXXXX.torrent"));
tmpfile->setAutoRemove(false);
if (tmpfile->open()) { if (tmpfile->open()) {
QString filePath = tmpfile->fileName();
tmpfile->write(m_parser.torrent()); tmpfile->write(m_parser.torrent());
tmpfile->close(); tmpfile->close();
emit torrentReadyToBeDownloaded(tmpfile->fileName(), false, QString(), false); // XXX: tmpfile needs to be deleted on Windows before using the file
tmpfile->deleteLater(); // or it will complain that the file is used by another process.
delete tmpfile;
emit torrentReadyToBeDownloaded(filePath, false, QString(), false);
// Clean up
QFile::remove(filePath);
} 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; delete tmpfile;

Loading…
Cancel
Save