From b65a7ce7ebca6730fce5dcbfd820d8ef4124e18f Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Wed, 7 Nov 2012 22:08:53 +0100 Subject: libidevicerecovery: implemented progress callback logic --- src/asr.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/asr.c') diff --git a/src/asr.c b/src/asr.c index 401bc51..96d7396 100644 --- a/src/asr.c +++ b/src/asr.c @@ -27,6 +27,7 @@ #include "asr.h" #include "idevicerestore.h" +#include "common.h" #define ASR_VERSION 1 #define ASR_STREAM_ID 1 @@ -103,6 +104,15 @@ int asr_open_with_timeout(idevice_t device, asr_client_t* asr) { return 0; } +void asr_set_progress_callback(asr_client_t asr, asr_progress_cb_t cbfunc, void* userdata) +{ + if (!asr) { + return; + } + asr->progress_cb = cbfunc; + asr->progress_cb_data = userdata; +} + int asr_receive(asr_client_t asr, plist_t* data) { uint32_t size = 0; char* buffer = NULL; @@ -387,8 +397,11 @@ int asr_send_payload(asr_client_t asr, const char* filesystem) { } bytes += size; - progress = ((double) bytes/ (double) length) * 100.0; - print_progress_bar(progress); + progress = ((double) bytes/ (double) length); + if (asr->progress_cb && ((int)(progress*100) > asr->lastprogress)) { + asr->progress_cb(progress, asr->progress_cb_data); + asr->lastprogress = (int)(progress*100); + } } // if last chunk wasn't terminated with a checksum we do it here -- cgit v1.1-32-gdbae