Skip to content

Commit

Permalink
updated -nameOfFileCurrentlyDownloading
Browse files Browse the repository at this point in the history
  • Loading branch information
yurrriq committed Dec 22, 2013
1 parent 620259a commit d2e789c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions EWCacheManager/EWCacheManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
@interface EWCacheManager : NSObject {
NSString *path;
NSString *currentDownloadFilename;
}

@property (nonatomic, weak) id <EWCacheManagerDelegate> delegate;
Expand Down
8 changes: 5 additions & 3 deletions EWCacheManager/EWCacheManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ - (void)downloadFileWithRequest:(NSURLRequest *)request
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:[[EWCacheManager sharedManager] pathForFilename:filename] append:NO];

[operation setDownloadProgressBlock: ^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
if (![filename isEqualToString:currentDownloadFilename]) {
currentDownloadFilename = filename;
}
_fileProgress = (float)totalBytesRead / totalBytesExpectedToRead;
_queueProgress = (float)(_fileProgress + self.requestedFilesCount - self.downloadClient.operationQueue.operationCount) / self.requestedFilesCount;
}];
Expand Down Expand Up @@ -126,10 +129,9 @@ - (NSUInteger)requestedFilesCount {
}

- (NSString *)nameOfFileCurrentlyDownloading {
if (!_downloadClient) return nil;
if (!_downloadClient || !(_downloadClient.operationQueue.operationCount > 0) || currentDownloadFilename.length == 0) return nil;

return [_downloadClient.operationQueue.operations.lastObject description];
return currentDownloadFilename;
}


@end

0 comments on commit d2e789c

Please # to comment.