Fix torrent download on win32 (all seems functional now).

This commit is contained in:
Christophe Dumez
2010-05-30 17:23:41 +00:00
parent cfc4e7c8f6
commit 47e337dc5d
4 changed files with 2074 additions and 2052 deletions

View File

@@ -168,7 +168,7 @@ Bittorrent::~Bittorrent() {
qDebug("BTSession destructor IN");
if(!exiting) {
// Do some BT related saving
#ifndef LIBTORRENT_0_15
#ifndef LIBTORRENT_0_15
saveDHTEntry();
#endif
saveSessionState();
@@ -938,6 +938,15 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
QString hash;
boost::intrusive_ptr<torrent_info> t;
#ifdef Q_WS_WIN
// Windows hack
if(!path.endsWith(".torrent")) {
if(QFile::rename(path, path+".torrent"))
path += ".torrent";
}
qDebug("Downloading torrent at path: %s", qPrintable(path));
#endif
// Checking if BT_backup Dir exists
// create it if it is not
if(! torrentBackup.exists()) {
@@ -2282,6 +2291,19 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
const int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toLocal8Bit()));
if(index < 0) {
// Add file to torrent download list
#ifdef Q_WS_WIN
// Windows hack
if(!file_path.endsWith(".torrent")) {
Q_ASSERT(QFile::exists(file_path));
qDebug("Torrent name does not end with .torrent, fixing...");
if(QFile::rename(file_path, file_path+".torrent")) {
file_path += ".torrent";
} else {
qDebug("Failed to rename torrent file!");
}
}
qDebug("Downloading torrent at path: %s", qPrintable(file_path));
#endif
emit newDownloadedTorrent(file_path, url);
} else {
url_skippingDlg.removeAt(index);

View File

@@ -73,24 +73,27 @@ void downloadThread::processDlFinished(QNetworkReply* reply) {
}
// Success
QString filePath;
QTemporaryFile tmpfile;
tmpfile.setAutoRemove(false);
if (tmpfile.open()) {
filePath = tmpfile.fileName();
QTemporaryFile *tmpfile = new QTemporaryFile;
tmpfile->setAutoRemove(false);
if (tmpfile->open()) {
filePath = tmpfile->fileName();
qDebug("Temporary filename is: %s", qPrintable(filePath));
if(reply->open(QIODevice::ReadOnly)) {
// TODO: Support GZIP compression
tmpfile.write(reply->readAll());
tmpfile->write(reply->readAll());
reply->close();
tmpfile.close();
tmpfile->close();
delete tmpfile;
// Send finished signal
emit downloadFinished(url, filePath);
} else {
// Error when reading the request
tmpfile.close();
tmpfile->close();
delete tmpfile;
emit downloadFailure(url, tr("I/O Error"));
}
} else {
delete tmpfile;
emit downloadFailure(url, tr("I/O Error"));
}
}

View File

@@ -155,11 +155,8 @@ void SearchEngine::checkForPythonExe() {
QString path_envar = QString::fromLocal8Bit(getenv("PATH"));
if(path_envar.isNull()) {
path_envar = "";
} else {
if(!path_envar.endsWith(";"))
path_envar += ";";
}
path_envar += python_path+";";
path_envar = python_path+";"+path_envar;
qDebug("New PATH envvar is: %s", qPrintable(path_envar));
QString envar = "PATH="+path_envar;
putenv(envar.toLocal8Bit().data());

View File

@@ -3,7 +3,7 @@ LANG_PATH = lang
ICONS_PATH = Icons
# Set the following variable to 1 to enable debug
DEBUG_MODE = 1
DEBUG_MODE = 0
# Global
TEMPLATE = app