a little simplification in the auto-import code

This commit is contained in:
Mitchell Livingston 2009-05-23 19:01:57 +00:00
parent bbb7ff0562
commit 81a0584a6e
1 changed files with 12 additions and 16 deletions

View File

@ -2449,35 +2449,31 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
fAutoImportedNames = [[NSMutableArray alloc] init];
[fAutoImportedNames setArray: importedNames];
for (NSInteger i = [newNames count] - 1; i >= 0; i--)
{
NSString * file = [newNames objectAtIndex: i],
* fullFile = [path stringByAppendingPathComponent: file];
if ([[[NSWorkspace sharedWorkspace] typeOfFile: fullFile error: NULL] isEqualToString: @"org.bittorrent.torrent"]
&& ![file hasPrefix: @"."])
[newNames replaceObjectAtIndex: i withObject: fullFile];
else
[newNames removeObjectAtIndex: i];
}
for (NSString * file in newNames)
{
if ([file hasPrefix: @"."])
continue;
NSString * fullFile = [path stringByAppendingPathComponent: file];
if (![[[NSWorkspace sharedWorkspace] typeOfFile: fullFile error: NULL] isEqualToString: @"org.bittorrent.torrent"])
continue;
tr_ctor * ctor = tr_ctorNew(fLib);
tr_ctorSetMetainfoFromFile(ctor, [file UTF8String]);
tr_ctorSetMetainfoFromFile(ctor, [fullFile UTF8String]);
switch (tr_torrentParse(ctor, NULL))
{
case TR_OK:
[self openFiles: [NSArray arrayWithObject: file] addType: ADD_AUTO forcePath: nil];
[self openFiles: [NSArray arrayWithObject: fullFile] addType: ADD_AUTO forcePath: nil];
[GrowlApplicationBridge notifyWithTitle: NSLocalizedString(@"Torrent File Auto Added", "Growl notification title")
description: [file lastPathComponent] notificationName: GROWL_AUTO_ADD iconData: nil priority: 0 isSticky: NO
description: file notificationName: GROWL_AUTO_ADD iconData: nil priority: 0 isSticky: NO
clickContext: nil];
break;
case TR_EINVALID:
[fAutoImportedNames removeObject: [file lastPathComponent]];
[fAutoImportedNames removeObject: file];
}
tr_ctorFree(ctor);