use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class DownloadManagerImpl method setAssumedComplete.
// Protected: Use requestAssumedCompleteMode outside of scope
protected void setAssumedComplete(boolean _assumedComplete) {
if (_assumedComplete) {
long completedOn = download_manager_state.getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_COMPLETED_TIME);
if (completedOn <= 0) {
long now = SystemTime.getCurrentTime();
download_manager_state.setLongParameter(DownloadManagerState.PARAM_DOWNLOAD_COMPLETED_TIME, now);
long last_file = download_manager_state.getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_FILE_COMPLETED_TIME);
if (last_file <= 0) {
Runnable set_it = new Runnable() {
public void run() {
// get a sensible value from actual files - useful when adding-for-seeding
long last_mod = 0;
DiskManagerFileInfo[] files = getDiskManagerFileInfoSet().getFiles();
for (DiskManagerFileInfo file : files) {
if (!file.isSkipped()) {
File f = file.getFile(true);
if (f.length() == file.getLength()) {
long mod = f.lastModified();
if (mod > last_mod) {
last_mod = mod;
}
}
}
}
if (last_mod == 0) {
last_mod = now;
}
download_manager_state.setLongParameter(DownloadManagerState.PARAM_DOWNLOAD_FILE_COMPLETED_TIME, last_mod);
if (last_mod < now) {
// update with more useful value
download_manager_state.setLongParameter(DownloadManagerState.PARAM_DOWNLOAD_COMPLETED_TIME, last_mod);
}
}
};
synchronized (init_lock) {
if (!initialised) {
post_init_tasks.add(set_it);
set_it = null;
}
}
if (set_it != null) {
set_it.run();
}
}
}
}
if (assumedComplete == _assumedComplete) {
return;
}
// Logger.log(new LogEvent(this, LogIDs.CORE, "setAssumedComplete("
// + _assumedComplete + ") was " + assumedComplete));
assumedComplete = _assumedComplete;
if (!assumedComplete) {
controller.setStateDownloading();
}
if (position != -1) {
// we are in a new list, move to the top of the list so that we continue
// seeding.
// -1 position means it hasn't been added to the global list. We
// shouldn't touch it, since it'll get a position once it's adding is
// complete
DownloadManager[] dms = { DownloadManagerImpl.this };
// pretend we are at the bottom of the new list
// so that move top will shift everything down one
position = globalManager.getDownloadManagers().size() + 1;
if (COConfigurationManager.getBooleanParameter(CFG_MOVE_COMPLETED_TOP)) {
globalManager.moveTop(dms);
} else {
globalManager.moveEnd(dms);
}
// we left a gap in incomplete list, fixup
globalManager.fixUpDownloadManagerPositions();
}
listeners.dispatch(LDT_COMPLETIONCHANGED, new Object[] { this, Boolean.valueOf(_assumedComplete) });
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class DownloadManagerImpl method copyDataFiles.
@Override
public void copyDataFiles(File parent_dir) throws DownloadManagerException {
if (parent_dir.exists()) {
if (!parent_dir.isDirectory()) {
throw (new DownloadManagerException("'" + parent_dir + "' is not a directory"));
}
} else {
if (!parent_dir.mkdirs()) {
throw (new DownloadManagerException("failed to create '" + parent_dir + "'"));
}
}
DiskManagerFileInfo[] files = controller.getDiskManagerFileInfoSet().getFiles();
if (torrent.isSimpleTorrent()) {
File file_from = files[0].getFile(true);
try {
File file_to = new File(parent_dir, file_from.getName());
if (file_to.exists()) {
if (file_to.length() != file_from.length()) {
throw (new Exception("target file '" + file_to + " already exists"));
}
} else {
FileUtil.copyFileWithException(file_from, file_to);
}
} catch (Throwable e) {
throw (new DownloadManagerException("copy of '" + file_from + "' failed", e));
}
} else {
try {
File sl_file = getSaveLocation();
String save_location = sl_file.getCanonicalPath();
if (!save_location.endsWith(File.separator)) {
save_location += File.separator;
}
parent_dir = new File(parent_dir, sl_file.getName());
if (!parent_dir.isDirectory()) {
parent_dir.mkdirs();
}
for (DiskManagerFileInfo file : files) {
if (!file.isSkipped() && file.getDownloaded() == file.getLength()) {
File file_from = file.getFile(true);
try {
String file_path = file_from.getCanonicalPath();
if (file_path.startsWith(save_location)) {
File file_to = new File(parent_dir, file_path.substring(save_location.length()));
if (file_to.exists()) {
if (file_to.length() != file_from.length()) {
throw (new Exception("target file '" + file_to + " already exists"));
}
} else {
File parent = file_to.getParentFile();
if (!parent.exists()) {
if (!parent.mkdirs()) {
throw (new Exception("Failed to make directory '" + parent + "'"));
}
}
FileUtil.copyFileWithException(file_from, file_to);
}
}
} catch (Throwable e) {
throw (new DownloadManagerException("copy of '" + file_from + "' failed", e));
}
}
}
} catch (Throwable e) {
throw (new DownloadManagerException("copy failed", e));
}
}
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class DownloadManagerStateImpl method generateEvidence.
@Override
public void generateEvidence(IndentWriter writer) {
writer.println("DownloadManagerState");
try {
writer.indent();
writer.println("parameters=" + parameters);
writer.println("flags=" + getFlags());
DiskManagerFileInfo primaryFile = getPrimaryFile();
if (primaryFile != null) {
writer.println("primary file=" + Debug.secretFileName(primaryFile.getFile(true).getAbsolutePath()));
}
} finally {
writer.exdent();
}
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class DownloadManagerStatsImpl method getSkippedFileSetSize.
private long getSkippedFileSetSize() {
if (saved_skipped_file_set_size < 0) {
DiskManagerFileInfo[] files = download_manager.getDiskManagerFileInfoSet().getFiles();
long skipped_file_set_size = 0;
long skipped_but_downloaded = 0;
for (int i = 0; i < files.length; i++) {
DiskManagerFileInfo file = files[i];
if (file.isSkipped()) {
skipped_file_set_size += file.getLength();
skipped_but_downloaded += file.getDownloaded();
}
}
setSkippedFileStats(skipped_file_set_size, skipped_but_downloaded);
}
return saved_skipped_file_set_size;
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class DownloadManagerStatsImpl method setShareRatio.
@Override
public void setShareRatio(int ratio) {
if (ratio < 0) {
ratio = 0;
}
if (ratio > 1000000) {
ratio = 1000000;
}
DiskManagerFileInfo[] files = download_manager.getDiskManagerFileInfoSet().getFiles();
long total_size = 0;
for (DiskManagerFileInfo file : files) {
if (!file.isSkipped()) {
total_size += file.getLength();
}
}
if (total_size == 0) {
return;
}
saved_hashfails = 0;
saved_discarded = 0;
saved_data_bytes_downloaded = 0;
saved_data_bytes_uploaded = 0;
long downloaded = getTotalGoodDataBytesReceived();
long uploaded = getTotalDataBytesSent();
// manipulate by updating downloaded to be one full copy and then uploaded as required
long target_downloaded = total_size;
long target_uploaded = (ratio * total_size) / 1000;
saved_data_bytes_downloaded = target_downloaded - downloaded;
saved_data_bytes_uploaded = target_uploaded - uploaded;
if (download_manager.getPeerManager() == null) {
saveSessionTotals();
}
}
Aggregations