From d21328b4918d6ada3d6a28b18cdc91b1dca9835f Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Tue, 19 Mar 2024 16:42:06 +0000 Subject: [PATCH] Minor improvements --- src/menu/cpak_handler.c | 38 ++++++++++++++++++-------- src/menu/cpak_handler.h | 19 ++++++++++++- src/menu/views/joypad_controller_pak.c | 2 +- 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/menu/cpak_handler.c b/src/menu/cpak_handler.c index 9624fce8..3eadbd4e 100644 --- a/src/menu/cpak_handler.c +++ b/src/menu/cpak_handler.c @@ -7,7 +7,19 @@ #define CPAK_BLOCKS 128 #define CPAK_BLOCK_SIZE MEMPAK_BLOCK_SIZE -int clone_pak_content_to_file(char *path, uint8_t port) { +cpak_err_t cpak_info_load(uint8_t port, cpak_info_t *cpak_info) +{ + int res = validate_mempak(port); + if (res != CONTROLLER_PAK_OK) { + return CONTROLLER_PAK_ERR_INVALID; + } + + // TODO: implementation. + + return CONTROLLER_PAK_OK; +} + +int cpak_clone_contents_to_file(char *path, uint8_t port) { uint8_t cpak_data[CPAK_BLOCKS * CPAK_BLOCK_SIZE]; int err; for (int i = 0; i < CPAK_BLOCKS; i++) { @@ -20,25 +32,27 @@ int clone_pak_content_to_file(char *path, uint8_t port) { FIL fil; UINT bytes_written; if (f_open(&fil, strip_sd_prefix(path), FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) { - return 1; + return CONTROLLER_PAK_ERR_IO; } - FRESULT fw_err = f_write(&fil, &cpak_data, sizeof(cpak_data), &bytes_written); + FRESULT fwrite_err = f_write(&fil, &cpak_data, sizeof(cpak_data), &bytes_written); f_close(&fil); - if (fw_err) { - return fw_err; + if (fwrite_err) { + return fwrite_err; } else { - return 0; + return CONTROLLER_PAK_OK; } } -// void overwite_pak_content_from_file(char *path, uint8_t port) { +cpak_err_t cpak_overwrite_contents_from_file(char *path, uint8_t port) { + // TODO: implementation. + return CONTROLLER_PAK_ERR_IO; +} -// } - -// void try_repair_pak() { - -// } +cpak_err_t cpak_attempt_repair() { + // TODO: implementation. + return CONTROLLER_PAK_ERR_IO; +} diff --git a/src/menu/cpak_handler.h b/src/menu/cpak_handler.h index 796d8520..f154e884 100644 --- a/src/menu/cpak_handler.h +++ b/src/menu/cpak_handler.h @@ -10,6 +10,23 @@ #ifndef CPAK_HANDLER_H__ #define CPAK_HANDLER_H__ -int clone_pak_content_to_file(char *path, uint8_t port); +/** @brief Controller Pak state enumeration. */ +typedef enum { + CONTROLLER_PAK_OK, + CONTROLLER_PAK_ERR_IO, + CONTROLLER_PAK_ERR_NO_FILE, + CONTROLLER_PAK_ERR_INVALID, +} cpak_err_t; + +/** @brief Controller Pak Information Structure. */ +typedef struct { + // header + // pages +} cpak_info_t; + +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(); #endif diff --git a/src/menu/views/joypad_controller_pak.c b/src/menu/views/joypad_controller_pak.c index 40fd8755..34c146d4 100644 --- a/src/menu/views/joypad_controller_pak.c +++ b/src/menu/views/joypad_controller_pak.c @@ -14,7 +14,7 @@ static void process (menu_t *menu) { // TODO: handle all ports if (accessory_is_cpak[0]) { // TODO: preferably with the time added to the filename so it does not overwrite the existing one! - clone_pak_content_to_file("sd://cpak/cpak_backup.mpk", 0); + cpak_clone_contents_to_file("sd://cpak/cpak_backup.mpk", 0); } }