diff --git a/source/editprofile.c b/source/editprofile.c index bb6b093..6d8dd1c 100644 --- a/source/editprofile.c +++ b/source/editprofile.c @@ -5,17 +5,6 @@ Result edit_profile(int profile_num, bool fusion_mode, u32 lowid, InstallType install_type) { - FS_MediaType media_type = (install_type == SD_CARD) ? MEDIATYPE_SD : MEDIATYPE_GAME_CARD; - // Open save archive - const u32 path[3] = { media_type, lowid, 0x00040000 }; - - FS_Archive save_archive; - FS_ArchiveID archive_id = (install_type == SD_CARD) ? ARCHIVE_USER_SAVEDATA : ARCHIVE_GAMECARD_SAVEDATA; - - Result res; - res = FSUSER_OpenArchive(&save_archive, archive_id, (FS_Path){PATH_BINARY, 12, path}); - if(R_FAILED(res)) return res; - char profile_path[0x107] = {0}; sprintf(profile_path, "/profile%i/pkprfl.bmssv", profile_num); printf("%s\n", profile_path); @@ -23,6 +12,7 @@ Result edit_profile(int profile_num, bool fusion_mode, u32 lowid, InstallType in // Open file Handle file_handle; + Result res; res = FSUSER_OpenFile(&file_handle, save_archive, fsMakePath(PATH_ASCII, profile_path), FS_OPEN_WRITE | FS_OPEN_READ, 0); if(R_FAILED(res)) { diff --git a/source/main.c b/source/main.c index ddfb859..88bbae3 100644 --- a/source/main.c +++ b/source/main.c @@ -4,6 +4,8 @@ #include "title.h" #include "const.h" #include "struct.h" +#include "save.h" +#include "main.h" int main() { @@ -22,6 +24,9 @@ int main() bool save_unseen = true; bool fusion_unseen = true; bool region_autochecked = false; + FS_Archive save_archive; + Result res; + SavesList saves_list; InstallType install_type; u32 lowid; @@ -96,22 +101,42 @@ int main() case SELECT_SAVE: // Save file selection if (save_unseen) { - printf("\n---------------------\nSelect a save file to modify.\nY for save 1, B for save 2, X for save 3.\nPress START to exit.\n"); + res = open_archive(lowid, install_type, &save_archive); + if(R_FAILED(res)) + { + fail_print(&res); + state = SUCCESS; + } + + saves_list = save_check(&save_archive); + if (saves_list.profile0) + { + printf("Press Y to select save 1.\n"); + } + if (saves_list.profile1) + { + printf("Press B to select save 2.\n"); + } + if (saves_list.profile2) + { + printf("Press X to select save 3.\n"); + } + // printf("\n---------------------\nSelect a save file to modify.\nY for save 1, B for save 2, X for save 3.\nPress START to exit.\n"); save_unseen = false; } - if (kDown & KEY_Y) // Save 1 was chosen + if (kDown & KEY_Y && saves_list.profile0) // Save 1 was chosen { profile_num = 0; printf("You selected the 1st save file.\n"); state = FUSION_OR_NOT; } - if (kDown & KEY_B) // Save 2 was chosen + if (kDown & KEY_B && saves_list.profile1) // Save 2 was chosen { profile_num = 1; printf("You selected the 2nd save file.\n"); state = FUSION_OR_NOT; } - if (kDown & KEY_X) // Save 3 was chosen + if (kDown & KEY_X && saves_list.profile2) // Save 3 was chosen { profile_num = 2; printf("You selected the 3rd save file.\n"); @@ -143,8 +168,7 @@ int main() Result res = edit_profile(profile_num, fusion_mode, lowid, install_type); if(R_FAILED(res)) { - printf("\x1b[s\x1b[30;16H%4lx\n\x1b[u", res); - printf("Something went wrong, please see the error message below.\n"); + fail_print(&res); } else { @@ -166,4 +190,10 @@ int main() cfguExit(); gfxExit(); return 0; +} + +void fail_print(Result* res) +{ + printf("\x1b[s\x1b[30;16H%4lx\n\x1b[u", *res); + printf("Something went wrong, please see the error message below.\n"); } \ No newline at end of file diff --git a/source/main.h b/source/main.h new file mode 100644 index 0000000..39af227 --- /dev/null +++ b/source/main.h @@ -0,0 +1,10 @@ +#include +#include <3ds.h> +#include "editprofile.h" +#include "title.h" +#include "const.h" +#include "struct.h" +#include "save.h" + +int main(); +void fail_print(Result* res); \ No newline at end of file diff --git a/source/save.c b/source/save.c new file mode 100644 index 0000000..8f88881 --- /dev/null +++ b/source/save.c @@ -0,0 +1,74 @@ +#include <3ds.h> +#include +#include +#include "struct.h" +#include "save.h" + +Result open_archive(u32 lowid, InstallType install_type, FS_Archive* save_archive) +{ + FS_MediaType media_type = (install_type == SD_CARD) ? MEDIATYPE_SD : MEDIATYPE_GAME_CARD; + const u32 path[3] = { media_type, lowid, 0x00040000 }; + + FS_ArchiveID archive_id = (install_type == SD_CARD) ? ARCHIVE_USER_SAVEDATA : ARCHIVE_GAMECARD_SAVEDATA; + + Result res; + res = FSUSER_OpenArchive(save_archive, archive_id, (FS_Path){PATH_BINARY, 12, path}); + if(R_FAILED(res)) return res; + + return 0; +} + +SavesList save_check(FS_Archive* save_archive) +{ + Result res; + SavesList saves_list = {false, false, false}; + + for (int i = 0; i < 3; ++i) + { + bool exist = file_check(i, save_archive); + if (exist) + { + saves_list.total_saves++; + } + switch(i) + { + case 0: + saves_list.profile0 = exist; + break; + + case 1: + saves_list.profile1 = exist; + break; + + case 2: + saves_list.profile2 = exist; + break; + } + } + + return saves_list; +} + +bool file_check(int i, FS_Archive* save_archive) +{ + char profile_path[0x107] = {0}; + sprintf(profile_path, "/profile%i/pkprfl.bmssv", i); + printf("%s\n", profile_path); + + // Open file + Handle file_handle; + + Result res; + res = FSUSER_OpenFile(&file_handle, *save_archive, fsMakePath(PATH_ASCII, profile_path), FS_OPEN_WRITE | FS_OPEN_READ, 0); + if(R_FAILED(res)) + { + return false; + } + FSFILE_Close(file_handle); + return true; +} + +Result open_file() +{ + +} diff --git a/source/save.h b/source/save.h new file mode 100644 index 0000000..cae6e24 --- /dev/null +++ b/source/save.h @@ -0,0 +1,13 @@ +#ifndef _SAVEH_ +#define _SAVEH_ + +#include <3ds.h> +#include +#include +#include "struct.h" + +Result open_archive(u32 lowid, InstallType install_type, FS_Archive* save_archive); +SavesList save_check(FS_Archive* save_archive); +bool file_check(int i, FS_Archive* save_archive); + +#endif \ No newline at end of file diff --git a/source/struct.h b/source/struct.h index 16e8bb6..a6e449e 100644 --- a/source/struct.h +++ b/source/struct.h @@ -8,10 +8,18 @@ typedef struct { int total_regions; } Regions; +typedef struct { + bool profile0; + bool profile1; + bool profile2; + int total_saves; +} SavesList; + typedef enum { MAIN_SCREEN, VERSION_TO_EDIT, SELECT_SAVE, + READ_SAVE, FUSION_OR_NOT, THE_WIZARD_IS_BUSY, SUCCESS