Permalink
Browse files

Got the cloud transfer metrics working. It now properly determines th…

…e remaining bytes to upload and download.
  • Loading branch information...
1 parent e374f60 commit aa2b685895a3c788f7fd4c7e80371b796a9df004 @drewmccormack committed Jan 30, 2013
@@ -33,7 +33,9 @@ extern NSString * const TICDSApplicationSyncManagerDidRefreshCloudTransferProgre
/** Start a new metadata query to asynchronously download cloud files not yet local. */
- (void)refreshCloudMetadataQuery;
-/** Start a metadata query to scan cloud files, and determine how much data still needs to be uploaded and downloaded */
+/** Start a metadata query to scan iCloud files, and determine how much data still needs to be uploaded and downloaded.
+ Access the results using the provided properties. Use the notification to determine when the asynchronous
+ calculation is finished. */
- (void)refreshCloudTransferProgress;
#pragma mark Dropbox-Related Methods
@@ -288,13 +288,23 @@ - (void)finishedGatheringCloudTransferProgress:(NSNotification *)notif
for ( NSURL *url in urls ) {
NSNumber *fileSizeNumber = nil;
NSNumber *percentDownloaded = nil, *percentUploaded = nil;
- [url getResourceValue:&fileSizeNumber forKey:NSMetadataItemFSSizeKey error:NULL];
- [url getResourceValue:&percentDownloaded forKey:NSMetadataUbiquitousItemPercentDownloadedKey error:NULL];
- [url getResourceValue:&percentUploaded forKey:NSMetadataUbiquitousItemPercentUploadedKey error:NULL];
+ NSNumber *uploaded = nil, *downloaded = nil;
+
+ [url getResourceValue:&fileSizeNumber forKey:NSURLFileSizeKey error:NULL];
+ [url getResourceValue:&percentDownloaded forKey:NSURLUbiquitousItemPercentDownloadedKey error:NULL];
+ [url getResourceValue:&percentUploaded forKey:NSURLUbiquitousItemPercentUploadedKey error:NULL];
+ [url getResourceValue:&uploaded forKey:NSURLUbiquitousItemIsUploadedKey error:NULL];
+ [url getResourceValue:&downloaded forKey:NSURLUbiquitousItemIsDownloadedKey error:NULL];
unsigned long long fileSize = fileSizeNumber.unsignedLongLongValue;
- if ( percentDownloaded && fileSizeNumber ) toDownload += percentDownloaded.doubleValue / 100.0 * fileSize;
- if ( percentUploaded && fileSizeNumber ) toUpload += percentUploaded.doubleValue / 100.0 * fileSize;
+ if ( uploaded && !uploaded.boolValue ) {
+ double percentage = percentUploaded ? percentUploaded.doubleValue : 100.0;
+ toUpload += percentage / 100.0 * fileSize;;
+ }
+ else if ( downloaded && !downloaded.boolValue ) {
+ double percentage = percentDownloaded ? percentDownloaded.doubleValue : 100.0;
+ toDownload += percentage / 100.0 * fileSize;
+ }
}
dispatch_async(dispatch_get_main_queue(), ^{
self.cloudBytesToDownload = toDownload;

0 comments on commit aa2b685

Please sign in to comment.