|
|
@ -74,6 +74,7 @@ import org.transdroid.daemon.task.GetTorrentDetailsTaskSuccessResult; |
|
|
|
import org.transdroid.daemon.task.RemoveTask; |
|
|
|
import org.transdroid.daemon.task.RemoveTask; |
|
|
|
import org.transdroid.daemon.task.RetrieveTask; |
|
|
|
import org.transdroid.daemon.task.RetrieveTask; |
|
|
|
import org.transdroid.daemon.task.RetrieveTaskSuccessResult; |
|
|
|
import org.transdroid.daemon.task.RetrieveTaskSuccessResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.SetDownloadLocationTask; |
|
|
|
import org.transdroid.daemon.task.SetFilePriorityTask; |
|
|
|
import org.transdroid.daemon.task.SetFilePriorityTask; |
|
|
|
import org.transdroid.daemon.task.SetLabelTask; |
|
|
|
import org.transdroid.daemon.task.SetLabelTask; |
|
|
|
import org.transdroid.daemon.task.SetTrackersTask; |
|
|
|
import org.transdroid.daemon.task.SetTrackersTask; |
|
|
@ -217,7 +218,7 @@ public class DelugeDirectAdapter implements IDaemonAdapter { |
|
|
|
case SetLabel: |
|
|
|
case SetLabel: |
|
|
|
return doSetLabel((SetLabelTask) task); |
|
|
|
return doSetLabel((SetLabelTask) task); |
|
|
|
case SetDownloadLocation: |
|
|
|
case SetDownloadLocation: |
|
|
|
return notSupported(task); |
|
|
|
return doSetDownloadLocation((SetDownloadLocationTask) task); |
|
|
|
case GetTorrentDetails: |
|
|
|
case GetTorrentDetails: |
|
|
|
return doGetTorrentDetails((GetTorrentDetailsTask) task); |
|
|
|
return doGetTorrentDetails((GetTorrentDetailsTask) task); |
|
|
|
case SetTrackers: |
|
|
|
case SetTrackers: |
|
|
@ -377,6 +378,13 @@ public class DelugeDirectAdapter implements IDaemonAdapter { |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
|
|
|
|
private DaemonTaskResult doSetDownloadLocation(SetDownloadLocationTask task) |
|
|
|
|
|
|
|
throws DaemonException { |
|
|
|
|
|
|
|
sendRequest(RPC_METHOD_MOVESTORAGE, getTorrentIdsArg(task), task.getNewLocation()); |
|
|
|
|
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private List<Torrent> getTorrents() throws DaemonException { |
|
|
|
private List<Torrent> getTorrents() throws DaemonException { |
|
|
|
final Map response = (Map) sendRequest( |
|
|
|
final Map response = (Map) sendRequest( |
|
|
@ -502,6 +510,7 @@ public class DelugeDirectAdapter implements IDaemonAdapter { |
|
|
|
return files; |
|
|
|
return files; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
private Object sendRequest(String method, Object... args) |
|
|
|
private Object sendRequest(String method, Object... args) |
|
|
|
throws DaemonException { |
|
|
|
throws DaemonException { |
|
|
|
final List<Object> requests = new ArrayList<>(); |
|
|
|
final List<Object> requests = new ArrayList<>(); |
|
|
@ -549,6 +558,7 @@ public class DelugeDirectAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
private Object readResponse(InputStream in) throws DaemonException, IOException { |
|
|
|
private Object readResponse(InputStream in) throws DaemonException, IOException { |
|
|
|
final InflaterInputStream inflater = new InflaterInputStream(in); |
|
|
|
final InflaterInputStream inflater = new InflaterInputStream(in); |
|
|
|
final ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
final ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
@ -571,6 +581,7 @@ public class DelugeDirectAdapter implements IDaemonAdapter { |
|
|
|
return response.get(2); |
|
|
|
return response.get(2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
private byte[] compress(byte[] bytes) throws IOException { |
|
|
|
private byte[] compress(byte[] bytes) throws IOException { |
|
|
|
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); |
|
|
|
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); |
|
|
|
try { |
|
|
|
try { |
|
|
@ -587,6 +598,7 @@ public class DelugeDirectAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
private Socket openSocket() throws DaemonException { |
|
|
|
private Socket openSocket() throws DaemonException { |
|
|
|
try { |
|
|
|
try { |
|
|
|
final TrustManager[] trustAllCerts = new TrustManager[]{new AcceptAllTrustManager()}; |
|
|
|
final TrustManager[] trustAllCerts = new TrustManager[]{new AcceptAllTrustManager()}; |
|
|
@ -609,6 +621,7 @@ public class DelugeDirectAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
private byte[] loadFile(String url) throws DaemonException { |
|
|
|
private byte[] loadFile(String url) throws DaemonException { |
|
|
|
final File file = new File(URI.create(url)); |
|
|
|
final File file = new File(URI.create(url)); |
|
|
|
final BufferedInputStream in; |
|
|
|
final BufferedInputStream in; |
|
|
@ -666,6 +679,7 @@ public class DelugeDirectAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Move method to a common file used by both Adapters.
|
|
|
|
// TODO: Move method to a common file used by both Adapters.
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
private Priority convertDelugePriority(int priority) { |
|
|
|
private Priority convertDelugePriority(int priority) { |
|
|
|
// TODO: Handle version
|
|
|
|
// TODO: Handle version
|
|
|
|
switch (priority) { |
|
|
|
switch (priority) { |
|
|
@ -743,14 +757,21 @@ public class DelugeDirectAdapter implements IDaemonAdapter { |
|
|
|
return new String[]{task.getTargetTorrent().getUniqueID()}; |
|
|
|
return new String[]{task.getTargetTorrent().getUniqueID()}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Used to count torrents in labels. |
|
|
|
|
|
|
|
*/ |
|
|
|
private static class MutableInt { |
|
|
|
private static class MutableInt { |
|
|
|
|
|
|
|
|
|
|
|
int value = 1; |
|
|
|
int value = 1; |
|
|
|
|
|
|
|
|
|
|
|
MutableInt(int value) { |
|
|
|
MutableInt(int value) { |
|
|
|
this.value = value; |
|
|
|
this.value = value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void increment() { |
|
|
|
void increment() { |
|
|
|
++value; |
|
|
|
++value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int get() { |
|
|
|
int get() { |
|
|
|
return value; |
|
|
|
return value; |
|
|
|
} |
|
|
|
} |
|
|
|