mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 01:33:07 -07:00
- Remove old folders after renaming
This commit is contained in:
parent
28ecb2fe1d
commit
7d66c07cef
3 changed files with 181 additions and 159 deletions
13
src/misc.h
13
src/misc.h
|
@ -269,6 +269,19 @@ public:
|
|||
list.insert(i, value);
|
||||
}
|
||||
|
||||
static bool removeEmptyTree(QString path) {
|
||||
QDir dir(path);
|
||||
foreach(QString child, dir.entryList(QDir::AllDirs)) {
|
||||
if(child == "." || child == "..") continue;
|
||||
return removeEmptyTree(dir.absoluteFilePath(child));
|
||||
}
|
||||
QString dir_name = dir.dirName();
|
||||
if(dir.cdUp()) {
|
||||
return dir.rmdir(dir_name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static QString magnetUriToHash(QString magnet_uri) {
|
||||
QString hash = "";
|
||||
QRegExp regHex("urn:btih:([0-9A-Za-z]+)");
|
||||
|
|
|
@ -557,8 +557,9 @@ void PropertiesWidget::renameSelectedFile() {
|
|||
path_items.removeLast();
|
||||
path_items << new_name_last;
|
||||
QString new_path = path_items.join(QDir::separator());
|
||||
// XXX: Check for overwriting
|
||||
for(int i=0; i<h.num_files(); ++i) {
|
||||
// Check for overwriting
|
||||
int num_files = h.num_files();
|
||||
for(int i=0; i<num_files; ++i) {
|
||||
QString current_name = misc::toQString(h.get_torrent_info().file_at(i).path.string());
|
||||
#ifdef Q_WS_WIN
|
||||
if(current_name.contains(new_path, Qt::CaseInsensitive)) {
|
||||
|
@ -572,7 +573,7 @@ void PropertiesWidget::renameSelectedFile() {
|
|||
}
|
||||
}
|
||||
// Replace path in all files
|
||||
for(int i=0; i<h.num_files(); ++i) {
|
||||
for(int i=0; i<num_files; ++i) {
|
||||
QString current_name = misc::toQString(h.get_torrent_info().file_at(i).path.string());
|
||||
QString new_name = current_name.replace(old_path, new_path);
|
||||
qDebug("Rename %s to %s", current_name.toLocal8Bit().data(), new_name.toLocal8Bit().data());
|
||||
|
@ -580,6 +581,13 @@ void PropertiesWidget::renameSelectedFile() {
|
|||
}
|
||||
// Rename folder in torrent files model too
|
||||
PropListModel->setData(index, new_name_last);
|
||||
// Remove old folder
|
||||
QDir old_folder(h.save_path()+QDir::separator()+old_path);
|
||||
int timeout = 10;
|
||||
while(!misc::removeEmptyTree(old_folder.absolutePath()) && timeout > 0) {
|
||||
SleeperThread::msleep(100);
|
||||
--timeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -492,7 +492,8 @@ public:
|
|||
return;
|
||||
}
|
||||
// Create parent folder
|
||||
TreeItem *current_parent = new TreeItem(misc::toQString(t.name()), parent);
|
||||
QString root_name = misc::toQString(t.file_at(0).path.string()).split('/').first();
|
||||
TreeItem *current_parent = new TreeItem(root_name, parent);
|
||||
//parent->appendChild(current_parent);
|
||||
TreeItem *root_folder = current_parent;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue