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) {
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<TorrentFile> 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;

View File

@ -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("</td></tr>\n" +
"<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\" ");
if (storage.getInOrder())
buf.append("checked=\"checked\"");

View File

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