mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-22 16:37:21 -06:00
Improve strip torrent root folder
Fix issue when you rename the "root item" in the "Add New Torrent" dialog and uncheck "Create subfolder", it will create the subfolder with the renamed name. Fix PropertiesWidget first folder is expanded after app restart. Strip root folder if torrent was added via magnet link. Fix crash when you get name of torrent without metadata.
This commit is contained in:
@@ -276,22 +276,10 @@ TorrentInfo::PieceRange TorrentInfo::filePieces(int fileIndex) const
|
||||
static_cast<int>((firstOffset + fileSize - 1) / pieceLength()));
|
||||
}
|
||||
|
||||
libtorrent::file_storage TorrentInfo::files() const
|
||||
{
|
||||
if (!isValid()) return libtorrent::file_storage();
|
||||
return m_nativeInfo->files();
|
||||
}
|
||||
|
||||
libtorrent::file_storage TorrentInfo::origFiles() const
|
||||
{
|
||||
if (!isValid()) return libtorrent::file_storage();
|
||||
return m_nativeInfo->orig_files();
|
||||
}
|
||||
|
||||
void TorrentInfo::renameFile(uint index, const QString &newPath)
|
||||
{
|
||||
if (!isValid()) return;
|
||||
nativeInfo()->rename_file(index, newPath.toStdString());
|
||||
nativeInfo()->rename_file(index, Utils::Fs::toNativePath(newPath).toStdString());
|
||||
}
|
||||
|
||||
int BitTorrent::TorrentInfo::fileIndex(const QString& fileName) const
|
||||
@@ -305,10 +293,22 @@ int BitTorrent::TorrentInfo::fileIndex(const QString& fileName) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
void TorrentInfo::remapFiles(libtorrent::file_storage const &fileStorage)
|
||||
void TorrentInfo::stripRootFolder()
|
||||
{
|
||||
if (!isValid()) return;
|
||||
m_nativeInfo->remap_files(fileStorage);
|
||||
if (filesCount() <= 1) return;
|
||||
|
||||
libtorrent::file_storage files = m_nativeInfo->files();
|
||||
|
||||
// Solution for case of renamed root folder
|
||||
std::string testName = filePath(0).split('/').value(0).toStdString();
|
||||
if (files.name() != testName) {
|
||||
files.set_name(testName);
|
||||
for (int i = 0; i < files.num_files(); ++i)
|
||||
files.rename_file(i, files.file_path(i));
|
||||
}
|
||||
|
||||
files.set_name("");
|
||||
m_nativeInfo->remap_files(files);
|
||||
}
|
||||
|
||||
TorrentInfo::NativePtr TorrentInfo::nativeInfo() const
|
||||
|
||||
Reference in New Issue
Block a user