use of com.biglybt.core.disk.DiskManager in project BiglyBT by BiglySoftware.
the class CoreImpl method checkCloseActions.
protected void checkCloseActions() {
List<DownloadManager> managers = getGlobalManager().getDownloadManagers();
boolean is_downloading = false;
boolean is_seeding = false;
for (DownloadManager manager : managers) {
if (manager.isPaused()) {
return;
}
if (manager.getDownloadState().getFlag(DownloadManagerState.FLAG_METADATA_DOWNLOAD)) {
return;
}
if (manager.getDownloadState().getFlag(DownloadManagerState.FLAG_LOW_NOISE)) {
// don't count these as interesting as the user isn't directly interested in them
continue;
}
int state = manager.getState();
if (state == DownloadManager.STATE_FINISHING) {
is_downloading = true;
} else {
if (state == DownloadManager.STATE_DOWNLOADING) {
PEPeerManager pm = manager.getPeerManager();
if (pm != null) {
if (pm.hasDownloadablePiece()) {
is_downloading = true;
} else {
// its effectively seeding, change so logic about recheck obeyed below
state = DownloadManager.STATE_SEEDING;
}
}
} else {
if (!manager.isDownloadComplete(false)) {
if (state != DownloadManager.STATE_STOPPED && state != DownloadManager.STATE_ERROR) {
// an incomplete download that is in an active state counts as downloading even
// if it is currently queued/waiting as it is 'on its way' to being in a downloading
// state
is_downloading = true;
}
}
}
if (state == DownloadManager.STATE_SEEDING) {
DiskManager disk_manager = manager.getDiskManager();
if (disk_manager != null && disk_manager.getCompleteRecheckStatus() != -1) {
// wait until recheck is complete before we mark as downloading-complete
is_downloading = true;
} else {
is_seeding = true;
}
}
}
}
long now = SystemTime.getMonotonousTime();
if (is_downloading) {
ca_last_time_downloading = now;
ca_last_time_seeding = -1;
} else if (is_seeding) {
ca_last_time_seeding = now;
}
String dl_act = COConfigurationManager.getStringParameter("On Downloading Complete Do");
if (!dl_act.equals("Nothing")) {
if (ca_last_time_downloading >= 0 && !is_downloading && now - ca_last_time_downloading >= 30 * 1000) {
executeInternalCloseAction(true, true, dl_act, null);
}
}
String se_act = COConfigurationManager.getStringParameter("On Seeding Complete Do");
if (!se_act.equals("Nothing")) {
if (ca_last_time_seeding >= 0 && !is_seeding && now - ca_last_time_seeding >= 30 * 1000) {
executeInternalCloseAction(true, false, se_act, null);
}
}
}
use of com.biglybt.core.disk.DiskManager in project BiglyBT by BiglySoftware.
the class CoreImpl method checkSleepActions.
protected void checkSleepActions() {
boolean ps_downloading = COConfigurationManager.getBooleanParameter("Prevent Sleep Downloading");
boolean ps_fp_seed = COConfigurationManager.getBooleanParameter("Prevent Sleep FP Seeding");
String tag_name = COConfigurationManager.getStringParameter("Prevent Sleep Tag");
Tag ps_tag = null;
tag_name = tag_name.trim();
if (!tag_name.isEmpty()) {
ps_tag = TagManagerFactory.getTagManager().getTagType(TagType.TT_DOWNLOAD_MANUAL).getTag(tag_name, true);
}
String declining_subsystems = "";
for (PowerManagementListener l : power_listeners) {
try {
if (!l.requestPowerStateChange(PowerManagementListener.ST_SLEEP, null)) {
declining_subsystems += (declining_subsystems.length() == 0 ? "" : ",") + l.getPowerName();
}
} catch (Throwable e) {
Debug.out(e);
}
}
PlatformManager platform = PlatformManagerFactory.getPlatformManager();
if (declining_subsystems.length() == 0 && !(ps_downloading || ps_fp_seed || ps_tag != null)) {
if (platform.getPreventComputerSleep()) {
setPreventComputerSleep(platform, false, "configuration change");
}
return;
}
boolean prevent_sleep = false;
String prevent_reason = null;
if (declining_subsystems.length() > 0) {
prevent_sleep = true;
prevent_reason = "subsystems declined sleep: " + declining_subsystems;
} else if (ps_tag != null && ps_tag.getTaggedCount() > 0) {
prevent_sleep = true;
prevent_reason = "tag '" + tag_name + "' has entries";
} else {
List<DownloadManager> managers = getGlobalManager().getDownloadManagers();
for (DownloadManager manager : managers) {
int state = manager.getState();
if (state == DownloadManager.STATE_FINISHING || manager.getDownloadState().getFlag(DownloadManagerState.FLAG_METADATA_DOWNLOAD)) {
if (ps_downloading) {
prevent_sleep = true;
prevent_reason = "active downloads";
break;
}
} else {
if (state == DownloadManager.STATE_DOWNLOADING) {
PEPeerManager pm = manager.getPeerManager();
if (pm != null) {
if (pm.hasDownloadablePiece()) {
if (ps_downloading) {
prevent_sleep = true;
prevent_reason = "active downloads";
break;
}
} else {
// its effectively seeding, change so logic about recheck obeyed below
state = DownloadManager.STATE_SEEDING;
}
}
}
if (state == DownloadManager.STATE_SEEDING && ps_fp_seed) {
DiskManager disk_manager = manager.getDiskManager();
if (disk_manager != null && disk_manager.getCompleteRecheckStatus() != -1) {
if (ps_downloading) {
prevent_sleep = true;
prevent_reason = "active downloads";
break;
}
} else {
try {
DefaultRankCalculator calc = StartStopRulesDefaultPlugin.getRankCalculator(PluginCoreUtils.wrap(manager));
if (calc.getCachedIsFP()) {
prevent_sleep = true;
prevent_reason = "first-priority seeding";
break;
}
} catch (Throwable e) {
}
}
}
}
}
}
if (prevent_sleep != platform.getPreventComputerSleep()) {
if (prevent_sleep) {
prevent_sleep_remove_trigger = false;
} else {
if (!prevent_sleep_remove_trigger) {
prevent_sleep_remove_trigger = true;
return;
}
}
if (prevent_reason == null) {
if (ps_downloading && ps_fp_seed) {
prevent_reason = "no active downloads or first-priority seeding";
} else if (ps_downloading) {
prevent_reason = "no active downloads";
} else {
prevent_reason = "no active first-priority seeding";
}
}
setPreventComputerSleep(platform, prevent_sleep, prevent_reason);
}
}
use of com.biglybt.core.disk.DiskManager in project BiglyBT by BiglySoftware.
the class DownloadManagerStatsImpl method getSizeExcludingDND.
@Override
public long getSizeExcludingDND() {
DiskManager dm = download_manager.getDiskManager();
if (dm != null) {
return dm.getSizeExcludingDND();
}
long totalLength = download_manager.getSize();
return totalLength - getSkippedFileSetSize();
}
use of com.biglybt.core.disk.DiskManager in project BiglyBT by BiglySoftware.
the class DownloadManagerStatsImpl method recalcDownloadCompleteBytes.
@Override
public void recalcDownloadCompleteBytes() {
DiskManager dm = getDiskManagerIfNotTransient();
if (dm != null) {
long total = dm.getTotalLength();
saved_completed_download_bytes = total - dm.getRemaining();
}
if (saved_completed_download_bytes < 0) {
// recalc
DiskManagerFileInfo[] files = download_manager.getDiskManagerFileInfoSet().getFiles();
long total_size = 0;
for (DiskManagerFileInfo file : files) {
total_size += file.getDownloaded();
}
saved_completed_download_bytes = total_size;
}
}
use of com.biglybt.core.disk.DiskManager in project BiglyBT by BiglySoftware.
the class EnhancedDownloadManager method getContiguousAvailableBytes.
public long getContiguousAvailableBytes(int file_index, long file_start_offset, long stop_counting_after) {
if (file_index < 0 || file_index >= enhanced_files.length) {
return (-1);
}
EnhancedDownloadManagerFile efile = enhanced_files[file_index];
DiskManagerFileInfo file = efile.getFile();
DiskManager dm = download_manager.getDiskManager();
if (dm == null) {
if (file.getDownloaded() == file.getLength()) {
return (file.getLength() - file_start_offset);
}
return (-1);
}
int piece_size = dm.getPieceLength();
long start_index = efile.getByteOffestInTorrent() + file_start_offset;
int first_piece_index = (int) (start_index / piece_size);
int first_piece_offset = (int) (start_index % piece_size);
int last_piece_index = file.getLastPieceNumber();
DiskManagerPiece[] pieces = dm.getPieces();
DiskManagerPiece first_piece = pieces[first_piece_index];
long available = 0;
if (!first_piece.isDone()) {
boolean[] blocks = first_piece.getWritten();
if (blocks == null) {
if (first_piece.isDone()) {
available = first_piece.getLength() - first_piece_offset;
}
} else {
int piece_offset = 0;
for (int j = 0; j < blocks.length; j++) {
if (blocks[j]) {
int block_size = first_piece.getBlockSize(j);
piece_offset = piece_offset + block_size;
if (available == 0) {
if (piece_offset > first_piece_offset) {
available = piece_offset - first_piece_offset;
}
} else {
available += block_size;
}
} else {
break;
}
}
}
} else {
available = first_piece.getLength() - first_piece_offset;
for (int i = first_piece_index + 1; i <= last_piece_index; i++) {
if (stop_counting_after > 0 && available >= stop_counting_after) {
break;
}
DiskManagerPiece piece = pieces[i];
if (piece.isDone()) {
available += piece.getLength();
} else {
boolean[] blocks = piece.getWritten();
if (blocks == null) {
if (piece.isDone()) {
available += piece.getLength();
} else {
break;
}
} else {
for (int j = 0; j < blocks.length; j++) {
if (blocks[j]) {
available += piece.getBlockSize(j);
} else {
break;
}
}
}
break;
}
}
}
long max_available = file.getLength() - file_start_offset;
if (available > max_available) {
available = max_available;
}
return (available);
}
Aggregations