summaryrefslogtreecommitdiffstats
path: root/src/irecovery.c
diff options
context:
space:
mode:
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 {
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));