diff options
Diffstat (limited to 'tools/idevicebackup.c')
| -rw-r--r-- | tools/idevicebackup.c | 67 |
1 files changed, 60 insertions, 7 deletions
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c index 0a7fd70..0da7093 100644 --- a/tools/idevicebackup.c +++ b/tools/idevicebackup.c | |||
| @@ -857,6 +857,8 @@ int main(int argc, char *argv[]) | |||
| 857 | } | 857 | } |
| 858 | } | 858 | } |
| 859 | 859 | ||
| 860 | mobilebackup_error_t err; | ||
| 861 | |||
| 860 | /* Manifest.plist (backup manifest (backup state)) */ | 862 | /* Manifest.plist (backup manifest (backup state)) */ |
| 861 | char *manifest_path = mobilebackup_build_path(backup_directory, "Manifest", ".plist"); | 863 | char *manifest_path = mobilebackup_build_path(backup_directory, "Manifest", ".plist"); |
| 862 | 864 | ||
| @@ -906,7 +908,7 @@ int main(int argc, char *argv[]) | |||
| 906 | /* request backup from device with manifest from last backup */ | 908 | /* request backup from device with manifest from last backup */ |
| 907 | printf("Requesting backup from device...\n"); | 909 | printf("Requesting backup from device...\n"); |
| 908 | 910 | ||
| 909 | mobilebackup_error_t err = mobilebackup_request_backup(mobilebackup, manifest_plist, "/", "1.6"); | 911 | err = mobilebackup_request_backup(mobilebackup, manifest_plist, "/", "1.6"); |
| 910 | if (err == MOBILEBACKUP_E_SUCCESS) { | 912 | if (err == MOBILEBACKUP_E_SUCCESS) { |
| 911 | if (is_full_backup) | 913 | if (is_full_backup) |
| 912 | printf("Full backup mode.\n"); | 914 | printf("Full backup mode.\n"); |
| @@ -1225,16 +1227,67 @@ int main(int argc, char *argv[]) | |||
| 1225 | } | 1227 | } |
| 1226 | } | 1228 | } |
| 1227 | /* request restore from device with manifest (BackupMessageRestoreMigrate) */ | 1229 | /* request restore from device with manifest (BackupMessageRestoreMigrate) */ |
| 1228 | /* loop over Files entries in Manifest data plist */ | 1230 | int restore_flags = MB_RESTORE_NOTIFY_SPRINGBOARD | MB_RESTORE_PRESERVE_SETTINGS | MB_RESTORE_PRESERVE_CAMERA_ROLL; |
| 1229 | /* read mddata/mdinfo files and send to device using DLSendFile */ | 1231 | err = mobilebackup_request_restore(mobilebackup, manifest_plist, restore_flags, "1.6"); |
| 1230 | /* if all hunks of a file are sent, device must send ack */ | 1232 | if (err != MOBILEBACKUP_E_SUCCESS) { |
| 1231 | /* observe notification_proxy id com.apple.mobile.application_installed */ | 1233 | if (err == MOBILEBACKUP_E_BAD_VERSION) { |
| 1232 | /* loop over Applications entries in Manifest data plist */ | 1234 | printf("ERROR: Could not start restore process: backup protocol version mismatch!\n"); |
| 1235 | } else if (err == MOBILEBACKUP_E_REPLY_NOT_OK) { | ||
| 1236 | printf("ERROR: Could not start restore process: device refused to start the restore process.\n"); | ||
| 1237 | } else { | ||
| 1238 | printf("ERROR: Could not start backup process: unspecified error occured (%d)\n", err); | ||
| 1239 | } | ||
| 1240 | plist_free(backup_data); | ||
| 1241 | break; | ||
| 1242 | } | ||
| 1243 | |||
| 1244 | if (files && (plist_get_node_type(files) == PLIST_DICT)) { | ||
| 1245 | plist_dict_iter iter = NULL; | ||
| 1246 | plist_dict_new_iter(files, &iter); | ||
| 1247 | if (iter) { | ||
| 1248 | /* loop over Files entries in Manifest data plist */ | ||
| 1249 | char *hash = NULL; | ||
| 1250 | int file_ok = 0; | ||
| 1251 | int total_files = plist_dict_get_size(files); | ||
| 1252 | int cur_file = 1; | ||
| 1253 | node = NULL; | ||
| 1254 | plist_dict_next_item(files, iter, &hash, &node); | ||
| 1255 | while (node) { | ||
| 1256 | printf("Sending files %d/%d (%d%%) \r", cur_file, total_files, (cur_file*100/total_files)); | ||
| 1257 | cur_file++; | ||
| 1258 | |||
| 1259 | /* TODO: read mddata/mdinfo files and send to device using DLSendFile */ | ||
| 1260 | /* TODO: if all hunks of a file are sent, device must send ack */ | ||
| 1261 | /* err = mobilebackup_receive_restore_file_received(mobilebackup, &result); */ | ||
| 1262 | node = NULL; | ||
| 1263 | free(hash); | ||
| 1264 | hash = NULL; | ||
| 1265 | if (!file_ok) { | ||
| 1266 | break; | ||
| 1267 | } | ||
| 1268 | plist_dict_next_item(files, iter, &hash, &node); | ||
| 1269 | } | ||
| 1270 | printf("\n"); | ||
| 1271 | free(iter); | ||
| 1272 | if (!file_ok) { | ||
| 1273 | plist_free(backup_data); | ||
| 1274 | break; | ||
| 1275 | } | ||
| 1276 | } | ||
| 1277 | } | ||
| 1278 | /* TODO: observe notification_proxy id com.apple.mobile.application_installed */ | ||
| 1279 | /* TODO: loop over Applications entries in Manifest data plist */ | ||
| 1233 | /* send AppInfo entries */ | 1280 | /* send AppInfo entries */ |
| 1234 | /* receive com.apple.mobile.application_installed notification */ | 1281 | /* receive com.apple.mobile.application_installed notification */ |
| 1235 | /* receive BackupMessageRestoreApplicationReceived from device */ | 1282 | /* receive BackupMessageRestoreApplicationReceived from device */ |
| 1283 | plist_free(backup_data); | ||
| 1284 | |||
| 1236 | /* signal restore finished message to device; BackupMessageRestoreComplete */ | 1285 | /* signal restore finished message to device; BackupMessageRestoreComplete */ |
| 1237 | /* close down notification_proxy connection */ | 1286 | err = mobilebackup_send_restore_complete(mobilebackup); |
| 1287 | if (err != MOBILEBACKUP_E_SUCCESS) { | ||
| 1288 | printf("ERROR: Could not send BackupMessageRestoreComplete, error code %d\n", err); | ||
| 1289 | } | ||
| 1290 | /* TODO: close down notification_proxy connection */ | ||
| 1238 | /* close down lockdown connection as it is no longer needed */ | 1291 | /* close down lockdown connection as it is no longer needed */ |
| 1239 | lockdownd_client_free(client); | 1292 | lockdownd_client_free(client); |
| 1240 | client = NULL; | 1293 | client = NULL; |
