N64FlashcartMenu/src/menu/cpak_handler.c

45 lines
913 B
C
Raw Normal View History

2024-03-18 01:15:47 +01:00
#include <libdragon.h>
#include <fatfs/ff.h>
#include "../utils/fs.h"
#include "cpak_handler.h"
2024-03-18 02:14:09 +01:00
#define CPAK_BLOCKS 128
#define CPAK_BLOCK_SIZE MEMPAK_BLOCK_SIZE
2024-03-18 01:15:47 +01:00
2024-03-18 01:33:07 +01:00
int clone_pak_content_to_file(char *path, uint8_t port) {
2024-03-18 02:14:09 +01:00
uint8_t cpak_data[CPAK_BLOCKS * CPAK_BLOCK_SIZE];
2024-03-18 01:15:47 +01:00
int err;
2024-03-18 02:14:09 +01:00
for (int i = 0; i < CPAK_BLOCKS; i++) {
err = read_mempak_sector(port, i, &cpak_data[i * CPAK_BLOCK_SIZE]);
2024-03-18 01:15:47 +01:00
if (err) {
return err;
}
}
FIL fil;
UINT bytes_written;
if (f_open(&fil, strip_sd_prefix(path), FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) {
return 1;
}
2024-03-18 02:14:09 +01:00
FRESULT fw_err = f_write(&fil, &cpak_data, sizeof(cpak_data), &bytes_written);
2024-03-18 01:15:47 +01:00
f_close(&fil);
if (fw_err) {
return fw_err;
}
else {
return 0;
}
}
2024-03-18 02:14:09 +01:00
// void overwite_pak_content_from_file(char *path, uint8_t port) {
// }
// void try_repair_pak() {
// }