mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-21 08:09:35 +08:00
parent
e157ca2430
commit
a54f57611c
@ -2149,12 +2149,26 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri
|
|||||||
p = magnetUri.addTorrentParams();
|
p = magnetUri.addTorrentParams();
|
||||||
}
|
}
|
||||||
else if (torrentInfo.isValid()) {
|
else if (torrentInfo.isValid()) {
|
||||||
if (!addData.resumed && !addData.hasRootFolder)
|
if (!addData.resumed) {
|
||||||
torrentInfo.stripRootFolder();
|
if (!addData.hasRootFolder)
|
||||||
|
torrentInfo.stripRootFolder();
|
||||||
|
|
||||||
|
// Metadata
|
||||||
|
if (!addData.hasSeedStatus)
|
||||||
|
findIncompleteFiles(torrentInfo, savePath);
|
||||||
|
|
||||||
|
// if torrent name wasn't explicitly set we handle the case of
|
||||||
|
// initial renaming of torrent content and rename torrent accordingly
|
||||||
|
if (addData.name.isEmpty()) {
|
||||||
|
QString contentName = torrentInfo.rootFolder();
|
||||||
|
if (contentName.isEmpty() && (torrentInfo.filesCount() == 1))
|
||||||
|
contentName = torrentInfo.fileName(0);
|
||||||
|
|
||||||
|
if (!contentName.isEmpty() && (contentName != torrentInfo.name()))
|
||||||
|
addData.name = contentName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Metadata
|
|
||||||
if (!addData.resumed && !addData.hasSeedStatus)
|
|
||||||
findIncompleteFiles(torrentInfo, savePath);
|
|
||||||
p.ti = torrentInfo.nativeInfo();
|
p.ti = torrentInfo.nativeInfo();
|
||||||
hash = torrentInfo.hash();
|
hash = torrentInfo.hash();
|
||||||
}
|
}
|
||||||
|
@ -362,24 +362,29 @@ int BitTorrent::TorrentInfo::fileIndex(const QString& fileName) const
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentInfo::hasRootFolder() const
|
QString TorrentInfo::rootFolder() const
|
||||||
{
|
{
|
||||||
QString testRootFolder;
|
QString rootFolder;
|
||||||
for (int i = 0; i < filesCount(); ++i) {
|
for (int i = 0; i < filesCount(); ++i) {
|
||||||
const QString filePath = this->filePath(i);
|
const QString filePath = this->filePath(i);
|
||||||
if (QDir::isAbsolutePath(filePath)) continue;
|
if (QDir::isAbsolutePath(filePath)) continue;
|
||||||
|
|
||||||
const auto filePathElements = filePath.splitRef('/');
|
const auto filePathElements = filePath.splitRef('/');
|
||||||
// if at least one file has no root folder, no common root folder exists
|
// if at least one file has no root folder, no common root folder exists
|
||||||
if (filePathElements.count() <= 1) return false;
|
if (filePathElements.count() <= 1) return "";
|
||||||
|
|
||||||
if (testRootFolder.isEmpty())
|
if (rootFolder.isEmpty())
|
||||||
testRootFolder = filePathElements.at(0).toString();
|
rootFolder = filePathElements.at(0).toString();
|
||||||
else if (testRootFolder != filePathElements.at(0))
|
else if (rootFolder != filePathElements.at(0))
|
||||||
return false;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return rootFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TorrentInfo::hasRootFolder() const
|
||||||
|
{
|
||||||
|
return !rootFolder().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentInfo::stripRootFolder()
|
void TorrentInfo::stripRootFolder()
|
||||||
|
@ -104,6 +104,7 @@ namespace BitTorrent
|
|||||||
|
|
||||||
void renameFile(uint index, const QString &newPath);
|
void renameFile(uint index, const QString &newPath);
|
||||||
|
|
||||||
|
QString rootFolder() const;
|
||||||
bool hasRootFolder() const;
|
bool hasRootFolder() const;
|
||||||
void stripRootFolder();
|
void stripRootFolder();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user