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