From 0bcbb5918b4ddd1fd403392ee2ec42ee188d7ff6 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Mar 2018 13:01:44 -0300 Subject: [PATCH] Improve backup progress. --- Signal/src/util/OWSBackupImportJob.m | 25 +++++++++++++++++-- .../translations/en.lproj/Localizable.strings | 22 ++++++++++++---- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/Signal/src/util/OWSBackupImportJob.m b/Signal/src/util/OWSBackupImportJob.m index 1ca547a60..172a948bd 100644 --- a/Signal/src/util/OWSBackupImportJob.m +++ b/Signal/src/util/OWSBackupImportJob.m @@ -242,10 +242,11 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe // A map of "record name"-to-"downloaded file path". self.downloadedFileMap = [NSMutableDictionary new]; - [self downloadNextFileFromCloud:recordNames completion:completion]; + [self downloadNextFileFromCloud:recordNames recordCount:recordNames.count completion:completion]; } - (void)downloadNextFileFromCloud:(NSMutableArray *)recordNames + recordCount:(NSUInteger)recordCount completion:(OWSBackupJobCompletion)completion { OWSAssert(recordNames); @@ -263,11 +264,15 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe NSString *recordName = recordNames.lastObject; [recordNames removeLastObject]; + [self updateProgressWithDescription:NSLocalizedString(@"BACKUP_IMPORT_PHASE_DOWNLOAD", + @"Indicates that the backup import data is being downloaded.") + progress:@((recordCount - recordNames.count) / (CGFloat)recordCount)]; + if (![recordName isKindOfClass:[NSString class]]) { DDLogError(@"%@ invalid record name in manifest: %@", self.logTag, [recordName class]); // Invalid record name in the manifest. This may be recoverable. // Ignore this for now and proceed with the other downloads. - return [self downloadNextFileFromCloud:recordNames completion:completion]; + return [self downloadNextFileFromCloud:recordNames recordCount:recordCount completion:completion]; } // Use a predictable file path so that multiple "import backup" attempts @@ -302,11 +307,18 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe NSString *attachmentsDirPath = [TSAttachmentStream attachmentsFolder]; + NSUInteger count = 0; for (NSString *recordName in self.attachmentRecordMap) { if (self.isComplete) { return; } + count++; + [self updateProgressWithDescription:NSLocalizedString(@"BACKUP_IMPORT_PHASE_RESTORING_FILES", + @"Indicates that the backup import data is being restored.") + progress:@(count / (CGFloat)self.attachmentRecordMap.count)]; + + NSString *dstRelativePath = self.attachmentRecordMap[recordName]; if (! [self restoreFileWithRecordName:recordName dstRelativePath:dstRelativePath dstDirPath:attachmentsDirPath]) { @@ -322,6 +334,10 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__); + [self updateProgressWithDescription:NSLocalizedString(@"BACKUP_IMPORT_PHASE_RESTORING_DATABASE", + @"Indicates that the backup database is being restored.") + progress:nil]; + NSString *jobDatabaseDirPath = [self.jobTempDirPath stringByAppendingPathComponent:@"database"]; if (![OWSFileSystem ensureDirectoryExists:jobDatabaseDirPath]) { OWSProdLogAndFail(@"%@ Could not create jobDatabaseDirPath.", self.logTag); @@ -497,6 +513,11 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__); + [self updateProgressWithDescription:NSLocalizedString(@"BACKUP_IMPORT_PHASE_FINALIZING", + @"Indicates that the backup import data is being finalized.") + progress:nil]; + + // It's okay that we do this in a separate transaction from the // restoration of backup contents. If some of migrations don't // complete, they'll be run the next time the app launches. diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index aeedab255..7a89b1173 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -164,16 +164,16 @@ "BACKUP_EXPORT_ERROR_SAVE_FILE_TO_CLOUD_FAILED" = "Backup could not upload data."; /* Indicates that the cloud is being cleaned up. */ -"BACKUP_EXPORT_PHASE_CLEAN_UP" = "Cleaning up backup data."; +"BACKUP_EXPORT_PHASE_CLEAN_UP" = "Cleaning Up Backup"; /* Indicates that the backup export is being configured. */ -"BACKUP_EXPORT_PHASE_CONFIGURATION" = "Initializing backup."; +"BACKUP_EXPORT_PHASE_CONFIGURATION" = "Initializing Backup"; /* Indicates that the backup export data is being exported. */ -"BACKUP_EXPORT_PHASE_EXPORT" = "Exporting backup data."; +"BACKUP_EXPORT_PHASE_EXPORT" = "Exporting Backup"; /* Indicates that the backup export data is being uploaded. */ -"BACKUP_EXPORT_PHASE_UPLOAD" = "Uploading backup data."; +"BACKUP_EXPORT_PHASE_UPLOAD" = "Uploading Backup"; /* Error indicating the a backup import could not import the user's data. */ "BACKUP_IMPORT_ERROR_COULD_NOT_IMPORT" = "Backup could not be imported."; @@ -182,11 +182,23 @@ "BACKUP_IMPORT_ERROR_DOWNLOAD_FILE_FROM_CLOUD_FAILED" = "Could not download backup data."; /* Indicates that the backup import is being configured. */ -"BACKUP_IMPORT_PHASE_CONFIGURATION" = "Configuring backup restore."; +"BACKUP_IMPORT_PHASE_CONFIGURATION" = "Configuring Backup"; + +/* Indicates that the backup import data is being downloaded. */ +"BACKUP_IMPORT_PHASE_DOWNLOAD" = "Downloading Backup Data"; + +/* Indicates that the backup import data is being finalized. */ +"BACKUP_IMPORT_PHASE_FINALIZING" = "Finalizing Backup"; /* Indicates that the backup import data is being imported. */ "BACKUP_IMPORT_PHASE_IMPORT" = "Importing backup."; +/* Indicates that the backup database is being restored. */ +"BACKUP_IMPORT_PHASE_RESTORING_DATABASE" = "Restoring Database"; + +/* Indicates that the backup import data is being restored. */ +"BACKUP_IMPORT_PHASE_RESTORING_FILES" = "Restoring Files"; + /* An explanation of the consequences of blocking another user. */ "BLOCK_BEHAVIOR_EXPLANATION" = "Blocked users will not be able to call you or send you messages.";