summaryrefslogtreecommitdiffstats
path: root/src/irecovery.c
diff options
context:
space:
mode:
authorGravatar Joshua Hill2010-06-06 18:52:47 -0400
committerGravatar Joshua Hill2010-06-06 18:52:47 -0400
commit09caab6993bfe2e696ab47776189a4216547c6a9 (patch)
tree3a409e309d5c20327b3e93dddc71d6bc43124f82 /src/irecovery.c
parentff1d99f386c9a0667d5f4056ab8ffaba70e91324 (diff)
downloadlibirecovery-09caab6993bfe2e696ab47776189a4216547c6a9.tar.gz
libirecovery-09caab6993bfe2e696ab47776189a4216547c6a9.tar.bz2
Moved progress bar into irecovery and finished implementing progress notications
Diffstat (limited to 'src/irecovery.c')
-rw-r--r--src/irecovery.c38
1 files changed, 38 insertions, 0 deletions
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));