summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/utils.c22
-rw-r--r--common/utils.h1
-rw-r--r--tools/idevicebackup.c27
-rw-r--r--tools/idevicebackup2.c25
4 files changed, 30 insertions, 45 deletions
diff --git a/common/utils.c b/common/utils.c
index f95ecfd..4a45d95 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -139,6 +139,28 @@ char *string_build_path(const char *elem, ...)
139 return out; 139 return out;
140} 140}
141 141
142char *string_format_size(uint64_t size)
143{
144 char buf[80];
145 double sz;
146 if (size >= 1000000000000LL) {
147 sz = ((double)size / 1000000000000.0f);
148 sprintf(buf, "%0.1f TB", sz);
149 } else if (size >= 1000000000LL) {
150 sz = ((double)size / 1000000000.0f);
151 sprintf(buf, "%0.1f GB", sz);
152 } else if (size >= 1000000LL) {
153 sz = ((double)size / 1000000.0f);
154 sprintf(buf, "%0.1f MB", sz);
155 } else if (size >= 1000LL) {
156 sz = ((double)size / 1000.0f);
157 sprintf(buf, "%0.1f KB", sz);
158 } else {
159 sprintf(buf, "%d Bytes", (int)size);
160 }
161 return strdup(buf);
162}
163
142char *string_toupper(char* str) 164char *string_toupper(char* str)
143{ 165{
144 char *res = strdup(str); 166 char *res = strdup(str);
diff --git a/common/utils.h b/common/utils.h
index 5cd4a53..97d3748 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -38,6 +38,7 @@ char *stpcpy(char *s1, const char *s2);
38#endif 38#endif
39char *string_concat(const char *str, ...); 39char *string_concat(const char *str, ...);
40char *string_build_path(const char *elem, ...); 40char *string_build_path(const char *elem, ...);
41char *string_format_size(uint64_t size);
41char *string_toupper(char *str); 42char *string_toupper(char *str);
42char *generate_uuid(); 43char *generate_uuid();
43 44
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c
index 8260de6..195f837 100644
--- a/tools/idevicebackup.c
+++ b/tools/idevicebackup.c
@@ -224,25 +224,6 @@ static void notify_cb(const char *notification, void *userdata)
224 } 224 }
225} 225}
226 226
227static char* format_size_for_display(uint64_t size)
228{
229 char buf[32];
230 double sz;
231 if (size >= 1000000000LL) {
232 sz = ((double)size / 1000000000.0f);
233 sprintf(buf, "%0.1f GB", sz);
234 } else if (size >= 1000000LL) {
235 sz = ((double)size / 1000000.0f);
236 sprintf(buf, "%0.1f MB", sz);
237 } else if (size >= 1000LL) {
238 sz = ((double)size / 1000.0f);
239 sprintf(buf, "%0.1f kB", sz);
240 } else {
241 sprintf(buf, "%d Bytes", (int)size);
242 }
243 return strdup(buf);
244}
245
246static plist_t mobilebackup_factory_info_plist_new(const char* udid) 227static plist_t mobilebackup_factory_info_plist_new(const char* udid)
247{ 228{
248 /* gather data from lockdown */ 229 /* gather data from lockdown */
@@ -1037,7 +1018,7 @@ int main(int argc, char *argv[])
1037 node = plist_dict_get_item(node_tmp, "BackupTotalSizeKey"); 1018 node = plist_dict_get_item(node_tmp, "BackupTotalSizeKey");
1038 if (node) { 1019 if (node) {
1039 plist_get_uint_val(node, &backup_total_size); 1020 plist_get_uint_val(node, &backup_total_size);
1040 format_size = format_size_for_display(backup_total_size); 1021 format_size = string_format_size(backup_total_size);
1041 printf("Backup data requires %s on the disk.\n", format_size); 1022 printf("Backup data requires %s on the disk.\n", format_size);
1042 free(format_size); 1023 free(format_size);
1043 } 1024 }
@@ -1067,15 +1048,15 @@ int main(int argc, char *argv[])
1067 plist_get_uint_val(node, &file_size); 1048 plist_get_uint_val(node, &file_size);
1068 backup_real_size += file_size; 1049 backup_real_size += file_size;
1069 1050
1070 format_size = format_size_for_display(backup_real_size); 1051 format_size = string_format_size(backup_real_size);
1071 printf("(%s", format_size); 1052 printf("(%s", format_size);
1072 free(format_size); 1053 free(format_size);
1073 1054
1074 format_size = format_size_for_display(backup_total_size); 1055 format_size = string_format_size(backup_total_size);
1075 printf("/%s): ", format_size); 1056 printf("/%s): ", format_size);
1076 free(format_size); 1057 free(format_size);
1077 1058
1078 format_size = format_size_for_display(file_size); 1059 format_size = string_format_size(file_size);
1079 printf("Receiving file %s (%s)... \n", filename_source, format_size); 1060 printf("Receiving file %s (%s)... \n", filename_source, format_size);
1080 free(format_size); 1061 free(format_size);
1081 1062
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c
index 4fe5751..a43cbda 100644
--- a/tools/idevicebackup2.c
+++ b/tools/idevicebackup2.c
@@ -189,25 +189,6 @@ static int mkdir_with_parents(const char *dir, int mode)
189 return res; 189 return res;
190} 190}
191 191
192static char* format_size_for_display(uint64_t size)
193{
194 char buf[32];
195 double sz;
196 if (size >= 1000000000LL) {
197 sz = ((double)size / 1000000000.0f);
198 sprintf(buf, "%0.1f GB", sz);
199 } else if (size >= 1000000LL) {
200 sz = ((double)size / 1000000.0f);
201 sprintf(buf, "%0.1f MB", sz);
202 } else if (size >= 1000LL) {
203 sz = ((double)size / 1000.0f);
204 sprintf(buf, "%0.1f kB", sz);
205 } else {
206 sprintf(buf, "%d Bytes", (int)size);
207 }
208 return strdup(buf);
209}
210
211static plist_t mobilebackup_factory_info_plist_new(const char* udid, lockdownd_client_t lockdown, afc_client_t afc) 192static plist_t mobilebackup_factory_info_plist_new(const char* udid, lockdownd_client_t lockdown, afc_client_t afc)
212{ 193{
213 /* gather data from lockdown */ 194 /* gather data from lockdown */
@@ -404,10 +385,10 @@ static void print_progress(uint64_t current, uint64_t total)
404 385
405 print_progress_real((double)progress, 0); 386 print_progress_real((double)progress, 0);
406 387
407 format_size = format_size_for_display(current); 388 format_size = string_format_size(current);
408 PRINT_VERBOSE(1, " (%s", format_size); 389 PRINT_VERBOSE(1, " (%s", format_size);
409 free(format_size); 390 free(format_size);
410 format_size = format_size_for_display(total); 391 format_size = string_format_size(total);
411 PRINT_VERBOSE(1, "/%s) ", format_size); 392 PRINT_VERBOSE(1, "/%s) ", format_size);
412 free(format_size); 393 free(format_size);
413 394
@@ -543,7 +524,7 @@ static int mb2_handle_send_file(mobilebackup2_client_t mobilebackup2, const char
543 524
544 total = fst.st_size; 525 total = fst.st_size;
545 526
546 char *format_size = format_size_for_display(total); 527 char *format_size = string_format_size(total);
547 PRINT_VERBOSE(1, "Sending '%s' (%s)\n", path, format_size); 528 PRINT_VERBOSE(1, "Sending '%s' (%s)\n", path, format_size);
548 free(format_size); 529 free(format_size);
549 530