Skip to content

Commit

Permalink
Merge pull request #288 from vktr/f/fix-magnet-links-disappearing
Browse files Browse the repository at this point in the history
Save magnet links correctly.
  • Loading branch information
vktr committed May 16, 2016
2 parents 5db0d84 + 051b867 commit 3e7f2ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/client/ui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <sstream>

#include <commctrl.h>
#include <picotorrent/core/hash.hpp>
#include <picotorrent/core/session.hpp>
#include <picotorrent/core/session_metrics.hpp>
#include <picotorrent/core/torrent.hpp>
Expand Down Expand Up @@ -580,6 +581,11 @@ std::string main_window::on_list_display(const std::pair<int, int> &p)
switch (p.first)
{
case COLUMN_NAME:
if (t->name().empty())
{
return t->info_hash()->to_string();
}

return t->name();
case COLUMN_QUEUE_POSITION:
if (t->queue_position() < 0)
Expand All @@ -589,6 +595,11 @@ std::string main_window::on_list_display(const std::pair<int, int> &p)

return std::to_string(t->queue_position() + 1);
case COLUMN_SIZE:
if (t->state() == core::torrent_state::state_t::downloading_metadata)
{
return "-";
}

TCHAR size[128];
StrFormatByteSize64(t->size(), size, ARRAYSIZE(size));
return to_string(size);
Expand Down
20 changes: 16 additions & 4 deletions src/core/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct load_item
std::string resume_data;
std::string magnet_uri;
std::string save_path;
std::string url;
};

struct session_log_item
Expand Down Expand Up @@ -366,8 +367,9 @@ void session::load_torrents()
continue;
}

item.magnet_uri = node.dict_find_string_value("pT-url");
item.magnet_uri = node.dict_find_string_value("pT-magnetUri");
item.save_path = node.dict_find_string_value("pT-savePath", config_->default_save_path.c_str());
item.url = node.dict_find_string_value("pT-url");

int64_t queuePosition = node.dict_find_int_value("pT-queuePosition", maxPosition);
if (queuePosition < 0) { queuePosition = maxPosition; }
Expand Down Expand Up @@ -402,7 +404,6 @@ void session::load_torrents()
if (ec)
{
LOG(error) << "Failed to read resume data, " << ec.message();
continue;
}
}

Expand Down Expand Up @@ -441,7 +442,14 @@ void session::load_torrents()
params.save_path = item.save_path;
}

params.url = item.magnet_uri;
if (item.url.empty())
{
params.url = item.magnet_uri;
}
else
{
params.url = item.url;
}

sess_->async_add_torrent(params);
}
Expand Down Expand Up @@ -482,9 +490,13 @@ void session::notify()
{
save_torrent(*al->handle.torrent_file());
}
else if (!al->params.url.empty())
else if (!al->params.url.empty() || !al->params.info_hash.is_all_zeros())
{
// Save resume data
al->handle.save_resume_data();

lt::entry::dictionary_type e;
e.insert({ "pT-magnetUri", "magnet:?xt=urn:btih:" + lt::to_hex(al->params.info_hash.to_string()) });
e.insert({ "pT-queuePosition", al->handle.status().queue_position });
e.insert({ "pT-url", al->params.url });

Expand Down

0 comments on commit 3e7f2ba

Please sign in to comment.