Skip to content

Commit 20d299a

Browse files
committed
Option to set files to high priority when <n> pieces remaining
1 parent b65d96f commit 20d299a

File tree

9 files changed

+221
-16
lines changed

9 files changed

+221
-16
lines changed

core/src/com/biglybt/core/download/DownloadManagerState.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@
9696
public static final String AT_REAL_DM_MAGNET_TIME = "rdmmt"; // long
9797
public static final String AT_PLUGIN_OPTIONS = "pluginoptions"; // Map
9898
public static final String AT_PO_ENABLE_ANNOUNCE = "enableannounce"; // boolean, def=true
99-
99+
public static final String AT_SET_FILE_PRIORITY_REM_PIECE = "sfp.rp"; // int
100+
100101
public static final String AT_TRANSIENT_FLAGS = "t_flags";
101102
public static final String AT_TRANSIENT_TAG_SORT = "t_tagsort";
102103

core/src/com/biglybt/core/download/impl/DownloadManagerController.java

+1
Original file line numberDiff line numberDiff line change
@@ -3910,6 +3910,7 @@ public DiskManagerListener_Default(boolean open_for_seeding) {
39103910
DiskManager dm,
39113911
DiskManagerPiece piece )
39123912
{
3913+
download_manager.informPieceDoneChanged( piece );
39133914
}
39143915

39153916
@Override

core/src/com/biglybt/core/download/impl/DownloadManagerImpl.java

+72-10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import com.biglybt.core.disk.*;
3636
import com.biglybt.core.disk.impl.DiskManagerImpl;
3737
import com.biglybt.core.disk.impl.DiskManagerUtil;
38+
import com.biglybt.core.disk.impl.piecemapper.DMPieceList;
39+
import com.biglybt.core.disk.impl.piecemapper.DMPieceMapEntry;
3840
import com.biglybt.core.download.*;
3941
import com.biglybt.core.global.GlobalManager;
4042
import com.biglybt.core.global.GlobalManagerEvent;
@@ -723,6 +725,8 @@ public void completionChanged(DownloadManager manager, boolean bCompleted){
723725
private int message_mode = -1;
724726

725727
private volatile int tcp_port_override;
728+
729+
private volatile int set_file_priority_high_pieces_rem = 0;
726730

727731
// Only call this with STATE_QUEUED, STATE_WAITING, or STATE_STOPPED unless you know what you are doing
728732

@@ -1096,7 +1100,7 @@ protected Boolean initialValue(){
10961100
};
10971101

10981102
@Override
1099-
public void
1103+
public void
11001104
attributeEventOccurred(
11011105
DownloadManager dm, String attribute_name, int event_type)
11021106
{
@@ -1131,13 +1135,17 @@ protected Boolean initialValue(){
11311135

11321136
tc.resetTrackerUrl( false );
11331137
}
1138+
}else if ( attribute_name.equals( DownloadManagerState.AT_SET_FILE_PRIORITY_REM_PIECE )){
1139+
1140+
readParameters();
11341141
}
11351142
}
11361143
};
11371144

11381145
download_manager_state.addListener(attr_listener, DownloadManagerState.AT_FILE_LINKS2, DownloadManagerStateAttributeListener.WRITTEN);
11391146
download_manager_state.addListener(attr_listener, DownloadManagerState.AT_PARAMETERS, DownloadManagerStateAttributeListener.WRITTEN);
11401147
download_manager_state.addListener(attr_listener, DownloadManagerState.AT_NETWORKS, DownloadManagerStateAttributeListener.WRITTEN);
1148+
download_manager_state.addListener(attr_listener, DownloadManagerState.AT_SET_FILE_PRIORITY_REM_PIECE, DownloadManagerStateAttributeListener.WRITTEN);
11411149

11421150
torrent = download_manager_state.getTorrent();
11431151

@@ -1647,19 +1655,23 @@ public void perform(TimerEvent event){
16471655
protected void
16481656
readParameters()
16491657
{
1650-
max_connections = getDownloadState().getIntParameter( DownloadManagerState.PARAM_MAX_PEERS );
1651-
max_connections_when_seeding_enabled = getDownloadState().getBooleanParameter( DownloadManagerState.PARAM_MAX_PEERS_WHEN_SEEDING_ENABLED );
1652-
max_connections_when_seeding = getDownloadState().getIntParameter( DownloadManagerState.PARAM_MAX_PEERS_WHEN_SEEDING );
1653-
max_seed_connections = getDownloadState().getIntParameter( DownloadManagerState.PARAM_MAX_SEEDS );
1654-
max_uploads = getDownloadState().getIntParameter( DownloadManagerState.PARAM_MAX_UPLOADS );
1655-
max_uploads_when_seeding_enabled = getDownloadState().getBooleanParameter( DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING_ENABLED );
1656-
max_uploads_when_seeding = getDownloadState().getIntParameter( DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING );
1657-
max_upload_when_busy_bps = getDownloadState().getIntParameter( DownloadManagerState.PARAM_MAX_UPLOAD_WHEN_BUSY ) * 1024;
1658+
DownloadManagerState state = getDownloadState();
1659+
1660+
max_connections = state.getIntParameter( DownloadManagerState.PARAM_MAX_PEERS );
1661+
max_connections_when_seeding_enabled = state.getBooleanParameter( DownloadManagerState.PARAM_MAX_PEERS_WHEN_SEEDING_ENABLED );
1662+
max_connections_when_seeding = state.getIntParameter( DownloadManagerState.PARAM_MAX_PEERS_WHEN_SEEDING );
1663+
max_seed_connections = state.getIntParameter( DownloadManagerState.PARAM_MAX_SEEDS );
1664+
max_uploads = state.getIntParameter( DownloadManagerState.PARAM_MAX_UPLOADS );
1665+
max_uploads_when_seeding_enabled = state.getBooleanParameter( DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING_ENABLED );
1666+
max_uploads_when_seeding = state.getIntParameter( DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING );
1667+
max_upload_when_busy_bps = state.getIntParameter( DownloadManagerState.PARAM_MAX_UPLOAD_WHEN_BUSY ) * 1024;
16581668

16591669
max_uploads = Math.max( max_uploads, DownloadManagerState.MIN_MAX_UPLOADS );
16601670
max_uploads_when_seeding = Math.max( max_uploads_when_seeding, DownloadManagerState.MIN_MAX_UPLOADS );
16611671

1662-
upload_priority_manual = getDownloadState().getIntParameter( DownloadManagerState.PARAM_UPLOAD_PRIORITY );
1672+
upload_priority_manual = state.getIntParameter( DownloadManagerState.PARAM_UPLOAD_PRIORITY );
1673+
1674+
set_file_priority_high_pieces_rem = state.getIntAttribute( DownloadManagerState.AT_SET_FILE_PRIORITY_REM_PIECE );
16631675
}
16641676

16651677
protected int[]
@@ -4149,6 +4161,56 @@ public boolean isDownloadComplete(boolean bIncludeDND) {
41494161
informPrioritiesChange( files );
41504162
}
41514163

4164+
protected void
4165+
informPieceDoneChanged(
4166+
DiskManagerPiece piece )
4167+
{
4168+
int num = set_file_priority_high_pieces_rem;
4169+
4170+
if ( num > 0 ){
4171+
4172+
DiskManager dm = getDiskManager();
4173+
4174+
if ( dm != null ){
4175+
4176+
DiskManagerPiece[] pieces = dm.getPieces();
4177+
4178+
DMPieceList list = piece.getPieceList();
4179+
4180+
for ( int i=0;i<list.size();i++) {
4181+
4182+
DMPieceMapEntry entry = list.get( i );
4183+
4184+
DiskManagerFileInfo info = entry.getFile();
4185+
4186+
if ( info.getPriority() != 0 ){
4187+
4188+
continue;
4189+
}
4190+
4191+
int start = info.getFirstPieceNumber();
4192+
4193+
int end = start + info.getNbPieces();
4194+
4195+
int remaining = 0;
4196+
4197+
for ( int j = start; j < end; j++ ){
4198+
4199+
if ( !pieces[ j ].isDone() ){
4200+
4201+
remaining++;
4202+
}
4203+
}
4204+
4205+
if ( remaining <= num ){
4206+
4207+
info.setPriority( 1 );
4208+
}
4209+
}
4210+
}
4211+
}
4212+
}
4213+
41524214
protected void
41534215
informFileCompletionChange(
41544216
DiskManagerFileInfo file )

core/src/com/biglybt/internat/MessagesBundle.properties

+5
Original file line numberDiff line numberDiff line change
@@ -5548,6 +5548,11 @@ sb.dblclick.action.independent=Independent
55485548
ConfigView.section.file.always.create.sub.folder=Always create a sub-folder to contain torrent data files
55495549
label.set.as.default.for.new.views=Set as default for new views
55505550
ConfigView.section.interface.cleartables=Reset all table column configurations
5551+
ConfigView.label.set.file.pri.pieces.rem=Set Files to High Priority When Pieces Remaining
5552+
value.invalid.title=Invalid Value
5553+
value.invalid.text=Invalid value entered
5554+
enter.number=Enter Number
5555+
number.of.pieces=Number of Pieces
55515556

55525557
#
55535558
#

uis/src/com/biglybt/ui/swt/SimpleTextEntryWindow.java

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.biglybt.core.util.TimerEvent;
4343
import com.biglybt.core.util.UrlUtils;
4444
import com.biglybt.ui.swt.components.LinkLabel;
45+
import com.biglybt.ui.swt.components.shell.ShellFactory;
4546
import com.biglybt.ui.swt.pifimpl.AbstractUISWTInputReceiver;
4647
import com.biglybt.ui.swt.utils.DragDropUtils;
4748

@@ -118,6 +119,11 @@ private void promptForInput0() {
118119
if ( parent_shell == null ){
119120

120121
parent = Display.getDefault().getActiveShell();
122+
123+
if ( parent != null && parent.getData( ShellFactory.NOT_A_GOOD_PARENT ) != null ){
124+
125+
parent = null;
126+
}
121127
}
122128

123129
if (parent == null) {

uis/src/com/biglybt/ui/swt/TorrentMenuFancy.java

+40
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
import com.biglybt.ui.common.table.TableStructureEventDispatcher;
6868
import com.biglybt.ui.common.util.MenuItemManager;
6969
import com.biglybt.ui.mdi.MultipleDocumentInterface;
70+
import com.biglybt.ui.swt.components.shell.ShellFactory;
71+
import com.biglybt.ui.swt.components.shell.ShellFactory.AEShell;
7072
import com.biglybt.ui.swt.exporttorrent.wizard.ExportTorrentWizard;
7173
import com.biglybt.ui.swt.imageloader.ImageLoader;
7274
import com.biglybt.ui.swt.minibar.DownloadBar;
@@ -427,6 +429,8 @@ public void dispose() {
427429
}
428430
};
429431

432+
shell.setData( ShellFactory.NOT_A_GOOD_PARENT, "" );
433+
430434
//FormLayout shellLayout = new FormLayout();
431435
RowLayout shellLayout = new RowLayout(SWT.VERTICAL);
432436
shellLayout.fill = true;
@@ -1532,6 +1536,42 @@ public void run(DownloadManager dm) {
15321536

15331537
itemMaskDLComp.setEnabled( dms.length > 0 );
15341538

1539+
// set file priority when pieces remaining
1540+
1541+
MenuItem itemSetFilePriority = new MenuItem(menu, SWT.PUSH);
1542+
1543+
String sfp_text = MessageText.getString( "ConfigView.label.set.file.pri.pieces.rem" );
1544+
1545+
int sfp_def;
1546+
1547+
if ( dms.length == 1 ){
1548+
1549+
sfp_def = dms[0].getDownloadState().getIntAttribute( DownloadManagerState.AT_SET_FILE_PRIORITY_REM_PIECE );
1550+
1551+
if ( sfp_def > 0 ){
1552+
1553+
sfp_text += " (" + sfp_def + ")";
1554+
}
1555+
}else{
1556+
1557+
sfp_def = -1;
1558+
}
1559+
1560+
itemSetFilePriority.setText(sfp_text+"...");
1561+
1562+
itemSetFilePriority.addListener(SWT.Selection, new ListenerDMTask(dms) {
1563+
@Override
1564+
public void run(DownloadManager[] dms) {
1565+
Utils.numberPrompt( "enter.number", "number.of.pieces", sfp_def>0?sfp_def:null, (num)->{
1566+
for ( DownloadManager dm: dms ){
1567+
dm.getDownloadState().setIntAttribute(DownloadManagerState.AT_SET_FILE_PRIORITY_REM_PIECE, num);
1568+
}
1569+
});
1570+
}
1571+
});
1572+
1573+
itemSetFilePriority.setEnabled( dms.length > 0 );
1574+
15351575
if (userMode > 1 && isSeedingView) {
15361576

15371577
boolean canSetSuperSeed = false;

uis/src/com/biglybt/ui/swt/TorrentUtil.java

+38-3
Original file line numberDiff line numberDiff line change
@@ -1293,16 +1293,15 @@ public void run(DownloadManager dm) {
12931293

12941294
itemRestoreResume.setEnabled( restoreEnabled);
12951295

1296-
// mask dl comp
1296+
// mask dl comp
12971297

12981298
MenuItem itemMaskDLComp = new MenuItem(menuFiles, SWT.CHECK);
12991299

13001300
if ( dms.length> 0 ){
13011301
itemMaskDLComp.setSelection( allMaskDC );
13021302
}
13031303

1304-
Messages.setLanguageText(itemMaskDLComp,
1305-
"ConfigView.label.hap");
1304+
Messages.setLanguageText(itemMaskDLComp,"ConfigView.label.hap");
13061305
itemMaskDLComp.addListener(SWT.Selection, new ListenerDMTask(dms) {
13071306
@Override
13081307
public void run(DownloadManager dm) {
@@ -1312,6 +1311,42 @@ public void run(DownloadManager dm) {
13121311

13131312
itemMaskDLComp.setEnabled( dms.length > 0 );
13141313

1314+
// set file priority when pieces remaining
1315+
1316+
MenuItem itemSetFilePriority = new MenuItem(menuFiles, SWT.PUSH);
1317+
1318+
String sfp_text = MessageText.getString( "ConfigView.label.set.file.pri.pieces.rem" );
1319+
1320+
int sfp_def;
1321+
1322+
if ( dms.length == 1 ){
1323+
1324+
sfp_def = dms[0].getDownloadState().getIntAttribute( DownloadManagerState.AT_SET_FILE_PRIORITY_REM_PIECE );
1325+
1326+
if ( sfp_def > 0 ){
1327+
1328+
sfp_text += " (" + sfp_def + ")";
1329+
}
1330+
}else{
1331+
1332+
sfp_def = -1;
1333+
}
1334+
1335+
itemSetFilePriority.setText(sfp_text + "...");
1336+
1337+
itemSetFilePriority.addListener(SWT.Selection, new ListenerDMTask(dms) {
1338+
@Override
1339+
public void run(DownloadManager[] dms) {
1340+
Utils.numberPrompt( "enter.number", "number.of.pieces", sfp_def>0?sfp_def:null, (num)->{
1341+
for ( DownloadManager dm: dms ){
1342+
dm.getDownloadState().setIntAttribute(DownloadManagerState.AT_SET_FILE_PRIORITY_REM_PIECE, num);
1343+
}
1344+
});
1345+
}
1346+
});
1347+
1348+
itemSetFilePriority.setEnabled( dms.length > 0 );
1349+
13151350
// Advanced -> archive
13161351

13171352
final List<Download> ar_dms = new ArrayList<>();

uis/src/com/biglybt/ui/swt/Utils.java

+55
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.biglybt.core.logging.Logger;
7070
import com.biglybt.core.speedmanager.SpeedLimitHandler;
7171
import com.biglybt.core.torrent.PlatformTorrentUtils;
72+
import com.biglybt.core.torrent.impl.TorrentOpenFileOptions;
7273
import com.biglybt.core.util.*;
7374
import com.biglybt.pifimpl.local.PluginCoreUtils;
7475
import com.biglybt.platform.PlatformManager;
@@ -99,6 +100,8 @@
99100
import com.biglybt.pif.platform.PlatformManagerException;
100101
import com.biglybt.pif.sharing.ShareManager;
101102
import com.biglybt.pif.ui.Graphic;
103+
import com.biglybt.pif.ui.UIInputReceiver;
104+
import com.biglybt.pif.ui.UIInputReceiverListener;
102105
import com.biglybt.pif.utils.PooledByteBuffer;
103106

104107
/**
@@ -7184,4 +7187,56 @@ public void handleEvent(Event e) {
71847187
{
71857188
return( FileUtil.listRootsWithTimeout( 250 ));
71867189
}
7190+
7191+
public static void
7192+
numberPrompt(
7193+
String title_resource,
7194+
String text_resource,
7195+
Integer def,
7196+
Consumer<Integer> cons )
7197+
{
7198+
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow( title_resource, text_resource );
7199+
7200+
if ( def != null ){
7201+
7202+
entryWindow.setPreenteredText( String.valueOf( def ), false );
7203+
entryWindow.selectPreenteredText( true );
7204+
}
7205+
7206+
entryWindow.prompt(
7207+
new UIInputReceiverListener() {
7208+
@Override
7209+
public void
7210+
UIInputReceiverClosed(
7211+
UIInputReceiver entryWindow )
7212+
{
7213+
if (!entryWindow.hasSubmittedInput()){
7214+
7215+
return;
7216+
}
7217+
7218+
String sReturn = entryWindow.getSubmittedInput();
7219+
7220+
if ( sReturn == null ){
7221+
7222+
return;
7223+
}
7224+
7225+
try{
7226+
int num = Integer.valueOf(sReturn).intValue();
7227+
7228+
cons.accept( num );
7229+
7230+
}catch ( Throwable e ){
7231+
7232+
new MessageBoxShell(SWT.ICON_ERROR | SWT.OK,
7233+
MessageText.getString("value.invalid.title"),
7234+
MessageText.getString("value.invalid.text", new String[]{ sReturn })).open(
7235+
(n)->{
7236+
Utils.execSWTThreadLater(1,()->numberPrompt(title_resource,text_resource, def, cons ));
7237+
});
7238+
}
7239+
}
7240+
});
7241+
}
71877242
}

uis/src/com/biglybt/ui/swt/components/shell/ShellFactory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.eclipse.swt.events.DisposeEvent;
2424
import org.eclipse.swt.events.DisposeListener;
2525
import org.eclipse.swt.graphics.Image;
26-
import org.eclipse.swt.graphics.Point;
2726
import org.eclipse.swt.widgets.Display;
2827
import org.eclipse.swt.widgets.Shell;
2928

@@ -42,7 +41,8 @@
4241
*/
4342
public final class ShellFactory
4443
{
45-
44+
public static final String NOT_A_GOOD_PARENT = "ShellFactory.NOT_A_GOOD_PARENT";
45+
4646
public static Shell createMainShell(int styles) {
4747
Shell parent = null;
4848

0 commit comments

Comments
 (0)