From 02dbcc01f5ea54c5e5672b1c84bc1d454b650da8 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Tue, 19 Mar 2024 23:00:32 +0000 Subject: [PATCH] Improve repair function --- src/menu/cpak_handler.c | 16 +++++++++++++--- src/menu/cpak_handler.h | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/menu/cpak_handler.c b/src/menu/cpak_handler.c index 9165f898..bc896a8e 100644 --- a/src/menu/cpak_handler.c +++ b/src/menu/cpak_handler.c @@ -61,7 +61,17 @@ cpak_err_t cpak_overwrite_contents_from_file(char *path, uint8_t port) { return CONTROLLER_PAK_ERR_IO; } -cpak_err_t cpak_attempt_repair() { - // TODO: implementation. - return CONTROLLER_PAK_ERR_IO; +cpak_err_t cpak_attempt_repair(uint8_t port, bool allow_formatting) { + int result = validate_mempak(port); + if (result == CONTROLLER_PAK_OK) { + return CONTROLLER_PAK_OK; + } + + // TODO: repair implementation. + + // last resort would be to format it completely! + if (result == -3 && allow_formatting) { + result = format_mempak(port); + } + return result; } diff --git a/src/menu/cpak_handler.h b/src/menu/cpak_handler.h index a30aef28..82c36607 100644 --- a/src/menu/cpak_handler.h +++ b/src/menu/cpak_handler.h @@ -28,6 +28,6 @@ typedef struct { cpak_err_t cpak_info_load(uint8_t port, cpak_info_t *cpak_info); int cpak_clone_contents_to_file(char *path, uint8_t port); cpak_err_t cpak_overwrite_contents_from_file(char *path, uint8_t port); -cpak_err_t cpak_attempt_repair(); +cpak_err_t cpak_attempt_repair(uint8_t port, bool allow_formatting); #endif