📄 globalmanagerimpl.java
字号:
try
{
NonDaemonTaskRunner.run(new NonDaemonTask() {
final GlobalManagerImpl this$0;
public Object run()
{
return null;
}
public String getName()
{
return "Stopping global manager";
}
{
this$0 = GlobalManagerImpl.this;
super();
}
});
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
checker.stopIt();
if (COConfigurationManager.getBooleanParameter("Pause Downloads On Exit"))
{
pauseDownloads(true);
stopAllDownloads(true);
saveDownloads(true);
} else
{
saveDownloads(true);
stopAllDownloads(true);
}
if (stats_writer != null)
stats_writer.destroy();
DownloadManagerStateFactory.saveGlobalStateCache();
managers_cow = new ArrayList();
manager_map.clear();
informDestroyed();
return;
}
public void stopAllDownloads()
{
stopAllDownloads(false);
}
protected void stopAllDownloads(boolean for_close)
{
if (for_close && progress_listener != null)
progress_listener.reportCurrentTask(MessageText.getString("splash.unloadingTorrents"));
long lastListenerUpdate = 0L;
List managers = sortForStop();
int nbDownloads = managers.size();
for (int i = 0; i < nbDownloads; i++)
{
DownloadManager manager = (DownloadManager)managers.get(i);
long now = SystemTime.getCurrentTime();
if (progress_listener != null && now - lastListenerUpdate > 100L)
{
lastListenerUpdate = now;
int currentDownload = i + 1;
progress_listener.reportPercent((100 * currentDownload) / nbDownloads);
progress_listener.reportCurrentTask((new StringBuilder()).append(MessageText.getString("splash.unloadingTorrent")).append(" ").append(currentDownload).append(" ").append(MessageText.getString("splash.of")).append(" ").append(nbDownloads).append(" : ").append(manager.getTorrentFileName()).toString());
}
int state = manager.getState();
if (state != 70 && state != 65)
manager.stopIt(for_close ? 71 : 70, false, false);
}
}
public void startAllDownloads()
{
Iterator iter = managers_cow.iterator();
do
{
if (!iter.hasNext())
break;
DownloadManager manager = (DownloadManager)iter.next();
if (manager.getState() == 70)
manager.stopIt(75, false, false);
} while (true);
}
public boolean pauseDownload(DownloadManager manager)
{
if (manager.getTorrent() == null)
return false;
int state = manager.getState();
if (state == 70 || state == 100 || state == 65)
break MISSING_BLOCK_LABEL_130;
HashWrapper wrapper;
boolean forced;
wrapper = manager.getTorrent().getHashWrapper();
forced = manager.isForceStart();
paused_list_mon.enter();
paused_list.add(((Object) (new Object[] {
wrapper, new Boolean(forced)
})));
paused_list_mon.exit();
break MISSING_BLOCK_LABEL_113;
Exception exception;
exception;
paused_list_mon.exit();
throw exception;
manager.stopIt(70, false, false);
return true;
TOTorrentException e;
e;
Debug.printStackTrace(e);
return false;
}
public void pauseDownloads()
{
pauseDownloads(false);
}
protected void pauseDownloads(boolean tag_only)
{
Iterator i$;
List managers = sortForStop();
i$ = managers.iterator();
_L2:
DownloadManager manager;
if (!i$.hasNext())
break; /* Loop/switch isn't completed */
manager = (DownloadManager)i$.next();
if (manager.getTorrent() == null)
continue; /* Loop/switch isn't completed */
int state = manager.getState();
if (state == 70 || state == 100 || state == 65)
continue; /* Loop/switch isn't completed */
boolean forced = manager.isForceStart();
paused_list_mon.enter();
paused_list.add(((Object) (new Object[] {
manager.getTorrent().getHashWrapper(), new Boolean(forced)
})));
paused_list_mon.exit();
break MISSING_BLOCK_LABEL_152;
Exception exception;
exception;
paused_list_mon.exit();
throw exception;
if (!tag_only)
manager.stopIt(70, false, false);
continue; /* Loop/switch isn't completed */
TOTorrentException e;
e;
Debug.printStackTrace(e);
if (true) goto _L2; else goto _L1
_L1:
}
public boolean canPauseDownload(DownloadManager manager)
{
if (manager.getTorrent() == null)
return false;
int state = manager.getState();
return state != 70 && state != 100 && state != 65;
}
public boolean isPaused(DownloadManager manager)
{
if (paused_list.size() == 0)
return false;
int i;
paused_list_mon.enter();
i = 0;
_L1:
boolean flag;
if (i >= paused_list.size())
break MISSING_BLOCK_LABEL_88;
Object data[] = (Object[])(Object[])paused_list.get(i);
HashWrapper hash = (HashWrapper)data[0];
DownloadManager this_manager = getDownloadManager(hash);
if (this_manager != manager)
break MISSING_BLOCK_LABEL_82;
flag = true;
paused_list_mon.exit();
return flag;
i++;
goto _L1
i = 0;
paused_list_mon.exit();
return i;
Exception exception;
exception;
paused_list_mon.exit();
throw exception;
}
public boolean canPauseDownloads()
{
for (Iterator i = managers_cow.iterator(); i.hasNext();)
{
DownloadManager manager = (DownloadManager)i.next();
if (canPauseDownload(manager))
return true;
}
return false;
}
public void resumeDownload(DownloadManager manager)
{
boolean resume_ok;
boolean force;
resume_ok = false;
force = false;
paused_list_mon.enter();
int i = 0;
do
{
if (i >= paused_list.size())
break;
Object data[] = (Object[])(Object[])paused_list.get(i);
HashWrapper hash = (HashWrapper)data[0];
force = ((Boolean)data[1]).booleanValue();
DownloadManager this_manager = getDownloadManager(hash);
if (this_manager == manager)
{
resume_ok = true;
paused_list.remove(i);
break;
}
i++;
} while (true);
paused_list_mon.exit();
break MISSING_BLOCK_LABEL_120;
Exception exception;
exception;
paused_list_mon.exit();
throw exception;
if (resume_ok && manager.getState() == 70)
if (force)
manager.setForceStart(true);
else
manager.stopIt(75, false, false);
return;
}
public void resumeDownloads()
{
paused_list_mon.enter();
for (int i = 0; i < paused_list.size(); i++)
{
Object data[] = (Object[])(Object[])paused_list.get(i);
HashWrapper hash = (HashWrapper)data[0];
boolean force = ((Boolean)data[1]).booleanValue();
DownloadManager manager = getDownloadManager(hash);
if (manager == null || manager.getState() != 70)
continue;
if (force)
manager.setForceStart(true);
else
manager.stopIt(75, false, false);
}
paused_list.clear();
paused_list_mon.exit();
break MISSING_BLOCK_LABEL_139;
Exception exception;
exception;
paused_list_mon.exit();
throw exception;
}
public boolean canResumeDownloads()
{
int i;
paused_list_mon.enter();
i = 0;
_L1:
boolean flag;
if (i >= paused_list.size())
break MISSING_BLOCK_LABEL_85;
Object data[] = (Object[])(Object[])paused_list.get(i);
HashWrapper hash = (HashWrapper)data[0];
DownloadManager manager = getDownloadManager(hash);
if (manager == null || manager.getState() != 70)
break MISSING_BLOCK_LABEL_79;
flag = true;
paused_list_mon.exit();
return flag;
i++;
goto _L1
paused_list_mon.exit();
break MISSING_BLOCK_LABEL_107;
Exception exception;
exception;
paused_list_mon.exit();
throw exception;
return false;
}
private List sortForStop()
{
List managers = new ArrayList(managers_cow);
Collections.sort(managers, new Comparator() {
final GlobalManagerImpl this$0;
public int compare(DownloadManager o1, DownloadManager o2)
{
int s1 = o1.getState();
int s2 = o2.getState();
if (s2 == 75)
return 1;
return s1 != 75 ? 0 : -1;
}
public volatile int compare(Object x0, Object x1)
{
return compare((DownloadManager)x0, (DownloadManager)x1);
}
{
this$0 = GlobalManagerImpl.this;
super();
}
});
return managers;
}
private void loadDownloads()
{
if (cripple_downloads_config)
{
loadingComplete = true;
loadingSem.releaseForever();
return;
}
int triggerOnCount;
ArrayList downloadsAdded;
long lastListenerUpdate;
DownloadManagerStateFactory.loadGlobalStateCache();
triggerOnCount = 2;
downloadsAdded = new ArrayList();
lastListenerUpdate = 0L;
ArrayList pause_data;
if (progress_listener != null)
progress_listener.reportCurrentTask(MessageText.getString("splash.loadingTorrents"));
Map map = FileUtil.readResilientConfigFile("downloads.config");
boolean debug = Boolean.getBoolean("debug");
Iterator iter = null;
List downloads = (List)map.get("downloads");
int nbDownloads;
if (downloads == null)
{
iter = map.values().iterator();
nbDownloads = map.size();
} else
{
iter = downloads.iterator();
nbDownloads = downloads.size();
}
int currentDownload = 0;
do
{
if (!iter.hasNext())
break;
currentDownload++;
Map mDownload = (Map)iter.next();
try
{
byte torrent_hash[] = (byte[])(byte[])mDownload.get("torrent_hash");
Long lPersistent = (Long)mDownload.get("persistent");
boolean persistent = lPersistent == null || lPersistent.longValue() == 1L;
String fileName = new String((byte[])(byte[])mDownload.get("torrent"), "UTF8");
if (progress_listener != null && SystemTime.getCurrentTime() - lastListenerUpdate > 100L)
{
lastListenerUpdate = SystemTime.getCurrentTime();
String shortFileName = fileName;
try
{
File f = new File(fileName);
shortFileName = f.getName();
}
catch (Exception e) { }
progress_listener.reportPercent((100 * currentDownload) / nbDownloads);
progress_listener.reportCurrentTask((new StringBuilder()).append(MessageText.getString("splash.loadingTorrent")).append(" ").append(currentDownload).append(" ").append(MessageText.getString("splash.of")).append(" ").append(nbDownloads).append(" : ").append(shortFileName).toString());
}
byte torrent_save_dir_bytes[] = (byte[])(byte[])mDownload.get("save_dir");
String torrent_save_dir;
String torrent_save_file;
if (torrent_save_dir_bytes != null)
{
byte torrent_save_file_bytes[] = (byte[])(byte[])mDownload.get("save_file");
torrent_save_dir = new String(torrent_save_dir_bytes, "UTF8");
if (torrent_save_file_bytes != null)
torrent_save_file = new String(torrent_save_file_bytes, "UTF8");
else
torrent_save_file = null;
} else
{
byte savePathBytes[] = (byte[])(byte[])mDownload.get("path");
torrent_save_dir = new String(savePathBytes, "UTF8");
torrent_save_file = null;
}
int state = 0;
if (debug)
state = 70;
else
if (mDownload.containsKey("state"))
{
state = ((Long)mDownload.get("state")).intValue();
if (state != 70 && state != 75 && state != 0)
state = 75;
} else
{
int stopped = ((Long)mDownload.get("stopped")).intValue();
if (stopped == 1)
state = 70;
}
Long seconds_downloading = (Long)mDownload.get("secondsDownloading");
boolean has_ever_been_started = seconds_downloading != null && seconds_downloading.longValue() > 0L;
if (torrent_hash != null)
saved_download_manager_state.put(new HashWrapper(torrent_hash), mDownload);
if (persistent)
{
List file_priorities = (List)mDownload.get("file_priorities");
DownloadManager dm = DownloadManagerFactory.create(this, torrent_hash, fileName, torrent_save_dir, torrent_save_file, state, true, true, has_ever_been_started, file_priorities);
if (addDownloadManager(dm, false, false) == dm)
{
downloadsAdded.add(dm);
if (downloadsAdded.size() >= triggerOnCount)
{
triggerOnCount *= 2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -