tool has nicer .. progress

This commit is contained in:
Carsten Haitzler 2014-11-26 22:03:38 +09:00
parent 4345456ff4
commit 83983c560a
4 changed files with 40 additions and 11 deletions

32
mrk.c
View File

@ -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"))

View File

@ -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

View File

@ -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");

View File

@ -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;
}