summaryrefslogtreecommitdiffstats
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
parentff1d99f386c9a0667d5f4056ab8ffaba70e91324 (diff)
downloadlibirecovery-09caab6993bfe2e696ab47776189a4216547c6a9.tar.gz
libirecovery-09caab6993bfe2e696ab47776189a4216547c6a9.tar.bz2
Moved progress bar into irecovery and finished implementing progress notications
-rw-r--r--include/libirecovery.h1
-rw-r--r--src/irecovery.c38
-rw-r--r--src/libirecovery.c38
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 {
54typedef struct { 54typedef struct {
55 int size; 55 int size;
56 char* data; 56 char* data;
57 double progress;
57 irecv_event_type type; 58 irecv_event_type type;
58} irecv_event_t; 59} irecv_event_t;
59 60
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 {
33static unsigned int quit = 0; 33static unsigned int quit = 0;
34static unsigned int verbose = 0; 34static unsigned int verbose = 0;
35 35
36void print_progress_bar(const char* operation, double progress);
36int received_cb(irecv_client_t client, const irecv_event_t* event); 37int received_cb(irecv_client_t client, const irecv_event_t* event);
38int progress_cb(irecv_client_t client, const irecv_event_t* event);
37int precommand_cb(irecv_client_t client, const irecv_event_t* event); 39int precommand_cb(irecv_client_t client, const irecv_event_t* event);
38int postcommand_cb(irecv_client_t client, const irecv_event_t* event); 40int postcommand_cb(irecv_client_t client, const irecv_event_t* event);
39 41
@@ -89,6 +91,7 @@ void append_command_to_history(char* cmd) {
89void init_shell(irecv_client_t client) { 91void init_shell(irecv_client_t client) {
90 irecv_error_t error = 0; 92 irecv_error_t error = 0;
91 load_command_history(); 93 load_command_history();
94 irecv_event_subscribe(client, IRECV_PROGRESS, &progress_cb, NULL);
92 irecv_event_subscribe(client, IRECV_RECEIVED, &received_cb, NULL); 95 irecv_event_subscribe(client, IRECV_RECEIVED, &received_cb, NULL);
93 irecv_event_subscribe(client, IRECV_PRECOMMAND, &precommand_cb, NULL); 96 irecv_event_subscribe(client, IRECV_PRECOMMAND, &precommand_cb, NULL);
94 irecv_event_subscribe(client, IRECV_POSTCOMMAND, &postcommand_cb, NULL); 97 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) {
157 return 0; 160 return 0;
158} 161}
159 162
163int progress_cb(irecv_client_t client, const irecv_event_t* event) {
164 if (event->type == IRECV_PROGRESS) {
165 print_progress_bar(event->data, event->progress);
166 }
167 return 0;
168}
169
170void print_progress_bar(const char* operation, double progress) {
171 int i = 0;
172 if(progress < 0) {
173 return;
174 }
175
176 if(progress > 100) {
177 progress = 100;
178 }
179
180 printf("\r%s [", operation);
181 for(i = 0; i < 50; i++) {
182 if(i < progress / 2) {
183 printf("=");
184 } else {
185 printf(" ");
186 }
187 }
188
189 printf("] %3.1f%%", progress);
190 fflush(stdout);
191 if(progress == 100) {
192 printf("\n");
193 }
194}
195
160void print_usage() { 196void print_usage() {
161 printf("iRecovery - iDevice Recovery Utility\n"); 197 printf("iRecovery - iDevice Recovery Utility\n");
162 printf("Usage: ./irecovery [args]\n"); 198 printf("Usage: ./irecovery [args]\n");
@@ -238,6 +274,7 @@ int main(int argc, char** argv) {
238 break; 274 break;
239 275
240 case kSendFile: 276 case kSendFile:
277 irecv_event_subscribe(client, IRECV_PROGRESS, &progress_cb, NULL);
241 error = irecv_send_file(client, argument); 278 error = irecv_send_file(client, argument);
242 debug("%s\n", irecv_strerror(error)); 279 debug("%s\n", irecv_strerror(error));
243 break; 280 break;
@@ -249,6 +286,7 @@ int main(int argc, char** argv) {
249 286
250 case kSendExploit: 287 case kSendExploit:
251 if (argument != NULL) { 288 if (argument != NULL) {
289 irecv_event_subscribe(client, IRECV_PROGRESS, &progress_cb, NULL);
252 error = irecv_send_file(client, argument); 290 error = irecv_send_file(client, argument);
253 if (error != IRECV_E_SUCCESS) { 291 if (error != IRECV_E_SUCCESS) {
254 debug("%s\n", irecv_strerror(error)); 292 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
324 } 324 }
325 325
326 int i = 0; 326 int i = 0;
327 double count = 0;
328 double progress = 0; 327 double progress = 0;
328 unsigned int count = 0;
329 unsigned int status = 0; 329 unsigned int status = 0;
330 for (i = 0; i < packets; i++) { 330 for (i = 0; i < packets; i++) {
331 int size = i + 1 < packets ? 0x800 : last; 331 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
349 count += size; 349 count += size;
350 if(client->progress_callback != NULL) { 350 if(client->progress_callback != NULL) {
351 irecv_event_t event; 351 irecv_event_t event;
352 event.progress = ((double) count/ (double) length) * 100.0;
352 event.type = IRECV_PROGRESS; 353 event.type = IRECV_PROGRESS;
353 event.data = NULL; 354 event.data = "Uploading";
354 event.size = count/length; 355 event.size = count;
355 client->progress_callback(client, &event); 356 client->progress_callback(client, &event);
356 } 357 }
357 else if((count / (double) length) * 100.0 > progress) {
358 progress = (count / (double) length) * 100.0;
359 irecv_print_progress("Uploading", progress);
360 }
361 } 358 }
362 359
363 libusb_control_transfer(client->handle, 0x21, 1, 0, 0, buffer, 0, 1000); 360 libusb_control_transfer(client->handle, 0x21, 1, 0, 0, buffer, 0, 1000);
@@ -525,30 +522,3 @@ const char* irecv_strerror(irecv_error_t error) {
525 522
526 return NULL; 523 return NULL;
527} 524}
528
529void irecv_print_progress(const char* operation, float progress) {
530 int i = 0;
531 if(progress < 0) {
532 return;
533 }
534
535 if(progress > 100) {
536 progress = 100;
537 }
538
539 printf("\r%s [", operation);
540 for(i = 0; i < 50; i++) {
541 if(i < progress / 2) {
542 printf("=");
543 } else {
544 printf(" ");
545 }
546 }
547
548 printf("] %3.1f%%", progress);
549 fflush(stdout);
550 if(progress == 100) {
551 printf("\n");
552 }
553
554}