Skip to content

Commit

Permalink
Add option to force recheck torrents (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
vktr committed Feb 25, 2018
1 parent b92da0b commit 6272c2f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lang/1033.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
"invalid_regex": "Invalid regular expression",
"info_hash": "Info hash",
"fails": "Fails",
"verified": "Verified"
"verified": "Verified",
"force_recheck": "Force recheck"
}
}
17 changes: 17 additions & 0 deletions src/picotorrent/mainframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,23 @@ void MainFrame::OnSessionAlert()

break;
}
case lt::torrent_checked_alert::alert_type:
{
lt::torrent_checked_alert* tca = lt::alert_cast<lt::torrent_checked_alert>(alert);

auto it = std::find(
m_state->pause_after_checking.begin(),
m_state->pause_after_checking.end(),
tca->handle.info_hash());

if (it != m_state->pause_after_checking.end())
{
tca->handle.pause();
m_state->pause_after_checking.erase(it);
}

break;
}
case lt::torrent_removed_alert::alert_type:
{
lt::torrent_removed_alert* tra = lt::alert_cast<lt::torrent_removed_alert>(alert);
Expand Down
1 change: 1 addition & 0 deletions src/picotorrent/sessionstate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace pt
bool IsSelected(libtorrent::sha1_hash const& hash);

std::vector<libtorrent::sha1_hash> loaded_torrents;
std::vector<libtorrent::sha1_hash> pause_after_checking;
std::vector<libtorrent::torrent_handle> selected_torrents;
std::unique_ptr<libtorrent::session> session;
std::map<libtorrent::sha1_hash, libtorrent::torrent_handle> torrents;
Expand Down
21 changes: 21 additions & 0 deletions src/picotorrent/torrentcontextmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ BEGIN_EVENT_TABLE(TorrentContextMenu, wxMenu)
EVT_MENU(ptID_REMOVE, TorrentContextMenu::Remove)
EVT_MENU(ptID_COPY_INFO_HASH, TorrentContextMenu::CopyInfoHash)
EVT_MENU(ptID_OPEN_IN_EXPLORER, TorrentContextMenu::OpenInExplorer)
EVT_MENU(ptID_FORCE_RECHECK, TorrentContextMenu::ForceRecheck)
END_EVENT_TABLE()

TorrentContextMenu::TorrentContextMenu(
Expand Down Expand Up @@ -79,6 +80,7 @@ TorrentContextMenu::TorrentContextMenu(
}

AppendSeparator();
Append(ptID_FORCE_RECHECK, i18n(tr, "force_recheck"));
Append(ptID_MOVE, i18n(tr, "move"));
Append(ptID_REMOVE, i18n(tr, "remove"));
AppendSeparator();
Expand All @@ -104,6 +106,25 @@ void TorrentContextMenu::CopyInfoHash(wxCommandEvent& WXUNUSED(event))
}
}

void TorrentContextMenu::ForceRecheck(wxCommandEvent& WXUNUSED(event))
{
for (lt::torrent_handle& th : m_state->selected_torrents)
{
th.force_recheck();

lt::torrent_status ts = th.status();

bool paused = ((ts.flags & lt::torrent_flags::paused)
&& !(ts.flags & lt::torrent_flags::auto_managed));

if (paused)
{
th.resume();
m_state->pause_after_checking.push_back(ts.info_hash);
}
}
}

void TorrentContextMenu::Move(wxCommandEvent& WXUNUSED(event))
{
wxDirDialog dlg(
Expand Down
4 changes: 3 additions & 1 deletion src/picotorrent/torrentcontextmenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ namespace pt
ptID_QUEUE_TOP,
ptID_QUEUE_BOTTOM,
ptID_COPY_INFO_HASH,
ptID_OPEN_IN_EXPLORER
ptID_OPEN_IN_EXPLORER,
ptID_FORCE_RECHECK
};

wxDECLARE_EVENT_TABLE();

void CopyInfoHash(wxCommandEvent&);
void ForceRecheck(wxCommandEvent&);
void Move(wxCommandEvent&);
void OpenInExplorer(wxCommandEvent&);
void Pause(wxCommandEvent&);
Expand Down

0 comments on commit 6272c2f

Please sign in to comment.