Browse Source

Merge pull request #368 from Niluge-KiWi/rtorrent_fix_stop_pause

Fix stop/pause for rtorrent
pull/311/merge
Eric Kok 7 years ago committed by GitHub
parent
commit
06b041c2f2
  1. 48
      app/src/main/java/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java

48
app/src/main/java/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java

@ -135,7 +135,8 @@ public class RtorrentAdapter implements IDaemonAdapter { @@ -135,7 +135,8 @@ public class RtorrentAdapter implements IDaemonAdapter {
"d.custom=seedingtime",
"d.custom1=",
"d.peers_complete=",
"d.peers_accounted=" });
"d.peers_accounted=",
"d.is_open=" });
// @formatter:on
return new RetrieveTaskSuccessResult((RetrieveTask) task, onTorrentsRetrieved(result),
lastKnownLabels);
@ -226,49 +227,51 @@ public class RtorrentAdapter implements IDaemonAdapter { @@ -226,49 +227,51 @@ public class RtorrentAdapter implements IDaemonAdapter {
case Pause:
// Pause a torrent
makeRtorrentCall(log, "d.pause", new String[]{task.getTargetTorrent().getUniqueID()});
makeRtorrentCall(log, "d.stop", new String[]{task.getTargetTorrent().getUniqueID()});
return new DaemonTaskSuccessResult(task);
case PauseAll:
// Resume all torrents
makeRtorrentCall(log, "d.multicall2", new String[]{"","main", "d.pause="});
makeRtorrentCall(log, "d.multicall2", new String[]{"","main", "d.stop="});
return new DaemonTaskSuccessResult(task);
case Resume:
// Resume a torrent
makeRtorrentCall(log, "d.resume", new String[]{task.getTargetTorrent().getUniqueID()});
makeRtorrentCall(log, "d.start", new String[]{task.getTargetTorrent().getUniqueID()});
return new DaemonTaskSuccessResult(task);
case ResumeAll:
// Resume all torrents
makeRtorrentCall(log, "d.multicall2", new String[]{"", "main", "d.resume="});
makeRtorrentCall(log, "d.multicall2", new String[]{"", "main", "d.start="});
return new DaemonTaskSuccessResult(task);
case Stop:
// Stop a torrent
makeRtorrentCall(log, "d.stop", new String[]{task.getTargetTorrent().getUniqueID()});
makeRtorrentCall(log, "d.close", new String[]{task.getTargetTorrent().getUniqueID()});
return new DaemonTaskSuccessResult(task);
case StopAll:
// Stop all torrents
makeRtorrentCall(log, "d.multicall2", new String[]{"", "main", "d.stop="});
makeRtorrentCall(log, "d.multicall2", new String[]{"", "main", "d.stop=", "d.close="});
return new DaemonTaskSuccessResult(task);
case Start:
// Start a torrent
makeRtorrentCall(log, "d.open", new String[]{task.getTargetTorrent().getUniqueID()});
makeRtorrentCall(log, "d.start", new String[]{task.getTargetTorrent().getUniqueID()});
return new DaemonTaskSuccessResult(task);
case StartAll:
// Start all torrents
makeRtorrentCall(log, "d.multicall2", new String[]{"", "main", "d.start="});
makeRtorrentCall(log, "d.multicall2", new String[]{"", "main", "d.open=", "d.start="});
return new DaemonTaskSuccessResult(task);
case SetFilePriorities:
@ -454,7 +457,7 @@ public class RtorrentAdapter implements IDaemonAdapter { @@ -454,7 +457,7 @@ public class RtorrentAdapter implements IDaemonAdapter {
i,
(String)info[0], // hash
(String)info[1], // name
convertTorrentStatus((Long)info[2], (Long)info[13], (Long)info[14], (Long)info[15]), // status
convertTorrentStatus((Long)info[2], (Long)info[24], (Long)info[13], (Long)info[14], (Long)info[15]), // status
basePath.substring(0, basePath.indexOf((String)info[17])), // locationDir
((Long)info[3]).intValue(), // rateDownload
((Long)info[4]).intValue(), // rateUpload
@ -486,7 +489,7 @@ public class RtorrentAdapter implements IDaemonAdapter { @@ -486,7 +489,7 @@ public class RtorrentAdapter implements IDaemonAdapter {
i,
(String)info[0], // hash
(String)info[1], // name
convertTorrentStatus(((Integer)info[2]).longValue(), ((Integer)info[13]).longValue(), ((Integer)info[14]).longValue(), ((Integer)info[15]).longValue()), // status
convertTorrentStatus(((Integer)info[2]).longValue(), ((Integer)info[24]).longValue(), ((Integer)info[13]).longValue(), ((Integer)info[14]).longValue(), ((Integer)info[15]).longValue()), // status
basePath.substring(0, basePath.indexOf((String)info[17])), // locationDir
rateDownload, // rateDownload
(Integer)info[4], // rateUpload
@ -607,19 +610,24 @@ public class RtorrentAdapter implements IDaemonAdapter { @@ -607,19 +610,24 @@ public class RtorrentAdapter implements IDaemonAdapter {
}
}
private TorrentStatus convertTorrentStatus(Long state, Long complete, Long active, Long checking) {
if (state == 0) {
return TorrentStatus.Queued;
} else if (active == 1) {
if (complete == 1) {
return TorrentStatus.Seeding;
} else {
return TorrentStatus.Downloading;
}
} else if (checking == 1) {
private TorrentStatus convertTorrentStatus(Long state, Long open, Long complete, Long active, Long checking) {
if (checking == 1) {
return TorrentStatus.Checking;
} else {
}
if (open == 1) {
// links with tracker/peers are open: not stopped
if (state == 1 && active == 1) {
if (complete == 1) {
return TorrentStatus.Seeding;
} else {
return TorrentStatus.Downloading;
}
}
return TorrentStatus.Paused;
} else {
// maybe could be Stopped or Waiting
return TorrentStatus.Queued;
}
}

Loading…
Cancel
Save