From 29729d35e7b8198d9245129e0dfc138c8304748d Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Thu, 22 May 2008 21:06:56 +0000 Subject: [PATCH] streamline FileListNode.m, moving asserts to more appropriate locations --- macosx/FileListNode.h | 2 +- macosx/FileListNode.m | 17 +++++++++-------- macosx/Torrent.m | 8 ++++---- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/macosx/FileListNode.h b/macosx/FileListNode.h index e99106054..df341df92 100644 --- a/macosx/FileListNode.h +++ b/macosx/FileListNode.h @@ -40,7 +40,7 @@ - (id) initWithFileName: (NSString *) name path: (NSString *) path size: (uint64_t) size index: (int) index; - (void) insertChild: (FileListNode *) child; -- (void) insertIndex: (NSUInteger) index; +- (void) insertIndex: (NSUInteger) index withSize: (uint64_t) size; - (BOOL) isFolder; - (NSString *) name; diff --git a/macosx/FileListNode.m b/macosx/FileListNode.m index 56a8314ce..2a6a6751c 100644 --- a/macosx/FileListNode.m +++ b/macosx/FileListNode.m @@ -37,6 +37,7 @@ if ((self = [self initWithFolder: YES name: name path: path])) { fChildren = [[NSMutableArray alloc] init]; + fSize = 0; } return self; @@ -55,16 +56,22 @@ - (void) insertChild: (FileListNode *) child { + NSAssert(fIsFolder, @"method can only be invoked on files"); + [fChildren addObject: child]; } -- (void) insertIndex: (NSUInteger) index +- (void) insertIndex: (NSUInteger) index withSize: (uint64_t) size { + NSAssert(fIsFolder, @"method can only be invoked on files"); + [fIndexes addIndex: index]; + fSize += size; } - (id) copyWithZone: (NSZone *) zone { + //this object is essentially immutable after initial setup return [self retain]; } @@ -103,16 +110,12 @@ - (uint64_t) size { - NSAssert(!fIsFolder, @"method can only be invoked on files currently"); - return fSize; } - (NSImage *) icon { - NSAssert(!fIsFolder, @"method can only be invoked on files currently"); - - if (!fIcon) + if (!fIsFolder && !fIcon) { fIcon = [[[NSWorkspace sharedWorkspace] iconForFileType: [fName pathExtension]] retain]; [fIcon setFlipped: YES]; @@ -122,8 +125,6 @@ - (NSArray *) children { - NSAssert(fIsFolder, @"method can only be invoked on folders"); - return fChildren; } diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 20c0baf9a..c1cd388cf 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -1664,11 +1664,11 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * if ([pathComponents count] > 0) { - //determine if node already exists + //determine if folder node already exists NSEnumerator * enumerator = [fileList objectEnumerator]; FileListNode * node; while ((node = [enumerator nextObject])) - if ([[node name] isEqualToString: name]) + if ([[node name] isEqualToString: name] && [node isFolder]) break; if (!node) @@ -1678,7 +1678,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * [node release]; } - [node insertIndex: i]; + [node insertIndex: i withSize: file->length]; [self insertPath: pathComponents forParent: node fileSize: file->length index: i]; } else @@ -1729,7 +1729,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * if (isFolder) { - [node insertIndex: index]; + [node insertIndex: index withSize: size]; [components removeObjectAtIndex: 0]; [self insertPath: components forParent: node fileSize: size index: index];