diff options
| author | 2010-06-10 03:14:39 +0200 | |
|---|---|---|
| committer | 2010-06-10 03:14:39 +0200 | |
| commit | 5a00e7f1794c873475c32ea7aa125c09d3249359 (patch) | |
| tree | 09dd88477c4203608e616f888c524852a346fb72 | |
| parent | ca9b622a9e8f3386f53c417f32c5303416b6800f (diff) | |
| download | libimobiledevice-5a00e7f1794c873475c32ea7aa125c09d3249359.tar.gz libimobiledevice-5a00e7f1794c873475c32ea7aa125c09d3249359.tar.bz2 | |
idevicebackup: Finish implementing sending application data for restore
| -rw-r--r-- | tools/idevicebackup.c | 71 |
1 files changed, 68 insertions, 3 deletions
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c index 87a404e..b9fb81a 100644 --- a/tools/idevicebackup.c +++ b/tools/idevicebackup.c | |||
| @@ -1378,9 +1378,74 @@ int main(int argc, char *argv[]) | |||
| 1378 | } | 1378 | } |
| 1379 | /* TODO: observe notification_proxy id com.apple.mobile.application_installed */ | 1379 | /* TODO: observe notification_proxy id com.apple.mobile.application_installed */ |
| 1380 | /* TODO: loop over Applications entries in Manifest data plist */ | 1380 | /* TODO: loop over Applications entries in Manifest data plist */ |
| 1381 | /* send AppInfo entries */ | 1381 | plist_t applications = plist_dict_get_item(backup_data, "Applications"); |
| 1382 | /* receive com.apple.mobile.application_installed notification */ | 1382 | if (applications && (plist_get_node_type(applications) == PLIST_DICT) && restore_ok) { |
| 1383 | /* receive BackupMessageRestoreApplicationReceived from device */ | 1383 | plist_dict_iter iter = NULL; |
| 1384 | plist_dict_new_iter(applications, &iter); | ||
| 1385 | if (iter) { | ||
| 1386 | /* loop over Application entries in Manifest data plist */ | ||
| 1387 | char *hash = NULL; | ||
| 1388 | int total_files = plist_dict_get_size(applications); | ||
| 1389 | int cur_file = 1; | ||
| 1390 | plist_t tmp_node = NULL; | ||
| 1391 | plist_t dict = NULL; | ||
| 1392 | plist_t array = NULL; | ||
| 1393 | node = NULL; | ||
| 1394 | plist_dict_next_item(applications, iter, &hash, &node); | ||
| 1395 | while (node) { | ||
| 1396 | printf("Restoring Application %s %d/%d (%d%%)...", hash, cur_file, total_files, (cur_file*100/total_files)); | ||
| 1397 | /* FIXME: receive com.apple.mobile.application_installed notification */ | ||
| 1398 | /* send AppInfo entry */ | ||
| 1399 | tmp_node = plist_dict_get_item(node, "AppInfo"); | ||
| 1400 | |||
| 1401 | dict = plist_new_dict(); | ||
| 1402 | plist_dict_insert_item(dict, "AppInfo", plist_copy(tmp_node)); | ||
| 1403 | plist_dict_insert_item(dict, "BackupMessageTypeKey", plist_new_string("BackupMessageRestoreApplicationSent")); | ||
| 1404 | |||
| 1405 | array = plist_new_array(); | ||
| 1406 | plist_array_append_item(array, plist_new_string("DLMessageProcessMessage")); | ||
| 1407 | plist_array_append_item(array, dict); | ||
| 1408 | |||
| 1409 | err = mobilebackup_send(mobilebackup, array); | ||
| 1410 | if (err != MOBILEBACKUP_E_SUCCESS) { | ||
| 1411 | printf("ERROR: Unable to restore application %s due to error %d. Aborting...\n", hash, err); | ||
| 1412 | restore_ok = 0; | ||
| 1413 | } | ||
| 1414 | |||
| 1415 | plist_free(array); | ||
| 1416 | array = NULL; | ||
| 1417 | dict = NULL; | ||
| 1418 | |||
| 1419 | /* receive BackupMessageRestoreApplicationReceived from device */ | ||
| 1420 | if (restore_ok) { | ||
| 1421 | err = mobilebackup_receive_restore_application_received(mobilebackup, NULL); | ||
| 1422 | if (err != MOBILEBACKUP_E_SUCCESS) { | ||
| 1423 | printf("ERROR: Failed to receive an ack from the device for this application due to error %d. Aborting...\n", err); | ||
| 1424 | restore_ok = 0; | ||
| 1425 | } | ||
| 1426 | } | ||
| 1427 | |||
| 1428 | tmp_node = NULL; | ||
| 1429 | node = NULL; | ||
| 1430 | free(hash); | ||
| 1431 | hash = NULL; | ||
| 1432 | |||
| 1433 | if (restore_ok) { | ||
| 1434 | printf("DONE\n"); | ||
| 1435 | cur_file++; | ||
| 1436 | plist_dict_next_item(applications, iter, &hash, &node); | ||
| 1437 | } else | ||
| 1438 | break; | ||
| 1439 | } | ||
| 1440 | free(iter); | ||
| 1441 | |||
| 1442 | if (restore_ok) | ||
| 1443 | printf("All applications restored.\n"); | ||
| 1444 | else | ||
| 1445 | printf("Failed to restore applications.\n"); | ||
| 1446 | } | ||
| 1447 | } | ||
| 1448 | |||
| 1384 | plist_free(backup_data); | 1449 | plist_free(backup_data); |
| 1385 | 1450 | ||
| 1386 | /* signal restore finished message to device; BackupMessageRestoreComplete */ | 1451 | /* signal restore finished message to device; BackupMessageRestoreComplete */ |
