i2psnark: Fix autostart for torrent files copied into the dir

Use Collator for case-insensitive sort
Use Exception.getLocalizedMessage()
Prevent duplicate torrent starts
Don't write debug info to wrapper log
Increase max piece size
Navbar cleanup
This commit is contained in:
zzz
2019-12-21 12:54:48 +00:00
parent ccaf4ce4b9
commit fcd8a3ae69
6 changed files with 19 additions and 18 deletions

View File

@ -552,6 +552,8 @@ public class Snark
* @throws RuntimeException via fatal() * @throws RuntimeException via fatal()
*/ */
public synchronized void startTorrent() { public synchronized void startTorrent() {
if (!stopped)
return;
starting = true; starting = true;
try { try {
x_startTorrent(); x_startTorrent();

View File

@ -1590,7 +1590,7 @@ public class SnarkManager implements CompleteListener, ClientApp {
fis = new FileInputStream(sfile); fis = new FileInputStream(sfile);
} catch (IOException ioe) { } catch (IOException ioe) {
// catch this here so we don't try do delete it below // catch this here so we don't try do delete it below
addMessage(_t("Cannot open \"{0}\"", sfile.getName()) + ": " + ioe.getMessage()); addMessage(_t("Cannot open \"{0}\"", sfile.getName()) + ": " + ioe.getLocalizedMessage());
return false; return false;
} }
@ -1654,13 +1654,13 @@ public class SnarkManager implements CompleteListener, ClientApp {
} catch (IOException ioe) { } catch (IOException ioe) {
// close before rename/delete for windows // close before rename/delete for windows
if (fis != null) try { fis.close(); fis = null; } catch (IOException ioe2) {} if (fis != null) try { fis.close(); fis = null; } catch (IOException ioe2) {}
String err = _t("Torrent in \"{0}\" is invalid", sfile.toString()) + ": " + ioe.getMessage(); String err = _t("Torrent in \"{0}\" is invalid", sfile.toString()) + ": " + ioe.getLocalizedMessage();
addMessage(err); addMessage(err);
_log.error(err, ioe); _log.error(err, ioe);
disableTorrentFile(filename); disableTorrentFile(filename);
return false; return false;
} catch (OutOfMemoryError oom) { } catch (OutOfMemoryError oom) {
addMessage(_t("ERROR - Out of memory, cannot create torrent from {0}", sfile.getName()) + ": " + oom.getMessage()); addMessage(_t("ERROR - Out of memory, cannot create torrent from {0}", sfile.getName()) + ": " + oom.getLocalizedMessage());
return false; return false;
} finally { } finally {
if (fis != null) try { fis.close(); } catch (IOException ioe) {} if (fis != null) try { fis.close(); } catch (IOException ioe) {}
@ -2232,13 +2232,17 @@ public class SnarkManager implements CompleteListener, ClientApp {
*/ */
private void locked_saveTorrentStatus(byte[] ih, Properties config) { private void locked_saveTorrentStatus(byte[] ih, Properties config) {
File conf = configFile(_configDir, ih); File conf = configFile(_configDir, ih);
if (shouldAutoStart() && !conf.exists()) {
// force on for new torrents
config.setProperty(PROP_META_RUNNING, "true");
}
File subdir = conf.getParentFile(); File subdir = conf.getParentFile();
if (!subdir.exists()) if (!subdir.exists())
subdir.mkdirs(); subdir.mkdirs();
try { try {
DataHelper.storeProps(config, conf); DataHelper.storeProps(config, conf);
if (_log.shouldInfo()) if (_log.shouldInfo())
_log.info("Saved config to " + conf); _log.info("Saved config to " + conf /* , new Exception() */ );
} catch (IOException ioe) { } catch (IOException ioe) {
_log.error("Unable to save the config to " + conf); _log.error("Unable to save the config to " + conf);
} }
@ -2391,12 +2395,13 @@ public class SnarkManager implements CompleteListener, ClientApp {
} else if (info.getTotalLength() <= 0) { } else if (info.getTotalLength() <= 0) {
return _t("Torrent \"{0}\" has no data!", info.getName()); return _t("Torrent \"{0}\" has no data!", info.getName());
} else if (info.getTotalLength() > Storage.MAX_TOTAL_SIZE) { } else if (info.getTotalLength() > Storage.MAX_TOTAL_SIZE) {
/*
System.out.println("torrent info: " + info.toString()); System.out.println("torrent info: " + info.toString());
List<Long> lengths = info.getLengths(); List<Long> lengths = info.getLengths();
if (lengths != null) if (lengths != null)
for (int i = 0; i < lengths.size(); i++) for (int i = 0; i < lengths.size(); i++)
System.out.println("File " + i + " is " + lengths.get(i) + " long."); System.out.println("File " + i + " is " + lengths.get(i) + " long.");
*/
return _t("Torrents larger than {0}B are not supported yet \"{1}\"!", Storage.MAX_TOTAL_SIZE, info.getName()); return _t("Torrents larger than {0}B are not supported yet \"{1}\"!", Storage.MAX_TOTAL_SIZE, info.getName());
} else { } else {
// ok // ok
@ -2414,7 +2419,7 @@ public class SnarkManager implements CompleteListener, ClientApp {
filename = sfile.getCanonicalPath(); filename = sfile.getCanonicalPath();
} catch (IOException ioe) { } catch (IOException ioe) {
_log.error("Unable to remove the torrent " + filename, ioe); _log.error("Unable to remove the torrent " + filename, ioe);
addMessage(_t("Error: Could not remove the torrent {0}", filename) + ": " + ioe.getMessage()); addMessage(_t("Error: Could not remove the torrent {0}", filename) + ": " + ioe.getLocalizedMessage());
return null; return null;
} }
int remaining = 0; int remaining = 0;
@ -2709,8 +2714,8 @@ public class SnarkManager implements CompleteListener, ClientApp {
} }
Set<String> existingNames = listTorrentFiles(); Set<String> existingNames = listTorrentFiles();
if (_log.shouldLog(Log.DEBUG)) //if (_log.shouldLog(Log.DEBUG))
_log.debug("DirMon found: " + DataHelper.toString(foundNames) + " existing: " + DataHelper.toString(existingNames)); // _log.debug("DirMon found: " + DataHelper.toString(foundNames) + " existing: " + DataHelper.toString(existingNames));
// lets find new ones first... // lets find new ones first...
boolean shouldStart = shouldAutoStart(); boolean shouldStart = shouldAutoStart();
for (String name : foundNames) { for (String name : foundNames) {
@ -3086,14 +3091,15 @@ public class SnarkManager implements CompleteListener, ClientApp {
} }
} }
} }
/** /**
* ignore case, current locale * ignore case, current locale
* @since 0.9 * @since 0.9
*/ */
private static class IgnoreCaseComparator implements Comparator<Tracker>, Serializable { private static class IgnoreCaseComparator implements Comparator<Tracker>, Serializable {
private final Collator coll = Collator.getInstance();
public int compare(Tracker l, Tracker r) { public int compare(Tracker l, Tracker r) {
return l.name.toLowerCase().compareTo(r.name.toLowerCase()); return coll.compare(l.name, r.name);
} }
} }
} }

View File

@ -85,7 +85,7 @@ public class Storage implements Closeable
/** The default piece size. */ /** The default piece size. */
private static final int DEFAULT_PIECE_SIZE = 256*1024; private static final int DEFAULT_PIECE_SIZE = 256*1024;
/** bigger than this will be rejected */ /** bigger than this will be rejected */
public static final int MAX_PIECE_SIZE = 16*1024*1024; public static final int MAX_PIECE_SIZE = 32*1024*1024;
/** The maximum number of pieces in a torrent. */ /** The maximum number of pieces in a torrent. */
public static final int MAX_PIECES = 32*1024; public static final int MAX_PIECES = 32*1024;
public static final long MAX_TOTAL_SIZE = MAX_PIECE_SIZE * (long) MAX_PIECES; public static final long MAX_TOTAL_SIZE = MAX_PIECE_SIZE * (long) MAX_PIECES;

View File

@ -728,7 +728,6 @@ td.subHeaderPriority, td.priority {
td.subHeaderPriority { td.subHeaderPriority {
background: #020; background: #020;
font-weight: bold; font-weight: bold;
background: url(images/snarktopnav.png) repeat-x scroll center center #110011;
background-image: linear-gradient(to bottom, #030 0%, #020 50%, #000 51%); background-image: linear-gradient(to bottom, #030 0%, #020 50%, #000 51%);
text-align: center !important; text-align: center !important;
padding: 0 1px !important; padding: 0 1px !important;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 B

View File

@ -80,12 +80,6 @@ body {
.snarknavbar { .snarknavbar {
margin: -10px 0 10px 0 !important; margin: -10px 0 10px 0 !important;
padding: 15px 10px 14px; padding: 15px 10px 14px;
border: 1px solid #101;
border-radius: 0 0 4px 4px;
box-shadow: inset 0 0 0 1px #3f173f, inset 0 0 3px 1px #212;
filter: drop-shadow(0 1px 4px #101);
background: #101 url(images/snarktopnav.png) repeat-x scroll center center;
background: linear-gradient(to bottom, #522852, #4a2449 11%, #321831 33%, #281428 51%, #1c0e1c 52%, #101 54%);
min-width: 600px; min-width: 600px;
width: 70%; width: 70%;
text-align: center; text-align: center;