diff --git a/apps/i2psnark/java/src/org/klomp/snark/Storage.java b/apps/i2psnark/java/src/org/klomp/snark/Storage.java index edcab93cb..04b9f7c11 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/Storage.java +++ b/apps/i2psnark/java/src/org/klomp/snark/Storage.java @@ -316,15 +316,34 @@ public class Storage } /** + * Get index to pass to remaining(), getPriority(), setPriority() + * * @param file non-canonical path (non-directory) + * @return internal index of file; -1 if unknown file + * @since 0.9.15 + */ + public int indexOf(File file) { + for (int i = 0; i < _torrentFiles.size(); i++) { + File f = _torrentFiles.get(i).RAFfile; + if (f.equals(file)) + return i; + } + return -1; + } + + /** + * @param fileIndex as obtained from indexOf * @return number of bytes remaining; -1 if unknown file * @since 0.7.14 */ - public long remaining(File file) { + public long remaining(int fileIndex) { + if (fileIndex < 0 || fileIndex >= _torrentFiles.size()) + return -1; long bytes = 0; - for (TorrentFile tf : _torrentFiles) { - File f = tf.RAFfile; - if (f.equals(file)) { + for (int i = 0; i < _torrentFiles.size(); i++) { + TorrentFile tf = _torrentFiles.get(i); + if (i == fileIndex) { + File f = tf.RAFfile; if (complete()) return 0; int psz = piece_size; @@ -350,37 +369,30 @@ public class Storage } /** - * @param file non-canonical path (non-directory) + * @param fileIndex as obtained from indexOf * @since 0.8.1 */ - public int getPriority(File file) { + public int getPriority(int fileIndex) { if (complete() || metainfo.getFiles() == null) return 0; - for (TorrentFile tf : _torrentFiles) { - File f = tf.RAFfile; - if (f.equals(file)) - return tf.priority; - } - return 0; + if (fileIndex < 0 || fileIndex >= _torrentFiles.size()) + return 0; + return _torrentFiles.get(fileIndex).priority; } /** * Must call Snark.updatePiecePriorities() * (which calls getPiecePriorities()) after calling this. - * @param file non-canonical path (non-directory) + * @param fileIndex as obtained from indexOf * @param pri default 0; <0 to disable * @since 0.8.1 */ - public void setPriority(File file, int pri) { + public void setPriority(int fileIndex, int pri) { if (complete() || metainfo.getFiles() == null) return; - for (TorrentFile tf : _torrentFiles) { - File f = tf.RAFfile; - if (f.equals(file)) { - tf.priority = pri; - return; - } - } + if (fileIndex < 0 || fileIndex >= _torrentFiles.size()) + return; + _torrentFiles.get(fileIndex).priority = pri; } /** 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 e8fdcff91..9e346db71 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java +++ b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java @@ -1432,8 +1432,7 @@ public class I2PSnarkServlet extends BasicServlet { out.write(""); + out.write(" onclick=\"document.location='" + encodedBaseName + "/';\">"); } else { out.write('>'); } @@ -2692,6 +2691,7 @@ public class I2PSnarkServlet extends BasicServlet { boolean complete = false; String status = ""; long length = item.length(); + int fileIndex = -1; int priority = 0; if (item.isDirectory()) { complete = true; @@ -2703,8 +2703,9 @@ public class I2PSnarkServlet extends BasicServlet { status = toImg("cancel") + ' ' + _("Torrent not found?"); } else { Storage storage = snark.getStorage(); + fileIndex = storage.indexOf(item); - long remaining = storage.remaining(item); + long remaining = storage.remaining(fileIndex); if (remaining < 0) { complete = true; status = toImg("cancel") + ' ' + _("File not found in torrent?"); @@ -2712,7 +2713,7 @@ public class I2PSnarkServlet extends BasicServlet { complete = true; status = toImg("tick") + ' ' + _("Complete"); } else { - priority = storage.getPriority(item); + priority = storage.getPriority(fileIndex); if (priority < 0) status = toImg("cancel"); else if (priority == 0) @@ -2764,17 +2765,17 @@ public class I2PSnarkServlet extends BasicServlet { if (showPriority) { buf.append(""); if ((!complete) && (!item.isDirectory())) { - buf.append(" 0) buf.append("checked=\"true\""); buf.append('>').append(_("High")); - buf.append("').append(_("Normal")); - buf.append("').append(_("Skip")); @@ -2873,10 +2874,10 @@ public class I2PSnarkServlet extends BasicServlet { String key = entry.getKey(); if (key.startsWith("pri.")) { try { - File file = new File(key.substring(4)); + int fileIndex = Integer.parseInt(key.substring(4)); String val = entry.getValue()[0]; // jetty arrays int pri = Integer.parseInt(val); - storage.setPriority(file, pri); + storage.setPriority(fileIndex, pri); //System.err.println("Priority now " + pri + " for " + file); } catch (Throwable t) { t.printStackTrace(); } } diff --git a/apps/i2psnark/java/src/org/klomp/snark/web/URIUtil.java b/apps/i2psnark/java/src/org/klomp/snark/web/URIUtil.java index aae95b515..10f33b022 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/web/URIUtil.java +++ b/apps/i2psnark/java/src/org/klomp/snark/web/URIUtil.java @@ -84,6 +84,7 @@ class URIUtil case '<': case '>': case ' ': + case ':': buf=new StringBuilder(path.length()*2); break loop; default: @@ -139,6 +140,9 @@ class URIUtil case 0x7f: buf.append("%7F"); continue; + case ':': + buf.append("%3A"); + continue; default: if (c <= 0x1f) // includes negative toHex(c,buf); @@ -183,6 +187,9 @@ class URIUtil case ' ': buf.append("%20"); continue; + case ':': + buf.append("%3A"); + continue; default: if (c <= 0x1f || (c >= 0x7f && c <= 0x9f) || Character.isSpaceChar(c)) toHex(c,buf); diff --git a/history.txt b/history.txt index 474f1ec42..42de88f60 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,6 @@ +2014-09-09 zzz + * i2psnark: Escape fixes + 2014-08-31 zzz * Build: Add support for bundling router infos in the package * I2PTunnel: Allow changing of spoof host and target host/port without diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 25340f779..421ff4f63 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -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 = 15; + public final static long BUILD = 16; /** for example "-test" */ public final static String EXTRA = "-rc";