📄 downloadmanagerimpl.java
字号:
}
} else
{
if (save_dir_file.getParent() == null)
throw new NoStackException((new StringBuilder()).append("Data location '").append(torrent_save_dir).append("' is invalid").toString());
torrent_save_dir = save_dir_file.getParent().toString();
torrent_save_file = save_dir_file.getName();
}
} else
{
if (save_dir_file.exists())
{
if (!save_dir_file.isDirectory())
throw new NoStackException((new StringBuilder()).append("'").append(torrent_save_dir).append("' is not a directory").toString());
if (save_dir_file.getName().equals(display_name))
torrent_save_dir = save_dir_file.getParent().toString();
}
torrent_save_file = display_name;
}
}
torrent_save_location = new File(torrent_save_dir, torrent_save_file);
File linked_target = getSaveLocation();
if (!linked_target.exists() && !new_torrent && !Constants.isWindows && has_ever_been_started)
throw new NoStackException((new StringBuilder()).append(MessageText.getString("DownloadManager.error.datamissing")).append(" ").append(Debug.secretFileName(linked_target.toString())).toString());
if (new_torrent)
{
download_manager_state.setLongParameter("stats.download.added.time", SystemTime.getCurrentTime());
boolean low_noise = TorrentUtils.getFlag(torrent, 1);
if (low_noise)
download_manager_state.setFlag(16L, true);
download_manager_state.setTrackerResponseCache(new HashMap());
if (for_seeding)
{
DiskManagerFactory.setTorrentResumeDataNearlyComplete(download_manager_state);
download_manager_state.setFlag(8L, true);
} else
{
download_manager_state.clearResumeData();
}
} else
{
long add_time = download_manager_state.getLongParameter("stats.download.added.time");
if (add_time == 0L)
{
try
{
add_time = (new File(torrentFileName)).lastModified();
}
catch (Throwable e) { }
if (add_time == 0L)
add_time = SystemTime.getCurrentTime();
download_manager_state.setLongParameter("stats.download.added.time", add_time);
}
}
torrent_comment = StringInterner.intern(locale_decoder.decodeString(torrent.getComment()));
if (torrent_comment == null)
torrent_comment = "";
torrent_created_by = locale_decoder.decodeString(torrent.getCreatedBy());
if (torrent_created_by == null)
torrent_created_by = "";
if (download_manager_state.isResumeDataComplete() || for_seeding)
{
stats.setDownloadCompleted(1000);
setAssumedComplete(true);
} else
{
setAssumedComplete(false);
}
dl_identity_obtained = true;
break MISSING_BLOCK_LABEL_959;
TOTorrentException e;
e;
setFailed(TorrentUtils.exceptionToText(e));
dl_identity_obtained = true;
break MISSING_BLOCK_LABEL_959;
e;
Debug.printStackTrace(e);
setFailed(MessageText.getString("DownloadManager.error.unsupportedencoding"));
dl_identity_obtained = true;
break MISSING_BLOCK_LABEL_959;
e;
Debug.outNoStack(e.getMessage());
dl_identity_obtained = true;
break MISSING_BLOCK_LABEL_959;
e;
Debug.printStackTrace(e);
setFailed(e);
dl_identity_obtained = true;
break MISSING_BLOCK_LABEL_959;
Exception exception;
exception;
dl_identity_obtained = true;
throw exception;
if (download_manager_state == null)
{
read_torrent_state = (new Object[] {
torrent_save_dir, torrent_save_file, torrent_hash, new Boolean(new_torrent), new Boolean(for_seeding), new Boolean(has_ever_been_started), new Integer(initial_state)
});
download_manager_state = DownloadManagerStateImpl.getDownloadState(this);
if (torrent_save_file == null)
torrent_save_location = new File(torrent_save_dir);
else
torrent_save_location = new File(torrent_save_dir, torrent_save_file);
} else
{
if (torrent_save_file == null)
torrent_save_location = new File(torrent_save_dir);
if (download_manager_state.getNetworks().length == 0 && torrent != null)
{
String networks[] = AENetworkClassifier.getNetworks(torrent, display_name);
download_manager_state.setNetworks(networks);
}
}
if (torrent_save_location != null)
{
try
{
torrent_save_location = torrent_save_location.getCanonicalFile();
}
// Misplaced declaration of an exception variable
catch (String networks[])
{
torrent_save_location = torrent_save_location.getAbsoluteFile();
}
getSaveLocation();
}
controller.setInitialState(initial_state);
break MISSING_BLOCK_LABEL_1243;
Exception exception1;
exception1;
if (torrent_save_location != null)
{
try
{
torrent_save_location = torrent_save_location.getCanonicalFile();
}
catch (Throwable e)
{
torrent_save_location = torrent_save_location.getAbsoluteFile();
}
getSaveLocation();
}
controller.setInitialState(initial_state);
throw exception1;
}
protected void readTorrent()
{
if (read_torrent_state == null)
{
return;
} else
{
readTorrent((String)read_torrent_state[0], (String)read_torrent_state[1], (byte[])(byte[])read_torrent_state[2], ((Boolean)read_torrent_state[3]).booleanValue(), ((Boolean)read_torrent_state[4]).booleanValue(), ((Boolean)read_torrent_state[5]).booleanValue(), ((Integer)read_torrent_state[6]).intValue());
return;
}
}
protected void readParameters()
{
max_connections = getDownloadState().getIntParameter("max.peers");
max_connections_when_seeding_enabled = getDownloadState().getBooleanParameter("max.peers.when.seeding.enabled");
max_connections_when_seeding = getDownloadState().getIntParameter("max.peers.when.seeding");
max_seed_connections = getDownloadState().getIntParameter("max.seeds");
max_uploads = getDownloadState().getIntParameter("max.uploads");
max_uploads_when_seeding_enabled = getDownloadState().getBooleanParameter("max.uploads.when.seeding.enabled");
max_uploads_when_seeding = getDownloadState().getIntParameter("max.uploads.when.seeding");
max_upload_when_busy_bps = getDownloadState().getIntParameter("max.upload.when.busy") * 1024;
max_uploads = Math.max(max_uploads, 2);
max_uploads_when_seeding = Math.max(max_uploads_when_seeding, 2);
}
protected int getMaxConnections()
{
return max_connections;
}
protected int getMaxConnectionsWhenSeeding()
{
return max_connections_when_seeding;
}
protected boolean isMaxConnectionsWhenSeedingEnabled()
{
return max_connections_when_seeding_enabled;
}
protected int getMaxSeedConnections()
{
return max_seed_connections;
}
protected boolean isMaxUploadsWhenSeedingEnabled()
{
return max_uploads_when_seeding_enabled;
}
protected int getMaxUploadsWhenSeeding()
{
return max_uploads_when_seeding;
}
public int getMaxUploads()
{
return max_uploads;
}
public void setMaxUploads(int max)
{
download_manager_state.setIntParameter("max.uploads", max);
}
public int getEffectiveMaxUploads()
{
if (isMaxUploadsWhenSeedingEnabled() && getState() == 60)
return getMaxUploadsWhenSeeding();
else
return max_uploads;
}
public int getEffectiveUploadRateLimitBytesPerSecond()
{
int local_max_bps = stats.getUploadRateLimitBytesPerSecond();
int rate = local_max_bps;
if (max_upload_when_busy_bps != 0)
{
long now = SystemTime.getCurrentTime();
if (now < last_upload_when_busy_update || now - last_upload_when_busy_update > 5000L)
{
last_upload_when_busy_update = now;
String key = TransferSpeedValidator.getActiveUploadParameter(globalManager);
int global_limit_bps = COConfigurationManager.getIntParameter(key) * 1024;
if (global_limit_bps > 0 && max_upload_when_busy_bps < global_limit_bps)
{
local_max_bps = local_max_bps != 0 ? local_max_bps : global_limit_bps;
GlobalManagerStats gm_stats = globalManager.getStats();
int actual = gm_stats.getDataSendRateNoLAN() + gm_stats.getProtocolSendRateNoLAN();
int move_by = (local_max_bps - max_upload_when_busy_bps) / 10;
if (move_by < 1024)
move_by = 1024;
if (global_limit_bps - actual <= 2048)
{
if (current_upload_when_busy_bps == 0)
current_upload_when_busy_bps = local_max_bps;
int prev_upload_when_busy_bps = current_upload_when_busy_bps;
current_upload_when_busy_bps -= move_by;
if (current_upload_when_busy_bps < max_upload_when_busy_bps)
current_upload_when_busy_bps = max_upload_when_busy_bps;
if (current_upload_when_busy_bps < prev_upload_when_busy_bps)
last_upload_when_busy_dec_time = now;
} else
if (current_upload_when_busy_bps != 0 && (upload_when_busy_min_secs == 0 || now < last_upload_when_busy_dec_time || now - last_upload_when_busy_dec_time >= (long)(upload_when_busy_min_secs * 1000)))
{
current_upload_when_busy_bps += move_by;
if (current_upload_when_busy_bps >= local_max_bps)
current_upload_when_busy_bps = 0;
}
if (current_upload_when_busy_bps > 0)
rate = current_upload_when_busy_bps;
} else
{
current_upload_when_busy_bps = 0;
}
} else
if (current_upload_when_busy_bps > 0)
rate = current_upload_when_busy_bps;
}
return rate;
}
protected void setFileLinks()
{
cached_save_location = null;
DiskManagerFactory.setFileLinks(this, download_manager_state.getFileLinks());
controller.fileInfoChanged();
}
protected void clearFileLinks()
{
download_manager_state.clearFileLinks();
}
protected void updateFileLinks(File old_save_path, File new_save_path)
{
try
{
old_save_path = old_save_path.getCanonicalFile();
}
catch (IOException ioe)
{
old_save_path = old_save_path.getAbsoluteFile();
}
try
{
new_save_path = new_save_path.getCanonicalFile();
}
catch (IOException ioe)
{
new_save_path = new_save_path.getAbsoluteFile();
}
String old_path = old_save_path.getPath();
String new_path = new_save_path.getPath();
CaseSensitiveFileMap links = download_manager_state.getFileLinks();
for (Iterator it = links.keySetIterator(); it.hasNext();)
{
File from = (File)it.next();
File to = links.get(from);
String from_s = from != null ? from.getAbsolutePath() : null;
String to_s = to != null ? to.getAbsolutePath() : null;
try
{
updateFileLink(old_path, new_path, from_s, to_s);
}
catch (Exception e)
{
Debug.printStackTrace(e);
}
}
}
protected void updateFileLink(String old_path, String new_path, String from_loc, String to_loc)
{
if (to_loc == null)
return;
if (torrent.isSimpleTorrent())
if (!old_path.equals(from_loc))
{
throw new RuntimeException((new StringBuilder()).append("assert failure: old_path=").append(old_path).append(", from_loc=").append(from_loc).toString());
} else
{
download_manager_state.setFileLink(new File(old_path), null);
download_manager_state.setFileLink(new File(new_path), new File(new_path));
return;
}
String from_loc_to_use = FileUtil.translateMoveFilePath(old_path, new_path, from_loc);
if (from_loc_to_use == null)
return;
String to_loc_to_use = FileUtil.translateMoveFilePath(old_path, new_path, to_loc);
if (to_loc_to_use == null)
to_loc_to_use = to_loc;
download_manager_state.setFileLink(new File(from_loc), null);
download_manager_state.setFileLink(new File(from_loc_to_use), new File(to_loc_to_use));
}
/**
* @deprecated Method filesExist is deprecated
*/
public boolean filesExist()
{
return filesExist(true);
}
public boolean filesExist(boolean expected_to_be_allocated)
{
return controller.filesExist(expected_to_be_allocated);
}
public boolean isPersistent()
{
return persistent;
}
public String getDisplayName()
{
DownloadManagerState dms = getDownloadState();
if (dms != null)
{
String result = dms.getDisplayName();
if (result != null)
return result;
}
return display_name;
}
public String getInternalName()
{
return internal_name;
}
public String getErrorDetails()
{
return controller.getErrorDetail();
}
public long getSize()
{
if (torrent != null)
return torrent.getSize();
else
return 0L;
}
protected void setFailed()
{
setFailed((String)null);
}
protected void setFailed(Throwable e)
{
setFailed(Debug.getNestedExceptionMessage(e));
}
protected void setFailed(String str)
{
controller.setFailed(str);
}
protected void setTorrentInvalid(String str)
{
setFailed(str);
torrent = null;
}
public void saveResumeData()
{
if (getState() == 50)
try
{
getDiskManager().saveResumeData(true);
}
catch (Exception e)
{
setFailed((new StringBuilder()).append("Resume data save fails: ").append(Debug.getNestedExceptionMessage(e)).toString());
}
if (!assumedComplete)
download_manager_state.save();
}
public void saveDownload()
{
DiskManager disk_manager = controller.getDiskManager();
if (disk_manager != null)
disk_manager.saveState();
download_manager_state.save();
}
public void initialize()
{
if (torrent == null)
readTorrent();
if (torrent == null)
{
setFailed();
return;
}
if (assumedComplete && !filesExist(true))
return;
download_manager_state.setActive(true);
this_mon.enter();
if (tracker_client != null)
{
Debug.out("DownloadManager: initialize called with tracker client still available");
tracker_client.destroy();
}
tracker_client = TRTrackerAnnouncerFactory.create(torrent, download_manager_state.getNetworks());
tracker_client.setTrackerResponseCache(download_manager_state.getTrackerResponseCache());
tracker_client.addListener(tracker_client_listener);
this_mon.exit();
break MISSING_BLOCK_LABEL_148;
TRTrackerAnnouncerException e;
e;
this_mon.exit();
throw e;
controller.initializeDiskManager(open_for_seeding);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -