Progress: 50%.
This commit is contained in:
parent
159d38e210
commit
fa9ca77bfd
1 changed files with 227 additions and 16 deletions
|
|
@ -94,9 +94,13 @@ void TorrentSession::launchSession()
|
|||
if(!std::filesystem::exists(resume_files_location)) {
|
||||
std::filesystem::create_directories(resume_files_location);
|
||||
}
|
||||
item->writeData((fs::path(resume_files_location) /
|
||||
fs::path(item->title.toStdString())).string() + ".searchitem");
|
||||
|
||||
auto search_item_path = (fs::path(resume_files_location) /
|
||||
fs::path(item->title.toStdString())).string() + ".searchitem";
|
||||
if(!std::filesystem::exists(search_item_path))
|
||||
item->writeData((fs::path(resume_files_location) /
|
||||
fs::path(item->title.toStdString())).string() + ".searchitem");
|
||||
else
|
||||
qDebug() << ".seachitem for: " << item->title.toStdString() << " already exists.";
|
||||
|
||||
// load resume data from disk and pass it in as we add the magnet link
|
||||
std::string resume_files_name = fs::path(resume_files_location) /
|
||||
|
|
@ -108,9 +112,14 @@ void TorrentSession::launchSession()
|
|||
|
||||
lt::add_torrent_params magnet = lt::parse_magnet_uri(item->magnet.toStdString());
|
||||
if (buf.size()) {
|
||||
qDebug() << "Loading info from resume file.";
|
||||
lt::add_torrent_params atp = lt::read_resume_data(buf);
|
||||
if (atp.info_hashes == magnet.info_hashes) magnet = std::move(atp);
|
||||
if (atp.info_hashes == magnet.info_hashes) {
|
||||
magnet = std::move(atp);
|
||||
qDebug() << "Magnet hashes matched.";
|
||||
}
|
||||
}
|
||||
qDebug() << "Download path: " << download_path.string();
|
||||
magnet.save_path = download_path.string(); // save location
|
||||
|
||||
ses.async_add_torrent(std::move(magnet));
|
||||
|
|
@ -144,7 +153,6 @@ void TorrentSession::launchSession()
|
|||
h.save_resume_data(lt::torrent_handle::only_if_modified
|
||||
| lt::torrent_handle::save_info_dict);
|
||||
}
|
||||
|
||||
// when resume data is ready, save it
|
||||
if (auto rd = lt::alert_cast<lt::save_resume_data_alert>(a)) {
|
||||
std::ofstream of(resume_files_name, std::ios_base::binary);
|
||||
|
|
@ -179,8 +187,8 @@ void TorrentSession::launchSession()
|
|||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
ses.post_torrent_updates();
|
||||
QCoreApplication::processEvents();
|
||||
// save resume data once every 30 seconds
|
||||
if (clk::now() - last_save_resume > std::chrono::seconds(30)) {
|
||||
// save resume data once every 3 seconds
|
||||
if (clk::now() - last_save_resume > std::chrono::seconds(3)) {
|
||||
h.save_resume_data(lt::torrent_handle::only_if_modified
|
||||
| lt::torrent_handle::save_info_dict);
|
||||
last_save_resume = clk::now();
|
||||
|
|
|
|||
Loading…
Reference in a new issue