- add_torrent_params_t addParams;
- QFile torrent_file(path);
- if (!torrent_file.exists())
- {
- qWarning() << "Torrent file " << path << "doesn't exist";
- return;
- }
-
- qDebug() << "addTorrent: " << path << " save to " << save_path;
- boost::intrusive_ptr<libtorrent::torrent_info> tiTmp
- = new libtorrent::torrent_info
- (boost::filesystem::path(path.toStdString()));
- addParams.ti = tiTmp;
-
- // save_path is the only mandatory parameter, rest are optional.
- addParams.save_path = boost::filesystem::path(save_path.toStdString());
- //addParams.storage_mode = libtorrent::storage_mode_allocate;
-
- TorrentHandlePtr handle(new TorrentHandle(btSession_.add_torrent(addParams)));
- QString hash = Hash2QStr(handle->hash());
-
- TorrentState state;
-
- state.hash = hash;
- state.name = handle->name();
- state.action = TorrentState::action_add;
- state.state = handle->state();
- state.progress = handle->progress() * torrent_progress_max;
- state.down_rate = handle->downloadRate();
- state.up_rate = handle->uploadRate();
- state.seeds = handle->numSeeds();
- state.leeches = handle->numLeeches();
- state.total_size = handle->getTotalSize();
-
- torrents_[hash] = handle;
-
- emit alert(state, ParamsMap_t());
+ return addTorrent_(path, save_path, other_params, false);
+}
+
+void TorrentSession::addTorrent_(const QString &path, const QString &save_path
+ , const qtrapids::ParamsMap_t &other_params
+ , bool is_restore_session)
+{
+ add_torrent_params_t addParams;
+ QFile torrent_file(path);
+ QDir::home().mkdir(settings_->getTorrentsSubDir());
+
+ if (!torrent_file.exists()) {
+ qWarning() << "Torrent file " << path << "doesn't exist";
+ return;
+ }
+
+ QString new_torrent_fname(QDir(settings_->getTorrentsDir())
+ .filePath(QFileInfo(path).fileName()));
+#ifdef QTRAPIDS_DEBUG
+ qDebug() << "copy to " << new_torrent_fname;
+#endif
+
+ torrent_file.copy(new_torrent_fname);
+
+#ifdef QTRAPIDS_DEBUG
+ qDebug() << "addTorrent: " << path << " save to " << save_path;
+#endif
+
+ boost::intrusive_ptr<libtorrent::torrent_info> tiTmp
+ = new libtorrent::torrent_info
+ (boost::filesystem::path(new_torrent_fname.toStdString()));
+ addParams.ti = tiTmp;
+
+ QString download_dir;
+ if (!save_path.isEmpty()) {
+ download_dir = save_path;
+ } else {
+ download_dir = settings_->getDownloadDir();
+ }
+ // save_path is the only mandatory parameter, rest are optional.
+ addParams.save_path = boost::filesystem::path(download_dir.toStdString());
+ //addParams.storage_mode = libtorrent::storage_mode_allocate;
+
+ TorrentHandlePtr handle(new TorrentHandle(btSession_.add_torrent(addParams)));
+ QString hash = Hash2QStr(handle->hash());
+
+ if (!is_restore_session) {
+ db_->addTorrent(hash, path, save_path);
+ }
+
+ TorrentState state;
+
+ state.hash = hash;
+ state.name = handle->name();
+ state.action = TorrentState::action_add;
+ state.state = handle->state();
+ state.progress = handle->progress() * torrent_progress_max;
+ state.down_rate = handle->downloadRate();
+ state.up_rate = handle->uploadRate();
+ state.seeds = handle->numSeeds();
+ state.leeches = handle->numLeeches();
+ state.total_size = handle->getTotalSize();
+
+ torrents_[hash] = handle;
+
+ emit alert(state, ParamsMap_t());