164 const QByteArray allData = ((metadata.isEmpty() || data.isEmpty())
165 ? data : (data.chopped(1) + metadata.mid(1)));
168 const lt::bdecode_node root = lt::bdecode(allData, ec);
169 if (ec || (root.type() != lt::bdecode_node::dict_t))
172 LoadTorrentParams torrentParams;
173 torrentParams.restored =
true;
174 torrentParams.category =
fromLTString(root.dict_find_string_value(
"qBt-category"));
175 torrentParams.name =
fromLTString(root.dict_find_string_value(
"qBt-name"));
176 torrentParams.hasSeedStatus = root.dict_find_int_value(
"qBt-seedStatus");
177 torrentParams.firstLastPiecePriority = root.dict_find_int_value(
"qBt-firstLastPiecePriority");
182 torrentParams.useAutoTMM = torrentParams.savePath.isEmpty();
183 if (!torrentParams.useAutoTMM)
191 const lt::bdecode_node contentLayoutNode = root.dict_find(
"qBt-contentLayout");
192 if (contentLayoutNode.type() == lt::bdecode_node::string_t)
194 const QString contentLayoutStr =
fromLTString(contentLayoutNode.string_value());
195 torrentParams.contentLayout =
Utils::String::toEnum(contentLayoutStr, TorrentContentLayout::Original);
199 const bool hasRootFolder = root.dict_find_int_value(
"qBt-hasRootFolder");
200 torrentParams.contentLayout = (hasRootFolder ? TorrentContentLayout::Original : TorrentContentLayout::NoSubfolder);
208 const lt::string_view ratioLimitString = root.dict_find_string_value(
"qBt-ratioLimit");
209 if (ratioLimitString.empty())
212 torrentParams.ratioLimit =
fromLTString(ratioLimitString).toDouble();
214 const lt::bdecode_node tagsNode = root.dict_find(
"qBt-tags");
215 if (tagsNode.type() == lt::bdecode_node::list_t)
217 for (
int i = 0; i < tagsNode.list_size(); ++i)
219 const QString tag =
fromLTString(tagsNode.list_string_value_at(i));
220 torrentParams.tags.insert(tag);
224 lt::add_torrent_params &p = torrentParams.ltAddTorrentParams;
226 p = lt::read_resume_data(root, ec);
229 if (p.flags & lt::torrent_flags::stop_when_ready)
232 torrentParams.stopped =
true;
233 torrentParams.operatingMode = TorrentOperatingMode::AutoManaged;
235 p.flags &= ~lt::torrent_flags::paused;
236 p.flags |= lt::torrent_flags::auto_managed;
240 torrentParams.stopped = (p.flags & lt::torrent_flags::paused) && !(p.flags & lt::torrent_flags::auto_managed);
241 torrentParams.operatingMode = (p.flags & lt::torrent_flags::paused) || (p.flags & lt::torrent_flags::auto_managed)
242 ? TorrentOperatingMode::AutoManaged : TorrentOperatingMode::Forced;
245 const bool hasMetadata = (p.ti && p.ti->is_valid());
246 if (!hasMetadata && !root.dict_find(
"info-hash"))
249 return torrentParams;
static const int USE_GLOBAL_SEEDING_TIME
static const qreal USE_GLOBAL_RATIO
QString fromPortablePath(const QString &portablePath) const
static const Profile * instance()
QString toUniformPath(const QString &path)
T toEnum(const QString &serializedValue, const T &defaultValue)
QString fromLTString(const LTStr &str)