Merge latest fixes from stable branch

This commit is contained in:
Christophe Dumez 2010-06-03 20:08:19 +00:00
parent b67938aa3f
commit 4e1366bf0d
8 changed files with 69 additions and 29 deletions

View file

@ -945,12 +945,12 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
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));
// 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
@ -1626,7 +1626,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
if(append) {
const qulonglong file_size = h.filesize_at(i);
if(file_size > 0 && (fp[i]/(double)file_size) < 1.) {
const QString &name = misc::toQString(h.get_torrent_info().file_at(i).path.string());
const QString &name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
if(!name.endsWith(".!qB")) {
const QString new_name = name+".!qB";
qDebug("Renaming %s to %s", qPrintable(name), qPrintable(new_name));
@ -1634,7 +1634,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
}
}
} else {
QString name = misc::toQString(h.get_torrent_info().file_at(i).path.string());
QString name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
if(name.endsWith(".!qB")) {
const QString old_name = name;
name.chop(4);
@ -1927,7 +1927,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
qDebug("Checking if the torrent contains torrent files to download");
// Check if there are torrent files inside
for(int i=0; i<h.get_torrent_info().num_files(); ++i) {
const QString &torrent_relpath = misc::toQString(h.get_torrent_info().file_at(i).path.string());
const QString &torrent_relpath = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
if(torrent_relpath.endsWith(".torrent")) {
qDebug("Found possible recursive torrent download.");
const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath;
@ -1974,6 +1974,22 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
}
}
}
else if (file_renamed_alert* p = dynamic_cast<file_renamed_alert*>(a.get())) {
QTorrentHandle h(p->handle);
if(h.is_valid() && h.num_files() > 1) {
// Check if folders were renamed
QStringList old_path_parts = misc::toQStringU(h.get_torrent_info().orig_files().at(p->index).path.string()).split("/");
old_path_parts.removeLast();
QString old_path = old_path_parts.join("/");
QStringList new_path_parts = misc::toQStringU(p->name).split("/");
new_path_parts.removeLast();
if(old_path != new_path_parts.join("/")) {
old_path = h.save_path()+"/"+old_path;
qDebug("Detected folder renaming, attempt to delete old folder: %s", qPrintable(old_path));
QDir().rmpath(old_path);
}
}
}
else if (storage_moved_alert* p = dynamic_cast<storage_moved_alert*>(a.get())) {
QTorrentHandle h(p->handle);
if(h.is_valid()) {
@ -2052,7 +2068,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
else if (file_completed_alert* p = dynamic_cast<file_completed_alert*>(a.get())) {
QTorrentHandle h(p->handle);
if(appendqBExtension) {
QString name = misc::toQString(h.get_torrent_info().file_at(p->index).path.string());
QString name = misc::toQStringU(h.get_torrent_info().file_at(p->index).path.string());
if(name.endsWith(".!qB")) {
const QString old_name = name;
name.chop(4);