From d0384341feec0915645ecf650a15cbd716faae43 Mon Sep 17 00:00:00 2001 From: "Thomas \"Cakeisalie5\" Touhey" Date: Sat, 28 Jan 2017 12:53:39 +0100 Subject: [PATCH] Should have implemented getting. --- src/p7os/main.c | 19 ++++++++----------- src/p7os/prepare.c | 11 +++-------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/p7os/main.c b/src/p7os/main.c index fdf8ec8..8048242 100644 --- a/src/p7os/main.c +++ b/src/p7os/main.c @@ -61,15 +61,13 @@ int main(int ac, char **av) p7_handle_t *handle = NULL; int err; if (args.com) err = p7_cominit(&handle, initflags, args.com); else err = p7_init(&handle, initflags); - if (err) goto init_error; + if (err) goto fail; /* prepare */ if (!args.noprepare) { /* make the preparation thing */ - if (prepare_ops(handle, args.uexe)) { - if (args.local) fclose(args.local); - return (1); - } + if ((err = prepare_ops(handle, args.uexe))) + goto fail; handle = NULL; /* was only about preparing? */ @@ -82,7 +80,7 @@ int main(int ac, char **av) /* re-open the handle */ if (args.com) err = p7_cominit(&handle, initflags, args.com); else err = p7_init(&handle, initflags); - if (err) goto init_error; + if (err) goto fail; } /* check according to menu */ @@ -90,10 +88,9 @@ int main(int ac, char **av) /* backup the thing menu */ case mn_get: /* get the os */ - fprintf(stderr, "Unimplemented, yet.\n"); err = 1; + err = p7_backup_rom(handle, args.local); + if (err) goto fail; fclose(args.local); - /* if there was an error, delete created file */ - if (err) remove(args.localpath); break; } @@ -103,9 +100,9 @@ int main(int ac, char **av) /* then we're good */ return (0); -init_error: +fail: /* displaying error */ - switch (err) { + if (err > 0) switch (err) { case p7_error_nocalc: log(error_noconnexion); break; case p7_error_noaccess: log(error_noaccess); break; case p7_error_unsupported: log(error_unsupported); break; diff --git a/src/p7os/prepare.c b/src/p7os/prepare.c index eb94637..89e0eac 100644 --- a/src/p7os/prepare.c +++ b/src/p7os/prepare.c @@ -12,10 +12,6 @@ /* ************************************************************************** */ /* Error messages */ /* ************************************************************************** */ -/* Generic error */ -static const char error_gen[] = -"An error has occured: %s\n"; - /* Unable to open the embedded thingy */ static const char error_fmemopen[] = "Unable to open the embedded update.exe.\n"; @@ -37,7 +33,7 @@ extern char _binary_cake_exe_bin_end[]; * * @arg handle the libp7 handle. * @arg uexe the update.exe to use (NULL if use the embedded one). - * @return if something went wrong (0 if ok). + * @return the error (-1 if not a libp7 error, 0 if ok) */ int prepare_ops(p7_handle_t *handle, FILE *uexe) @@ -56,16 +52,15 @@ int prepare_ops(p7_handle_t *handle, FILE *uexe) uexe = fmemopen(cake_exe_str, usize, "r"); if (!uexe) { fprintf(stderr, error_fmemopen); - return (1); + return (-1); } } /* send the thing */ if ((err = p7_sendexe_stream(handle, uexe, (p7uint_t)usize, 0x88030000, 0x88030000))) { - fprintf(stderr, error_gen, p7_strerror(err)); fclose(uexe); - return (1); + return (err); } /* no error! */