|
|
@ -1637,30 +1637,32 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
void Bittorrent::changeLabelInTorrentSavePath(QTorrentHandle h, QString old_label, QString new_label) { |
|
|
|
void Bittorrent::changeLabelInTorrentSavePath(QTorrentHandle h, QString old_label, QString new_label) { |
|
|
|
if(!h.is_valid()) return; |
|
|
|
if(!h.is_valid()) return; |
|
|
|
if(!appendLabelToSavePath) return; |
|
|
|
if(!appendLabelToSavePath) return; |
|
|
|
const QString &old_save_path = TorrentPersistentData::getSavePath(h.hash()); |
|
|
|
if(old_label == new_label) return; |
|
|
|
QDir old_dir(old_save_path); |
|
|
|
QString old_save_path = TorrentPersistentData::getSavePath(h.hash()); |
|
|
|
const bool move_storage = (old_dir == QDir(h.save_path())); |
|
|
|
if(!old_save_path.startsWith(defaultSavePath)) return; |
|
|
|
if(!old_label.isEmpty()) { |
|
|
|
QString new_save_path = old_save_path.replace(defaultSavePath, ""); |
|
|
|
Q_ASSERT(old_dir.dirName() == old_label); |
|
|
|
QStringList path_parts = new_save_path.split(QDir::separator(), QString::SkipEmptyParts); |
|
|
|
QString path = old_save_path; |
|
|
|
if(path_parts.empty()) { |
|
|
|
// Cd UP
|
|
|
|
if(!new_label.isEmpty()) |
|
|
|
if(path.endsWith(QDir::separator())) |
|
|
|
path_parts << new_label; |
|
|
|
path.chop(1); |
|
|
|
} else { |
|
|
|
QStringList path_items = path.split(QDir::separator()); |
|
|
|
if(old_label.isEmpty() || path_parts.first() != old_label) { |
|
|
|
path_items.removeLast(); |
|
|
|
path_parts.prepend(new_label); |
|
|
|
old_dir = QDir(path_items.join(QDir::separator())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
QString new_save_path; |
|
|
|
|
|
|
|
if(new_label.isEmpty()) { |
|
|
|
|
|
|
|
new_save_path = old_dir.absolutePath(); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
new_save_path = old_dir.absoluteFilePath(new_label); |
|
|
|
if(new_label.isEmpty()) |
|
|
|
|
|
|
|
path_parts.removeAt(0); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
path_parts.replace(0, new_label); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
new_save_path = defaultSavePath; |
|
|
|
|
|
|
|
if(!new_save_path.endsWith(QDir::separator())) new_save_path += QDir::separator(); |
|
|
|
|
|
|
|
new_save_path += path_parts.join(QDir::separator()); |
|
|
|
TorrentPersistentData::saveSavePath(h.hash(), new_save_path); |
|
|
|
TorrentPersistentData::saveSavePath(h.hash(), new_save_path); |
|
|
|
if(move_storage) { |
|
|
|
|
|
|
|
// Move storage
|
|
|
|
// Move storage
|
|
|
|
|
|
|
|
qDebug("Moving storage to %s", qPrintable(new_save_path)); |
|
|
|
|
|
|
|
QDir().mkpath(new_save_path); |
|
|
|
h.move_storage(new_save_path); |
|
|
|
h.move_storage(new_save_path); |
|
|
|
} |
|
|
|
|
|
|
|
emit savePathChanged(h); |
|
|
|
emit savePathChanged(h); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|