📄 torrentutil.java
字号:
{
menu = menu1;
super(x0);
}
});
MenuItem itemDeleteData = new MenuItem(menuRemove, 8);
Messages.setLanguageText(itemDeleteData, "MyTorrentsView.menu.removeand.deletedata");
itemDeleteData.addListener(13, new DMTask(dms, menu) {
final Menu val$menu;
public void run(DownloadManager dm)
{
TorrentUtil.removeTorrent(dm, false, true, menu.getShell());
}
{
menu = menu1;
super(x0);
}
});
MenuItem itemDeleteBoth = new MenuItem(menuRemove, 8);
Messages.setLanguageText(itemDeleteBoth, "MyTorrentsView.menu.removeand.deleteboth");
itemDeleteBoth.addListener(13, new DMTask(dms, menu) {
final Menu val$menu;
public void run(DownloadManager dm)
{
TorrentUtil.removeTorrent(dm, true, true, menu.getShell());
}
{
menu = menu1;
super(x0);
}
});
}
private static void addCategorySubMenu(DownloadManager dms[], Menu menuCategory, Composite composite)
{
MenuItem items[] = menuCategory.getItems();
for (int i = 0; i < items.length; i++)
items[i].dispose();
Category categories[] = CategoryManager.getCategories();
Arrays.sort(categories);
boolean allow_category_selection = categories.length > 0;
if (allow_category_selection)
{
boolean user_category_found = false;
int i = 0;
do
{
if (i >= categories.length)
break;
if (categories[i].getType() == 0)
{
user_category_found = true;
break;
}
i++;
} while (true);
allow_category_selection = user_category_found;
}
if (allow_category_selection)
{
Category catUncat = CategoryManager.getCategory(2);
if (catUncat != null)
{
MenuItem itemCategory = new MenuItem(menuCategory, 8);
Messages.setLanguageText(itemCategory, catUncat.getName());
itemCategory.addListener(13, new DMTask(dms, catUncat) {
final Category val$catUncat;
public void run(DownloadManager dm)
{
dm.getDownloadState().setCategory(catUncat);
}
{
catUncat = category;
super(x0);
}
});
new MenuItem(menuCategory, 2);
}
for (int i = 0; i < categories.length; i++)
{
Category category = categories[i];
if (category.getType() == 0)
{
MenuItem itemCategory = new MenuItem(menuCategory, 8);
itemCategory.setText(category.getName());
itemCategory.addListener(13, new DMTask(dms, category) {
final Category val$category;
public void run(DownloadManager dm)
{
dm.getDownloadState().setCategory(category);
}
{
category = category1;
super(x0);
}
});
}
}
new MenuItem(menuCategory, 2);
}
MenuItem itemAddCategory = new MenuItem(menuCategory, 8);
Messages.setLanguageText(itemAddCategory, "MyTorrentsView.menu.setCategory.add");
itemAddCategory.addListener(13, new DMTask(dms, composite) {
final Composite val$composite;
public void run(DownloadManager dms[])
{
CategoryAdderWindow adderWindow = new CategoryAdderWindow(composite.getDisplay());
Category newCategory = adderWindow.getNewCategory();
if (newCategory != null)
TorrentUtil.assignToCategory(dms, newCategory);
}
{
composite = composite1;
super(x0);
}
});
}
private static void moveSelectedTorrentsTo(TableView tv, DownloadManager dms[], int iNewPos)
{
if (dms == null || dms.length == 0)
return;
TableColumnCore sortColumn = tv != null ? tv.getSortColumn() : null;
boolean isSortAscending = sortColumn != null ? sortColumn.isSortAscending() : true;
for (int i = 0; i < dms.length; i++)
{
DownloadManager dm = dms[i];
int iOldPos = dm.getPosition();
dm.getGlobalManager().moveTo(dm, iNewPos);
if (isSortAscending)
{
if (iOldPos > iNewPos)
iNewPos++;
continue;
}
if (iOldPos < iNewPos)
iNewPos--;
}
if (tv != null)
{
boolean bForceSort = sortColumn.getName().equals("#");
tv.columnInvalidate("#");
tv.refreshTable(bForceSort);
}
}
private static void changeDirSelectedTorrents(DownloadManager dms[], Shell shell)
{
if (dms.length <= 0)
return;
String sDefPath = COConfigurationManager.getBooleanParameter("Use default data dir") ? COConfigurationManager.getStringParameter("Default save path") : "";
if (sDefPath.length() > 0)
{
File f = new File(sDefPath);
if (!f.exists())
FileUtil.mkdirs(f);
}
DirectoryDialog dDialog = new DirectoryDialog(shell, 0x20000);
dDialog.setFilterPath(sDefPath);
dDialog.setMessage(MessageText.getString("MainWindow.dialog.choose.savepath"));
String sSavePath = dDialog.open();
if (sSavePath != null)
{
for (int i = 0; i < dms.length; i++)
{
DownloadManager dm = dms[i];
if (dm.getState() != 100)
continue;
dm.setTorrentSaveDir(sSavePath);
if (dm.filesExist(true))
{
dm.stopIt(70, false, false);
ManagerUtils.queue(dm, shell);
}
}
}
}
public static void runTorrents(Object download_managers[])
{
for (int i = download_managers.length - 1; i >= 0; i--)
{
DownloadManager dm = (DownloadManager)download_managers[i];
if (dm != null)
ManagerUtils.run(dm);
}
}
public static void hostTorrents(Object download_managers[], AzureusCore azureus_core, Composite composite)
{
DMTask task = new DMTask(toDMS(download_managers), azureus_core, composite) {
final AzureusCore val$azureus_core;
final Composite val$composite;
public void run(DownloadManager dm)
{
ManagerUtils.host(azureus_core, dm, composite);
}
{
azureus_core = azureuscore;
composite = composite1;
super(x0);
}
};
task.go();
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null)
uiFunctions.openView(9, null);
}
public static void publishTorrents(Object download_managers[], AzureusCore azureus_core, Composite composite)
{
DMTask task = new DMTask(toDMS(download_managers), azureus_core, composite) {
final AzureusCore val$azureus_core;
final Composite val$composite;
public void run(DownloadManager dm)
{
ManagerUtils.publish(azureus_core, dm, composite);
}
{
azureus_core = azureuscore;
composite = composite1;
super(x0);
}
};
task.go();
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null)
uiFunctions.openView(9, null);
}
public static void removeTorrent(DownloadManager dm, boolean bDeleteTorrent, boolean bDeleteData, Shell shell)
{
ManagerUtils.remove(dm, shell, bDeleteTorrent, bDeleteData);
}
public static void removeTorrents(Object download_managers[], Shell shell)
{
DMTask task = new DMTask(toDMS(download_managers), shell) {
final Shell val$shell;
public void run(DownloadManager dm)
{
TorrentUtil.removeTorrent(dm, false, false, shell);
}
{
shell = shell1;
super(x0);
}
};
task.go();
}
public static void stopTorrents(Object download_managers[], Shell shell)
{
DMTask task = new DMTask(toDMS(download_managers), shell) {
final Shell val$shell;
public void run(DownloadManager dm)
{
ManagerUtils.stop(dm, shell);
}
{
shell = shell1;
super(x0);
}
};
task.go();
}
public static void queueTorrents(Object download_managers[], Shell shell)
{
DMTask task = new DMTask(toDMS(download_managers), shell) {
final Shell val$shell;
public void run(DownloadManager dm)
{
ManagerUtils.queue(dm, shell);
}
{
shell = shell1;
super(x0);
}
};
task.go();
}
public static void resumeTorrents(Object download_managers[])
{
DMTask task = new DMTask(toDMS(download_managers)) {
public void run(DownloadManager dm)
{
ManagerUtils.start(dm);
}
};
task.go();
}
public static void assignToCategory(Object download_managers[], Category category)
{
DMTask task = new DMTask(toDMS(download_managers), category) {
final Category val$category;
public void run(DownloadManager dm)
{
dm.getDownloadState().setCategory(category);
}
{
category = category1;
super(x0);
}
};
task.go();
}
public static void promptUserForComment(DownloadManager dms[])
{
if (dms.length == 0)
return;
DownloadManager dm = dms[0];
String suggested = dm.getDownloadState().getUserComment();
String msg_key_prefix = "MyTorrentsView.menu.edit_comment.enter.";
SimpleTextEntryWindow text_entry = new SimpleTextEntryWindow(Display.getCurrent());
text_entry.setTitle((new StringBuilder()).append(msg_key_prefix).append("title").toString());
text_entry.setMessage((new StringBuilder()).append(msg_key_prefix).append("message").toString());
text_entry.setPreenteredText(suggested, false);
text_entry.setMultiLine(true);
text_entry.prompt();
if (text_entry.hasSubmittedInput())
{
String value = text_entry.getSubmittedInput();
String value_to_set = value.length() != 0 ? value : null;
DMTask task = new DMTask(dms, value_to_set) {
final String val$value_to_set;
public void run(DownloadManager dm)
{
dm.getDownloadState().setUserComment(value_to_set);
}
{
value_to_set = s;
super(x0);
}
};
task.go();
}
}
private static DownloadManager[] toDMS(Object objects[])
{
if (objects instanceof DownloadManager[])
{
return (DownloadManager[])(DownloadManager[])objects;
} else
{
DownloadManager result[] = new DownloadManager[objects.length];
System.arraycopy(((Object) (objects)), 0, result, 0, result.length);
return result;
}
}
public static boolean isFileTorrent(File torrentFile, Shell parentShell, String torrentName)
{
String sFirstChunk = null;
try
{
sFirstChunk = FileUtil.readFileAsString(torrentFile, 16384).toLowerCase();
}
catch (IOException e)
{
Debug.out("warning", e);
}
if (sFirstChunk == null)
sFirstChunk = "";
if (!sFirstChunk.startsWith("d"))
{
if (parentShell != null)
{
boolean isHTML = sFirstChunk.indexOf("<html") >= 0;
MessageBoxShell boxShell = new MessageBoxShell(parentShell, MessageText.getString("OpenTorrentWindow.mb.notTorrent.title"), MessageText.getString("OpenTorrentWindow.mb.notTorrent.text", new String[] {
torrentName, isHTML ? "" : MessageText.getString("OpenTorrentWindow.mb.notTorrent.cannot.display")
}), new String[] {
MessageText.getString("Button.ok")
}, 0);
if (isHTML)
boxShell.setHtml(sFirstChunk);
boxShell.open();
}
return false;
} else
{
return true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -