separate code for determining if there is a download with same name and location

This commit is contained in:
Mitchell Livingston 2007-05-11 18:56:59 +00:00
parent 02710f8092
commit 3af24be44e
5 changed files with 49 additions and 31 deletions

View File

@ -238,10 +238,26 @@ char * tr_torrentGetFolder( tr_torrent_t * tor )
return tor->destination;
}
int tr_torrentDuplicateDownload( tr_torrent_t * tor )
{
tr_torrent_t * current, * next;
/* Check if a torrent with the same name and destination is already active */
for( current = tor->handle->torrentList; current; current = current->next )
{
if( current != tor && current->status != TR_STATUS_PAUSE
&& !strcmp( tor->destination, current->destination )
&& !strcmp( tor->info.name, current->info.name ) )
{
return 1;
}
}
return 0;
}
void tr_torrentStart( tr_torrent_t * tor )
{
char name[32];
tr_torrent_t * current, * next;
if( tor->status & ( TR_STATUS_STOPPING | TR_STATUS_STOPPED ) )
{
@ -250,17 +266,12 @@ void tr_torrentStart( tr_torrent_t * tor )
}
/* Don't start if a torrent with the same name and destination is already active */
for( current = tor->handle->torrentList; current; current = current->next )
if( tr_torrentDuplicateDownload( tor ) )
{
if( current != tor && current->status != TR_STATUS_PAUSE
&& !strcmp( tor->destination, current->destination )
&& !strcmp( tor->info.name, current->info.name ) )
{
tor->error = TR_ERROR_IO_DUP_NAME;
snprintf( tor->errorString, sizeof( tor->errorString ),
"%s", tr_errorString( TR_ERROR_IO_DUP_NAME ) );
return;
}
tor->error = TR_ERROR_IO_DUP_DOWNLOAD;
snprintf( tor->errorString, sizeof( tor->errorString ),
"%s", tr_errorString( TR_ERROR_IO_DUP_DOWNLOAD ) );
return;
}
tr_lockLock( &tor->lock );

View File

@ -64,21 +64,21 @@ extern "C" {
* Error codes
**********************************************************************/
/* General errors */
#define TR_OK 0x00000000
#define TR_ERROR 0x81000000
#define TR_ERROR_ASSERT 0x82000000
#define TR_OK 0x00000000
#define TR_ERROR 0x81000000
#define TR_ERROR_ASSERT 0x82000000
/* I/O errors */
#define TR_ERROR_IO_MASK 0x000000FF
#define TR_ERROR_IO_PARENT 0x80000001
#define TR_ERROR_IO_PERMISSIONS 0x80000002
#define TR_ERROR_IO_SPACE 0x80000004
#define TR_ERROR_IO_RESOURCES 0x80000008
#define TR_ERROR_IO_DUP_NAME 0x8000000A
#define TR_ERROR_IO_OTHER 0x80000010
#define TR_ERROR_IO_MASK 0x000000FF
#define TR_ERROR_IO_PARENT 0x80000001
#define TR_ERROR_IO_PERMISSIONS 0x80000002
#define TR_ERROR_IO_SPACE 0x80000004
#define TR_ERROR_IO_RESOURCES 0x80000008
#define TR_ERROR_IO_DUP_DOWNLOAD 0x8000000A
#define TR_ERROR_IO_OTHER 0x80000010
/* Misc */
#define TR_ERROR_TC_MASK 0x00000F00
#define TR_ERROR_TC_ERROR 0x80000100
#define TR_ERROR_TC_WARNING 0x80000200
#define TR_ERROR_TC_MASK 0x00000F00
#define TR_ERROR_TC_ERROR 0x80000100
#define TR_ERROR_TC_WARNING 0x80000200
#define TR_ERROR_ISSET( num, code ) ( (code) == ( (code) & (num) ) )
@ -269,14 +269,17 @@ tr_info_t * tr_torrentInfo( tr_torrent_t * );
**********************************************************************/
int tr_torrentScrape( tr_torrent_t *, int * s, int * l, int * d );
void tr_torrentSetFolder( tr_torrent_t *, const char * );
char * tr_torrentGetFolder( tr_torrent_t * );
int tr_torrentDuplicateDownload( tr_torrent_t * tor );
/***********************************************************************
* tr_torrentStart
***********************************************************************
* Starts downloading. The download is launched in a seperate thread,
* therefore tr_torrentStart returns immediately.
**********************************************************************/
void tr_torrentSetFolder( tr_torrent_t *, const char * );
char * tr_torrentGetFolder( tr_torrent_t * );
void tr_torrentStart( tr_torrent_t * );
/***********************************************************************

View File

@ -395,7 +395,7 @@ tr_errorString( int code )
return "Insufficient permissions";
case TR_ERROR_IO_SPACE:
return "Insufficient free space";
case TR_ERROR_IO_DUP_NAME:
case TR_ERROR_IO_DUP_DOWNLOAD:
return "Already active transfer with same name and download folder";
case TR_ERROR_IO_RESOURCES:
return "Insufficient resources";

View File

@ -875,14 +875,18 @@
NSSortDescriptor * descriptor = [oldDescriptors objectAtIndex: 0];
[descriptors addObject: descriptor];
useSecond = ![[descriptor key] isEqualToString: @"IP"];
asc = [descriptor ascending];
if ((useSecond = ![[descriptor key] isEqualToString: @"IP"]))
{
#warning different for different sorts
NSLog(@"%@", [[fPeerTable highlightedTableColumn] identifier]);
asc = [descriptor ascending];
}
}
//sort by IP after primary sort
if (useSecond)
{
#warning different for different sorts
NSSortDescriptor * secondDescriptor = [[NSSortDescriptor alloc] initWithKey: @"IP" ascending: asc
selector: @selector(compareIP:)];
[descriptors addObject: secondDescriptor];

View File

@ -764,7 +764,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
[alert setMessageText: NSLocalizedString(@"There was an error moving the data file.", "Move error alert -> title")];
[alert setInformativeText: [NSString stringWithFormat:
NSLocalizedString(@"The move operation of \"%@\" cannot be done.",
" Move error alert -> message"), [self name]]];
"Move error alert -> message"), [self name]]];
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Move error alert -> button")];
[alert runModal];