📄 opentorrentwindow.java
字号:
{
this$0 = OpenTorrentWindow.this;
super();
}
};
setPasteKeyListener(shell, pasteKeyListener);
Utils.createTorrentDropTarget(shell, false);
shell.pack();
if (!Utils.linkShellMetricsToConfig(shell, "OpenTorrentWindow"))
Utils.centreWindow(shell);
resizeTables(3);
shell.open();
if (cSaveTo != null && !cSaveTo.isDisposed())
cSaveTo.setFocus();
try
{
UIFunctionsManager.getUIFunctions().getUIUpdater().addUpdater(this);
}
catch (Exception e)
{
Debug.out(e);
}
}
protected void okPressed()
{
int j;
if (bClosed)
return;
if (torrentList.size() == 0 && downloaders.size() == 0)
{
close(true, false);
return;
}
File file = new File(cmbDataDir.getText());
File fileDefSavePath = new File(COConfigurationManager.getStringParameter("Default save path"));
if (file.equals(fileDefSavePath) && !fileDefSavePath.isDirectory())
FileUtil.mkdirs(fileDefSavePath);
boolean isPathInvalid = cmbDataDir.getText().length() == 0 || file.isFile();
if (!isPathInvalid && !file.isDirectory())
{
int doCreate = Utils.openMessageBox(shellForChildren, 196, "OpenTorrentWindow.mb.askCreateDir", new String[] {
file.toString()
});
if (doCreate == 64)
{
isPathInvalid = !FileUtil.mkdirs(file);
} else
{
cmbDataDir.setFocus();
return;
}
}
if (isPathInvalid)
{
Utils.openMessageBox(shellForChildren, 33, "OpenTorrentWindow.mb.noGlobalDestDir", new String[] {
file.toString()
});
cmbDataDir.setFocus();
return;
}
String sExistingFiles = "";
int iNumExistingFiles = 0;
for (int i = 0; i < torrentList.size(); i++)
{
TorrentInfo info = (TorrentInfo)torrentList.get(i);
file = new File(info.getDataDir());
if (!file.isDirectory() && !FileUtil.mkdirs(file))
{
Utils.openMessageBox(shellForChildren, 33, "OpenTorrentWindow.mb.noDestDir", new String[] {
file.toString(), info.getTorrentName()
});
return;
}
if (!info.isValid)
{
Utils.openMessageBox(shellForChildren, 33, "OpenTorrentWindow.mb.notValid", new String[] {
info.getTorrentName()
});
return;
}
TorrentFileInfo files[] = info.getFiles();
for (j = 0; j < files.length; j++)
{
TorrentFileInfo fileInfo = files[j];
if (!fileInfo.getDestFileFullName().exists())
continue;
sExistingFiles = (new StringBuilder()).append(sExistingFiles).append(fileInfo.orgFullName).append(" - ").append(info.getTorrentName()).append("\n").toString();
if (++iNumExistingFiles > 5)
break;
}
}
if (sExistingFiles.length() > 0)
{
if (iNumExistingFiles > 5)
sExistingFiles = (new StringBuilder()).append(sExistingFiles).append(MessageText.getString("OpenTorrentWindow.mb.existingFiles.partialList", new String[] {
(new StringBuilder()).append("").append(iNumExistingFiles).toString()
})).append("\n").toString();
if (Utils.openMessageBox(shellForChildren, 296, "OpenTorrentWindow.mb.existingFiles", new String[] {
sExistingFiles
}) != 32)
return;
}
String sDefaultPath = COConfigurationManager.getStringParameter("Default save path");
if (sDestDir.equals(sDefaultPath))
break MISSING_BLOCK_LABEL_875;
File fDestDir = new File(sDestDir);
int iDirPos = -1;
int i = 0;
do
{
if (i >= dirList.size())
break;
String sDirName = dirList.get(i);
File dir = new File(sDirName);
if (dir.equals(fDestDir))
{
iDirPos = i;
break;
}
i++;
} while (true);
if (iDirPos > 0 && iDirPos < dirList.size())
dirList.remove(iDirPos);
dirList.add(0, sDestDir);
if (dirList.size() > 15)
dirList.remove(dirList.size() - 1);
i = 0;
_L5:
File dirJ;
int i;
if (i >= dirList.size())
break; /* Loop/switch isn't completed */
dirJ = new File(dirList.get(i));
i = 0;
_L3:
if (i >= dirList.size()) goto _L2; else goto _L1
_L1:
if (i == i)
continue; /* Loop/switch isn't completed */
try
{
File dirI = new File(dirList.get(i));
if (!dirI.equals(dirJ))
continue; /* Loop/switch isn't completed */
dirList.remove(i);
if (i > i)
i--;
i--;
}
catch (Exception e) { }
i++;
goto _L3
_L2:
i++;
if (true) goto _L5; else goto _L4
Exception e;
e;
_L4:
COConfigurationManager.setParameter("saveTo_list", dirList);
COConfigurationManager.save();
if (COConfigurationManager.getBooleanParameter("DefaultDir.AutoUpdate") && !COConfigurationManager.getBooleanParameter("Use default data dir"))
COConfigurationManager.setParameter("Default save path", sDestDir);
openTorrents();
close(true, false);
return;
}
private GridLayout FixupLayout(GridLayout layout, boolean bFixMargin)
{
if (Constants.isOSX)
{
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
if (bFixMargin)
{
layout.marginHeight = 0;
layout.marginWidth = 0;
}
}
return layout;
}
private void updateDataDirCombo()
{
if (cmbDataDir == null)
return;
int indexes[];
bSkipDataDirModify = true;
indexes = torrentTable.getSelectionIndices();
if (indexes.length != 0)
break MISSING_BLOCK_LABEL_43;
cmbDataDir.setText(sDestDir);
bSkipDataDirModify = false;
return;
boolean allSame = true;
String lastDir = null;
int i = 0;
do
{
if (i >= indexes.length)
break;
TorrentInfo info = (TorrentInfo)torrentList.get(indexes[i]);
if (lastDir != null && !info.sDestDir.equals(lastDir))
{
allSame = false;
break;
}
lastDir = info.sDestDir;
i++;
} while (true);
if (allSame && lastDir != null)
{
cmbDataDir.setText(lastDir);
sDestDir = lastDir;
} else
{
cmbDataDir.setText("");
}
bSkipDataDirModify = false;
break MISSING_BLOCK_LABEL_157;
Exception exception;
exception;
bSkipDataDirModify = false;
throw exception;
}
private void updateStartModeCombo()
{
if (cmbStartMode == null)
return;
int indexes[] = torrentTable.getSelectionIndices();
String sItemsText[] = new String[startModes.length];
int iMaxMatches = 0;
int iIndexToSelect = getDefaultStartMode();
for (int i = 0; i < startModes.length; i++)
{
int iMatches = 0;
for (int j = 0; j < indexes.length; j++)
{
TorrentInfo info = (TorrentInfo)torrentList.get(indexes[j]);
if (info.iStartID == i)
iMatches++;
}
if (iMatches > iMaxMatches)
{
iMaxMatches = iMatches;
iIndexToSelect = i;
}
String sText = MessageText.getString((new StringBuilder()).append("OpenTorrentWindow.startMode.").append(startModes[i]).toString());
if (iMatches > 0)
sText = (new StringBuilder()).append(sText).append(" ").append(MessageText.getString("OpenTorrentWindow.xOfTotal", new String[] {
Integer.toString(iMatches), Integer.toString(indexes.length)
})).toString();
sItemsText[i] = sText;
}
cmbStartMode.setItems(sItemsText);
cmbStartMode.select(iIndexToSelect);
cmbStartMode.layout(true);
}
private void updateQueueLocationCombo()
{
if (cmbQueueLocation == null)
return;
int indexes[] = torrentTable.getSelectionIndices();
String sItemsText[] = new String[queueLocations.length];
int iMaxMatches = 0;
int iIndexToSelect = 1;
for (int i = 0; i < queueLocations.length; i++)
{
int iMatches = 0;
for (int j = 0; j < indexes.length; j++)
{
TorrentInfo info = (TorrentInfo)torrentList.get(indexes[j]);
if (info.iQueueLocation == i)
iMatches++;
}
if (iMatches > iMaxMatches)
{
iMaxMatches = iMatches;
iIndexToSelect = i;
}
String sText = MessageText.getString((new StringBuilder()).append("OpenTorrentWindow.addPosition.").append(queueLocations[i]).toString());
if (iMatches > 0)
sText = (new StringBuilder()).append(sText).append(" ").append(MessageText.getString("OpenTorrentWindow.xOfTotal", new String[] {
Integer.toString(iMatches), Integer.toString(indexes.length)
})).toString();
sItemsText[i] = sText;
}
cmbQueueLocation.setItems(sItemsText);
cmbQueueLocation.select(iIndexToSelect);
}
private void setPasteKeyListener(Control c, KeyListener keyListener)
{
if (!(c instanceof Text) && !(c instanceof Combo) && !(c instanceof Composite) || (c instanceof Table))
c.addKeyListener(keyListener);
if (c instanceof Composite)
{
Control controls[] = ((Composite)c).getChildren();
for (int i = 0; i < controls.length; i++)
setPasteKeyListener(controls[i], keyListener);
}
}
private void browseURL()
{
new OpenUrlWindow(core, shellForChildren, null, null, this);
}
private void close(boolean dispose, boolean bCancel)
{
stOpenTorrentWindow = null;
bClosed = true;
try
{
UIFunctionsManager.getUIFunctions().getUIUpdater().removeUpdater(this);
}
catch (Exception e)
{
Debug.out(e);
}
if (dispose && shell != null && !shell.isDisposed())
shell.dispose();
Utils.disposeSWTObjects(disposeList);
if (downloaders.size() > 0)
{
TorrentDownloader element;
for (Iterator iter = downloaders.iterator(); iter.hasNext(); element.cancel())
element = (TorrentDownloader)iter.next();
downloaders.clear();
}
if (bCancel)
{
Iterator iter = torrentList.iterator();
do
{
if (!iter.hasNext())
break;
TorrentInfo info = (TorrentInfo)iter.next();
if (info.bDeleteFileOnCancel)
{
File file = new File(info.sFileName);
if (file.exists())
file.delete();
}
} while (true);
torrentList.clear();
}
}
private void createTorrentListArea(Composite cArea)
{
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.numColumns = 2;
cArea.setLayout(layout);
torrentTable = new Table(cArea, 0x10010802);
GridData gridData = new GridData(784);
gridData.heightHint = 50;
gridData.widthHint = 450;
torrentTable.setLayoutData(gridData);
TableColumn tc = new TableColumn(torrentTable, 0);
Messages.setLanguageText(tc, "OpenTorrentWindow.torrentTable.name");
tc.setWidth(150);
tc = new TableColumn(torrentTable, 0);
Messages.setLanguageText(tc, "OpenTorrentWindow.torrentTable.saveLocation");
tc.setWidth(150);
tc = new TableColumn(torrentTable, 0);
Messages.setLanguageText(tc, "OpenTorrentWindow.startMode");
tc.setWidth(70);
tc = new TableColumn(torrentTable, 0);
Messages.setLanguageText(tc, "OpenTorrentWindow.addPosition");
tc.setWidth(80);
if (Utils.LAST_TABLECOLUMN_EXPANDS)
tc.setData("Width", new Long(80L));
torrentTable.addListener(36, new Listener() {
final OpenTorrentWindow this$0;
public void handleEvent(Event event)
{
if (bClosed)
return;
TableItem item = (TableItem)event.item;
int index = torrentTable.indexOf(item);
if (index < 0)
return;
TorrentInfo info = (TorrentInfo)torrentList.get(index);
item.setText(new String[] {
info.getTorrentName(), info.getDataDir(), MessageText.getString((new StringBuilder()).append("OpenTorrentWindow.startMode.").append(OpenTorrentWindow.startModes[info.iStartID]).toString()), MessageText.getString((new StringBuilder()).append("OpenTorrentWindow.addPosition.").append(OpenTorrentWindow.queueLocations[info.iQueueLocation]).toString())
});
if (!info.isValid)
{
item.setForeground(Colors.red);
Font font = item.getFont();
FontData fd[] = font.getFontData();
for (int i = 0; i < fd.length; i++)
fd[i].setStyle(2);
font = new Font(item.getDisplay(), fd);
disposeList.add(font);
item.setFont(font);
}
Utils.alternateRowBackground(item);
}
{
this$0 = OpenTorrentWindow.this;
super();
}
});
torrentTable.addSelectionListener(new SelectionAdapter() {
final OpenTorrentWindow this$0;
public void widgetSelected(SelectionEvent e)
{
dataFiles.clear();
int indexes[] = torrentTable.getSelectionIndices();
for (int i = 0; i < indexes.length; i++)
{
TorrentInfo info = (TorrentInfo)torrentList.get(indexes[i]);
TorrentFileInfo files[] = info.getFiles();
dataFiles.addAll(Arrays.asList(files));
}
updateDataDirCombo();
updateStartModeCombo();
updateQueueLocationCombo();
dataFileTable.setItemCount(dataFiles.size());
dataFileTable.clearAll();
editCell(-1);
updateSize();
resizeTables(2);
}
{
this$0 = OpenTorrentWindow.this;
super();
}
});
torrentTable.addKeyListener(new KeyAdapter() {
final OpenTorrentWindow this$0;
public void keyPressed(KeyEvent e)
{
if (e.character == '\177')
{
deleteSelected(torrentTable, torrentList);
e.doit = false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -