📄 filedownloadwindow.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: FileDownloadWindow.java
package org.gudy.azureus2.ui.swt;
import com.aelitis.azureus.core.AzureusCore;
import java.io.File;
import java.net.URLDecoder;
import java.util.Map;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Shell;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.torrentdownloader.*;
import org.gudy.azureus2.core3.util.AERunnable;
import org.gudy.azureus2.ui.swt.mainwindow.TorrentOpener;
import org.gudy.azureus2.ui.swt.progress.IProgressReport;
import org.gudy.azureus2.ui.swt.progress.IProgressReportConstants;
import org.gudy.azureus2.ui.swt.progress.IProgressReporter;
import org.gudy.azureus2.ui.swt.progress.IProgressReporterListener;
import org.gudy.azureus2.ui.swt.progress.ProgressReporterWindow;
import org.gudy.azureus2.ui.swt.progress.ProgressReportingManager;
// Referenced classes of package org.gudy.azureus2.ui.swt:
// Utils
public class FileDownloadWindow
implements TorrentDownloaderCallBackInterface, IProgressReportConstants
{
AzureusCore _azureus_core;
TorrentDownloader downloader;
TorrentDownloaderCallBackInterface listener;
IProgressReporter pReporter;
Shell parent;
String original_url;
String decoded_url;
String referrer;
Map request_properties;
String dirName;
String shortURL;
public FileDownloadWindow(AzureusCore _azureus_core, Shell parent, String url, String referrer, Map request_properties)
{
this(_azureus_core, parent, url, referrer, request_properties, null);
}
public FileDownloadWindow(AzureusCore _azureus_core, Shell parent, String url, String referrer, Map request_properties, TorrentDownloaderCallBackInterface listener)
{
dirName = null;
shortURL = null;
this._azureus_core = _azureus_core;
this.parent = parent;
original_url = url;
this.referrer = referrer;
this.listener = listener;
this.request_properties = request_properties;
try
{
decoded_url = URLDecoder.decode(original_url, "UTF8");
}
catch (Throwable e)
{
decoded_url = original_url;
}
Utils.execSWTThread(new AERunnable() {
final FileDownloadWindow this$0;
public void runSupport()
{
init();
}
{
this$0 = FileDownloadWindow.this;
super();
}
});
}
private void init()
{
if (COConfigurationManager.getBooleanParameter("Save Torrent Files"))
try
{
dirName = COConfigurationManager.getDirectoryParameter("General_sDefaultTorrent_Directory");
}
catch (Exception egnore) { }
if (dirName == null)
{
DirectoryDialog dd = new DirectoryDialog(parent, 0);
dd.setText(MessageText.getString("fileDownloadWindow.saveTorrentIn"));
dirName = dd.open();
}
if (dirName == null)
{
return;
} else
{
pReporter = ProgressReportingManager.getInstance().addReporter();
setupAndShowDialog();
downloader = TorrentDownloaderFactory.create(this, original_url, referrer, request_properties, dirName);
downloader.setIgnoreReponseCode(true);
downloader.start();
return;
}
}
private void setupAndShowDialog()
{
if (null != pReporter)
{
pReporter.setName((new StringBuilder()).append(MessageText.getString("fileDownloadWindow.state_downloading")).append(": ").append(getFileName(decoded_url)).toString());
pReporter.appendDetailMessage((new StringBuilder()).append(MessageText.getString("fileDownloadWindow.downloading")).append(getShortURL(decoded_url)).toString());
pReporter.setTitle(MessageText.getString("fileDownloadWindow.title"));
pReporter.setIndeterminate(true);
pReporter.setCancelAllowed(true);
pReporter.setRetryAllowed(true);
pReporter.addListener(new IProgressReporterListener() {
final FileDownloadWindow this$0;
public int report(IProgressReport pReport)
{
switch (pReport.getReportType())
{
case 3: // '\003'
case 4: // '\004'
default:
break;
case 1: // '\001'
if (null != downloader)
{
downloader.cancel();
Logger.log(new LogEvent(LogIDs.LOGGER, MessageText.getString("FileDownload.canceled", new String[] {
getShortURL(decoded_url)
})));
}
break;
case 2: // '\002'
return 1;
case 5: // '\005'
if (pReport.isRetryAllowed())
{
downloader.cancel();
downloader = TorrentDownloaderFactory.create(FileDownloadWindow.this, original_url, referrer, request_properties, dirName);
downloader.setIgnoreReponseCode(true);
downloader.start();
}
break;
}
return 0;
}
{
this$0 = FileDownloadWindow.this;
super();
}
});
ProgressReporterWindow.open(pReporter, 2);
}
}
public void TorrentDownloaderEvent(int state, TorrentDownloader inf)
{
if (listener != null)
listener.TorrentDownloaderEvent(state, inf);
update();
}
private void update()
{
int state = downloader.getDownloadState();
int percentDone = downloader.getPercentDone();
IProgressReport pReport = pReporter.getProgressReport();
switch (state)
{
case 5: // '\005'
default:
break;
case 6: // '\006'
if (!pReport.isCanceled())
pReporter.cancel();
return;
case 2: // '\002'
pReporter.setPercentage(percentDone, downloader.getStatus());
break;
case 4: // '\004'
if (pReport.isCanceled())
{
return;
} else
{
pReporter.setErrorMessage((new StringBuilder()).append(MessageText.getString("fileDownloadWindow.state_error")).append(downloader.getError()).toString());
return;
}
case 3: // '\003'
pReporter.setDone();
if (listener == null)
TorrentOpener.openTorrent(downloader.getFile().getAbsolutePath());
return;
}
}
private String getShortURL(String url)
{
if (null == shortURL)
{
shortURL = url;
int amp_pos = shortURL.indexOf('&');
if (amp_pos != -1)
shortURL = (new StringBuilder()).append(shortURL.substring(0, amp_pos + 1)).append("...").toString();
shortURL = shortURL.replaceAll("&", "&&");
}
return shortURL;
}
private String getFileName(String url)
{
String lc_url;
String title;
lc_url = url.toLowerCase();
int idx = lc_url.indexOf("&title=");
if (idx < 0)
break MISSING_BLOCK_LABEL_72;
title = url.substring(idx + "&title=".length());
idx = title.indexOf('&');
if (idx <= 0)
break MISSING_BLOCK_LABEL_72;
title = title.substring(0, idx);
title = title.replace('+', ' ');
if (title.length() > 0)
return title;
url = getShortURL(url);
lc_url = url.toLowerCase();
if (lc_url.startsWith("magnet:") || lc_url.startsWith("dht:"))
return url;
String tmp;
tmp = url.substring(url.lastIndexOf('/') + 1);
if (tmp.toLowerCase().lastIndexOf(".torrent") > 0)
tmp = tmp.substring(0, tmp.toLowerCase().lastIndexOf(".torrent"));
return (new StringBuilder()).append(tmp).append(".torrent").toString();
Exception t;
t;
return url;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -