Skip to content

Commit

Permalink
Added option to put dnd data in different folder
Browse files Browse the repository at this point in the history
  • Loading branch information
parg committed Nov 22, 2024
1 parent ab477be commit 0a56c7c
Show file tree
Hide file tree
Showing 11 changed files with 614 additions and 334 deletions.
2 changes: 2 additions & 0 deletions core/src/com/biglybt/core/config/ConfigKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ public static class File {
public static final String SCFG_RENAME_INCOMPLETE_FILES_EXTENSION = "Rename Incomplete Files Extension";
public static final String BCFG_ENABLE_SUBFOLDER_FOR_DND_FILES = "Enable Subfolder for DND Files";
public static final String SCFG_SUBFOLDER_FOR_DND_FILES = "Subfolder for DND Files";
public static final String BCFG_ENABLE_ALT_LOC_FOR_DND_FILES = "Enable Alternative Location for DND Files";
public static final String SCFG_ALT_LOC_FOR_DND_FILES = "Alternative Location for DND Files";
/** Despite name, this is the DND file prefix when SCFG_SUBFOLDER_FOR_DND_FILES is true */
public static final String BCFG_USE_INCOMPLETE_FILE_PREFIX = "Use Incomplete File Prefix";
public static final String BCFG_DOWNLOAD_HISTORY_ENABLED = "Download History Enabled";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ public class ConfigurationDefaults {

def.put("Enable Subfolder for DND Files", FALSE );
def.put("Subfolder for DND Files", ".dnd_az!" );

def.put(ConfigKeys.File.BCFG_ENABLE_ALT_LOC_FOR_DND_FILES, FALSE );
def.put(ConfigKeys.File.SCFG_ALT_LOC_FOR_DND_FILES, FileUtil.getUserFile( "active" ).getAbsolutePath());

def.put("Max File Links Supported", 2048 );

def.put("Ip Filter Enabled", TRUE);
Expand Down
159 changes: 2 additions & 157 deletions core/src/com/biglybt/core/disk/impl/DiskManagerFileInfoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
public File
getCacheFileControlFileDir()
{
return( diskManager.getDownloadState().getStateFile( ));
return( diskManager.getDownloadState().getStateDir());
}

@Override
Expand Down Expand Up @@ -456,162 +456,7 @@ public Boolean isSkipping(){

if ( dm != null && !dm.isDestroyed()){

DownloadManagerState dm_state = diskManager.getDownloadState();

String dnd_sf = dm_state.getAttribute( DownloadManagerState.AT_DND_SUBFOLDER );

if ( dnd_sf != null ){

File link = getLink();

File file = getFile( false );

if ( _skipped ){

if ( link == null || link.equals( file )){

File parent = file.getParentFile();

if ( parent != null ){

File new_parent = FileUtil.newFile( parent, dnd_sf );

// add prefix if not already present

String prefix = dm_state.getAttribute( DownloadManagerState.AT_DND_PREFIX );

String file_name = file.getName();

if ( prefix != null && !file_name.startsWith( prefix )){

file_name = prefix + file_name;
}

File new_file = FileUtil.newFile( new_parent, file_name );

if ( !new_file.exists()){

if ( !new_parent.exists()){

new_parent.mkdirs();
}

if ( new_parent.canWrite()){

boolean ok;

try{
dm_state.setFileLink( file_index, file, new_file );

cache_file.moveFile( new_file, null );

ok = true;

}catch( Throwable e ){

ok = false;

Debug.out( e );
}

if ( !ok ){

dm_state.setFileLink( file_index, file, link );
}
}
}
}
}
}else{

if ( link != null && !file.exists()){

File parent = file.getParentFile();

if ( parent != null && parent.canWrite()){

File new_parent = parent.getName().equals( dnd_sf )?parent:FileUtil.newFile( parent, dnd_sf );

// use link name to handle incomplete file suffix if set

File new_file = FileUtil.newFile( new_parent, link.getName());

if ( new_file.equals( link )){

boolean ok;

try{
String file_name = file.getName();

String prefix = dm_state.getAttribute( DownloadManagerState.AT_DND_PREFIX );

boolean prefix_removed = false;

if ( prefix != null && file_name.startsWith(prefix)){

file_name = file_name.substring( prefix.length());

prefix_removed = true;
}

String incomp_ext = dm_state.getAttribute( DownloadManagerState.AT_INCOMP_FILE_SUFFIX );

if ( incomp_ext != null && incomp_ext.length() > 0 &&
getDownloaded() != getLength()){

// retain the prefix if enabled and we have a suffix

if ( prefix == null ){

prefix = "";
}

File new_link = FileUtil.newFile( file.getParentFile(), prefix + file_name + incomp_ext );

dm_state.setFileLink( file_index, file, new_link );

cache_file.moveFile( new_link, null );

}else if ( prefix_removed ){

File new_link = FileUtil.newFile( file.getParentFile(), file_name );

dm_state.setFileLink( file_index, file, new_link );

cache_file.moveFile( new_link, null );

}else{

dm_state.setFileLink( file_index, file, null );

cache_file.moveFile( file, null );
}

File[] files = new_parent.listFiles();

if ( files != null && files.length == 0 ){

new_parent.delete();
}

ok = true;

}catch( Throwable e ){

ok = false;

Debug.out( e );
}

if ( !ok ){

dm_state.setFileLink( file_index, file, link );
}
}
}
}
}
}
DiskManagerUtil.setSkippedInternalSupport( dm, this, cache_file,_skipped );
}
}
}
Expand Down
Loading

0 comments on commit 0a56c7c

Please sign in to comment.