]> granicus.if.org Git - transmission/commitdiff
streamline FileListNode.m, moving asserts to more appropriate locations
authorMitchell Livingston <livings124@transmissionbt.com>
Thu, 22 May 2008 21:06:56 +0000 (21:06 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Thu, 22 May 2008 21:06:56 +0000 (21:06 +0000)
macosx/FileListNode.h
macosx/FileListNode.m
macosx/Torrent.m

index e9910605451cb9274911e8f18fb4acd1461489b1..df341df9228d6ebbfa7c3bfbf5d5b9af2bb55df0 100644 (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;
index 56a8314ce05e552e4b174afa575ba0589735d539..2a6a6751c58591f0cd3f8d8714e5adb95b64c025 100644 (file)
@@ -37,6 +37,7 @@
     if ((self = [self initWithFolder: YES name: name path: path]))
     {
         fChildren = [[NSMutableArray alloc] init];
+        fSize = 0;
     }
     
     return self;
 
 - (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];
 }
 
 
 - (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];
 
 - (NSArray *) children
 {
-    NSAssert(fIsFolder, @"method can only be invoked on folders");
-    
     return fChildren;
 }
 
index 20c0baf9afd3f629d201715db4f232817e3d7707..c1cd388cfd7525d056269d505458808116cbf5a2 100644 (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];