From bdbe24b6e3c6687effbbe0e9bd812df10403a9ae Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 7 Dec 2008 02:36:26 +0000 Subject: [PATCH] store a flat (non-nested) list of files for each transfer --- macosx/FileListNode.h | 2 -- macosx/FileListNode.m | 17 ----------------- macosx/Torrent.h | 3 ++- macosx/Torrent.m | 31 ++++++++++++++++++++++++------- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/macosx/FileListNode.h b/macosx/FileListNode.h index b909072d3..0bad7f3ca 100644 --- a/macosx/FileListNode.h +++ b/macosx/FileListNode.h @@ -52,6 +52,4 @@ - (NSArray *) children; -- (BOOL) containsPath: (NSString *) fullPath; - @end diff --git a/macosx/FileListNode.m b/macosx/FileListNode.m index 776e5a6c8..a75150669 100644 --- a/macosx/FileListNode.m +++ b/macosx/FileListNode.m @@ -128,23 +128,6 @@ return fChildren; } -- (BOOL) containsPath: (NSString *) fullPath -{ - if ([fullPath isEqualToString: fPath]) - return YES; - - if (fIsFolder && [fullPath hasPrefix: fPath]) - { - NSEnumerator * enumerator = [fChildren objectEnumerator]; - FileListNode * node; - while ((node = [enumerator nextObject])) - if ([node containsPath: fullPath]) - return YES; - } - - return NO; -} - @end @implementation FileListNode (Private) diff --git a/macosx/Torrent.h b/macosx/Torrent.h index 6a9699413..7dc397e38 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -60,7 +60,7 @@ typedef enum NSString * fNameString, * fHashString; tr_file_stat * fFileStat; - NSArray * fFileList; + NSArray * fFileList, * fFlatFileList; NSIndexSet * fPreviousFinishedIndexes; NSDate * fPreviousFinishedIndexesDate; @@ -240,6 +240,7 @@ typedef enum - (NSArray *) fileList; - (NSInteger) fileCount; - (void) updateFileStat; +- (NSArray *) flatFileList; //methods require fileStats to have been updated recently to be accurate - (CGFloat) fileProgress: (FileListNode *) node; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 691d7eae7..1a0c52439 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -43,7 +43,8 @@ - (void) updateDownloadFolder; - (void) createFileList; -- (void) insertPath: (NSMutableArray *) components forParent: (FileListNode *) parent fileSize: (uint64_t) size index: (NSInteger) index; +- (void) insertPath: (NSMutableArray *) components forParent: (FileListNode *) parent fileSize: (uint64_t) size + index: (NSInteger) index flatList: (NSMutableArray *) flatFileList; - (void) completenessChange: (NSNumber *) status; @@ -188,6 +189,7 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo [fIcon release]; [fFileList release]; + [fFlatFileList release]; [fQuickPauseDict release]; @@ -460,11 +462,11 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo file = [[self name] stringByAppendingPathComponent: file]; BOOL isExtra = YES; - NSEnumerator * nodeEnumerator = [fFileList objectEnumerator]; + NSEnumerator * nodeEnumerator = [fFlatFileList objectEnumerator]; FileListNode * node; while ((node = [nodeEnumerator nextObject])) { - if ([node containsPath: file]) + if ([[node fullPath] hasPrefix: file]) { isExtra = NO; break; @@ -1487,6 +1489,11 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo return (CGFloat)have / [node size]; } +- (NSArray *) flatFileList +{ + return fFlatFileList; +} + - (BOOL) canChangeDownloadCheckForFile: (NSInteger) index { if (!fFileStat) @@ -1775,7 +1782,8 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo if ([self isFolder]) { NSInteger count = [self fileCount]; - NSMutableArray * fileList = [[NSMutableArray alloc] initWithCapacity: count]; + NSMutableArray * fileList = [[NSMutableArray alloc] initWithCapacity: count], + * flatFileList = [[NSMutableArray alloc] initWithCapacity: count]; for (NSInteger i = 0; i < count; i++) { @@ -1803,12 +1811,13 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo } [node insertIndex: i withSize: file->length]; - [self insertPath: pathComponents forParent: node fileSize: file->length index: i]; + [self insertPath: pathComponents forParent: node fileSize: file->length index: i flatList: flatFileList]; } else { FileListNode * node = [[FileListNode alloc] initWithFileName: name path: path size: file->length index: i]; [fileList addObject: node]; + [flatFileList addObject: node]; [node release]; } @@ -1817,16 +1826,21 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo fFileList = [[NSArray alloc] initWithArray: fileList]; [fileList release]; + + fFlatFileList = [[NSArray alloc] initWithArray: flatFileList]; + [flatFileList release]; } else { FileListNode * node = [[FileListNode alloc] initWithFileName: [self name] path: @"" size: [self size] index: 0]; fFileList = [[NSArray arrayWithObject: node] retain]; + fFlatFileList = [fFileList copy]; [node release]; } } -- (void) insertPath: (NSMutableArray *) components forParent: (FileListNode *) parent fileSize: (uint64_t) size index: (NSInteger) index +- (void) insertPath: (NSMutableArray *) components forParent: (FileListNode *) parent fileSize: (uint64_t) size + index: (NSInteger) index flatList: (NSMutableArray *) flatFileList { NSString * name = [components objectAtIndex: 0]; BOOL isFolder = [components count] > 1; @@ -1846,7 +1860,10 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo if (isFolder) node = [[FileListNode alloc] initWithFolderName: name path: [parent fullPath]]; else + { node = [[FileListNode alloc] initWithFileName: name path: [parent fullPath] size: size index: index]; + [flatFileList addObject: node]; + } [parent insertChild: node]; [node release]; @@ -1857,7 +1874,7 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo [node insertIndex: index withSize: size]; [components removeObjectAtIndex: 0]; - [self insertPath: components forParent: node fileSize: size index: index]; + [self insertPath: components forParent: node fileSize: size index: index flatList: flatFileList]; } }