📄 globalmanagerimpl.java
字号:
loadDownloads();
}
}
public DownloadManager addDownloadManager(String fileName, String savePath)
{
return addDownloadManager(fileName, null, savePath, 0, true);
}
public DownloadManager addDownloadManager(String fileName, byte optionalHash[], String savePath, int initialState, boolean persistent)
{
return addDownloadManager(fileName, optionalHash, savePath, initialState, persistent, false, null);
}
public DownloadManager addDownloadManager(String torrent_file_name, byte optionalHash[], String savePath, int initialState, boolean persistent, boolean for_seeding, DownloadManagerInitialisationAdapter _adapter)
{
return addDownloadManager(torrent_file_name, optionalHash, savePath, null, initialState, persistent, for_seeding, _adapter);
}
public DownloadManager addDownloadManager(String torrent_file_name, byte optionalHash[], String savePath, String saveFile, int initialState, boolean persistent, boolean for_seeding,
DownloadManagerInitialisationAdapter _adapter)
{
boolean needsFixup;
DownloadManagerInitialisationAdapter adapter;
List file_priorities;
File torrentDir;
File fDest;
HashWrapper hash;
boolean deleteDest;
boolean removeFromAddingDM;
needsFixup = false;
loadingSem.reserve(60000L);
adapter = getDMAdapter(_adapter);
file_priorities = null;
if (!persistent)
{
Map save_download_state = (Map)saved_download_manager_state.get(new HashWrapper(optionalHash));
if (save_download_state != null)
{
if (save_download_state.containsKey("state"))
{
int saved_state = ((Long)save_download_state.get("state")).intValue();
if (saved_state == 70)
initialState = saved_state;
}
file_priorities = (List)save_download_state.get("file_priorities");
Long lPosition = (Long)save_download_state.get("position");
if (lPosition != null && lPosition.longValue() != -1L)
needsFixup = true;
}
}
torrentDir = null;
fDest = null;
hash = null;
deleteDest = false;
removeFromAddingDM = false;
String fName;
File f = new File(torrent_file_name);
if (!f.exists())
throw new IOException((new StringBuilder()).append("Torrent file '").append(torrent_file_name).append("' doesn't exist").toString());
if (!f.isFile())
throw new IOException((new StringBuilder()).append("Torrent '").append(torrent_file_name).append("' is not a file").toString());
fDest = TorrentUtils.copyTorrentFileToSaveDir(f, persistent);
fName = fDest.getCanonicalPath();
DownloadManager downloadmanager;
if (optionalHash != null)
{
hash = new HashWrapper(optionalHash);
} else
{
TOTorrent torrent = TorrentUtils.readFromFile(fDest, false);
hash = torrent.getHashWrapper();
}
if (hash == null)
break MISSING_BLOCK_LABEL_416;
removeFromAddingDM = true;
DownloadManager existingDM = getDownloadManager(hash);
if (existingDM == null)
break MISSING_BLOCK_LABEL_334;
deleteDest = true;
downloadmanager = existingDM;
return downloadmanager;
addingDM_monitor.enter();
if (!addingDMs.contains(hash))
break MISSING_BLOCK_LABEL_377;
removeFromAddingDM = false;
deleteDest = true;
downloadmanager = null;
addingDM_monitor.exit();
return downloadmanager;
addingDMs.add(hash);
addingDM_monitor.exit();
break MISSING_BLOCK_LABEL_416;
Exception exception;
exception;
addingDM_monitor.exit();
throw exception;
Exception e;
e;
DownloadManager manager;
DownloadManager new_manager = DownloadManagerFactory.create(this, optionalHash, fName, savePath, saveFile, initialState, persistent, for_seeding, file_priorities, adapter);
manager = addDownloadManager(new_manager, true, true);
if (manager == null || manager != new_manager)
deleteDest = true;
break MISSING_BLOCK_LABEL_713;
IOException e;
e;
System.out.println((new StringBuilder()).append("DownloadManager::addDownloadManager: fails - td = ").append(torrentDir).append(", fd = ").append(fDest).toString());
Debug.printStackTrace(e);
manager = DownloadManagerFactory.create(this, optionalHash, torrent_file_name, savePath, saveFile, initialState, persistent, for_seeding, file_priorities, adapter);
manager = addDownloadManager(manager, true, true);
break MISSING_BLOCK_LABEL_713;
e;
manager = DownloadManagerFactory.create(this, optionalHash, torrent_file_name, savePath, saveFile, initialState, persistent, for_seeding, file_priorities, adapter);
manager = addDownloadManager(manager, true, true);
break MISSING_BLOCK_LABEL_713;
local;
if (deleteDest)
{
fDest.delete();
try
{
File backupFile = new File((new StringBuilder()).append(fDest.getCanonicalPath()).append(".bak").toString());
if (backupFile.exists())
backupFile.delete();
}
catch (IOException e) { }
}
if (!removeFromAddingDM || hash == null)
break MISSING_BLOCK_LABEL_711;
addingDM_monitor.enter();
addingDMs.remove(hash);
addingDM_monitor.exit();
break MISSING_BLOCK_LABEL_711;
Exception exception2;
exception2;
addingDM_monitor.exit();
throw exception2;
JVM INSTR ret 24;
if (needsFixup && manager != null && manager.getPosition() <= downloadManagerCount(manager.isDownloadComplete(false)))
fixUpDownloadManagerPositions();
return manager;
}
protected DownloadManager addDownloadManager(DownloadManager download_manager, boolean save, boolean notifyListeners)
{
if (isStopping)
break MISSING_BLOCK_LABEL_1165;
loadExistingTorrentsNow(false);
DownloadManager downloadmanager;
managers_mon.enter();
int existing_index = managers_cow.indexOf(download_manager);
if (existing_index == -1)
break MISSING_BLOCK_LABEL_74;
DownloadManager existing = (DownloadManager)managers_cow.get(existing_index);
download_manager.destroy(true);
downloadmanager = existing;
managers_mon.exit();
return downloadmanager;
DownloadManagerStats dm_stats = download_manager.getStats();
HashWrapper hashwrapper = null;
try
{
hashwrapper = download_manager.getTorrent().getHashWrapper();
}
catch (Exception e1) { }
Map save_download_state = (Map)saved_download_manager_state.get(hashwrapper);
long saved_data_bytes_downloaded = 0L;
long saved_data_bytes_uploaded = 0L;
long saved_discarded = 0L;
long saved_hashfails = 0L;
long saved_SecondsDownloading = 0L;
long saved_SecondsOnlySeeding = 0L;
if (save_download_state != null)
{
saved_download_manager_state.remove(hashwrapper);
int maxDL = save_download_state.get("maxdl") != null ? ((Long)save_download_state.get("maxdl")).intValue() : 0;
int maxUL = save_download_state.get("maxul") != null ? ((Long)save_download_state.get("maxul")).intValue() : 0;
Long lDownloaded = (Long)save_download_state.get("downloaded");
Long lUploaded = (Long)save_download_state.get("uploaded");
Long lCompleted = (Long)save_download_state.get("completed");
Long lDiscarded = (Long)save_download_state.get("discarded");
Long lHashFailsCount = (Long)save_download_state.get("hashfails");
Long lHashFailsBytes = (Long)save_download_state.get("hashfailbytes");
Long nbUploads = (Long)save_download_state.get("uploads");
if (nbUploads != null)
{
int maxUploads = nbUploads.intValue();
if (maxUploads != 4 && download_manager.getMaxUploads() == 4)
download_manager.setMaxUploads(maxUploads);
}
dm_stats.setDownloadRateLimitBytesPerSecond(maxDL);
dm_stats.setUploadRateLimitBytesPerSecond(maxUL);
if (lCompleted != null)
dm_stats.setDownloadCompleted(lCompleted.intValue());
if (lDiscarded != null)
saved_discarded = lDiscarded.longValue();
if (lHashFailsBytes != null)
saved_hashfails = lHashFailsBytes.longValue();
else
if (lHashFailsCount != null)
{
TOTorrent torrent = download_manager.getTorrent();
if (torrent != null)
saved_hashfails = lHashFailsCount.longValue() * torrent.getPieceLength();
}
Long lPosition = (Long)save_download_state.get("position");
String sCategory = null;
if (save_download_state.containsKey("category"))
try
{
sCategory = new String((byte[])(byte[])save_download_state.get("category"), "UTF8");
}
catch (UnsupportedEncodingException e)
{
Debug.printStackTrace(e);
}
if (sCategory != null)
{
org.gudy.azureus2.core3.category.Category cat = CategoryManager.getCategory(sCategory);
if (cat != null)
download_manager.getDownloadState().setCategory(cat);
}
download_manager.requestAssumedCompleteMode();
if (lDownloaded != null && lUploaded != null)
{
boolean bCompleted = download_manager.isDownloadComplete(false);
long lUploadedValue = lUploaded.longValue();
long lDownloadedValue = lDownloaded.longValue();
if (bCompleted && lDownloadedValue == 0L)
{
int dl_copies = COConfigurationManager.getIntParameter("StartStopManager_iAddForSeedingDLCopyCount");
lDownloadedValue = download_manager.getSize() * (long)dl_copies;
download_manager.getDownloadState().setFlag(1L, true);
}
saved_data_bytes_downloaded = lDownloadedValue;
saved_data_bytes_uploaded = lUploadedValue;
}
if (lPosition != null)
download_manager.setPosition(lPosition.intValue());
Long lSecondsDLing = (Long)save_download_state.get("secondsDownloading");
if (lSecondsDLing != null)
saved_SecondsDownloading = lSecondsDLing.longValue();
Long lSecondsOnlySeeding = (Long)save_download_state.get("secondsOnlySeeding");
if (lSecondsOnlySeeding != null)
saved_SecondsOnlySeeding = lSecondsOnlySeeding.longValue();
Long already_allocated = (Long)save_download_state.get("allocated");
if (already_allocated != null && already_allocated.intValue() == 1)
download_manager.setDataAlreadyAllocated(true);
Long creation_time = (Long)save_download_state.get("creationTime");
if (creation_time != null)
{
long ct = creation_time.longValue();
if (ct < SystemTime.getCurrentTime())
download_manager.setCreationTime(ct);
}
} else
if (dm_stats.getDownloadCompleted(false) == 1000)
{
int dl_copies = COConfigurationManager.getIntParameter("StartStopManager_iAddForSeedingDLCopyCount");
saved_data_bytes_downloaded = download_manager.getSize() * (long)dl_copies;
}
dm_stats.restoreSessionTotals(saved_data_bytes_downloaded, saved_data_bytes_uploaded, saved_discarded, saved_hashfails, saved_SecondsDownloading, saved_SecondsOnlySeeding);
boolean isCompleted = download_manager.isDownloadComplete(false);
if (download_manager.getPosition() == -1)
{
int endPosition = 0;
for (int i = 0; i < managers_cow.size(); i++)
{
DownloadManager dm = (DownloadManager)managers_cow.get(i);
boolean dmIsCompleted = dm.isDownloadComplete(false);
if (dmIsCompleted == isCompleted)
endPosition++;
}
download_manager.setPosition(endPosition + 1);
}
download_manager.requestAssumedCompleteMode();
List new_download_managers = new ArrayList(managers_cow);
new_download_managers.add(download_manager);
managers_cow = new_download_managers;
TOTorrent torrent = download_manager.getTorrent();
if (torrent != null)
try
{
manager_map.put(new HashWrapper(torrent.getHash()), download_manager);
}
catch (TOTorrentException e)
{
Debug.printStackTrace(e);
}
if (COConfigurationManager.getBooleanParameter("Set Completion Flag For Completed Downloads On Start") && download_manager.isDownloadComplete(true))
download_manager.getDownloadState().setFlag(8L, true);
if (notifyListeners)
listeners.dispatch(1, download_manager);
download_manager.addListener(this);
if (save_download_state != null)
{
Long lForceStart = (Long)save_download_state.get("forceStart");
if (lForceStart == null)
{
Long lStartStopLocked = (Long)save_download_state.get("startStopLocked");
if (lStartStopLocked != null)
lForceStart = lStartStopLocked;
}
if (lForceStart != null && lForceStart.intValue() == 1)
download_manager.setForceStart(true);
}
managers_mon.exit();
break MISSING_BLOCK_LABEL_1154;
Exception exception;
exception;
managers_mon.exit();
throw exception;
if (save)
saveDownloads(false);
return download_manager;
Logger.log(new LogEvent(LOGID, 3, "Tried to add a DownloadManager after shutdown of GlobalManager."));
return null;
}
public List getDownloadManagers()
{
return managers_cow;
}
public DownloadManager getDownloadManager(TOTorrent torrent)
{
if (torrent == null)
return null;
return getDownloadManager(torrent.getHashWrapper());
TOTorrentException e;
e;
return null;
}
public DownloadManager getDownloadManager(HashWrapper hw)
{
return (DownloadManager)manager_map.get(hw);
}
public void canDownloadManagerBeRemoved(DownloadManager manager, boolean remove_torrent, boolean remove_data)
throws GlobalManagerDownloadRemovalVetoException
{
try
{
removal_listeners.dispatchWithException(1, ((Object) (new Object[] {
manager, new Boolean(remove_torrent), new Boolean(remove_data)
})));
}
catch (Throwable e)
{
if (e instanceof GlobalManagerDownloadRemovalVetoException)
{
throw (GlobalManagerDownloadRemovalVetoException)e;
} else
{
GlobalManagerDownloadRemovalVetoException gmv = new GlobalManagerDownloadRemovalVetoException("Error running veto check");
gmv.initCause(e);
throw gmv;
}
}
}
public void removeDownloadManager(DownloadManager manager)
throws GlobalManagerDownloadRemovalVetoException
{
removeDownloadManager(manager, false, false);
}
public void removeDownloadManager(DownloadManager manager, boolean remove_torrent, boolean remove_data)
throws GlobalManagerDownloadRemovalVetoException
{
if (!managers_cow.contains(manager))
return;
canDownloadManagerBeRemoved(manager, remove_torrent, remove_data);
manager.stopIt(70, remove_torrent, remove_data);
managers_mon.enter();
List new_download_managers = new ArrayList(managers_cow);
new_download_managers.remove(manager);
managers_cow = new_download_managers;
TOTorrent torrent = manager.getTorrent();
if (torrent != null)
try
{
manager_map.remove(new HashWrapper(torrent.getHash()));
}
catch (TOTorrentException e)
{
Debug.printStackTrace(e);
}
managers_mon.exit();
break MISSING_BLOCK_LABEL_135;
Exception exception;
exception;
managers_mon.exit();
throw exception;
TOTorrent torrent = manager.getTorrent();
if (torrent != null)
TorrentUtils.removeCreatedTorrent(torrent);
manager.destroy(false);
fixUpDownloadManagerPositions();
listeners.dispatch(2, manager);
manager.removeListener(this);
saveDownloads(false);
DownloadManagerState dms = manager.getDownloadState();
if (dms.getCategory() != null)
dms.setCategory(null);
if (manager.getTorrent() != null)
trackerScraper.remove(manager.getTorrent());
if (host_support != null)
host_support.torrentRemoved(manager.getTorrentFileName(), manager.getTorrent());
dms.delete();
return;
}
public void stopGlobalManager()
{
managers_mon.enter();
if (isStopping)
{
managers_mon.exit();
return;
}
isStopping = true;
managers_mon.exit();
break MISSING_BLOCK_LABEL_47;
Exception exception;
exception;
managers_mon.exit();
throw exception;
stats.save();
informDestroyInitiated();
if (host_support != null)
host_support.destroy();
torrent_folder_watcher.destroy();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -