Setting for creating subfolder on multifile torrents. Closes #588.

This commit is contained in:
sledgehammer999
2015-11-07 20:44:53 +02:00
committed by Vladimir Golovnev (Glassez)
parent 07af8c9648
commit 4b2d8a7941
13 changed files with 88 additions and 5 deletions

View File

@@ -1652,6 +1652,11 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri
p = magnetUri.addTorrentParams();
}
else if (torrentInfo.isValid()) {
if (!addData.resumed && !addData.createSubfolder && torrentInfo.filesCount() > 1) {
libtorrent::file_storage files = torrentInfo.files();
files.set_name("");
torrentInfo.remapFiles(files);
}
// Metadata
if (!addData.resumed && !addData.hasSeedStatus)
findIncompleteFiles(torrentInfo, savePath);

View File

@@ -147,6 +147,7 @@ namespace BitTorrent
QVector<int> filePriorities; // used if TorrentInfo is set
bool ignoreShareRatio = false;
bool skipChecking = false;
bool createSubfolder = true;
};
struct TorrentStatusReport

View File

@@ -152,6 +152,7 @@ TorrentState::operator int() const
return m_value;
}
, createSubfolder(in.createSubfolder)
// TorrentHandle
const qreal TorrentHandle::USE_GLOBAL_RATIO = -2.;
@@ -230,6 +231,9 @@ QString TorrentHandle::name() const
if (name.isEmpty())
name = QString::fromStdString(m_nativeStatus.name);
if (name.isEmpty())
name = QString::fromStdString(m_torrentInfo.origFiles().name());
if (name.isEmpty())
name = m_hash;

View File

@@ -98,6 +98,7 @@ namespace BitTorrent
bool sequential;
bool hasSeedStatus;
bool skipChecking;
bool createSubfolder;
TriStateBool addForced;
TriStateBool addPaused;
// for new torrents

View File

@@ -276,6 +276,18 @@ 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;
@@ -293,6 +305,12 @@ int BitTorrent::TorrentInfo::fileIndex(const QString& fileName) const
return -1;
}
void TorrentInfo::remapFiles(libtorrent::file_storage const &fileStorage)
{
if (!isValid()) return;
m_nativeInfo->remap_files(fileStorage);
}
TorrentInfo::NativePtr TorrentInfo::nativeInfo() const
{
return m_nativeInfo;

View File

@@ -98,8 +98,12 @@ namespace BitTorrent
PieceRange filePieces(const QString &file) const;
PieceRange filePieces(int fileIndex) const;
libtorrent::file_storage files() const;
libtorrent::file_storage origFiles() const;
void renameFile(uint index, const QString &newPath);
void remapFiles(libtorrent::file_storage const &fileStorage);
NativePtr nativeInfo() const;
private:

View File

@@ -263,6 +263,16 @@ void Preferences::setLastLocationPath(const QString &path)
setValue("Preferences/Downloads/LastLocationPath", Utils::Fs::fromNativePath(path));
}
bool Preferences::getTorrentCreateSubfolder() const
{
return value("Preferences/Downloads/CreateSubfolder", true).toBool();
}
void Preferences::setTorrentCreateSubfolder(bool b)
{
setValue("Preferences/Downloads/CreateSubfolder", b);
}
QVariantHash Preferences::getScanDirs() const
{
return value("Preferences/Downloads/ScanDirsV2").toHash();

View File

@@ -138,6 +138,8 @@ public:
void setLastLocationPath(const QString &path);
QVariantHash getScanDirs() const;
void setScanDirs(const QVariantHash &dirs);
bool getTorrentCreateSubfolder() const;
void setTorrentCreateSubfolder(bool b);
QString getScanDirsLastPath() const;
void setScanDirsLastPath(const QString &path);
bool isMailNotificationEnabled() const;