Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
networkfusion committed Mar 19, 2024
1 parent ec708de commit 646c107
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
38 changes: 26 additions & 12 deletions src/menu/cpak_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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) {

// }

// void try_repair_pak() {
cpak_err_t cpak_overwrite_contents_from_file(char *path, uint8_t port) {
// TODO: implementation.
return CONTROLLER_PAK_ERR_IO;
}

// }
cpak_err_t cpak_attempt_repair() {
// TODO: implementation.
return CONTROLLER_PAK_ERR_IO;
}
19 changes: 18 additions & 1 deletion src/menu/cpak_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/menu/views/joypad_controller_pak.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 646c107

Please sign in to comment.