remove redundant code when creating a torrent's file list

This commit is contained in:
Mitchell Livingston 2013-02-19 00:54:55 +00:00
parent de6d57af43
commit 539aeb2edd
1 changed files with 10 additions and 41 deletions

View File

@ -53,7 +53,7 @@
- (void) ratioLimitHit; - (void) ratioLimitHit;
- (void) idleLimitHit; - (void) idleLimitHit;
- (void) metadataRetrieved; - (void) metadataRetrieved;
- (void)renameFinished: (BOOL) success withNodes: (NSArray *) nodes completionHandler: (void (^)(BOOL)) completionHandler oldPath: (NSString *) oldPath newName: (NSString *) newName; - (void)renameFinished: (BOOL) success nodes: (NSArray *) nodes completionHandler: (void (^)(BOOL)) completionHandler oldPath: (NSString *) oldPath newName: (NSString *) newName;
- (BOOL) shouldShowEta; - (BOOL) shouldShowEta;
- (NSString *) etaString; - (NSString *) etaString;
@ -101,7 +101,7 @@ void renameCallback(tr_torrent * torrent, const char * oldPathCharString, const
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary * contextDict = [(NSDictionary *)contextInfo autorelease]; NSDictionary * contextDict = [(NSDictionary *)contextInfo autorelease];
Torrent * torrentObject = [contextDict objectForKey: @"Torrent"]; Torrent * torrentObject = [contextDict objectForKey: @"Torrent"];
[torrentObject renameFinished: error == 0 withNodes: [contextDict objectForKey: @"Nodes"] completionHandler: [contextDict objectForKey: @"CompletionHandler"] oldPath: oldPath newName: newName]; [torrentObject renameFinished: error == 0 nodes: [contextDict objectForKey: @"Nodes"] completionHandler: [contextDict objectForKey: @"CompletionHandler"] oldPath: oldPath newName: newName];
}); });
} }
} }
@ -1724,8 +1724,9 @@ int trashDataFile(const char * filename)
if ([self isFolder]) if ([self isFolder])
{ {
const NSInteger count = [self fileCount]; const NSInteger count = [self fileCount];
NSMutableArray * fileList = [NSMutableArray array], NSMutableArray * flatFileList = [NSMutableArray arrayWithCapacity: count];
* flatFileList = [NSMutableArray arrayWithCapacity: count];
FileListNode * tempNode = [[FileListNode alloc] initWithFolderName:nil path:nil torrent:self];
for (NSInteger i = 0; i < count; i++) for (NSInteger i = 0; i < count; i++)
{ {
@ -1733,47 +1734,15 @@ int trashDataFile(const char * filename)
NSString * fullPath = [NSString stringWithUTF8String: file->name]; NSString * fullPath = [NSString stringWithUTF8String: file->name];
NSArray * pathComponents = [fullPath pathComponents]; NSArray * pathComponents = [fullPath pathComponents];
NSAssert1([pathComponents count] >= 2, @"Not enough components in path %@", fullPath); [self insertPathForComponents: pathComponents withComponentIndex: 1 forParent: tempNode fileSize: file->length index: i flatList: flatFileList];
NSString * path = [pathComponents objectAtIndex: 0];
NSString * name = [pathComponents objectAtIndex: 1];
if ([pathComponents count] > 2)
{
//determine if folder node already exists
__block FileListNode * node = nil;
[fileList enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(FileListNode * searchNode, NSUInteger idx, BOOL * stop) {
if ([[searchNode name] isEqualToString: name] && [searchNode isFolder])
{
node = searchNode;
*stop = YES;
}
}];
if (!node)
{
node = [[FileListNode alloc] initWithFolderName: name path: path torrent: self];
[fileList addObject: node];
[node release];
}
[node insertIndex: i withSize: file->length];
[self insertPathForComponents: pathComponents withComponentIndex: 2 forParent: node fileSize: file->length index: i flatList: flatFileList];
}
else
{
FileListNode * node = [[FileListNode alloc] initWithFileName: name path: path size: file->length index: i torrent: self];
[fileList addObject: node];
[flatFileList addObject: node];
[node release];
}
} }
[self sortFileList: fileList]; [self sortFileList: [tempNode children]];
[self sortFileList: flatFileList]; [self sortFileList: flatFileList];
fFileList = [[NSArray alloc] initWithArray: fileList]; fFileList = [[NSArray alloc] initWithArray: [tempNode children]];
fFlatFileList = [[NSArray alloc] initWithArray: flatFileList]; fFlatFileList = [[NSArray alloc] initWithArray: flatFileList];
[tempNode release];
} }
else else
{ {
@ -1919,7 +1888,7 @@ int trashDataFile(const char * filename)
[[NSNotificationCenter defaultCenter] postNotificationName: @"ResetInspector" object: self userInfo: @{ @"Torrent" : self }]; [[NSNotificationCenter defaultCenter] postNotificationName: @"ResetInspector" object: self userInfo: @{ @"Torrent" : self }];
} }
- (void)renameFinished: (BOOL) success withNodes: (NSArray *) nodes completionHandler: (void (^)(BOOL)) completionHandler oldPath: (NSString *) oldPath newName: (NSString *) newName - (void)renameFinished: (BOOL) success nodes: (NSArray *) nodes completionHandler: (void (^)(BOOL)) completionHandler oldPath: (NSString *) oldPath newName: (NSString *) newName
{ {
NSParameterAssert(completionHandler != nil); NSParameterAssert(completionHandler != nil);
NSParameterAssert(oldPath != nil); NSParameterAssert(oldPath != nil);