Only try to download torrent files that will end in .torrent (even if the url doesn't).
This commit is contained in:
parent
ed82ce2223
commit
faa173ecd2
|
@ -454,7 +454,6 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
||||||
|
|
||||||
- (void) handleOpenContentsEvent: (NSAppleEventDescriptor *) event replyEvent: (NSAppleEventDescriptor *) replyEvent
|
- (void) handleOpenContentsEvent: (NSAppleEventDescriptor *) event replyEvent: (NSAppleEventDescriptor *) replyEvent
|
||||||
{
|
{
|
||||||
NSURL * url;
|
|
||||||
NSString * urlString;
|
NSString * urlString;
|
||||||
|
|
||||||
NSAppleEventDescriptor * directObject = [event paramDescriptorForKeyword: keyDirectObject];
|
NSAppleEventDescriptor * directObject = [event paramDescriptorForKeyword: keyDirectObject];
|
||||||
|
@ -463,51 +462,62 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
||||||
unsigned i;
|
unsigned i;
|
||||||
for (i = 1; i <= [directObject numberOfItems]; i++)
|
for (i = 1; i <= [directObject numberOfItems]; i++)
|
||||||
if ((urlString = [[directObject descriptorAtIndex: i] stringValue]))
|
if ((urlString = [[directObject descriptorAtIndex: i] stringValue]))
|
||||||
{
|
|
||||||
url = [[NSURL alloc] initWithString: urlString];
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if ((urlString = [directObject stringValue]))
|
else
|
||||||
url = [[NSURL alloc] initWithString: urlString];
|
urlString = [directObject stringValue];
|
||||||
else;
|
|
||||||
|
|
||||||
if (url)
|
if (urlString)
|
||||||
{
|
[self openURL: [[[NSURL alloc] initWithString: urlString] autorelease]];
|
||||||
[self openURL: url];
|
|
||||||
[url release];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) openURL: (NSURL *) url
|
- (void) openURL: (NSURL *) url
|
||||||
{
|
{
|
||||||
#warning check for .torrent
|
#warning remove when quitting
|
||||||
NSURLDownload * torrentDownload = [[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url]
|
NSURLDownload * torrentDownload = [[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url]
|
||||||
delegate: self];
|
delegate: self];
|
||||||
|
|
||||||
NSString * tempPath = [NSTemporaryDirectory() stringByAppendingPathComponent: [[url path] lastPathComponent]];
|
|
||||||
NSLog(tempPath);[torrentDownload setDestination: tempPath allowOverwrite: NO];
|
|
||||||
[fPendingTorrentDownloads setObject: tempPath forKey: url];
|
|
||||||
[torrentDownload release];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) download: (NSURLDownload *)download didFailWithError: (NSError *) error
|
- (void) download: (NSURLDownload *) download didReceiveResponse: (NSURLResponse *) response
|
||||||
{
|
{
|
||||||
[fPendingTorrentDownloads removeObjectForKey: [[download request] URL]];
|
NSString * suggestedName = [response suggestedFilename];
|
||||||
|
|
||||||
|
if ([[suggestedName pathExtension] caseInsensitiveCompare: @"torrent"] != NSOrderedSame)
|
||||||
|
{
|
||||||
|
NSRunAlertPanel(NSLocalizedString(@"Torrent download failed",
|
||||||
|
@"Download not a torrent -> title"), [NSString stringWithFormat:
|
||||||
|
NSLocalizedString(@"It appears that the file from %@ is not a torrent file",
|
||||||
|
@"Download not a torrent -> message"), [[[download request] URL] absoluteString]],
|
||||||
|
NSLocalizedString(@"OK", @"Download not a torrent -> button"), nil, nil);
|
||||||
|
|
||||||
|
[download cancel];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSString * path = [NSTemporaryDirectory() stringByAppendingPathComponent: [suggestedName lastPathComponent]];
|
||||||
|
[download setDestination: path allowOverwrite: NO];
|
||||||
|
[fPendingTorrentDownloads setObject: path forKey: [[download request] URL]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) download: (NSURLDownload *) download didFailWithError: (NSError *) error
|
||||||
|
{
|
||||||
NSRunAlertPanel(NSLocalizedString(@"Torrent download failed",
|
NSRunAlertPanel(NSLocalizedString(@"Torrent download failed",
|
||||||
@"Torrent download error -> title"), [NSString stringWithFormat:
|
@"Torrent download error -> title"), [NSString stringWithFormat:
|
||||||
NSLocalizedString(@"The torrent could not be downloaded from %@ because an error occurred (%@)",
|
NSLocalizedString(@"The torrent could not be downloaded from %@ because an error occurred (%@)",
|
||||||
@"Torrent download failed -> message"), [[[download request] URL] absoluteString],
|
@"Torrent download failed -> message"), [[[download request] URL] absoluteString],
|
||||||
[error localizedDescription]], NSLocalizedString(@"OK", @"Torrent download failed -> button"), nil, nil);
|
[error localizedDescription]], NSLocalizedString(@"OK", @"Torrent download failed -> button"), nil, nil);
|
||||||
|
|
||||||
|
[fPendingTorrentDownloads removeObjectForKey: [[download request] URL]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) downloadDidFinish: (NSURLDownload *) download
|
- (void) downloadDidFinish: (NSURLDownload *) download
|
||||||
{
|
{
|
||||||
#warning try to open, if not delete
|
#warning try to open, if not delete
|
||||||
|
|
||||||
[self openFiles: [NSArray arrayWithObject: [fPendingTorrentDownloads objectForKey: [[download request] URL]]]
|
[self openFiles: [NSArray arrayWithObject: [fPendingTorrentDownloads objectForKey: [[download request] URL]]]
|
||||||
ignoreDownloadFolder: NO];
|
ignoreDownloadFolder: NO];
|
||||||
|
|
||||||
|
[fPendingTorrentDownloads removeObjectForKey: [[download request] URL]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) openFiles: (NSArray *) filenames ignoreDownloadFolder: (BOOL) ignore
|
- (void) openFiles: (NSArray *) filenames ignoreDownloadFolder: (BOOL) ignore
|
||||||
|
|
Loading…
Reference in New Issue