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

📄 downloadmanagerimpl.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				return scrape_response == null || !scrape_response.isValid() || nbSeeds != scrape_response.getSeeds() || nbPeers != scrape_response.getPeers() ? 3 : 4;
			} else
			{
				return 4;
			}
		}
		return state != 100 ? 1 : 6;
	}

	public int getNATStatus()
	{
		int state = getState();
		PEPeerManager peerManager = controller.getPeerManager();
		TRTrackerAnnouncer tc = getTrackerClient();
		if (tc != null && peerManager != null && (state == 50 || state == 60))
		{
			if (peerManager.getNbRemoteConnectionsExcludingUDP() > 0)
				return 1;
			long last_good_time = peerManager.getLastRemoteConnectionTime();
			if (last_good_time > 0L)
				return SystemTime.getCurrentTime() - last_good_time >= 0x1b7740L ? 2 : 1;
			TRTrackerAnnouncerResponse announce_response = tc.getLastResponse();
			int trackerStatus = announce_response.getStatus();
			if (trackerStatus == 0 || trackerStatus == 1)
				return 0;
			if (SystemTime.getCurrentTime() - peerManager.getTimeStarted() < 0x2bf20L)
				return 0;
			TRTrackerScraperResponse scrape_response = getTrackerScrapeResponse();
			return scrape_response == null || !scrape_response.isValid() || peerManager.getNbSeeds() != scrape_response.getSeeds() || peerManager.getNbPeers() != scrape_response.getPeers() ? 3 : 0;
		} else
		{
			return 0;
		}
	}

	public int getPosition()
	{
		return position;
	}

	public void setPosition(int new_position)
	{
		informPositionChanged(new_position);
	}

	public void addTrackerListener(DownloadManagerTrackerListener listener)
	{
		tracker_listeners.addListener(listener);
	}

	public void removeTrackerListener(DownloadManagerTrackerListener listener)
	{
		tracker_listeners.removeListener(listener);
	}

	protected void deleteDataFiles()
	{
		DiskManagerFactory.deleteDataFiles(torrent, torrent_save_location.getParent(), torrent_save_location.getName());
		getDownloadState().setFlag(4L, true);
	}

	protected void deleteTorrentFile()
	{
		if (torrentFileName != null)
			TorrentUtils.delete(new File(torrentFileName));
	}

	public DownloadManagerState getDownloadState()
	{
		return download_manager_state;
	}

	public Object getData(String key)
	{
		return getUserData(key);
	}

	public void setData(String key, Object value)
	{
		setUserData(key, value);
	}

	public Object getUserData(Object key)
	{
		if (data == null)
			return null;
		else
			return data.get(key);
	}

	public void setUserData(Object key, Object value)
	{
		peer_listeners_mon.enter();
		if (data == null)
			data = new LightHashMap();
		if (value == null)
		{
			if (data.containsKey(key))
				data.remove(key);
		} else
		{
			data.put(key, value);
		}
		peer_listeners_mon.exit();
		break MISSING_BLOCK_LABEL_88;
		Exception exception;
		exception;
		peer_listeners_mon.exit();
		throw exception;
	}

	public boolean isDataAlreadyAllocated()
	{
		return data_already_allocated;
	}

	public void setDataAlreadyAllocated(boolean already_allocated)
	{
		data_already_allocated = already_allocated;
	}

	public void setSeedingRank(int rank)
	{
		iSeedingRank = rank;
	}

	public int getSeedingRank()
	{
		return iSeedingRank;
	}

	public long getCreationTime()
	{
		return creation_time;
	}

	public void setCreationTime(long t)
	{
		creation_time = t;
	}

	public boolean isExtendedMessagingEnabled()
	{
		return az_messaging_enabled;
	}

	public void setAZMessagingEnabled(boolean enable)
	{
		az_messaging_enabled = enable;
	}

	public void setCryptoLevel(int level)
	{
		crypto_level = level;
	}

	public int getCryptoLevel()
	{
		return crypto_level;
	}

	public void moveDataFiles(File new_parent_dir)
		throws DownloadManagerException
	{
		moveDataFiles(new_parent_dir, null);
	}

	public void renameDownload(String new_name)
		throws DownloadManagerException
	{
		moveDataFiles(null, new_name);
	}

	public void moveDataFiles(final File destination, final String new_name)
		throws DownloadManagerException
	{
		if (destination == null && new_name == null)
			throw new NullPointerException("destination and new name are both null");
		if (!canMoveDataFiles())
			throw new DownloadManagerException("canMoveDataFiles is false!");
		SaveLocationChange slc = new SaveLocationChange();
		slc.download_location = destination;
		slc.download_name = new_name;
		File current_location = getSaveLocation();
		if (slc.normaliseDownloadLocation(current_location).equals(current_location))
			return;
		try
		{
			FileUtil.runAsTask(new AzureusCoreOperationTask() {

				final File val$destination;
				final String val$new_name;
				final DownloadManagerImpl this$0;

				public void run(AzureusCoreOperation operation)
				{
					try
					{
						moveDataFilesSupport(destination, new_name);
					}
					catch (DownloadManagerException e)
					{
						throw new RuntimeException(e);
					}
				}

			
			{
				this$0 = DownloadManagerImpl.this;
				destination = file;
				new_name = s;
				super();
			}
			});
		}
		catch (RuntimeException e)
		{
			Throwable cause = e.getCause();
			if (cause instanceof DownloadManagerException)
				throw (DownloadManagerException)cause;
			else
				throw e;
		}
	}

	private void moveDataFilesSupport(File new_parent_dir, String new_filename)
		throws DownloadManagerException
	{
		boolean is_paused = pause();
		moveDataFilesSupport0(new_parent_dir, new_filename);
		if (is_paused)
			resume();
		break MISSING_BLOCK_LABEL_35;
		Exception exception;
		exception;
		if (is_paused)
			resume();
		throw exception;
	}

	private void moveDataFilesSupport0(File new_parent_dir, String new_filename)
		throws DownloadManagerException
	{
		if (!canMoveDataFiles())
			throw new DownloadManagerException("canMoveDataFiles is false!");
		if (new_filename != null)
			new_filename = FileUtil.convertOSSpecificChars(new_filename, false);
		File old_file = getSaveLocation();
		try
		{
			old_file = old_file.getCanonicalFile();
			if (new_parent_dir != null)
				new_parent_dir = new_parent_dir.getCanonicalFile();
		}
		catch (Throwable e)
		{
			Debug.printStackTrace(e);
			throw new DownloadManagerException("Failed to get canonical paths", e);
		}
		File current_save_location = old_file;
		File new_save_location = new File(new_parent_dir != null ? new_parent_dir : old_file.getParentFile(), new_filename != null ? new_filename : old_file.getName());
		if (current_save_location.equals(new_save_location))
			return;
		DiskManager dm = getDiskManager();
		if (dm == null || dm.getFiles() == null)
		{
			if (!old_file.exists())
			{
				FileUtil.mkdirs(new_save_location.getParentFile());
				setTorrentSaveDir(new_save_location.getParent().toString(), new_save_location.getName());
				return;
			}
			try
			{
				new_save_location = new_save_location.getCanonicalFile();
			}
			catch (Throwable e)
			{
				Debug.printStackTrace(e);
			}
			if (!old_file.equals(new_save_location))
				if (torrent.isSimpleTorrent())
				{
					if (controller.getDiskManagerFileInfo()[0].setLinkAtomic(new_save_location))
						setTorrentSaveDir(new_save_location.getParentFile().toString(), new_save_location.getName());
					else
						throw new DownloadManagerException("rename operation failed");
				} else
				{
					if (FileUtil.isAncestorOf(old_file, new_save_location))
					{
						Logger.logTextResource(new LogAlert(this, true, 3, "DiskManager.alert.movefilefails"), new String[] {
							old_file.toString(), "Target is sub-directory of files"
						});
						throw new DownloadManagerException("rename operation failed");
					}
					final HashSet files_to_move = new HashSet();
					files_to_move.add(null);
					DiskManagerFileInfo info_files[] = controller.getDiskManagerFileInfo();
					for (int i = 0; i < info_files.length; i++)
					{
						File f = info_files[i].getFile(true);
						try
						{
							f = f.getCanonicalFile();
						}
						catch (IOException ioe)
						{
							f = f.getAbsoluteFile();
						}
						for (boolean added_entry = files_to_move.add(f); added_entry; added_entry = files_to_move.add(f))
							f = f.getParentFile();

					}

					FileFilter ff = new FileFilter() {

						final HashSet val$files_to_move;
						final DownloadManagerImpl this$0;

						public boolean accept(File f)
						{
							return files_to_move.contains(f);
						}

			
			{
				this$0 = DownloadManagerImpl.this;
				files_to_move = hashset;
				super();
			}
					};
					if (FileUtil.renameFile(old_file, new_save_location, false, ff))
						setTorrentSaveDir(new_save_location.getParentFile().toString(), new_save_location.getName());
					else
						throw new DownloadManagerException("rename operation failed");
				}
		} else
		{
			dm.moveDataFiles(new_save_location.getParentFile(), new_save_location.getName());
		}
	}

	public void moveTorrentFile(File new_parent_dir)
		throws DownloadManagerException
	{
		moveTorrentFile(new_parent_dir, null);
	}

	public void moveTorrentFile(File new_parent_dir, String new_name)
		throws DownloadManagerException
	{
		boolean is_paused;
		SaveLocationChange slc = new SaveLocationChange();
		slc.torrent_location = new_parent_dir;
		slc.torrent_name = new_name;
		File torrent_file_now = new File(getTorrentFileName());
		if (!slc.isDifferentTorrentLocation(torrent_file_now))
			return;
		is_paused = pause();
		moveTorrentFile0(new_parent_dir, new_name);
		if (is_paused)
			resume();
		break MISSING_BLOCK_LABEL_79;
		Exception exception;
		exception;
		if (is_paused)
			resume();
		throw exception;
	}

	private void moveTorrentFile0(File new_parent_dir, String new_name)
		throws DownloadManagerException
	{
		if (!canMoveDataFiles())
		{
			throw new DownloadManagerException("Cannot move torrent file");
		} else
		{
			setTorrentFile(new_parent_dir, new_name);
			return;
		}
	}

	public void setTorrentFile(File new_parent_dir, String new_name)
		throws DownloadManagerException
	{
		File old_file = new File(getTorrentFileName());
		if (!old_file.exists())
		{
			Debug.out("torrent file doesn't exist!");
			return;
		}
		if (new_parent_dir == null)
			new_parent_dir = old_file.getParentFile();
		if (new_name == null)
			new_name = old_file.getName();
		File new_file = new File(new_parent_dir, new_name);
		try
		{
			old_file = old_file.getCanonicalFile();
			new_file = new_file.getCanonicalFile();
		}
		catch (Throwable e)
		{
			Debug.printStackTrace(e);
			throw new DownloadManagerException("Failed to get canonical paths", e);
		}
		if (new_file.equals(old_file))
			return;
		if (TorrentUtils.move(old_file, new_file))
			setTorrentFileName(new_file.toString());
		else
			throw new DownloadManagerException("rename operation failed");
	}

	public boolean isInDefaultSaveDir()
	{
		return DownloadManagerDefaultPaths.isInDefaultDownloadDir(this);
	}

	public boolean seedPieceRecheck()
	{
		PEPeerManager pm = controller.getPeerManager();
		if (pm != null)
			return pm.seedPieceRecheck();
		else
			return false;
	}

	public void addRateLimiter(LimitedRateGroup group, boolean upload)
	{
		controller.addRateLimiter(group, upload);
	}

	public void removeRateLimiter(LimitedRateGroup group, boolean upload)
	{
		controller.removeRateLimiter(group, upload);
	}

	public boolean isTrackerError()
	{
		TRTrackerAnnouncer announcer = getTrackerClient();
		if (announcer != null)
		{
			TRTrackerAnnouncerResponse resp = announcer.getLastResponse();
			if (resp != null && resp.getStatus() == 1)
				return true;
		} else
		{
			TRTrackerScraperResponse resp = getTrackerScrapeResponse();
			if (resp != null && resp.getStatus() == 1)
				return true;
		}
		return false;
	}

	public boolean isUnauthorisedOnTracker()
	{
		TRTrackerAnnouncer announcer = getTrackerClient();
		String status_str = null;
		if (announcer != null)
		{
			TRTrack

⌨️ 快捷键说明

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