📄 downloadimpl.java
字号:
return 0;
else
return download_manager.getDownloadState().getIntAttribute(name);
}
public void setIntAttribute(TorrentAttribute attribute, int value)
{
String name = convertAttribute(attribute);
if (name != null)
download_manager.getDownloadState().setIntAttribute(name, value);
}
public long getLongAttribute(TorrentAttribute attribute)
{
String name = convertAttribute(attribute);
if (name == null)
return 0L;
else
return download_manager.getDownloadState().getLongAttribute(name);
}
public void setLongAttribute(TorrentAttribute attribute, long value)
{
String name = convertAttribute(attribute);
if (name != null)
download_manager.getDownloadState().setLongAttribute(name, value);
}
protected String convertAttribute(TorrentAttribute attribute)
{
if (attribute.getName() == "Category")
return "category";
if (attribute.getName() == "Networks")
return "networks";
if (attribute.getName() == "TrackerClientExtensions")
return "trackerclientextensions";
if (attribute.getName() == "PeerSources")
return "peersources";
if (attribute.getName() == "DisplayName")
return "displayname";
if (attribute.getName() == "UserComment")
return "comment";
if (attribute.getName() == "RelativePath")
return "relativepath";
if (attribute.getName() == "ShareProperties")
return null;
if (attribute.getName().startsWith("Plugin."))
{
return attribute.getName();
} else
{
Debug.out((new StringBuilder()).append("Can't convert attribute '").append(attribute.getName()).append("'").toString());
return null;
}
}
protected TorrentAttribute convertAttribute(String name)
{
if (name.equals("category"))
return TorrentManagerImpl.getSingleton().getAttribute("Category");
if (name.equals("networks"))
return TorrentManagerImpl.getSingleton().getAttribute("Networks");
if (name.equals("peersources"))
return TorrentManagerImpl.getSingleton().getAttribute("PeerSources");
if (name.equals("trackerclientextensions"))
return TorrentManagerImpl.getSingleton().getAttribute("TrackerClientExtensions");
if (name.equals("displayname"))
return TorrentManagerImpl.getSingleton().getAttribute("DisplayName");
if (name.equals("comment"))
return TorrentManagerImpl.getSingleton().getAttribute("UserComment");
if (name.equals("relativepath"))
return TorrentManagerImpl.getSingleton().getAttribute("RelativePath");
if (name.startsWith("Plugin."))
return TorrentManagerImpl.getSingleton().getAttribute(name);
else
return null;
}
public void setCategory(String sName)
{
Category category = CategoryManager.getCategory(sName);
if (category == null)
category = CategoryManager.createCategory(sName);
download_manager.getDownloadState().setCategory(category);
}
public boolean isPersistent()
{
return download_manager.isPersistent();
}
public void remove()
throws DownloadException, DownloadRemovalVetoException
{
remove(false, false);
}
public void remove(boolean delete_torrent, boolean delete_data)
throws DownloadException, DownloadRemovalVetoException
{
int dl_state = download_manager.getState();
if (dl_state == 70 || dl_state == 100 || dl_state == 75)
{
GlobalManager globalManager = download_manager.getGlobalManager();
try
{
globalManager.removeDownloadManager(download_manager, delete_torrent, delete_data);
}
catch (GlobalManagerDownloadRemovalVetoException e)
{
throw new DownloadRemovalVetoException(e.getMessage());
}
} else
{
throw new DownloadRemovalVetoException(MessageText.getString("plugin.download.remove.veto.notstopped"));
}
}
public boolean canBeRemoved()
throws DownloadRemovalVetoException
{
int dl_state = download_manager.getState();
if (dl_state == 70 || dl_state == 100 || dl_state == 75)
{
GlobalManager globalManager = download_manager.getGlobalManager();
try
{
globalManager.canDownloadManagerBeRemoved(download_manager, false, false);
}
catch (GlobalManagerDownloadRemovalVetoException e)
{
throw new DownloadRemovalVetoException(e.getMessage(), e.isSilent());
}
} else
{
throw new DownloadRemovalVetoException(MessageText.getString("plugin.download.remove.veto.notstopped"));
}
return true;
}
public DownloadStats getStats()
{
return download_stats;
}
public boolean isComplete()
{
return download_manager.isDownloadComplete(false);
}
public boolean isComplete(boolean bIncludeDND)
{
return download_manager.isDownloadComplete(bIncludeDND);
}
public boolean isChecking()
{
return download_stats.getCheckingDoneInThousandNotation() != -1;
}
protected void isRemovable()
throws DownloadRemovalVetoException
{
for (int i = 0; i < removal_listeners.size(); i++)
try
{
((DownloadWillBeRemovedListener)removal_listeners.get(i)).downloadWillBeRemoved(this);
}
catch (DownloadRemovalVetoException e)
{
throw e;
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
protected void destroy()
{
download_manager.removeListener(this);
}
public void stateChanged(DownloadManager manager, int state)
{
int prev_state = latest_state;
latest_state = convertState(state);
boolean curr_forcedStart = isForceStart();
List listeners_to_use = listeners;
if (prev_state != latest_state || latest_forcedStart != curr_forcedStart)
{
latest_forcedStart = curr_forcedStart;
for (int i = 0; i < listeners_to_use.size(); i++)
try
{
long startTime = SystemTime.getCurrentTime();
DownloadListener listener = (DownloadListener)listeners_to_use.get(i);
listener.stateChanged(this, prev_state, latest_state);
long diff = SystemTime.getCurrentTime() - startTime;
if (diff > 1000L)
System.out.println((new StringBuilder()).append("Plugin should move long processes (").append(diff).append("ms) off of Download's stateChanged listener trigger. ").append(listener).toString());
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
}
public void downloadComplete(DownloadManager manager)
{
if (completion_listeners.isEmpty())
return;
Iterator itr = completion_listeners.iterator();
do
{
if (!itr.hasNext())
break;
DownloadCompletionListener dcl = (DownloadCompletionListener)itr.next();
long startTime = SystemTime.getCurrentTime();
try
{
dcl.onCompletion(this);
}
catch (Throwable t)
{
Debug.printStackTrace(t);
}
long diff = SystemTime.getCurrentTime() - startTime;
if (diff > 1000L)
System.out.println((new StringBuilder()).append("Plugin should move long processes (").append(diff).append("ms) off of Download's onCompletion listener trigger. ").append(dcl).toString());
} while (true);
}
public void completionChanged(DownloadManager downloadmanager, boolean flag)
{
}
public void filePriorityChanged(DownloadManager downloadmanager, org.gudy.azureus2.core3.disk.DiskManagerFileInfo diskmanagerfileinfo)
{
}
public void positionChanged(DownloadManager download, int oldPosition, int newPosition)
{
for (int i = 0; i < listeners.size(); i++)
try
{
long startTime = SystemTime.getCurrentTime();
DownloadListener listener = (DownloadListener)listeners.get(i);
listener.positionChanged(this, oldPosition, newPosition);
long diff = SystemTime.getCurrentTime() - startTime;
if (diff > 1000L)
System.out.println((new StringBuilder()).append("Plugin should move long processes (").append(diff).append("ms) off of Download's positionChanged listener trigger. ").append(listener).toString());
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
public void addListener(DownloadListener l)
{
listeners_mon.enter();
List new_listeners = new ArrayList(listeners);
new_listeners.add(l);
listeners = new_listeners;
listeners_mon.exit();
break MISSING_BLOCK_LABEL_52;
Exception exception;
exception;
listeners_mon.exit();
throw exception;
}
public void removeListener(DownloadListener l)
{
listeners_mon.enter();
List new_listeners = new ArrayList(listeners);
new_listeners.remove(l);
listeners = new_listeners;
listeners_mon.exit();
break MISSING_BLOCK_LABEL_52;
Exception exception;
exception;
listeners_mon.exit();
throw exception;
}
public void addAttributeListener(DownloadAttributeListener listener, TorrentAttribute attr, int event_type)
{
String attribute = convertAttribute(attr);
if (attribute == null)
return;
CopyOnWriteMap attr_map = getAttributeMapForType(event_type);
CopyOnWriteList listener_list = (CopyOnWriteList)attr_map.get(attribute);
boolean add_self = false;
if (listener_list == null)
{
listener_list = new CopyOnWriteList();
attr_map.put(attribute, listener_list);
}
add_self = listener_list.isEmpty();
listener_list.add(listener);
if (add_self)
download_manager.getDownloadState().addListener(this, attribute, event_type);
}
public void removeAttributeListener(DownloadAttributeListener listener, TorrentAttribute attr, int event_type)
{
String attribute = convertAttribute(attr);
if (attribute == null)
return;
CopyOnWriteMap attr_map = getAttributeMapForType(event_type);
CopyOnWriteList listener_list = (CopyOnWriteList)attr_map.get(attribute);
boolean remove_self = false;
if (listener_list != null)
{
listener_list.remove(listener);
remove_self = listener_list.isEmpty();
}
if (remove_self)
download_manager.getDownloadState().removeListener(this, attribute, event_type);
}
public DownloadAnnounceResult getLastAnnounceResult()
{
TRTrackerAnnouncer tc = download_manager.getTrackerClient();
if (tc != null)
last_announce_result.setContent(tc.getLastResponse());
return last_announce_result;
}
public DownloadScrapeResult getLastScrapeResult()
{
TRTrackerScraperResponse response = download_manager.getTrackerScrapeResponse();
last_scrape_result.setContent(response);
return last_scrape_result;
}
public void scrapeResult(TRTrackerScraperResponse response)
{
last_scrape_result.setContent(response);
for (int i = 0; i < tracker_listeners.size(); i++)
try
{
((DownloadTrackerListener)tracker_listeners.get(i)).scrapeResult(last_scrape_result);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
void announceTrackerResultsToListener(DownloadTrackerListener l)
{
l.announceResult(last_announce_result);
l.scrapeResult(last_scrape_result);
}
public void announceResult(TRTrackerAnnouncerResponse response)
{
last_announce_result.setContent(response);
List tracker_listeners_ref = tracker_listeners;
for (int i = 0; i < tracker_listeners_ref.size(); i++)
try
{
((DownloadTrackerListener)tracker_listeners_ref.get(i)).announceResult(last_announce_result);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
public void setAnnounceResult(DownloadAnnounceResult result)
{
download_manager.setAnnounceResult(result);
}
public void setScrapeResult(DownloadScrapeResult result)
{
download_manager.setScrapeResult(result);
}
public void stateChanged(DownloadManagerState state, DownloadManagerStateEvent event)
{
final int type = event.getType();
if (type == 1 || type == 2)
{
String name = (String)event.getData();
List property_listeners_ref = property_listeners;
final TorrentAttribute attr = convertAttribute(name);
if (attr != null)
{
for (int i = 0; i < property_listeners_ref.size(); i++)
try
{
((DownloadPropertyListener)property_listeners_ref.get(i)).propertyChanged(this, new DownloadPropertyEvent() {
final int val$type;
final TorrentAttribute val$attr;
final DownloadImpl this$0;
public int getType()
{
return type != 1 ? 2 : 1;
}
public Object getData()
{
return attr;
}
{
this$0 = DownloadImpl.this;
type = i;
attr = torrentattribute;
super();
}
});
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
}
}
public void addPropertyListener(DownloadPropertyListener l)
{
if ("com.aimedia.stopseeding.core.RatioWatcher".equals(l.getClass().getName()))
return;
PluginDeprecation.call("property listener", l);
tracker_listeners_mon.enter();
List new_property_listeners = new ArrayList(property_listeners);
new_property_listeners.add(l);
property_listeners = new_property_listeners;
if (property_listeners.size() == 1)
download_manager.getDownloadState().addListener(this);
tracker_listeners_mon.exit();
break MISSING_BLOCK_LABEL_102;
Exception exception;
exception;
tracker_listeners_mon.exit();
throw exception;
}
public void removePropertyListener(DownloadPropertyListener l)
{
if ("com.aimedia.stopseeding.core.RatioWatcher".equals(l.getClass().getName()))
return;
tracker_listeners_mon.enter();
List new_property_listeners = new ArrayList(property_listeners);
new_property_listeners.remove(l);
property_listeners = new_property_listeners;
if (property_listeners.size() == 0)
download_manager.getDownloadState().removeListener(this);
tracker_listeners_mon.exit();
break MISSING_BLOCK_LABEL_95;
Exception exception;
exception;
tracker_listeners_mon.exit();
throw exception;
}
public void torrentChanged()
{
TRTrackerAnnouncer client = download_manager.getTrackerClient();
if (client != null)
client.resetTrackerUrl(true);
}
public void addTrackerListener(DownloadTrackerListener l)
{
addTrackerListener(l, true);
}
public void addTrackerListener(DownloadTrackerListener l, boolean immediateTrigger)
{
tracker_listeners_mon.enter();
List new_tracker_listeners = new ArrayList(tracker_listeners);
new_tracker_listeners.add(l);
tracker_listeners = new_tracker_listeners;
if (tracker_listeners.size() == 1)
download_manager.addTrackerListener(this);
tracker_listeners_mon.exit();
break MISSING_BLOCK_LABEL_77;
Exception exception;
exception;
tracker_listeners_mon.exit();
throw exception;
if (immediateTrigger)
announceTrackerResultsToListener(l);
return;
}
public void removeTrackerListener(DownloadTrackerListener l)
{
tracker_listeners_mon.enter();
List new_tracker_listeners = new ArrayList(tracker_listeners);
new_tracker_listeners.remove(l);
tracker_listeners = new_tracker_listeners;
if (tracker_listeners.size() == 0)
download_manager.removeTrackerListener(this);
tracker_listeners_mon.exit();
break MISSING_BLOCK_LABEL_74;
Exception exception;
exception;
tracker_listeners_mon.exit();
throw exception;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -