forked from I2P_Developers/i2p.i2p
* i2psnark: Escape fixes
- fix ':' in name (again) - Change priority key from file name to file number so we don't hav to escape
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1432,8 +1432,7 @@ public class I2PSnarkServlet extends BasicServlet {
|
||||
out.write("</td><td class=\"snarkTorrentName\"");
|
||||
if (isMultiFile) {
|
||||
// link on the whole td
|
||||
String jsec = encodedBaseName.replace("'", "\\'");
|
||||
out.write(" onclick=\"document.location='" + jsec + "/';\">");
|
||||
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("<td class=\"priority\">");
|
||||
if ((!complete) && (!item.isDirectory())) {
|
||||
buf.append("<input type=\"radio\" value=\"5\" name=\"pri.").append(item).append("\" ");
|
||||
buf.append("<input type=\"radio\" value=\"5\" name=\"pri.").append(fileIndex).append("\" ");
|
||||
if (priority > 0)
|
||||
buf.append("checked=\"true\"");
|
||||
buf.append('>').append(_("High"));
|
||||
|
||||
buf.append("<input type=\"radio\" value=\"0\" name=\"pri.").append(item).append("\" ");
|
||||
buf.append("<input type=\"radio\" value=\"0\" name=\"pri.").append(fileIndex).append("\" ");
|
||||
if (priority == 0)
|
||||
buf.append("checked=\"true\"");
|
||||
buf.append('>').append(_("Normal"));
|
||||
|
||||
buf.append("<input type=\"radio\" value=\"-9\" name=\"pri.").append(item).append("\" ");
|
||||
buf.append("<input type=\"radio\" value=\"-9\" name=\"pri.").append(fileIndex).append("\" ");
|
||||
if (priority < 0)
|
||||
buf.append("checked=\"true\"");
|
||||
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(); }
|
||||
}
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user