|
35 | 35 | import com.biglybt.core.disk.*;
|
36 | 36 | import com.biglybt.core.disk.impl.DiskManagerImpl;
|
37 | 37 | 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; |
38 | 40 | import com.biglybt.core.download.*;
|
39 | 41 | import com.biglybt.core.global.GlobalManager;
|
40 | 42 | import com.biglybt.core.global.GlobalManagerEvent;
|
@@ -723,6 +725,8 @@ public void completionChanged(DownloadManager manager, boolean bCompleted){
|
723 | 725 | private int message_mode = -1;
|
724 | 726 |
|
725 | 727 | private volatile int tcp_port_override;
|
| 728 | + |
| 729 | + private volatile int set_file_priority_high_pieces_rem = 0; |
726 | 730 |
|
727 | 731 | // Only call this with STATE_QUEUED, STATE_WAITING, or STATE_STOPPED unless you know what you are doing
|
728 | 732 |
|
@@ -1096,7 +1100,7 @@ protected Boolean initialValue(){
|
1096 | 1100 | };
|
1097 | 1101 |
|
1098 | 1102 | @Override
|
1099 |
| - public void |
| 1103 | + public void |
1100 | 1104 | attributeEventOccurred(
|
1101 | 1105 | DownloadManager dm, String attribute_name, int event_type)
|
1102 | 1106 | {
|
@@ -1131,13 +1135,17 @@ protected Boolean initialValue(){
|
1131 | 1135 |
|
1132 | 1136 | tc.resetTrackerUrl( false );
|
1133 | 1137 | }
|
| 1138 | + }else if ( attribute_name.equals( DownloadManagerState.AT_SET_FILE_PRIORITY_REM_PIECE )){ |
| 1139 | + |
| 1140 | + readParameters(); |
1134 | 1141 | }
|
1135 | 1142 | }
|
1136 | 1143 | };
|
1137 | 1144 |
|
1138 | 1145 | download_manager_state.addListener(attr_listener, DownloadManagerState.AT_FILE_LINKS2, DownloadManagerStateAttributeListener.WRITTEN);
|
1139 | 1146 | download_manager_state.addListener(attr_listener, DownloadManagerState.AT_PARAMETERS, DownloadManagerStateAttributeListener.WRITTEN);
|
1140 | 1147 | 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); |
1141 | 1149 |
|
1142 | 1150 | torrent = download_manager_state.getTorrent();
|
1143 | 1151 |
|
@@ -1647,19 +1655,23 @@ public void perform(TimerEvent event){
|
1647 | 1655 | protected void
|
1648 | 1656 | readParameters()
|
1649 | 1657 | {
|
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; |
1658 | 1668 |
|
1659 | 1669 | max_uploads = Math.max( max_uploads, DownloadManagerState.MIN_MAX_UPLOADS );
|
1660 | 1670 | max_uploads_when_seeding = Math.max( max_uploads_when_seeding, DownloadManagerState.MIN_MAX_UPLOADS );
|
1661 | 1671 |
|
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 ); |
1663 | 1675 | }
|
1664 | 1676 |
|
1665 | 1677 | protected int[]
|
@@ -4149,6 +4161,56 @@ public boolean isDownloadComplete(boolean bIncludeDND) {
|
4149 | 4161 | informPrioritiesChange( files );
|
4150 | 4162 | }
|
4151 | 4163 |
|
| 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 | + |
4152 | 4214 | protected void
|
4153 | 4215 | informFileCompletionChange(
|
4154 | 4216 | DiskManagerFileInfo file )
|
|
0 commit comments