|
|
@ -1637,33 +1637,16 @@ 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; |
|
|
|
if(old_label == new_label) return; |
|
|
|
|
|
|
|
QString old_save_path = TorrentPersistentData::getSavePath(h.hash()); |
|
|
|
QString old_save_path = TorrentPersistentData::getSavePath(h.hash()); |
|
|
|
if(!old_save_path.startsWith(defaultSavePath)) return; |
|
|
|
if(!old_save_path.startsWith(defaultSavePath)) return; |
|
|
|
QString new_save_path = old_save_path.replace(defaultSavePath, ""); |
|
|
|
QString new_save_path = misc::updateLabelInSavePath(defaultSavePath, old_save_path, old_label, new_label); |
|
|
|
QStringList path_parts = new_save_path.split(QDir::separator(), QString::SkipEmptyParts); |
|
|
|
if(new_save_path != old_save_path) { |
|
|
|
if(path_parts.empty()) { |
|
|
|
// Move storage
|
|
|
|
if(!new_label.isEmpty()) |
|
|
|
qDebug("Moving storage to %s", qPrintable(new_save_path)); |
|
|
|
path_parts << new_label; |
|
|
|
QDir().mkpath(new_save_path); |
|
|
|
} else { |
|
|
|
h.move_storage(new_save_path); |
|
|
|
if(old_label.isEmpty() || path_parts.first() != old_label) { |
|
|
|
emit savePathChanged(h); |
|
|
|
path_parts.prepend(new_label); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
// Move storage
|
|
|
|
|
|
|
|
qDebug("Moving storage to %s", qPrintable(new_save_path)); |
|
|
|
|
|
|
|
QDir().mkpath(new_save_path); |
|
|
|
|
|
|
|
h.move_storage(new_save_path); |
|
|
|
|
|
|
|
emit savePathChanged(h); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Bittorrent::appendLabelToTorrentSavePath(QTorrentHandle h) { |
|
|
|
void Bittorrent::appendLabelToTorrentSavePath(QTorrentHandle h) { |
|
|
@ -1671,15 +1654,11 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
const QString &label = TorrentPersistentData::getLabel(h.hash()); |
|
|
|
const QString &label = TorrentPersistentData::getLabel(h.hash()); |
|
|
|
if(label.isEmpty()) return; |
|
|
|
if(label.isEmpty()) return; |
|
|
|
// Current save path
|
|
|
|
// Current save path
|
|
|
|
const QString &old_save_path = TorrentPersistentData::getSavePath(h.hash()); |
|
|
|
QString old_save_path = TorrentPersistentData::getSavePath(h.hash()); |
|
|
|
const QDir old_dir(old_save_path); |
|
|
|
QString new_save_path = misc::updateLabelInSavePath(defaultSavePath, old_save_path, "", label); |
|
|
|
if(old_dir.dirName() != label) { |
|
|
|
if(old_save_path != new_save_path) { |
|
|
|
const QString &new_save_path = old_dir.absoluteFilePath(label); |
|
|
|
// Move storage
|
|
|
|
TorrentPersistentData::saveSavePath(h.hash(), new_save_path); |
|
|
|
h.move_storage(new_save_path); |
|
|
|
if(old_dir == QDir(h.save_path())) { |
|
|
|
|
|
|
|
// Move storage
|
|
|
|
|
|
|
|
h.move_storage(new_save_path); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
emit savePathChanged(h); |
|
|
|
emit savePathChanged(h); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -2198,7 +2177,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
if(savePath.isEmpty()) { |
|
|
|
if(savePath.isEmpty()) { |
|
|
|
savePath = defaultSavePath; |
|
|
|
savePath = defaultSavePath; |
|
|
|
} |
|
|
|
} |
|
|
|
if(appendLabelToSavePath) { |
|
|
|
if(appendLabelToSavePath && savePath.startsWith(defaultSavePath)) { |
|
|
|
qDebug("appendLabelToSavePath is true"); |
|
|
|
qDebug("appendLabelToSavePath is true"); |
|
|
|
const QString &label = TorrentTempData::getLabel(hash); |
|
|
|
const QString &label = TorrentTempData::getLabel(hash); |
|
|
|
if(!label.isEmpty()) { |
|
|
|
if(!label.isEmpty()) { |
|
|
|