Changeset 1082


Ignore:
Timestamp:
Nov 12, 2006, 9:51:48 PM (15 years ago)
Author:
livings124
Message:

Only try to download torrent files that will end in .torrent (even if the url doesn't).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r1081 r1082  
    455455- (void) handleOpenContentsEvent: (NSAppleEventDescriptor *) event replyEvent: (NSAppleEventDescriptor *) replyEvent
    456456{
    457     NSURL * url;
    458457    NSString * urlString;
    459458
     
    464463        for (i = 1; i <= [directObject numberOfItems]; i++)
    465464            if ((urlString = [[directObject descriptorAtIndex: i] stringValue]))
    466             {
    467                 url = [[NSURL alloc] initWithString: urlString];
    468465                break;
    469             }
    470     }
    471     else if ((urlString = [directObject stringValue]))
    472         url = [[NSURL alloc] initWithString: urlString];
    473     else;
    474    
    475     if (url)
    476     {
    477         [self openURL: url];
    478         [url release];
    479     }
     466    }
     467    else
     468        urlString = [directObject stringValue];
     469   
     470    if (urlString)
     471        [self openURL: [[[NSURL alloc] initWithString: urlString] autorelease]];
    480472}
    481473
    482474- (void) openURL: (NSURL *) url
    483475{
    484     #warning check for .torrent
     476    #warning remove when quitting
    485477    NSURLDownload * torrentDownload = [[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url]
    486478                                        delegate: self];
    487    
    488     NSString * tempPath = [NSTemporaryDirectory() stringByAppendingPathComponent: [[url path] lastPathComponent]];
    489     NSLog(tempPath);[torrentDownload setDestination: tempPath allowOverwrite: NO];
    490     [fPendingTorrentDownloads setObject: tempPath forKey: url];
    491     [torrentDownload release];
    492 }
    493 
    494 - (void) download: (NSURLDownload *)download didFailWithError: (NSError *) error
    495 {
    496     [fPendingTorrentDownloads removeObjectForKey: [[download request] URL]];
    497    
     479}
     480
     481- (void) download: (NSURLDownload *) download didReceiveResponse: (NSURLResponse *) response
     482{
     483    NSString * suggestedName = [response suggestedFilename];
     484   
     485    if ([[suggestedName pathExtension] caseInsensitiveCompare: @"torrent"] != NSOrderedSame)
     486    {
     487        NSRunAlertPanel(NSLocalizedString(@"Torrent download failed",
     488            @"Download not a torrent -> title"), [NSString stringWithFormat:
     489            NSLocalizedString(@"It appears that the file from %@ is not a torrent file",
     490            @"Download not a torrent -> message"), [[[download request] URL] absoluteString]],
     491            NSLocalizedString(@"OK", @"Download not a torrent -> button"), nil, nil);
     492       
     493        [download cancel];
     494    }
     495    else
     496    {
     497        NSString * path = [NSTemporaryDirectory() stringByAppendingPathComponent: [suggestedName lastPathComponent]];
     498        [download setDestination: path allowOverwrite: NO];
     499        [fPendingTorrentDownloads setObject: path forKey: [[download request] URL]];
     500    }
     501}
     502
     503- (void) download: (NSURLDownload *) download didFailWithError: (NSError *) error
     504{
    498505    NSRunAlertPanel(NSLocalizedString(@"Torrent download failed",
    499506        @"Torrent download error -> title"), [NSString stringWithFormat:
     
    501508        @"Torrent download failed -> message"), [[[download request] URL] absoluteString],
    502509        [error localizedDescription]], NSLocalizedString(@"OK", @"Torrent download failed -> button"), nil, nil);
     510   
     511    [fPendingTorrentDownloads removeObjectForKey: [[download request] URL]];
    503512}
    504513
     
    506515{
    507516    #warning try to open, if not delete
    508    
    509517    [self openFiles: [NSArray arrayWithObject: [fPendingTorrentDownloads objectForKey: [[download request] URL]]]
    510518            ignoreDownloadFolder: NO];
     519   
     520    [fPendingTorrentDownloads removeObjectForKey: [[download request] URL]];
    511521}
    512522
Note: See TracChangeset for help on using the changeset viewer.