try {
hash = info.torrent.getHash();
} catch (TOTorrentException e1) {
}
DownloadManager dm = gm.addDownloadManager(info.sFileName, hash, info.sDestDir, info.sDestSubDir, iStartState, true, info.iStartID == STARTMODE_SEEDING, new DownloadManagerInitialisationAdapter()
{
public void initialised(DownloadManager dm) {
DiskManagerFileInfo[] fileInfos = dm.getDiskManagerFileInfo();
boolean reorder_mode = COConfigurationManager.getBooleanParameter( "Enable reorder storage mode" );
int reorder_mode_min_mb = COConfigurationManager.getIntParameter( "Reorder storage mode min MB" );
try
{
dm.getDownloadState().suppressStateSave(true);
boolean[] toSkip = new boolean[fileInfos.length];
boolean[] toCompact = new boolean[fileInfos.length];
boolean[] toReorderCompact = new boolean[fileInfos.length];
int comp_num = 0;
int reorder_comp_num = 0;
for (int iIndex = 0; iIndex < fileInfos.length; iIndex++)
{
DiskManagerFileInfo fileInfo = fileInfos[iIndex];
if (iIndex >= 0 && iIndex < files.length && files[iIndex].lSize == fileInfo.getLength())
{
// Always pull destination file from fileInfo and not from
// TorrentFileInfo because the destination may have changed
// by magic code elsewhere
File fDest = fileInfo.getFile(true);
if (files[iIndex].isLinked()){
fDest = files[iIndex].getDestFileFullName();
// Can't use fileInfo.setLink(fDest) as it renames
// the existing file if there is one
dm.getDownloadState().setFileLink( fileInfo.getFile(false), fDest);
}
if (!files[iIndex].bDownload){
toSkip[iIndex] = true;
if (!fDest.exists()){
if ( reorder_mode && ( fileInfo.getLength()/(1024*1024)) >= reorder_mode_min_mb ){
toReorderCompact[iIndex] = true;
reorder_comp_num++;
}else{
toCompact[iIndex] = true;
comp_num++;
}
}
}
}
}
if ( comp_num > 0 ){
dm.getDiskManagerFileInfoSet().setStorageTypes(toCompact, DiskManagerFileInfo.ST_COMPACT);
}
if ( reorder_comp_num > 0 ){
dm.getDiskManagerFileInfoSet().setStorageTypes(toReorderCompact, DiskManagerFileInfo.ST_REORDER_COMPACT );
}
dm.getDiskManagerFileInfoSet().setSkipped(toSkip, true);
}finally{
dm.getDownloadState().suppressStateSave(false);
}
}
});
// If dm is null, most likely there was an error printed.. let's hope
// the user was notified and skip the error quietly.
// We don't have to worry about deleting the file (info.bDelete..)
// since gm.addDown.. will handle it.
if (dm == null)
continue;
if (info.iQueueLocation == QUEUELOCATION_TOP)
addedTorrentsTop.add(dm);
if (info.iStartID == STARTMODE_FORCESTARTED) {
dm.setForceStart(true);
}
} catch (Exception e) {
if (shell == null)
new MessageSlideShell(Display.getCurrent(), SWT.ICON_ERROR,