📄 downloadmanagerimpl.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: DownloadManagerImpl.java
package org.gudy.azureus2.pluginsimpl.local.download;
import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.util.CopyOnWriteList;
import java.io.File;
import java.io.PrintStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.disk.DiskManager;
import org.gudy.azureus2.core3.download.DownloadManager;
import org.gudy.azureus2.core3.download.DownloadManagerInitialisationAdapter;
import org.gudy.azureus2.core3.download.impl.DownloadManagerDefaultPaths;
import org.gudy.azureus2.core3.download.impl.DownloadManagerMoveHandler;
import org.gudy.azureus2.core3.global.GlobalManager;
import org.gudy.azureus2.core3.global.GlobalManagerDownloadRemovalVetoException;
import org.gudy.azureus2.core3.global.GlobalManagerDownloadWillBeRemovedListener;
import org.gudy.azureus2.core3.global.GlobalManagerListener;
import org.gudy.azureus2.core3.torrent.TOTorrent;
import org.gudy.azureus2.core3.torrent.TOTorrentException;
import org.gudy.azureus2.core3.util.AEMonitor;
import org.gudy.azureus2.core3.util.Debug;
import org.gudy.azureus2.core3.util.FileUtil;
import org.gudy.azureus2.plugins.download.Download;
import org.gudy.azureus2.plugins.download.DownloadEventNotifier;
import org.gudy.azureus2.plugins.download.DownloadException;
import org.gudy.azureus2.plugins.download.DownloadManagerListener;
import org.gudy.azureus2.plugins.download.DownloadManagerStats;
import org.gudy.azureus2.plugins.download.DownloadRemovalVetoException;
import org.gudy.azureus2.plugins.download.DownloadWillBeAddedListener;
import org.gudy.azureus2.plugins.download.savelocation.DefaultSaveLocationManager;
import org.gudy.azureus2.plugins.download.savelocation.SaveLocationManager;
import org.gudy.azureus2.plugins.torrent.Torrent;
import org.gudy.azureus2.plugins.torrent.TorrentException;
import org.gudy.azureus2.pluginsimpl.local.torrent.TorrentImpl;
import org.gudy.azureus2.pluginsimpl.local.ui.UIManagerImpl;
// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.download:
// DownloadEventNotifierImpl, DownloadImpl, DownloadManagerStatsImpl
public class DownloadManagerImpl
implements org.gudy.azureus2.plugins.download.DownloadManager, DownloadManagerInitialisationAdapter
{
protected static DownloadManagerImpl singleton;
protected static AEMonitor class_mon = new AEMonitor("DownloadManager:class");
private GlobalManager global_manager;
private DownloadManagerStats stats;
private DownloadEventNotifierImpl global_dl_notifier;
private List listeners;
private CopyOnWriteList dwba_listeners;
private AEMonitor listeners_mon;
private List downloads;
private Map pending_dls;
private Map download_map;
public static DownloadManagerImpl getSingleton(AzureusCore azureus_core)
{
DownloadManagerImpl downloadmanagerimpl;
class_mon.enter();
if (singleton == null)
singleton = new DownloadManagerImpl(azureus_core);
downloadmanagerimpl = singleton;
class_mon.exit();
return downloadmanagerimpl;
Exception exception;
exception;
class_mon.exit();
throw exception;
}
protected DownloadManagerImpl(AzureusCore _azureus_core)
{
listeners = new ArrayList();
dwba_listeners = new CopyOnWriteList();
listeners_mon = new AEMonitor("DownloadManager:L");
downloads = new ArrayList();
pending_dls = new HashMap();
download_map = new HashMap();
global_manager = _azureus_core.getGlobalManager();
stats = new DownloadManagerStatsImpl(global_manager);
global_dl_notifier = new DownloadEventNotifierImpl(this);
global_manager.addListener(new GlobalManagerListener() {
final DownloadManagerImpl this$0;
public void downloadManagerAdded(DownloadManager dm)
{
addDownloadManager(dm);
}
public void downloadManagerRemoved(DownloadManager dm)
{
List listeners_ref;
DownloadImpl dl;
listeners_ref = null;
dl = null;
listeners_mon.enter();
dl = (DownloadImpl)download_map.get(dm);
if (dl == null)
{
System.out.println("DownloadManager:unknown manager removed");
} else
{
downloads.remove(dl);
download_map.remove(dm);
pending_dls.remove(dm);
dl.destroy();
listeners_ref = listeners;
}
listeners_mon.exit();
break MISSING_BLOCK_LABEL_128;
Exception exception;
exception;
listeners_mon.exit();
throw exception;
if (dl != null)
{
for (int i = 0; i < listeners_ref.size(); i++)
((DownloadManagerListener)listeners_ref.get(i)).downloadRemoved(dl);
}
return;
}
public void destroyInitiated()
{
}
public void destroyed()
{
}
public void seedingStatusChanged(boolean flag, boolean flag1)
{
}
{
this$0 = DownloadManagerImpl.this;
super();
}
});
global_manager.addDownloadWillBeRemovedListener(new GlobalManagerDownloadWillBeRemovedListener() {
final DownloadManagerImpl this$0;
public void downloadWillBeRemoved(DownloadManager dm, boolean remove_torrent, boolean remove_data)
throws GlobalManagerDownloadRemovalVetoException
{
DownloadImpl download = (DownloadImpl)download_map.get(dm);
if (download != null)
try
{
download.isRemovable();
}
catch (DownloadRemovalVetoException e)
{
throw new GlobalManagerDownloadRemovalVetoException(e.getMessage(), e.isSilent());
}
}
{
this$0 = DownloadManagerImpl.this;
super();
}
});
}
public void addDownload(File fileName)
{
UIManagerImpl.fireEvent(null, 2, fileName);
}
public void addDownload(URL url)
{
addDownload(url, ((URL) (null)), true, ((Map) (null)));
}
public void addDownload(URL url, boolean auto_download)
throws DownloadException
{
addDownload(url, ((URL) (null)), auto_download, ((Map) (null)));
}
public void addDownload(URL url, URL referrer)
{
addDownload(url, referrer, true, ((Map) (null)));
}
public void addDownload(URL url, Map request_properties)
{
addDownload(url, ((URL) (null)), true, request_properties);
}
public void addDownload(URL url, URL referrer, boolean auto_download, Map request_properties)
{
UIManagerImpl.fireEvent(null, 3, ((Object) (new Object[] {
url, referrer, new Boolean(auto_download), request_properties
})));
}
protected void addDownloadManager(DownloadManager dm)
{
List listeners_ref;
DownloadImpl dl;
listeners_ref = null;
dl = null;
listeners_mon.enter();
if (download_map.get(dm) == null)
{
dl = (DownloadImpl)pending_dls.remove(dm);
if (dl == null)
dl = new DownloadImpl(dm);
downloads.add(dl);
download_map.put(dm, dl);
listeners_ref = listeners;
}
listeners_mon.exit();
break MISSING_BLOCK_LABEL_101;
Exception exception;
exception;
listeners_mon.exit();
throw exception;
if (dl != null)
{
for (int i = 0; i < listeners_ref.size(); i++)
try
{
((DownloadManagerListener)listeners_ref.get(i)).downloadAdded(dl);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
return;
}
public Download addDownload(Torrent torrent)
throws DownloadException
{
return addDownload(torrent, null, null);
}
public Download addDownload(Torrent torrent, File torrent_file, File data_location)
throws DownloadException
{
return addDownload(torrent, torrent_file, data_location, getInitialState());
}
public Download addDownload(Torrent torrent, File torrent_file, File data_location, int initial_state)
throws DownloadException
{
if (torrent_file == null)
{
String torrent_dir = null;
if (COConfigurationManager.getBooleanParameter("Save Torrent Files"))
try
{
torrent_dir = COConfigurationManager.getDirectoryParameter("General_sDefaultTorrent_Directory");
}
catch (Exception egnore) { }
if (torrent_dir == null || torrent_dir.length() == 0)
throw new DownloadException("DownloadManager::addDownload: default torrent save directory must be configured");
torrent_file = new File((new StringBuilder()).append(torrent_dir).append(File.separator).append(torrent.getName()).append(".torrent").toString());
try
{
torrent.writeToFile(torrent_file);
}
catch (TorrentException e)
{
throw new DownloadException((new StringBuilder()).append("DownloadManager::addDownload: failed to write torrent to '").append(torrent_file.toString()).append("'").toString(), e);
}
} else
{
if (!torrent_file.exists())
throw new DownloadException((new StringBuilder()).append("DownloadManager::addDownload: torrent file does not exist - ").append(torrent_file.toString()).toString());
if (!torrent_file.isFile())
throw new DownloadException((new StringBuilder()).append("DownloadManager::addDownload: torrent filepath given is not a file - ").append(torrent_file.toString()).toString());
}
if (data_location == null)
{
String data_dir = COConfigurationManager.getStringParameter("Default save path");
if (data_dir == null || data_dir.length() == 0)
throw new DownloadException("DownloadManager::addDownload: default data save directory must be configured");
data_location = new File(data_dir);
FileUtil.mkdirs(data_location);
}
byte hash[] = null;
try
{
hash = torrent.getHash();
}
catch (Exception e) { }
boolean for_seeding = torrent.isComplete();
DownloadManager dm = global_manager.addDownloadManager(torrent_file.toString(), hash, data_location.toString(), initial_state, true, for_seeding, null);
if (dm == null)
{
throw new DownloadException("DownloadManager::addDownload - failed, download may already in the process of being added");
} else
{
addDownloadManager(dm);
return getDownload(dm);
}
}
public Download addDownloadStopped(Torrent torrent, File torrent_location, File data_location)
throws DownloadException
{
return addDownload(torrent, torrent_location, data_location, 70);
}
public Download addNonPersistentDownload(Torrent torrent, File torrent_file, File data_location)
throws DownloadException
{
byte hash[] = null;
try
{
hash = torrent.getHash();
}
catch (Exception e) { }
DownloadManager dm = global_manager.addDownloadManager(torrent_file.toString(), hash, data_location.toString(), getInitialState(), false);
if (dm == null)
{
throw new DownloadException("DownloadManager::addDownload - failed");
} else
{
addDownloadManager(dm);
return getDownload(dm);
}
}
protected int getInitialState()
{
boolean default_start_stopped = COConfigurationManager.getBooleanParameter("Default Start Torrents Stopped");
return default_start_stopped ? 70 : 0;
}
protected DownloadImpl getDownload(DownloadManager dm)
throws DownloadException
{
DownloadImpl dl = (DownloadImpl)download_map.get(dm);
if (dl == null)
throw new DownloadException("DownloadManager::getDownload: download not found");
else
return dl;
}
public static DownloadImpl[] getDownloadStatic(DownloadManager dm[])
{
ArrayList res = new ArrayList(dm.length);
for (int i = 0; i < dm.length; i++)
try
{
res.add(getDownloadStatic(dm[i]));
}
catch (DownloadException de) { }
return (DownloadImpl[])(DownloadImpl[])res.toArray(new DownloadImpl[res.size()]);
}
public static DownloadImpl getDownloadStatic(DownloadManager dm)
throws DownloadException
{
if (singleton != null)
return singleton.getDownload(dm);
else
throw new DownloadException("DownloadManager not initialised");
}
public static Download getDownloadStatic(DiskManager dm)
throws DownloadException
{
if (singleton != null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -