Skip to content

Commit 31b996e

Browse files
committed
Added option to automatically create a sub-folder for simple torrents
1 parent 421bc7b commit 31b996e

12 files changed

+229
-9
lines changed

core/src/com/biglybt/core/config/ConfigKeys.java

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public static class Connection {
114114
public static class File {
115115
public static final String BCFG_DEFAULT_DIR_BEST_GUESS = "DefaultDir.BestGuess";
116116
public static final String SCFG_DEFAULT_SAVE_PATH = "Default save path";
117+
public static final String BCFG_ALWAYS_CREATE_TORRENT_SUB_FOLDER = "Always Create Torrent Sub-Folder";
117118
public static final String BCFG_UI_ADDTORRENT_OPENOPTIONS_SEP = "ui.addtorrent.openoptions.sep";
118119
public static final String BCFG_DEFAULT_DIR_AUTO_SAVE_AUTO_RENAME = "DefaultDir.AutoSave.AutoRename";
119120
public static final String ICFG_UI_ADDTORRENT_OPENOPTIONS_AUTO_CLOSE_SECS = "ui.addtorrent.openoptions.auto.close.secs";

core/src/com/biglybt/core/config/impl/ConfigurationDefaults.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ public class ConfigurationDefaults {
324324

325325
def.put("Default save path", f.getAbsolutePath());
326326
def.put("saveTo_list.max_entries", new Long(15));
327-
327+
def.put(ConfigKeys.File.BCFG_ALWAYS_CREATE_TORRENT_SUB_FOLDER, FALSE );
328+
328329
def.put("update.start",TRUE);
329330
def.put("update.periodic",TRUE);
330331
def.put("update.opendialog",TRUE);

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

+33
Original file line numberDiff line numberDiff line change
@@ -4992,6 +4992,39 @@ public String getUTF8Name() {
49924992
throw( new TOTorrentException( "Not supported", TOTorrentException.RT_HASH_FAILS ));
49934993
}
49944994

4995+
@Override
4996+
public TOTorrent
4997+
setSimpleTorrentDisabled(
4998+
boolean disabled )
4999+
5000+
throws TOTorrentException
5001+
{
5002+
if ( fixup()){
5003+
5004+
return( delegate.setSimpleTorrentDisabled( disabled ));
5005+
5006+
}else{
5007+
5008+
throw( new TOTorrentException( "fixup failed", TOTorrentException.RT_CREATE_FAILED ));
5009+
}
5010+
}
5011+
5012+
@Override
5013+
public boolean
5014+
isSimpleTorrentDisabled()
5015+
5016+
throws TOTorrentException
5017+
{
5018+
if ( fixup()){
5019+
5020+
return( delegate.isSimpleTorrentDisabled());
5021+
5022+
}else{
5023+
5024+
throw( new TOTorrentException( "fixup failed", TOTorrentException.RT_CREATE_FAILED ));
5025+
}
5026+
}
5027+
49955028
@Override
49965029
public boolean
49975030
hasSameHashAs(

core/src/com/biglybt/core/lws/LWSTorrent.java

+19
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,25 @@ public String getUTF8Name() {
340340
throw( new TOTorrentException( "Not supported", TOTorrentException.RT_CREATE_FAILED ));
341341
}
342342

343+
@Override
344+
public TOTorrent
345+
setSimpleTorrentDisabled(
346+
boolean disabled )
347+
348+
throws TOTorrentException
349+
{
350+
throw( new TOTorrentException( "Not supported", TOTorrentException.RT_CREATE_FAILED ));
351+
}
352+
353+
@Override
354+
public boolean
355+
isSimpleTorrentDisabled()
356+
357+
throws TOTorrentException
358+
{
359+
throw( new TOTorrentException( "Not supported", TOTorrentException.RT_CREATE_FAILED ));
360+
}
361+
343362
@Override
344363
public void
345364
setHashOverride(

core/src/com/biglybt/core/torrent/TOTorrent.java

+11
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,17 @@
310310

311311
throws TOTorrentException;
312312

313+
public TOTorrent
314+
setSimpleTorrentDisabled(
315+
boolean disabled )
316+
317+
throws TOTorrentException;
318+
319+
public boolean
320+
isSimpleTorrentDisabled()
321+
322+
throws TOTorrentException;
323+
313324
/**
314325
* compares two torrents by hash
315326
* @param other

core/src/com/biglybt/core/torrent/impl/TOTorrentDeserialiseImpl.java

+10
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,16 @@
905905

906906
Debug.printStackTrace(e);
907907
}
908+
909+
try{
910+
if ( isSimpleTorrentDisabled()){
911+
912+
setSimpleTorrentDisabledInternal( true );
913+
}
914+
}catch( Throwable e ){
915+
916+
Debug.printStackTrace(e);
917+
}
908918
}catch( Throwable e ){
909919

910920
if ( e instanceof TOTorrentException){

core/src/com/biglybt/core/torrent/impl/TOTorrentImpl.java

+86-6
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@
121121
private byte[] torrent_hash_v2;
122122
private HashWrapper torrent_hash_wrapper_v2;
123123

124-
private boolean simple_torrent;
124+
private boolean simple_torrent_original;
125+
private boolean simple_torrent_effective;
126+
125127
private TOTorrentFileImpl[] files;
126128

127129
private long creation_date;
@@ -165,7 +167,8 @@
165167
torrent_name_utf8 = torrent_name;
166168

167169
setAnnounceURL(_announce_url);
168-
simple_torrent = _simple_torrent;
170+
171+
simple_torrent_original = simple_torrent_effective = _simple_torrent;
169172
}
170173

171174
protected void
@@ -498,7 +501,7 @@
498501

499502
info.put( TK_PIECES, flat_pieces );
500503

501-
if ( simple_torrent ){
504+
if ( simple_torrent_original ){
502505

503506
TOTorrentFile file = files[0];
504507

@@ -740,7 +743,7 @@
740743
public boolean
741744
isSimpleTorrent()
742745
{
743-
return( simple_torrent );
746+
return( simple_torrent_effective );
744747
}
745748

746749
@Override
@@ -1107,7 +1110,84 @@ protected void setCreatedBy(String _created_by) {
11071110
{
11081111
return( torrent_hash_override );
11091112
}
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 );
11101128

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+
11111191
@Override
11121192
public void
11131193
setPrivate(
@@ -1288,14 +1368,14 @@ protected void setCreatedBy(String _created_by) {
12881368
protected boolean
12891369
getSimpleTorrent()
12901370
{
1291-
return( simple_torrent );
1371+
return( simple_torrent_original );
12921372
}
12931373

12941374
protected void
12951375
setSimpleTorrent(
12961376
boolean _simple_torrent )
12971377
{
1298-
simple_torrent = _simple_torrent;
1378+
simple_torrent_original = simple_torrent_effective = _simple_torrent;
12991379
}
13001380

13011381
protected Map

core/src/com/biglybt/core/torrent/impl/TorrentOpenOptions.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,26 @@ public TOTorrent getTorrent() {
14771477
return torrent;
14781478
}
14791479

1480-
public void setTorrent(TOTorrent torrent) {
1480+
public void
1481+
setTorrent(
1482+
TOTorrent torrent )
1483+
{
1484+
try{
1485+
if ( torrent.isSimpleTorrent() && COConfigurationManager.getBooleanParameter( ConfigKeys.File.BCFG_ALWAYS_CREATE_TORRENT_SUB_FOLDER )){
1486+
1487+
String file = TorrentUtils.getTorrentFileName( torrent );
1488+
1489+
torrent = torrent.setSimpleTorrentDisabled( true );
1490+
1491+
if ( file != null ){
1492+
1493+
TorrentUtils.writeToFile( torrent, new File( file ), false );
1494+
}
1495+
}
1496+
}catch( Throwable e ){
1497+
Debug.out( e );
1498+
}
1499+
14811500
this.torrent = torrent;
14821501

14831502
if (COConfigurationManager.getBooleanParameter("DefaultDir.BestGuess") &&

core/src/com/biglybt/core/tracker/host/impl/TRHostExternalTorrent.java

+19
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,25 @@
351351
throw( new TOTorrentException( "Not supported", TOTorrentException.RT_HASH_FAILS ));
352352
}
353353

354+
@Override
355+
public TOTorrent
356+
setSimpleTorrentDisabled(
357+
boolean disabled )
358+
359+
throws TOTorrentException
360+
{
361+
throw( new TOTorrentException( "Not supported", TOTorrentException.RT_CREATE_FAILED ));
362+
}
363+
364+
@Override
365+
public boolean
366+
isSimpleTorrentDisabled()
367+
368+
throws TOTorrentException
369+
{
370+
throw( new TOTorrentException( "Not supported", TOTorrentException.RT_CREATE_FAILED ));
371+
}
372+
354373
@Override
355374
public boolean
356375
getPrivate()

core/src/com/biglybt/core/util/TorrentUtils.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@
134134
public static final String TORRENT_AZ_PROP_HASHTREE_STATE = "hash_tree";
135135
public static final String TORRENT_AZ_PROP_HYBRID_HASH_V2 = "hybrid_hash_v2";
136136
private static final String TORRENT_AZ_PROP_V2_ROOT_HASH_CACHE = "v2_root_hash_cache"; // used for non-v2 torrents only
137-
137+
public static final String TORRENT_AZ_PROP_SIMPLE_TORRENT_DISABLED = "simple_torrent_disable";
138+
138139
private static final String MEM_ONLY_TORRENT_PATH = "?/\\!:mem_only:!\\/?";
139140

140141
private static final long PC_MARKER = RandomUtils.nextLong();
@@ -4004,6 +4005,25 @@
40044005
throw( new TOTorrentException( "Not supported", TOTorrentException.RT_HASH_FAILS ));
40054006
}
40064007

4008+
@Override
4009+
public TOTorrent
4010+
setSimpleTorrentDisabled(
4011+
boolean disabled )
4012+
4013+
throws TOTorrentException
4014+
{
4015+
return( delegate.setSimpleTorrentDisabled(disabled));
4016+
}
4017+
4018+
@Override
4019+
public boolean
4020+
isSimpleTorrentDisabled()
4021+
4022+
throws TOTorrentException
4023+
{
4024+
return( delegate.isSimpleTorrentDisabled());
4025+
}
4026+
40074027
@Override
40084028
public boolean
40094029
getPrivate()

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

+1
Original file line numberDiff line numberDiff line change
@@ -5545,6 +5545,7 @@ ConfigView.section.style.guiUpdateDisableWhenMin=Disable all updates when minimi
55455545
sb.dblclick.action=Entry double-click 'Pop Out' type
55465546
sb.dblclick.action.ontop=On Top
55475547
sb.dblclick.action.independent=Independent
5548+
ConfigView.section.file.always.create.sub.folder=Always create a sub-folder to contain torrent data files
55485549

55495550
#
55505551
#

core/src/com/biglybt/ui/config/ConfigSectionFile.java

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ public void build() {
6969
pathParameter.setDialogTitleKey("ConfigView.dialog.choosedefaultsavepath");
7070
pathParameter.setDialogTitleKey("ConfigView.section.file.defaultdir.ask");
7171

72+
BooleanParameterImpl alwaysFolder = new BooleanParameterImpl(
73+
BCFG_ALWAYS_CREATE_TORRENT_SUB_FOLDER,
74+
"ConfigView.section.file.always.create.sub.folder");
75+
add(alwaysFolder, Parameter.MODE_INTERMEDIATE, listDefaultDir);
76+
77+
7278
// def dir: autoSave
7379

7480
String[] openValues = {

0 commit comments

Comments
 (0)