mirror of
https://github.com/transmission/transmission
synced 2025-03-03 10:15:45 +00:00
store a flat (non-nested) list of files for each transfer
This commit is contained in:
parent
418d04374c
commit
bdbe24b6e3
4 changed files with 26 additions and 27 deletions
|
@ -52,6 +52,4 @@
|
||||||
|
|
||||||
- (NSArray *) children;
|
- (NSArray *) children;
|
||||||
|
|
||||||
- (BOOL) containsPath: (NSString *) fullPath;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -128,23 +128,6 @@
|
||||||
return fChildren;
|
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
|
@end
|
||||||
|
|
||||||
@implementation FileListNode (Private)
|
@implementation FileListNode (Private)
|
||||||
|
|
|
@ -60,7 +60,7 @@ typedef enum
|
||||||
NSString * fNameString, * fHashString;
|
NSString * fNameString, * fHashString;
|
||||||
|
|
||||||
tr_file_stat * fFileStat;
|
tr_file_stat * fFileStat;
|
||||||
NSArray * fFileList;
|
NSArray * fFileList, * fFlatFileList;
|
||||||
|
|
||||||
NSIndexSet * fPreviousFinishedIndexes;
|
NSIndexSet * fPreviousFinishedIndexes;
|
||||||
NSDate * fPreviousFinishedIndexesDate;
|
NSDate * fPreviousFinishedIndexesDate;
|
||||||
|
@ -240,6 +240,7 @@ typedef enum
|
||||||
- (NSArray *) fileList;
|
- (NSArray *) fileList;
|
||||||
- (NSInteger) fileCount;
|
- (NSInteger) fileCount;
|
||||||
- (void) updateFileStat;
|
- (void) updateFileStat;
|
||||||
|
- (NSArray *) flatFileList;
|
||||||
|
|
||||||
//methods require fileStats to have been updated recently to be accurate
|
//methods require fileStats to have been updated recently to be accurate
|
||||||
- (CGFloat) fileProgress: (FileListNode *) node;
|
- (CGFloat) fileProgress: (FileListNode *) node;
|
||||||
|
|
|
@ -43,7 +43,8 @@
|
||||||
- (void) updateDownloadFolder;
|
- (void) updateDownloadFolder;
|
||||||
|
|
||||||
- (void) createFileList;
|
- (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;
|
- (void) completenessChange: (NSNumber *) status;
|
||||||
|
|
||||||
|
@ -188,6 +189,7 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo
|
||||||
[fIcon release];
|
[fIcon release];
|
||||||
|
|
||||||
[fFileList release];
|
[fFileList release];
|
||||||
|
[fFlatFileList release];
|
||||||
|
|
||||||
[fQuickPauseDict release];
|
[fQuickPauseDict release];
|
||||||
|
|
||||||
|
@ -460,11 +462,11 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo
|
||||||
file = [[self name] stringByAppendingPathComponent: file];
|
file = [[self name] stringByAppendingPathComponent: file];
|
||||||
BOOL isExtra = YES;
|
BOOL isExtra = YES;
|
||||||
|
|
||||||
NSEnumerator * nodeEnumerator = [fFileList objectEnumerator];
|
NSEnumerator * nodeEnumerator = [fFlatFileList objectEnumerator];
|
||||||
FileListNode * node;
|
FileListNode * node;
|
||||||
while ((node = [nodeEnumerator nextObject]))
|
while ((node = [nodeEnumerator nextObject]))
|
||||||
{
|
{
|
||||||
if ([node containsPath: file])
|
if ([[node fullPath] hasPrefix: file])
|
||||||
{
|
{
|
||||||
isExtra = NO;
|
isExtra = NO;
|
||||||
break;
|
break;
|
||||||
|
@ -1487,6 +1489,11 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo
|
||||||
return (CGFloat)have / [node size];
|
return (CGFloat)have / [node size];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSArray *) flatFileList
|
||||||
|
{
|
||||||
|
return fFlatFileList;
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL) canChangeDownloadCheckForFile: (NSInteger) index
|
- (BOOL) canChangeDownloadCheckForFile: (NSInteger) index
|
||||||
{
|
{
|
||||||
if (!fFileStat)
|
if (!fFileStat)
|
||||||
|
@ -1775,7 +1782,8 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo
|
||||||
if ([self isFolder])
|
if ([self isFolder])
|
||||||
{
|
{
|
||||||
NSInteger count = [self fileCount];
|
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++)
|
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];
|
[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
|
else
|
||||||
{
|
{
|
||||||
FileListNode * node = [[FileListNode alloc] initWithFileName: name path: path size: file->length index: i];
|
FileListNode * node = [[FileListNode alloc] initWithFileName: name path: path size: file->length index: i];
|
||||||
[fileList addObject: node];
|
[fileList addObject: node];
|
||||||
|
[flatFileList addObject: node];
|
||||||
[node release];
|
[node release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1817,16 +1826,21 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo
|
||||||
|
|
||||||
fFileList = [[NSArray alloc] initWithArray: fileList];
|
fFileList = [[NSArray alloc] initWithArray: fileList];
|
||||||
[fileList release];
|
[fileList release];
|
||||||
|
|
||||||
|
fFlatFileList = [[NSArray alloc] initWithArray: flatFileList];
|
||||||
|
[flatFileList release];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FileListNode * node = [[FileListNode alloc] initWithFileName: [self name] path: @"" size: [self size] index: 0];
|
FileListNode * node = [[FileListNode alloc] initWithFileName: [self name] path: @"" size: [self size] index: 0];
|
||||||
fFileList = [[NSArray arrayWithObject: node] retain];
|
fFileList = [[NSArray arrayWithObject: node] retain];
|
||||||
|
fFlatFileList = [fFileList copy];
|
||||||
[node release];
|
[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];
|
NSString * name = [components objectAtIndex: 0];
|
||||||
BOOL isFolder = [components count] > 1;
|
BOOL isFolder = [components count] > 1;
|
||||||
|
@ -1846,7 +1860,10 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo
|
||||||
if (isFolder)
|
if (isFolder)
|
||||||
node = [[FileListNode alloc] initWithFolderName: name path: [parent fullPath]];
|
node = [[FileListNode alloc] initWithFolderName: name path: [parent fullPath]];
|
||||||
else
|
else
|
||||||
|
{
|
||||||
node = [[FileListNode alloc] initWithFileName: name path: [parent fullPath] size: size index: index];
|
node = [[FileListNode alloc] initWithFileName: name path: [parent fullPath] size: size index: index];
|
||||||
|
[flatFileList addObject: node];
|
||||||
|
}
|
||||||
|
|
||||||
[parent insertChild: node];
|
[parent insertChild: node];
|
||||||
[node release];
|
[node release];
|
||||||
|
@ -1857,7 +1874,7 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo
|
||||||
[node insertIndex: index withSize: size];
|
[node insertIndex: index withSize: size];
|
||||||
|
|
||||||
[components removeObjectAtIndex: 0];
|
[components removeObjectAtIndex: 0];
|
||||||
[self insertPath: components forParent: node fileSize: size index: index];
|
[self insertPath: components forParent: node fileSize: size index: index flatList: flatFileList];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue