|
121 | 121 | private byte[] torrent_hash_v2;
|
122 | 122 | private HashWrapper torrent_hash_wrapper_v2;
|
123 | 123 |
|
124 |
| - private boolean simple_torrent; |
| 124 | + private boolean simple_torrent_original; |
| 125 | + private boolean simple_torrent_effective; |
| 126 | + |
125 | 127 | private TOTorrentFileImpl[] files;
|
126 | 128 |
|
127 | 129 | private long creation_date;
|
|
165 | 167 | torrent_name_utf8 = torrent_name;
|
166 | 168 |
|
167 | 169 | setAnnounceURL(_announce_url);
|
168 |
| - simple_torrent = _simple_torrent; |
| 170 | + |
| 171 | + simple_torrent_original = simple_torrent_effective = _simple_torrent; |
169 | 172 | }
|
170 | 173 |
|
171 | 174 | protected void
|
|
498 | 501 |
|
499 | 502 | info.put( TK_PIECES, flat_pieces );
|
500 | 503 |
|
501 |
| - if ( simple_torrent ){ |
| 504 | + if ( simple_torrent_original ){ |
502 | 505 |
|
503 | 506 | TOTorrentFile file = files[0];
|
504 | 507 |
|
|
740 | 743 | public boolean
|
741 | 744 | isSimpleTorrent()
|
742 | 745 | {
|
743 |
| - return( simple_torrent ); |
| 746 | + return( simple_torrent_effective ); |
744 | 747 | }
|
745 | 748 |
|
746 | 749 | @Override
|
@@ -1107,7 +1110,84 @@ protected void setCreatedBy(String _created_by) {
|
1107 | 1110 | {
|
1108 | 1111 | return( torrent_hash_override );
|
1109 | 1112 | }
|
| 1113 | + |
| 1114 | + |
| 1115 | + @Override |
| 1116 | + public TOTorrent |
| 1117 | + setSimpleTorrentDisabled( |
| 1118 | + boolean disabled ) |
| 1119 | + |
| 1120 | + throws TOTorrentException |
| 1121 | + { |
| 1122 | + |
| 1123 | + TOTorrent clone = TOTorrentFactory.deserialiseFromBEncodedByteArray( serialiseToByteArray()); |
| 1124 | + |
| 1125 | + TorrentUtils.clearTorrentFileName( clone ); |
| 1126 | + |
| 1127 | + Map<String,Object> private_props = (Map<String,Object>)clone.getAdditionalMapProperty( AZUREUS_PRIVATE_PROPERTIES ); |
1110 | 1128 |
|
| 1129 | + if ( disabled ){ |
| 1130 | + |
| 1131 | + if ( !simple_torrent_effective ){ |
| 1132 | + |
| 1133 | + throw( new TOTorrentException( "Torrent isn't simple", TOTorrentException.RT_CREATE_FAILED )); |
| 1134 | + } |
| 1135 | + }else{ |
| 1136 | + |
| 1137 | + if ( private_props == null || !private_props.containsKey( TorrentUtils.TORRENT_AZ_PROP_SIMPLE_TORRENT_DISABLED )){ |
| 1138 | + |
| 1139 | + throw( new TOTorrentException( "Torrent wasn't simple-disabled", TOTorrentException.RT_CREATE_FAILED )); |
| 1140 | + } |
| 1141 | + } |
| 1142 | + |
| 1143 | + if ( disabled ){ |
| 1144 | + |
| 1145 | + if ( private_props == null ){ |
| 1146 | + |
| 1147 | + private_props = new HashMap<>(); |
| 1148 | + } |
| 1149 | + |
| 1150 | + private_props.put( TorrentUtils.TORRENT_AZ_PROP_SIMPLE_TORRENT_DISABLED, 1L ); |
| 1151 | + |
| 1152 | + clone.setAdditionalMapProperty( AZUREUS_PRIVATE_PROPERTIES, private_props ); |
| 1153 | + |
| 1154 | + }else{ |
| 1155 | + |
| 1156 | + if ( private_props != null ){ |
| 1157 | + |
| 1158 | + private_props.remove( TorrentUtils.TORRENT_AZ_PROP_HYBRID_HASH_V2 ); |
| 1159 | + } |
| 1160 | + } |
| 1161 | + |
| 1162 | + try{ |
| 1163 | + // recreate with new properties so result represents this |
| 1164 | + |
| 1165 | + return( TOTorrentFactory.deserialiseFromBEncodedByteArray( BEncoder.encode( clone.serialiseToMap()))); |
| 1166 | + |
| 1167 | + }catch( Throwable e ){ |
| 1168 | + |
| 1169 | + throw( new TOTorrentException( "Encode failed", TOTorrentException.RT_CREATE_FAILED, e )); |
| 1170 | + } |
| 1171 | + } |
| 1172 | + |
| 1173 | + @Override |
| 1174 | + public boolean |
| 1175 | + isSimpleTorrentDisabled() |
| 1176 | + |
| 1177 | + throws TOTorrentException |
| 1178 | + { |
| 1179 | + Map<String,Object> private_props = (Map<String,Object>)getAdditionalMapProperty( AZUREUS_PRIVATE_PROPERTIES ); |
| 1180 | + |
| 1181 | + return( private_props != null && private_props.containsKey( TorrentUtils.TORRENT_AZ_PROP_SIMPLE_TORRENT_DISABLED )); |
| 1182 | + } |
| 1183 | + |
| 1184 | + protected void |
| 1185 | + setSimpleTorrentDisabledInternal( |
| 1186 | + boolean b ) |
| 1187 | + { |
| 1188 | + simple_torrent_effective = !b; |
| 1189 | + } |
| 1190 | + |
1111 | 1191 | @Override
|
1112 | 1192 | public void
|
1113 | 1193 | setPrivate(
|
@@ -1288,14 +1368,14 @@ protected void setCreatedBy(String _created_by) {
|
1288 | 1368 | protected boolean
|
1289 | 1369 | getSimpleTorrent()
|
1290 | 1370 | {
|
1291 |
| - return( simple_torrent ); |
| 1371 | + return( simple_torrent_original ); |
1292 | 1372 | }
|
1293 | 1373 |
|
1294 | 1374 | protected void
|
1295 | 1375 | setSimpleTorrent(
|
1296 | 1376 | boolean _simple_torrent )
|
1297 | 1377 | {
|
1298 |
| - simple_torrent = _simple_torrent; |
| 1378 | + simple_torrent_original = simple_torrent_effective = _simple_torrent; |
1299 | 1379 | }
|
1300 | 1380 |
|
1301 | 1381 | protected Map
|
|
0 commit comments