From 83983c560a44e8f6025893c8aae8db94c3370342 Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Wed, 26 Nov 2014 22:03:38 +0900 Subject: [PATCH] tool has nicer .. progress --- mrk.c | 32 ++++++++++++++++++++++++-------- mrklib.h | 2 +- mrklib_package.c | 12 +++++++++++- mrklib_svc.c | 5 ++++- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/mrk.c b/mrk.c index f75e4ca..d9b802f 100644 --- a/mrk.c +++ b/mrk.c @@ -30,24 +30,37 @@ _cb_disconnect(void *data, Mrk *server) _mrk_err("Disconnect\n"); } +static void +status(double pos) +{ + int i, p; + + p = pos * 60; + putchar('\r'); + putchar('['); + for (i = 0; i < p; i++) putchar('#'); + printf("] %2.1f%%", pos * 100.0); +} + static void _cb_upload_begin(void *data, Mrk *server) { - printf("["); + status(0.0); fflush(stdout); } static void _cb_upload_progress(void *data, Mrk *server, double pos) { - printf("%1.02f_", pos); + status(pos); fflush(stdout); } static void _cb_upload_end(void *data, Mrk *server) { - printf("]\n"); + status(1.0); + printf("\n"); fflush(stdout); } @@ -61,21 +74,22 @@ _cb_upload_success(void *data, Mrk *server, Eina_Bool success) static void _cb_download_begin(void *data, Mrk *server) { - printf("["); + status(0.0); fflush(stdout); } static void _cb_download_progress(void *data, Mrk *server, double pos) { - printf("%1.02f_", pos); + status(pos); fflush(stdout); } static void _cb_download_end(void *data, Mrk *server) { - printf("]\n"); + status(1.0); + printf("\n"); fflush(stdout); } @@ -100,7 +114,8 @@ _cb_download_success(void *data, Mrk *server, const char *file) } else if (install_bin) { - if (!mrk_package_bin_install(file)) _mrk_err("Failed to install\n"); + if (!mrk_package_bin_install(file, os, arch)) + _mrk_err("Failed to install\n"); if (!mrk_package_bin_clean()) _mrk_err("Failed to clean\n"); ecore_file_unlink(file); } @@ -209,7 +224,8 @@ main(int argc, char **argv) else if (!strcmp(argv[1], "inst")) { if (argc < 2) _mrk_err("Must provide FILE.MKB\n"); - if (!mrk_package_bin_install(argv[2])) _mrk_err("Failed to install\n"); + if (!mrk_package_bin_install(argv[2], os, arch)) + _mrk_err("Failed to install\n"); if (!mrk_package_bin_clean()) _mrk_err("Failed to clean\n"); } else if (!strcmp(argv[1], "clean")) diff --git a/mrklib.h b/mrklib.h index ac87880..3d0e839 100644 --- a/mrklib.h +++ b/mrklib.h @@ -133,7 +133,7 @@ EAPI Eina_Bool mrk_build_package_src(Mrk_Build *bld, const char *buildfile, con EAPI Eina_Bool mrk_package_src_extract(const char *file, const char *dst); EAPI Eina_Bool mrk_package_bin_clean(void); -EAPI Eina_Bool mrk_package_bin_install(const char *file); +EAPI Eina_Bool mrk_package_bin_install(const char *file, const char *os, const char *arch); EAPI Eina_Bool mrk_package_bin_remove(const char *name); // XXX: .mrk parsing api handled/exposed and other related functions diff --git a/mrklib_package.c b/mrklib_package.c index a355317..25154d4 100644 --- a/mrklib_package.c +++ b/mrklib_package.c @@ -156,7 +156,7 @@ mrk_package_bin_clean(void) } EAPI Eina_Bool -mrk_package_bin_install(const char *file) +mrk_package_bin_install(const char *file, const char *os, const char *arch) { Eet_File *ef, *ef2; #define err(reason) do { fprintf(stderr, "%s\n", reason); goto error; } while (0) @@ -173,7 +173,17 @@ mrk_package_bin_install(const char *file) char *s; Eina_List *files; char *name; + char *str; + str = read_string(ef, "arch"); + if (!str) err("no arch"); + snprintf(tmp, sizeof(tmp), "%s-%s", os, arch); + if (strcmp(tmp, str)) + { + free(str); + err("arch mismatch\n"); + } + free(str); name = read_string(ef, "name"); if (!name) err("no name"); if (!_mrk_util_plain_file_check(name)) err("name failed sanity check"); diff --git a/mrklib_svc.c b/mrklib_svc.c index c6a8a7f..0532e3d 100644 --- a/mrklib_svc.c +++ b/mrklib_svc.c @@ -191,11 +191,14 @@ fail: } else if ((e->minor == M_DOWN_DATA) || (e->minor == M_SRC_DATA)) { + double pos = 0.5; + + if (e->ref_to > 0) pos = (double)e->ref / (double)e->ref_to; if ((server->f) && (e->data) && (e->size > 0) && (e->size <= 10000)) { fwrite(e->data, e->size, 1, server->f); if (server->func.download_progress) - server->func.download_progress(server->data.download_progress, server, 0.5); + server->func.download_progress(server->data.download_progress, server, pos); } return EINA_TRUE; }