📄 torrentutils.java
字号:
return dm.getTorrent();
break MISSING_BLOCK_LABEL_60;
Throwable e;
e;
Debug.printStackTrace(e);
return null;
}
public static void setTLSDescription(String desc)
{
((Map)tls.get()).put("desc", desc);
}
public static String getTLSDescription()
{
return (String)((Map)tls.get()).get("desc");
}
public static Object getTLS()
{
return tls.get();
}
public static void setTLS(Object obj)
{
Map m = (Map)obj;
((Map)tls.get()).putAll(m);
}
public static URL getDecentralisedEmptyURL()
{
return new URL("dht://");
Throwable e;
e;
Debug.printStackTrace(e);
return null;
}
public static void setDecentralised(TOTorrent torrent)
{
try
{
byte hash[] = torrent.getHash();
torrent.setAnnounceURL(new URL((new StringBuilder()).append("dht://").append(ByteFormatter.encodeString(hash)).append(".dht/announce").toString()));
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
public static boolean isDecentralised(TOTorrent torrent)
{
if (torrent == null)
return false;
else
return isDecentralised(torrent.getAnnounceURL());
}
public static boolean isDecentralised(URL url)
{
if (url == null)
return false;
else
return url.getProtocol().equalsIgnoreCase("dht");
}
private static Map getAzureusProperties(TOTorrent torrent)
{
Map m = torrent.getAdditionalMapProperty("azureus_properties");
if (m == null)
{
m = new HashMap();
torrent.setAdditionalMapProperty("azureus_properties", m);
}
return m;
}
private static Map getAzureusPrivateProperties(TOTorrent torrent)
{
Map m = torrent.getAdditionalMapProperty("azureus_private_properties");
if (m == null)
{
m = new HashMap();
torrent.setAdditionalMapProperty("azureus_private_properties", m);
}
return m;
}
public static void setObtainedFrom(File file, String str)
{
try
{
TOTorrent torrent = readFromFile(file, false, false);
setObtainedFrom(torrent, str);
writeToFile(torrent);
}
catch (TOTorrentException e) { }
catch (Throwable e)
{
Debug.out(e);
}
}
public static void setObtainedFrom(TOTorrent torrent, String str)
{
Map m = getAzureusPrivateProperties(torrent);
try
{
m.put("obtained_from", str.getBytes("UTF-8"));
fireAttributeListener(torrent, "obtained_from", str);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
public static String getObtainedFrom(TOTorrent torrent)
{
byte from[];
Map m = getAzureusPrivateProperties(torrent);
from = (byte[])(byte[])m.get("obtained_from");
if (from == null)
break MISSING_BLOCK_LABEL_40;
return new String(from, "UTF-8");
Throwable e;
e;
Debug.printStackTrace(e);
return null;
}
public static void setFlag(TOTorrent torrent, int flag, boolean value)
{
Map m = getAzureusProperties(torrent);
Long flags = (Long)m.get("torrent_flags");
if (flags == null)
flags = new Long(0L);
m.put("torrent_flags", new Long(flags.intValue() | flag));
}
public static boolean getFlag(TOTorrent torrent, int flag)
{
Map m = getAzureusProperties(torrent);
Long flags = (Long)m.get("torrent_flags");
if (flags == null)
return false;
else
return (flags.intValue() & flag) != 0;
}
public static void setPluginStringProperty(TOTorrent torrent, String name, String value)
{
Map m = getAzureusProperties(torrent);
Object obj = m.get("plugins");
Map p;
if (obj instanceof Map)
{
p = (Map)obj;
} else
{
p = new HashMap();
m.put("plugins", p);
}
if (value == null)
p.remove(name);
else
p.put(name, value.getBytes());
}
public static String getPluginStringProperty(TOTorrent torrent, String name)
{
Map m = getAzureusProperties(torrent);
Object obj = m.get("plugins");
if (obj instanceof Map)
{
Map p = (Map)obj;
obj = p.get(name);
if (obj instanceof byte[])
return new String((byte[])(byte[])obj);
}
return null;
}
public static void setPluginMapProperty(TOTorrent torrent, String name, Map value)
{
Map m = getAzureusProperties(torrent);
Object obj = m.get("plugins");
Map p;
if (obj instanceof Map)
{
p = (Map)obj;
} else
{
p = new HashMap();
m.put("plugins", p);
}
if (value == null)
p.remove(name);
else
p.put(name, value);
}
public static Map getPluginMapProperty(TOTorrent torrent, String name)
{
Map m = getAzureusProperties(torrent);
Object obj = m.get("plugins");
if (obj instanceof Map)
{
Map p = (Map)obj;
obj = p.get(name);
if (obj instanceof Map)
return (Map)obj;
}
return null;
}
public static void setDHTBackupEnabled(TOTorrent torrent, boolean enabled)
{
Map m = getAzureusProperties(torrent);
m.put("dht_backup_enable", new Long(enabled ? 1L : 0L));
}
public static boolean getDHTBackupEnabled(TOTorrent torrent)
{
Map m = getAzureusProperties(torrent);
Object obj = m.get("dht_backup_enable");
if (obj instanceof Long)
return ((Long)obj).longValue() == 1L;
else
return true;
}
public static boolean isDHTBackupRequested(TOTorrent torrent)
{
Map m = getAzureusProperties(torrent);
Object obj = m.get("dht_backup_requested");
if (obj instanceof Long)
return ((Long)obj).longValue() == 1L;
else
return false;
}
public static void setDHTBackupRequested(TOTorrent torrent, boolean requested)
{
Map m = getAzureusProperties(torrent);
m.put("dht_backup_requested", new Long(requested ? 1L : 0L));
}
public static boolean isReallyPrivate(TOTorrent torrent)
{
if (torrent == null)
return false;
if (UrlUtils.containsPasskey(torrent.getAnnounceURL()))
return torrent.getPrivate();
else
return false;
}
public static boolean getPrivate(TOTorrent torrent)
{
if (torrent == null)
return false;
else
return torrent.getPrivate();
}
public static void setPrivate(TOTorrent torrent, boolean _private)
{
if (torrent == null)
return;
try
{
torrent.setPrivate(_private);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
public static Set getIgnoreSet()
{
return getIgnoreSetSupport(false);
}
public static synchronized Set getIgnoreSetSupport(boolean force)
{
if (ignore_set == null || force)
{
Set new_ignore_set = new HashSet();
String ignore_list = COConfigurationManager.getStringParameter("File.Torrent.IgnoreFiles", ".DS_Store;Thumbs.db;desktop.ini");
if (ignore_set == null)
COConfigurationManager.addParameterListener("File.Torrent.IgnoreFiles", new ParameterListener() {
public void parameterChanged(String parameterName)
{
TorrentUtils.getIgnoreSetSupport(true);
}
});
int pos = 0;
int p1;
do
{
p1 = ignore_list.indexOf(";", pos);
String bit;
if (p1 == -1)
{
bit = ignore_list.substring(pos);
} else
{
bit = ignore_list.substring(pos, p1);
pos = p1 + 1;
}
new_ignore_set.add(bit.trim().toLowerCase());
} while (p1 != -1);
ignore_set = new_ignore_set;
}
return ignore_set;
}
public static void registerMapFluff(String fluff[])
{
synchronized (org/gudy/azureus2/core3/util/TorrentUtils)
{
for (int i = 0; i < fluff.length; i++)
torrentFluffKeyset.add(fluff[i]);
}
}
public static File copyTorrentFileToSaveDir(File f, boolean persistent)
throws IOException
{
boolean saveTorrents = persistent && COConfigurationManager.getBooleanParameter("Save Torrent Files");
File torrentDir;
if (saveTorrents)
torrentDir = new File(COConfigurationManager.getDirectoryParameter("General_sDefaultTorrent_Directory"));
else
torrentDir = new File(f.getParent());
boolean moveWhenDone = COConfigurationManager.getBooleanParameter("Move Completed When Done");
String completedDir = COConfigurationManager.getStringParameter("Completed Files Directory", "");
if (moveWhenDone && completedDir.length() > 0)
{
File cFile = new File(completedDir, f.getName());
if (cFile.exists())
torrentDir = new File(completedDir);
}
FileUtil.mkdirs(torrentDir);
File fDest = new File(torrentDir, f.getName().replaceAll("%20", "."));
if (fDest.equals(f))
return f;
for (; fDest.exists(); fDest = new File(torrentDir, (new StringBuilder()).append("_").append(fDest.getName()).toString()));
fDest.createNewFile();
if (!FileUtil.copyFile(f, fDest))
throw new IOException("File copy failed");
else
return fDest;
}
public static DownloadManager getDownloadManager(HashWrapper hash)
{
return AzureusCoreFactory.getSingleton().getGlobalManager().getDownloadManager(hash);
Exception e;
e;
return null;
}
public static void recursiveEmptyDirDelete(File f)
{
recursiveEmptyDirDelete(f, true);
}
public static void recursiveEmptyDirDelete(File f, boolean log_warnings)
{
Set ignore_map = getIgnoreSet();
FileUtil.recursiveEmptyDirDelete(f, ignore_map, log_warnings);
}
public static String nicePrintTorrentHash(TOTorrent torrent)
{
return nicePrintTorrentHash(torrent, false);
}
public static String nicePrintTorrentHash(TOTorrent torrent, boolean tight)
{
byte hash[];
if (torrent == null)
hash = new byte[20];
else
try
{
hash = torrent.getHash();
}
catch (TOTorrentException e)
{
Debug.printStackTrace(e);
hash = new byte[20];
}
return ByteFormatter.nicePrint(hash, tight);
}
public static boolean isTorrentFile(String filename)
throws FileNotFoundException, IOException
{
File check;
check = new File(filename);
if (!check.exists())
throw new FileNotFoundException((new StringBuilder()).append("File ").append(filename).append(" not found.").toString());
if (!check.canRead())
throw new IOException((new StringBuilder()).append("File ").append(filename).append(" cannot be read.").toString());
if (check.isDirectory())
throw new FileIsADirectoryException((new StringBuilder()).append("File ").append(filename).append(" is a directory.").toString());
TOTorrentFactory.deserialiseFromBEncodedFile(check);
return true;
Throwable e;
e;
return false;
}
public static void addCreatedTorrent(TOTorrent torrent)
{
synchronized (created_torrents)
{
try
{
byte hash[] = torrent.getHash();
if (created_torrents.size() == 0)
COConfigurationManager.setParameter("my.created.torrents", created_torrents);
HashWrapper hw = new HashWrapper(hash);
if (!created_torrents_set.contains(hw))
{
created_torrents.add(hash);
created_torrents_set.add(hw);
COConfigurationManager.setDirty();
}
}
catch (TOTorrentException e) { }
}
}
public static void removeCreatedTorrent(TOTorrent torrent)
{
synchronized (created_torrents)
{
try
{
HashWrapper hw = torrent.getHashWrapper();
byte hash[] = hw.getBytes();
Iterator it = created_torrents.iterator();
do
{
if (!it.hasNext())
break;
byte h[] = (byte[])(byte[])it.next();
if (Arrays.equals(hash, h))
it.remove();
} while (true);
COConfigurationManager.setDirty();
created_torrents_set.remove(hw);
}
catch (TOTorrentException e) { }
}
}
public static boolean isCreatedTorrent(TOTorrent torrent)
{
List list = created_torrents;
JVM INSTR monitorenter ;
boolean res;
HashWrapper hw = torrent.getHashWrapper();
res = created_torrents_set.contains(hw);
if (!res)
res = torrent.isCreated();
return res;
TOTorrentException e;
e;
Debug.printStackTrace(e);
false;
list;
JVM INSTR monitorexit ;
return;
Exception exception;
exception;
throw exception;
}
public static String getMagnetURI(byte hash[])
{
return (new StringBuilder()).append("magnet:?xt=urn:btih:").append(Base32.encode(hash)).toString();
}
private static void fireAttributeListener(TOTorrent torrent, String attribute, Object value)
{
for (Iterator it = torrent_attribute_listeners.iterator(); it.hasNext();)
try
{
((torrentAttributeListener)it.next()).attributeSet(torrent, attribute, value);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
public static void addTorrentAttributeListener(torrentAttributeListener listener)
{
torrent_attribute_listeners.add(listener);
}
public static void removeTorrentAttributeListener(torrentAttributeListener listener)
{
torrent_attribute_listeners.remove(listener);
}
static
{
COConfigurationManager.addAndFireParameterListener("Save Torrent Backup", new ParameterListener() {
public void parameterChanged(String parameterName)
{
TorrentUtils.bSaveTorrentBackup = COConfigurationManager.getBooleanParameter(parameterName);
}
});
created_torrents = COConfigurationManager.getListParameter("my.created.torrents", new ArrayList());
created_torrents_set = new HashSet();
for (Iterator it = created_torrents.iterator(); it.hasNext(); created_torrents_set.add(new HashWrapper((byte[])(byte[])it.next())));
SimpleTimer.addPeriodicEvent("TorrentUtils:pieceDiscard", 0x15f90L, new TimerEventPerformer() {
public void perform(TimerEvent event)
{
long now = SystemTime.getCurrentTime();
synchronized (TorrentUtils.torrent_delegates)
{
for (Iterator it = TorrentUtils.torrent_delegates.keySet().iterator(); it.hasNext(); ((torrentDelegate)it.next()).discardPieces(now, false));
}
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -