diff options
author | Joshua Hill | 2010-06-06 18:52:47 -0400 |
---|---|---|
committer | Joshua Hill | 2010-06-06 18:52:47 -0400 |
commit | 09caab6993bfe2e696ab47776189a4216547c6a9 (patch) | |
tree | 3a409e309d5c20327b3e93dddc71d6bc43124f82 | |
parent | ff1d99f386c9a0667d5f4056ab8ffaba70e91324 (diff) | |
download | libirecovery-09caab6993bfe2e696ab47776189a4216547c6a9.tar.gz libirecovery-09caab6993bfe2e696ab47776189a4216547c6a9.tar.bz2 |
Moved progress bar into irecovery and finished implementing progress notications
-rw-r--r-- | include/libirecovery.h | 1 | ||||
-rw-r--r-- | src/irecovery.c | 38 | ||||
-rw-r--r-- | src/libirecovery.c | 38 |
3 files changed, 43 insertions, 34 deletions
diff --git a/include/libirecovery.h b/include/libirecovery.h index 0a99405..d01e022 100644 --- a/include/libirecovery.h +++ b/include/libirecovery.h @@ -54,6 +54,7 @@ typedef enum { typedef struct { int size; char* data; + double progress; irecv_event_type type; } irecv_event_t; diff --git a/src/irecovery.c b/src/irecovery.c index a763272..fcc745c 100644 --- a/src/irecovery.c +++ b/src/irecovery.c @@ -33,7 +33,9 @@ enum { static unsigned int quit = 0; static unsigned int verbose = 0; +void print_progress_bar(const char* operation, double progress); int received_cb(irecv_client_t client, const irecv_event_t* event); +int progress_cb(irecv_client_t client, const irecv_event_t* event); int precommand_cb(irecv_client_t client, const irecv_event_t* event); int postcommand_cb(irecv_client_t client, const irecv_event_t* event); @@ -89,6 +91,7 @@ void append_command_to_history(char* cmd) { void init_shell(irecv_client_t client) { irecv_error_t error = 0; load_command_history(); + irecv_event_subscribe(client, IRECV_PROGRESS, &progress_cb, NULL); irecv_event_subscribe(client, IRECV_RECEIVED, &received_cb, NULL); irecv_event_subscribe(client, IRECV_PRECOMMAND, &precommand_cb, NULL); irecv_event_subscribe(client, IRECV_POSTCOMMAND, &postcommand_cb, NULL); @@ -157,6 +160,39 @@ int postcommand_cb(irecv_client_t client, const irecv_event_t* event) { return 0; } +int progress_cb(irecv_client_t client, const irecv_event_t* event) { + if (event->type == IRECV_PROGRESS) { + print_progress_bar(event->data, event->progress); + } + return 0; +} + +void print_progress_bar(const char* operation, double progress) { + int i = 0; + if(progress < 0) { + return; + } + + if(progress > 100) { + progress = 100; + } + + printf("\r%s [", operation); + for(i = 0; i < 50; i++) { + if(i < progress / 2) { + printf("="); + } else { + printf(" "); + } + } + + printf("] %3.1f%%", progress); + fflush(stdout); + if(progress == 100) { + printf("\n"); + } +} + void print_usage() { printf("iRecovery - iDevice Recovery Utility\n"); printf("Usage: ./irecovery [args]\n"); @@ -238,6 +274,7 @@ int main(int argc, char** argv) { break; case kSendFile: + irecv_event_subscribe(client, IRECV_PROGRESS, &progress_cb, NULL); error = irecv_send_file(client, argument); debug("%s\n", irecv_strerror(error)); break; @@ -249,6 +286,7 @@ int main(int argc, char** argv) { case kSendExploit: if (argument != NULL) { + irecv_event_subscribe(client, IRECV_PROGRESS, &progress_cb, NULL); error = irecv_send_file(client, argument); if (error != IRECV_E_SUCCESS) { debug("%s\n", irecv_strerror(error)); diff --git a/src/libirecovery.c b/src/libirecovery.c index acf1d6b..4900fbf 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c @@ -324,8 +324,8 @@ irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, un } int i = 0; - double count = 0; double progress = 0; + unsigned int count = 0; unsigned int status = 0; for (i = 0; i < packets; i++) { int size = i + 1 < packets ? 0x800 : last; @@ -349,15 +349,12 @@ irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, un count += size; if(client->progress_callback != NULL) { irecv_event_t event; + event.progress = ((double) count/ (double) length) * 100.0; event.type = IRECV_PROGRESS; - event.data = NULL; - event.size = count/length; + event.data = "Uploading"; + event.size = count; client->progress_callback(client, &event); } - else if((count / (double) length) * 100.0 > progress) { - progress = (count / (double) length) * 100.0; - irecv_print_progress("Uploading", progress); - } } libusb_control_transfer(client->handle, 0x21, 1, 0, 0, buffer, 0, 1000); @@ -525,30 +522,3 @@ const char* irecv_strerror(irecv_error_t error) { return NULL; } - -void irecv_print_progress(const char* operation, float progress) { - int i = 0; - if(progress < 0) { - return; - } - - if(progress > 100) { - progress = 100; - } - - printf("\r%s [", operation); - for(i = 0; i < 50; i++) { - if(i < progress / 2) { - printf("="); - } else { - printf(" "); - } - } - - printf("] %3.1f%%", progress); - fflush(stdout); - if(progress == 100) { - printf("\n"); - } - -} |