saved_hashfails = lHashFailsBytes.longValue();
}else if ( lHashFailsCount != null) {
TOTorrent torrent = download_manager.getTorrent();
if ( torrent != null ){
saved_hashfails = lHashFailsCount.longValue() * torrent.getPieceLength();
}
}
Long lPosition = (Long) save_download_state.get("position");
// 2.2.0.1 - category moved to downloadstate - this here for
// migration purposes
String sCategory = null;
if (save_download_state.containsKey("category")){
try{
sCategory = new String((byte[]) save_download_state.get("category"), Constants.DEFAULT_ENCODING);
}catch( UnsupportedEncodingException e ){
Debug.printStackTrace(e);
}
}
if (sCategory != null) {
Category cat = CategoryManager.getCategory(sCategory);
if (cat != null) download_manager.getDownloadState().setCategory(cat);
}
download_manager.requestAssumedCompleteMode();
if (lDownloaded != null && lUploaded != null) {
boolean bCompleted = download_manager.isDownloadComplete(false);
long lUploadedValue = lUploaded.longValue();
long lDownloadedValue = lDownloaded.longValue();
if ( bCompleted && (lDownloadedValue == 0)){
//Gudy : I say if the torrent is complete, let's simply set downloaded
//to size in order to see a meaningfull share-ratio
//Gudy : Bypass this horrible hack, and I don't care of first priority seeding...
/*
if (lDownloadedValue != 0 && ((lUploadedValue * 1000) / lDownloadedValue < minQueueingShareRatio) )
lUploadedValue = ( download_manager.getSize()+999) * minQueueingShareRatio / 1000;
*/
// Parg: quite a few users have complained that they want "open-for-seeding" torrents to
// have an infinite share ratio for seeding rules (i.e. so they're not first priority)
int dl_copies = COConfigurationManager.getIntParameter("StartStopManager_iAddForSeedingDLCopyCount");
lDownloadedValue = download_manager.getSize() * dl_copies;
download_manager.getDownloadState().setFlag( DownloadManagerState.FLAG_ONLY_EVER_SEEDED, true );
}
saved_data_bytes_downloaded = lDownloadedValue;
saved_data_bytes_uploaded = lUploadedValue;
}
if (lPosition != null)
download_manager.setPosition(lPosition.intValue());
// no longer needed code
// else if (dm_stats.getDownloadCompleted(false) < 1000)
// dm.setPosition(bCompleted ? numCompleted : numDownloading);
Long lSecondsDLing = (Long)save_download_state.get("secondsDownloading");
if (lSecondsDLing != null) {
saved_SecondsDownloading = lSecondsDLing.longValue();
}
Long lSecondsOnlySeeding = (Long)save_download_state.get("secondsOnlySeeding");
if (lSecondsOnlySeeding != null) {
saved_SecondsOnlySeeding = lSecondsOnlySeeding.longValue();
}
Long already_allocated = (Long)save_download_state.get( "allocated" );
if( already_allocated != null && already_allocated.intValue() == 1 ) {
download_manager.setDataAlreadyAllocated( true );
}
Long creation_time = (Long)save_download_state.get( "creationTime" );
if ( creation_time != null ){
long ct = creation_time.longValue();
if ( ct < SystemTime.getCurrentTime()){
download_manager.setCreationTime( ct );
}
}
}else{
// no stats, bodge the uploaded for seeds
if ( dm_stats.getDownloadCompleted(false) == 1000 ){
int dl_copies = COConfigurationManager.getIntParameter("StartStopManager_iAddForSeedingDLCopyCount");
saved_data_bytes_downloaded = download_manager.getSize()*dl_copies;
}
}
dm_stats.restoreSessionTotals(
saved_data_bytes_downloaded,
saved_data_bytes_uploaded,
saved_discarded,
saved_hashfails,
saved_SecondsDownloading,
saved_SecondsOnlySeeding );
boolean isCompleted = download_manager.isDownloadComplete(false);
if (download_manager.getPosition() == -1) {
int endPosition = 0;
for (int i = 0; i < managers_cow.size(); i++) {
DownloadManager dm = (DownloadManager) managers_cow.get(i);
boolean dmIsCompleted = dm.isDownloadComplete(false);
if (dmIsCompleted == isCompleted)
endPosition++;
}
download_manager.setPosition(endPosition + 1);
}
// Even though when the DownloadManager was created, onlySeeding was
// most likely set to true for completed torrents (via the Initializer +
// readTorrent), there's a chance that the torrent file didn't have the
// resume data. If it didn't, but we marked it as complete in our
// downloads config file, we should set to onlySeeding
download_manager.requestAssumedCompleteMode();
List new_download_managers = new ArrayList( managers_cow );
new_download_managers.add(download_manager);
managers_cow = new_download_managers;
TOTorrent torrent = download_manager.getTorrent();
if ( torrent != null ){
try{
manager_map.put( new HashWrapper(torrent.getHash()), download_manager );
}catch( TOTorrentException e ){
Debug.printStackTrace( e );
}