streamline FileListNode.m, moving asserts to more appropriate locations

This commit is contained in:
Mitchell Livingston 2008-05-22 21:06:56 +00:00
parent 07763bac0b
commit 29729d35e7
3 changed files with 14 additions and 13 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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];