i2psnark: Enable sequential order option for single-file torrents (ticket #2234)

This commit is contained in:
zzz
2018-07-18 12:08:40 +00:00
parent 2a68a01a35
commit 1b0102bd1c
3 changed files with 12 additions and 9 deletions

View File

@ -440,9 +440,9 @@ public class Storage implements Closeable
*/ */
public int getPriority(int fileIndex) { public int getPriority(int fileIndex) {
if (complete() || metainfo.getFiles() == null) if (complete() || metainfo.getFiles() == null)
return 0; return PRIORITY_NORMAL;
if (fileIndex < 0 || fileIndex >= _torrentFiles.size()) if (fileIndex < 0 || fileIndex >= _torrentFiles.size())
return 0; return PRIORITY_NORMAL;
return _torrentFiles.get(fileIndex).priority; return _torrentFiles.get(fileIndex).priority;
} }
@ -488,7 +488,7 @@ public class Storage implements Closeable
void setFilePriorities(int[] p) { void setFilePriorities(int[] p) {
if (p == null) { if (p == null) {
for (TorrentFile tf : _torrentFiles) { for (TorrentFile tf : _torrentFiles) {
tf.priority = 0; tf.priority = PRIORITY_NORMAL;
} }
} else { } else {
int sz = _torrentFiles.size(); int sz = _torrentFiles.size();
@ -517,7 +517,7 @@ public class Storage implements Closeable
if (yes == _inOrder) if (yes == _inOrder)
return; return;
_inOrder = yes; _inOrder = yes;
if (complete() || metainfo.getFiles() == null) if (complete())
return; return;
if (yes) { if (yes) {
List<TorrentFile> sorted = _torrentFiles; List<TorrentFile> sorted = _torrentFiles;
@ -560,11 +560,11 @@ public class Storage implements Closeable
* Set the piece priority to the highest priority * Set the piece priority to the highest priority
* of all files spanning the piece. * of all files spanning the piece.
* Caller must pass array to the PeerCoordinator. * 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 * @since 0.8.1
*/ */
public int[] getPiecePriorities() { public int[] getPiecePriorities() {
if (complete() || metainfo.getFiles() == null) if (complete() || (metainfo.getFiles() == null && !_inOrder))
return null; return null;
int[] rv = new int[metainfo.getPieces()]; int[] rv = new int[metainfo.getPieces()];
int file = 0; int file = 0;

View File

@ -3286,11 +3286,14 @@ public class I2PSnarkServlet extends BasicServlet {
.append("\">\n"); .append("\">\n");
} }
boolean showInOrder = storage != null && !storage.complete() && boolean showInOrder = storage != null && !storage.complete() &&
meta != null && meta.getFiles() != null && meta.getFiles().size() > 1; meta != null;
if (showInOrder) { if (showInOrder) {
buf.append("</td></tr>\n" + buf.append("</td></tr>\n" +
"<tr id=\"torrentOrderControl\"><td colspan=\"2\">"); "<tr id=\"torrentOrderControl\"><td colspan=\"2\">");
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(":<input type=\"checkbox\" class=\"optbox\" name=\"enableInOrder\" id=\"enableInOrder\" "); buf.append(":<input type=\"checkbox\" class=\"optbox\" name=\"enableInOrder\" id=\"enableInOrder\" ");
if (storage.getInOrder()) if (storage.getInOrder())
buf.append("checked=\"checked\""); buf.append("checked=\"checked\"");

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 14; public final static long BUILD = 15;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "";