⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opentorrentwindow.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		TableColumn tc = new TableColumn(dataFileTable, 0);
		Messages.setLanguageText(tc, "OpenTorrentWindow.fileTable.fileName");
		tc.setWidth(150);
		tc = new TableColumn(dataFileTable, 0);
		Messages.setLanguageText(tc, "OpenTorrentWindow.fileTable.destinationName");
		tc.setWidth(140);
		tc = new TableColumn(dataFileTable, 0);
		Messages.setLanguageText(tc, "OpenTorrentWindow.fileTable.size");
		tc.setAlignment(0x20000);
		tc.setWidth(90);
		if (Utils.LAST_TABLECOLUMN_EXPANDS)
			tc.setData("Width", new Long(90L));
		dataFileTable.addListener(36, new Listener() {

			final OpenTorrentWindow this$0;

			public void handleEvent(Event event)
			{
				if (bClosed)
					return;
				TableItem item = (TableItem)event.item;
				int index = dataFileTable.indexOf(item);
				TorrentFileInfo file = (TorrentFileInfo)dataFiles.get(index);
				item.setText(new String[] {
					file.orgFullName, file.isLinked() ? file.getDestFileFullName().toString() : file.getDestFileName(), DisplayFormatters.formatByteCountToKiBEtc(file.lSize)
				});
				if (!file.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);
				Utils.setCheckedInSetData(item, file.bDownload);
				item.setGrayed(!file.okToDisable());
			}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
		dataFileTable.addSelectionListener(new SelectionAdapter() {

			final OpenTorrentWindow this$0;

			public void widgetSelected(SelectionEvent event)
			{
				if (event.detail == 32)
				{
					TableItem item = (TableItem)event.item;
					int index = dataFileTable.indexOf(item);
					TorrentFileInfo file = (TorrentFileInfo)dataFiles.get(index);
					if (!item.getChecked() && !file.okToDisable())
						item.setChecked(true);
					else
						file.bDownload = item.getChecked();
					updateSize();
				}
			}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
		dataFileTable.addMouseListener(new MouseAdapter() {

			final OpenTorrentWindow this$0;

			public void mouseDown(MouseEvent e)
			{
				editCell(-1);
				if (e.button != 1)
					return;
				TableItem items[] = dataFileTable.getItems();
				boolean found = false;
				int i;
label0:
				for (i = 0; i < items.length; i++)
				{
					TableItem item = items[i];
					Rectangle rect = item.getBounds();
					if (e.y < rect.y || rect.y + rect.height < e.y)
						continue;
					int j = 0;
					do
					{
						if (j >= dataFileTable.getColumnCount())
							continue label0;
						if (item.getBounds(j).contains(e.x, e.y))
						{
							found = j == 1;
							break label0;
						}
						j++;
					} while (true);
				}

				if (found)
					editCell(i);
			}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
		dataFileTable.setHeaderVisible(true);
		Menu menu = new Menu(dataFileTable);
		dataFileTable.setMenu(menu);
		MenuItem item = new MenuItem(menu, 8);
		Messages.setLanguageText(item, "OpenTorrentWindow.fileList.changeDestination");
		item.addSelectionListener(new SelectionAdapter() {

			final OpenTorrentWindow this$0;

			public void widgetSelected(SelectionEvent e)
			{
				int indexes[] = dataFileTable.getSelectionIndices();
				changeFileDestination(indexes);
			}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
		Composite cBottomArea = new Composite(cArea, 0);
		GridLayout gLayout = new GridLayout();
		gLayout.marginHeight = 0;
		gLayout.marginWidth = 0;
		gLayout.numColumns = 2;
		gLayout.verticalSpacing = 0;
		cBottomArea.setLayout(gLayout);
		gridData = new GridData(768);
		cBottomArea.setLayoutData(gridData);
		Composite cButtons = new Composite(cBottomArea, 0);
		RowLayout rLayout = new RowLayout(256);
		rLayout.wrap = false;
		rLayout.marginBottom = 0;
		rLayout.marginLeft = 0;
		rLayout.marginRight = 0;
		rLayout.marginTop = 0;
		cButtons.setLayout(rLayout);
		gridData = new GridData(0x1000008, 1, false, false);
		gridData.verticalSpan = 2;
		cButtons.setLayoutData(gridData);
		Button btnSelectAll = new Button(cButtons, 8);
		Messages.setLanguageText(btnSelectAll, "Button.selectAll");
		btnSelectAll.addListener(13, new Listener() {

			final OpenTorrentWindow this$0;

			public void handleEvent(Event event)
			{
				dataFileTable.selectAll();
			}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
		Button btnMarkSelected = new Button(cButtons, 8);
		Messages.setLanguageText(btnMarkSelected, "Button.markSelected");
		btnMarkSelected.addListener(13, new Listener() {

			final OpenTorrentWindow this$0;

			public void handleEvent(Event event)
			{
				int indexes[] = dataFileTable.getSelectionIndices();
				for (int i = 0; i < indexes.length; i++)
				{
					TorrentFileInfo file = (TorrentFileInfo)dataFiles.get(indexes[i]);
					file.bDownload = true;
				}

				dataFileTable.clearAll();
				updateSize();
			}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
		Button btnUnmarkSelected = new Button(cButtons, 8);
		Messages.setLanguageText(btnUnmarkSelected, "Button.unmarkSelected");
		btnUnmarkSelected.addListener(13, new Listener() {

			final OpenTorrentWindow this$0;

			public void handleEvent(Event event)
			{
				int indexes[] = dataFileTable.getSelectionIndices();
				for (int i = 0; i < indexes.length; i++)
				{
					TorrentFileInfo file = (TorrentFileInfo)dataFiles.get(indexes[i]);
					if (file.okToDisable())
						file.bDownload = false;
				}

				dataFileTable.clearAll();
				updateSize();
			}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
		dataFileTableLabel = new Label(cBottomArea, 64);
		dataFileTableLabel.setAlignment(0x20000);
		gridData = new GridData(0x1000008, 1, true, false);
		dataFileTableLabel.setLayoutData(gridData);
		diskspaceComp = new Composite(cBottomArea, 0);
		gLayout = new GridLayout(2, false);
		gLayout.marginHeight = gLayout.marginWidth = 1;
		gLayout.verticalSpacing = 0;
		gLayout.horizontalSpacing = 15;
		diskspaceComp.setLayout(gLayout);
		gridData = new GridData(0x1000008, 1, true, false);
		diskspaceComp.setLayoutData(gridData);
	}

	protected void changeFileDestination(int indexes[])
	{
		for (int i = 0; i < indexes.length; i++)
		{
			TorrentFileInfo fileInfo = (TorrentFileInfo)dataFiles.get(indexes[i]);
			int style = fileInfo.parent.iStartID != 3 ? 8192 : 4096;
			FileDialog fDialog = new FileDialog(shellForChildren, 0x20000 | style);
			String sFilterPath = fileInfo.getDestPathName();
			String sFileName = fileInfo.orgFileName;
			File f = new File(sFilterPath);
			if (!f.isDirectory())
				do
				{
					if (sFilterPath == null)
						break;
					String parentPath = f.getParent();
					if (parentPath == null)
						break;
					sFilterPath = parentPath;
					f = new File(sFilterPath);
				} while (!f.isDirectory());
			if (sFilterPath != null)
				fDialog.setFilterPath(sFilterPath);
			fDialog.setFileName(sFileName);
			fDialog.setText((new StringBuilder()).append(MessageText.getString("MainWindow.dialog.choose.savepath")).append(" (").append(fileInfo.orgFullName).append(")").toString());
			String sNewName = fDialog.open();
			if (sNewName == null)
				return;
			if (fileInfo.parent.iStartID == 3)
			{
				File file = new File(sNewName);
				if (file.length() == fileInfo.lSize)
					fileInfo.setFullDestName(sNewName);
				else
					Utils.openMessageBox(shellForChildren, 32, "OpenTorrentWindow.mb.badSize", new String[] {
						file.getName(), fileInfo.orgFullName
					});
			} else
			{
				fileInfo.setFullDestName(sNewName);
			}
		}

		checkSeedingMode();
		updateDataDirCombo();
		diskFreeInfoRefreshPending = true;
	}

	private int addTorrentsFromTextList(String sClipText, boolean bVerifyOnly)
	{
		String lines[] = null;
		int iNumFound = 0;
		int iNoTorrentLines = 0;
		int MAX_CONSECUTIVE_NONTORRENT_LINES = 100;
		String splitters[] = {
			"\r\n", "\n", "\r", "\t"
		};
		int i = 0;
		do
		{
			if (i >= splitters.length)
				break;
			if (sClipText.indexOf(splitters[i]) >= 0)
			{
				lines = sClipText.split(splitters[i]);
				break;
			}
			i++;
		} while (true);
		if (lines == null)
			lines = (new String[] {
				sClipText
			});
		for (i = 0; i < lines.length; i++)
		{
			String line = lines[i].trim();
			if (line.startsWith("\"") && line.endsWith("\""))
				if (line.length() < 3)
					line = "";
				else
					line = line.substring(1, line.length() - 2);
			boolean ok;
			if (line == "")
				ok = false;
			else
			if (UrlUtils.isURL(line))
			{
				ok = true;
			} else
			{
				File file = new File(line);
				if (!file.exists())
					ok = false;
				else
				if (file.isDirectory())
				{
					if (bVerifyOnly)
					{
						ok = true;
					} else
					{
						iNumFound += addTorrents(lines[i], null);
						ok = false;
					}
				} else
				{
					ok = true;
				}
			}
			if (!ok)
			{
				iNoTorrentLines++;
				lines[i] = null;
				if (iNoTorrentLines > 100)
					break;
			} else
			{
				iNumFound++;
				iNoTorrentLines = 0;
			}
		}

		if (bVerifyOnly)
			return iNumFound;
		else
			return addTorrents(null, lines);
	}

	private int addTorrents(String sTorrentFilePath, String sTorrentFilenames[])
	{
		sTorrentFilePath = ensureTrailingSeparator(sTorrentFilePath);
		if (sTorrentFilePath != null && sTorrentFilenames == null)
		{
			File dir = new File(sTorrentFilePath);
			if (!dir.isDirectory())
				return 0;
			File files[] = dir.listFiles(new FileFilter() {

				final OpenTorrentWindow this$0;

				public boolean accept(File arg0)
				{
					if (FileUtil.getCanonicalFileName(arg0.getName()).endsWith(".torrent"))
						return true;
					return FileUtil.getCanonicalFileName(arg0.getName()).endsWith(".tor");
				}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
			});
			if (files.length == 0)
				return 0;
			sTorrentFilenames = new String[files.length];
			for (int i = 0; i < files.length; i++)
				sTorrentFilenames[i] = files[i].getName();

		}
		int numAdded = 0;
		for (int i = 0; i < sTorrentFilenames.length; i++)
		{
			if (sTorrentFilenames[i] == null || sTorrentFilenames[i] == "")
				continue;
			String sFileName = (new StringBuilder()).append(sTorrentFilePath != null ? sTorrentFilePath : "").append(sTorrentFilenames[i]).toString();
			if (!(new File(sFileName)).exists())
			{
				String sURL = UrlUtils.parseTextForURL(sTorrentFilenames[i], true);
				if (sURL != null)
				{
					if (COConfigurationManager.getBooleanParameter("Add URL Silently"))
						new FileDownloadWindow(core, shellForChildren, sURL, null, null, this);
					else
						new OpenUrlWindow(core, shellForChildren, sURL, null, this);
					numAdded++;
					continue;
				}
			}
			if (addTorrent(sFileName, sFileName) != null)
				numAdded++;
		}

		if (numAdded > 0 && shell != null && torrentTable != null && !shell.isDisposed())
		{
			int iTotal = torrentList.size();
			torrentTable.setItemCount(iTotal);
			torrentTable.select(iTotal - numAdded, iTotal - 1);
			torrentTable.clearAll();
			torrentTable.notifyListeners(13, new Event());
			resizeTables(1);
			checkSeedingMode();
		}
		return numAdded;
	}

	private TorrentInfo addTorrent(String sFileName, final String sOriginatingLocation)
	{
		TorrentInfo info;
		TOTorrent torrent;
		boolean bDeleteFileOnCancel;
		info = null;
		torrent = null;
		bDeleteFileOnCancel = false;
		File fOriginal;
		fOriginal = new File(sFileName);
		if (fOriginal.isFile() && fOriginal.exists())
			break MISSING_BLOCK_LABEL_49;
		Utils.execSWTThread(new AERunnable() {

			final String val$sOriginatingLocation;
			final OpenTorrentWindow this$0;

			public void runSupport()
			{
				if (shell == null)
					new MessageSlideShell(Display.getCurrent(), 1, "OpenTorrentWindow.mb.openError", "", new String[] {
						sOriginatingLocation, "Not a File"
					}, -1);
				else
					Utils.openMessageBox(shell, 32, "OpenTorrentWindow.mb.openError", new String[] {
						sOriginatingLocation, "Not a File"
					});
			}

			
			{
				this$0 = OpenTorrentWindow.thi

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -