mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-10 13:54:23 +00:00
Fix download from URLs on Windows
Fix possible encoding problems in paths (Windows)
This commit is contained in:
parent
8568b29cc1
commit
04b63829d7
@ -77,22 +77,28 @@ void DownloadThread::processDlFinished(QNetworkReply* reply) {
|
|||||||
url = m_redirectMapping.take(url);
|
url = m_redirectMapping.take(url);
|
||||||
}
|
}
|
||||||
// Success
|
// Success
|
||||||
QTemporaryFile tmpfile;
|
QTemporaryFile *tmpfile = new QTemporaryFile;
|
||||||
tmpfile.setAutoRemove(false);
|
tmpfile->setAutoRemove(false);
|
||||||
if (tmpfile.open()) {
|
if (tmpfile->open()) {
|
||||||
QString filePath = tmpfile.fileName();
|
QString filePath = tmpfile->fileName();
|
||||||
qDebug("Temporary filename is: %s", qPrintable(filePath));
|
qDebug("Temporary filename is: %s", qPrintable(filePath));
|
||||||
if(reply->isOpen() || reply->open(QIODevice::ReadOnly)) {
|
if(reply->isOpen() || reply->open(QIODevice::ReadOnly)) {
|
||||||
// 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
|
||||||
|
// the signal is sent or the file stays locked on Windows
|
||||||
|
// for some reason.
|
||||||
|
delete tmpfile;
|
||||||
// Send finished signal
|
// Send finished signal
|
||||||
emit downloadFinished(url, filePath);
|
emit downloadFinished(url, filePath);
|
||||||
} else {
|
} else {
|
||||||
|
delete tmpfile;
|
||||||
// Error when reading the request
|
// Error when reading the request
|
||||||
emit downloadFailure(url, tr("I/O Error"));
|
emit downloadFailure(url, tr("I/O Error"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
delete tmpfile;
|
||||||
emit downloadFailure(url, tr("I/O Error"));
|
emit downloadFailure(url, tr("I/O Error"));
|
||||||
}
|
}
|
||||||
// Clean up
|
// Clean up
|
||||||
@ -134,7 +140,7 @@ QNetworkReply* DownloadThread::downloadUrl(const QString &url){
|
|||||||
#endif
|
#endif
|
||||||
// Process download request
|
// Process download request
|
||||||
qDebug("url is %s", qPrintable(url));
|
qDebug("url is %s", qPrintable(url));
|
||||||
const QUrl qurl = QUrl::fromEncoded(url.toLocal8Bit());
|
const QUrl qurl = QUrl::fromEncoded(url.toUtf8());
|
||||||
QNetworkRequest request(qurl);
|
QNetworkRequest request(qurl);
|
||||||
// Spoof Firefox 3.5 user agent to avoid
|
// Spoof Firefox 3.5 user agent to avoid
|
||||||
// Web server banning
|
// Web server banning
|
||||||
|
@ -238,7 +238,7 @@ void QBtSession::setUploadLimit(QString hash, long val) {
|
|||||||
void QBtSession::handleDownloadFailure(QString url, QString reason) {
|
void QBtSession::handleDownloadFailure(QString url, QString reason) {
|
||||||
emit downloadFromUrlFailure(url, reason);
|
emit downloadFromUrlFailure(url, reason);
|
||||||
// Clean up
|
// Clean up
|
||||||
const QUrl qurl = QUrl::fromEncoded(url.toLocal8Bit());
|
const QUrl qurl = QUrl::fromEncoded(url.toUtf8());
|
||||||
url_skippingDlg.removeOne(qurl);
|
url_skippingDlg.removeOne(qurl);
|
||||||
savepathLabel_fromurl.remove(qurl);
|
savepathLabel_fromurl.remove(qurl);
|
||||||
}
|
}
|
||||||
@ -976,9 +976,9 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString savePath;
|
QString savePath;
|
||||||
if(!from_url.isEmpty() && savepathLabel_fromurl.contains(QUrl::fromEncoded(from_url.toLocal8Bit()))) {
|
if(!from_url.isEmpty() && savepathLabel_fromurl.contains(QUrl::fromEncoded(from_url.toUtf8()))) {
|
||||||
// Enforcing the save path defined before URL download (from RSS for example)
|
// Enforcing the save path defined before URL download (from RSS for example)
|
||||||
QPair<QString, QString> savePath_label = savepathLabel_fromurl.take(QUrl::fromEncoded(from_url.toLocal8Bit()));
|
QPair<QString, QString> savePath_label = savepathLabel_fromurl.take(QUrl::fromEncoded(from_url.toUtf8()));
|
||||||
if(savePath_label.first.isEmpty())
|
if(savePath_label.first.isEmpty())
|
||||||
savePath = getSavePath(hash, fromScanDir, path, root_folder);
|
savePath = getSavePath(hash, fromScanDir, path, root_folder);
|
||||||
else
|
else
|
||||||
@ -1520,7 +1520,7 @@ void QBtSession::saveFastResumeData() {
|
|||||||
const QString file = torrentBackup.absoluteFilePath(h.hash()+".fastresume");
|
const QString file = torrentBackup.absoluteFilePath(h.hash()+".fastresume");
|
||||||
if(QFile::exists(file))
|
if(QFile::exists(file))
|
||||||
misc::safeRemove(file);
|
misc::safeRemove(file);
|
||||||
boost::filesystem::ofstream out(boost::filesystem::path(file.toLocal8Bit().constData()), std::ios_base::binary);
|
boost::filesystem::ofstream out(boost::filesystem::path(file.toUtf8().constData()), std::ios_base::binary);
|
||||||
out.unsetf(std::ios_base::skipws);
|
out.unsetf(std::ios_base::skipws);
|
||||||
bencode(std::ostream_iterator<char>(out), *rd->resume_data);
|
bencode(std::ostream_iterator<char>(out), *rd->resume_data);
|
||||||
// Remove torrent from session
|
// Remove torrent from session
|
||||||
@ -2075,7 +2075,7 @@ void QBtSession::readAlerts() {
|
|||||||
misc::safeRemove(file);
|
misc::safeRemove(file);
|
||||||
qDebug("Saving fastresume data in %s", qPrintable(file));
|
qDebug("Saving fastresume data in %s", qPrintable(file));
|
||||||
if (p->resume_data) {
|
if (p->resume_data) {
|
||||||
boost::filesystem::ofstream out(boost::filesystem::path(file.toLocal8Bit().constData()), std::ios_base::binary);
|
boost::filesystem::ofstream out(boost::filesystem::path(file.toUtf8().constData()), std::ios_base::binary);
|
||||||
out.unsetf(std::ios_base::skipws);
|
out.unsetf(std::ios_base::skipws);
|
||||||
bencode(std::ostream_iterator<char>(out), *p->resume_data);
|
bencode(std::ostream_iterator<char>(out), *p->resume_data);
|
||||||
}
|
}
|
||||||
@ -2479,7 +2479,7 @@ void QBtSession::addMagnetSkipAddDlg(QString uri) {
|
|||||||
|
|
||||||
void QBtSession::downloadUrlAndSkipDialog(QString url, QString save_path, QString label) {
|
void QBtSession::downloadUrlAndSkipDialog(QString url, QString save_path, QString label) {
|
||||||
//emit aboutToDownloadFromUrl(url);
|
//emit aboutToDownloadFromUrl(url);
|
||||||
const QUrl qurl = QUrl::fromEncoded(url.toLocal8Bit());
|
const QUrl qurl = QUrl::fromEncoded(url.toUtf8());
|
||||||
savepathLabel_fromurl[qurl] = qMakePair(save_path, label);
|
savepathLabel_fromurl[qurl] = qMakePair(save_path, label);
|
||||||
url_skippingDlg << qurl;
|
url_skippingDlg << qurl;
|
||||||
// Launch downloader thread
|
// Launch downloader thread
|
||||||
@ -2488,14 +2488,14 @@ void QBtSession::downloadUrlAndSkipDialog(QString url, QString save_path, QStrin
|
|||||||
|
|
||||||
// Add to Bittorrent session the downloaded torrent file
|
// Add to Bittorrent session the downloaded torrent file
|
||||||
void QBtSession::processDownloadedFile(QString url, QString file_path) {
|
void QBtSession::processDownloadedFile(QString url, QString file_path) {
|
||||||
const int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toLocal8Bit()));
|
const int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toUtf8()));
|
||||||
if(index < 0) {
|
if(index < 0) {
|
||||||
// Add file to torrent download list
|
// Add file to torrent download list
|
||||||
#ifdef Q_WS_WIN
|
#ifdef Q_WS_WIN
|
||||||
// Windows hack
|
// Windows hack
|
||||||
if(!file_path.endsWith(".torrent")) {
|
if(!file_path.endsWith(".torrent", Qt::CaseInsensitive)) {
|
||||||
Q_ASSERT(QFile::exists(file_path));
|
Q_ASSERT(QFile::exists(file_path));
|
||||||
qDebug("Torrent name does not end with .torrent, fixing...");
|
qDebug("Torrent name does not end with .torrent, from %s", qPrintable(file_path));
|
||||||
if(QFile::rename(file_path, file_path+".torrent")) {
|
if(QFile::rename(file_path, file_path+".torrent")) {
|
||||||
file_path += ".torrent";
|
file_path += ".torrent";
|
||||||
} else {
|
} else {
|
||||||
@ -2535,7 +2535,7 @@ void QBtSession::saveDHTEntry() {
|
|||||||
const QString dht_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state");
|
const QString dht_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state");
|
||||||
if(QFile::exists(dht_path))
|
if(QFile::exists(dht_path))
|
||||||
misc::safeRemove(dht_path);
|
misc::safeRemove(dht_path);
|
||||||
boost::filesystem::ofstream out(dht_path.toLocal8Bit().constData(), std::ios_base::binary);
|
boost::filesystem::ofstream out(dht_path.toUtf8().constData(), std::ios_base::binary);
|
||||||
out.unsetf(std::ios_base::skipws);
|
out.unsetf(std::ios_base::skipws);
|
||||||
bencode(std::ostream_iterator<char>(out), dht_state);
|
bencode(std::ostream_iterator<char>(out), dht_state);
|
||||||
qDebug("DHT entry saved");
|
qDebug("DHT entry saved");
|
||||||
|
@ -216,6 +216,8 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << Q_FUNC_INFO << filePath;
|
||||||
|
|
||||||
this->filePath = filePath;
|
this->filePath = filePath;
|
||||||
this->from_url = from_url;
|
this->from_url = from_url;
|
||||||
// Getting torrent file informations
|
// Getting torrent file informations
|
||||||
|
Loading…
x
Reference in New Issue
Block a user