From d2e789cfcb23385118f690ad7aef154bd9b279c0 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Sun, 22 Dec 2013 15:34:31 -0600 Subject: [PATCH] updated -nameOfFileCurrentlyDownloading --- EWCacheManager/EWCacheManager.h | 1 + EWCacheManager/EWCacheManager.m | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/EWCacheManager/EWCacheManager.h b/EWCacheManager/EWCacheManager.h index 661a4f7..71cb26f 100644 --- a/EWCacheManager/EWCacheManager.h +++ b/EWCacheManager/EWCacheManager.h @@ -24,6 +24,7 @@ */ @interface EWCacheManager : NSObject { NSString *path; + NSString *currentDownloadFilename; } @property (nonatomic, weak) id delegate; diff --git a/EWCacheManager/EWCacheManager.m b/EWCacheManager/EWCacheManager.m index 1dadeb4..e131931 100644 --- a/EWCacheManager/EWCacheManager.m +++ b/EWCacheManager/EWCacheManager.m @@ -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; }]; @@ -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