From 1b0102bd1cec573cbbf9cd37f22cf13181344175 Mon Sep 17 00:00:00 2001 From: zzz Date: Wed, 18 Jul 2018 12:08:40 +0000 Subject: [PATCH] i2psnark: Enable sequential order option for single-file torrents (ticket #2234) --- apps/i2psnark/java/src/org/klomp/snark/Storage.java | 12 ++++++------ .../src/org/klomp/snark/web/I2PSnarkServlet.java | 7 +++++-- router/java/src/net/i2p/router/RouterVersion.java | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/apps/i2psnark/java/src/org/klomp/snark/Storage.java b/apps/i2psnark/java/src/org/klomp/snark/Storage.java index 91dd34261..77843cd74 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/Storage.java +++ b/apps/i2psnark/java/src/org/klomp/snark/Storage.java @@ -440,9 +440,9 @@ public class Storage implements Closeable */ public int getPriority(int fileIndex) { if (complete() || metainfo.getFiles() == null) - return 0; + return PRIORITY_NORMAL; if (fileIndex < 0 || fileIndex >= _torrentFiles.size()) - return 0; + return PRIORITY_NORMAL; return _torrentFiles.get(fileIndex).priority; } @@ -488,7 +488,7 @@ public class Storage implements Closeable void setFilePriorities(int[] p) { if (p == null) { for (TorrentFile tf : _torrentFiles) { - tf.priority = 0; + tf.priority = PRIORITY_NORMAL; } } else { int sz = _torrentFiles.size(); @@ -517,7 +517,7 @@ public class Storage implements Closeable if (yes == _inOrder) return; _inOrder = yes; - if (complete() || metainfo.getFiles() == null) + if (complete()) return; if (yes) { List sorted = _torrentFiles; @@ -560,11 +560,11 @@ public class Storage implements Closeable * Set the piece priority to the highest priority * of all files spanning the piece. * Caller must pass array to the PeerCoordinator. - * @return null on error, if complete, or if only one file + * @return null on error, if complete, or if only one file and inOrder not set. * @since 0.8.1 */ public int[] getPiecePriorities() { - if (complete() || metainfo.getFiles() == null) + if (complete() || (metainfo.getFiles() == null && !_inOrder)) return null; int[] rv = new int[metainfo.getPieces()]; int file = 0; diff --git a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java index 7e61f65d5..0a9fb8e73 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java +++ b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java @@ -3286,11 +3286,14 @@ public class I2PSnarkServlet extends BasicServlet { .append("\">\n"); } boolean showInOrder = storage != null && !storage.complete() && - meta != null && meta.getFiles() != null && meta.getFiles().size() > 1; + meta != null; if (showInOrder) { buf.append("\n" + ""); - buf.append(_t("Download files in order")); + String txt = (meta.getFiles() != null && meta.getFiles().size() > 1) ? + _t("Download files in order") : + _t("Download pieces in order"); + buf.append(txt); buf.append(":