2020-12-27 22:33:23 +00:00
|
|
|
#include "gptmenu.h"
|
2022-01-22 00:59:17 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <bdk.h>
|
2020-12-27 22:33:23 +00:00
|
|
|
#include "../gfx/gfx.h"
|
|
|
|
#include "../gfx/menu.h"
|
|
|
|
#include "../gfx/gfxutils.h"
|
|
|
|
#include "../utils/vector.h"
|
|
|
|
#include "mountmanager.h"
|
|
|
|
#include "../fs/menus/explorer.h"
|
|
|
|
#include "../err.h"
|
|
|
|
#include "../tegraexplorer/tconf.h"
|
2020-12-30 21:51:07 +00:00
|
|
|
#include "emmcfile.h"
|
|
|
|
#include "../fs/fsutils.h"
|
2020-12-31 11:55:26 +00:00
|
|
|
#include "../utils/utils.h"
|
2020-12-27 22:33:23 +00:00
|
|
|
|
|
|
|
MenuEntry_t GptMenuHeader[] = {
|
|
|
|
{.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "<- Back"},
|
2020-12-30 21:51:07 +00:00
|
|
|
{.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "Clipboard -> Partition\n"},
|
|
|
|
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "BOOT0", .icon = 128, .showSize = 1, .size = 4, .sizeDef = 2},
|
|
|
|
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "BOOT1", .icon = 128, .showSize = 1, .size = 4, .sizeDef = 2}
|
2020-12-27 22:33:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const char *GptFSEntries[] = {
|
|
|
|
"PRODINFOF",
|
|
|
|
"SAFE",
|
|
|
|
"SYSTEM",
|
|
|
|
"USER"
|
|
|
|
};
|
|
|
|
|
|
|
|
void GptMenu(u8 MMCType){
|
|
|
|
if (connectMMC(MMCType))
|
|
|
|
return;
|
|
|
|
|
2020-12-31 11:55:26 +00:00
|
|
|
GptMenuHeader[1].optionUnion = (TConf.explorerCopyMode == CMODE_Copy) ? (COLORTORGB(COLOR_ORANGE)) : (COLORTORGB(COLOR_GREY) | SKIPBIT);
|
|
|
|
|
2020-12-27 22:33:23 +00:00
|
|
|
Vector_t GptMenu = newVec(sizeof(MenuEntry_t), 15);
|
2020-12-30 21:51:07 +00:00
|
|
|
GptMenu.count = ARR_LEN(GptMenuHeader);
|
2020-12-27 22:33:23 +00:00
|
|
|
memcpy(GptMenu.data, GptMenuHeader, sizeof(MenuEntry_t) * ARR_LEN(GptMenuHeader));
|
|
|
|
|
|
|
|
link_t *gpt = GetCurGPT();
|
|
|
|
|
|
|
|
LIST_FOREACH_ENTRY(emmc_part_t, part, gpt, link) {
|
|
|
|
MenuEntry_t entry = {.optionUnion = COLORTORGB(COLOR_VIOLET), .icon = 128, .name = part->name};
|
|
|
|
u64 total = (part->lba_end - part->lba_start) / 2 + 1;
|
|
|
|
u8 type = 1;
|
|
|
|
while (total > 1024){
|
|
|
|
total /= 1024;
|
|
|
|
type++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type > 3)
|
|
|
|
type = 3;
|
|
|
|
|
|
|
|
entry.showSize = 1;
|
|
|
|
entry.size = total;
|
|
|
|
entry.sizeDef = type;
|
|
|
|
|
|
|
|
for (int i = 0; i < ARR_LEN(GptFSEntries); i++){
|
|
|
|
if (!strcmp(part->name, GptFSEntries[i])){
|
|
|
|
entry.optionUnion = COLORTORGB(COLOR_WHITE);
|
|
|
|
entry.icon = 127;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vecAddElem(&GptMenu, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
vecDefArray(MenuEntry_t*, entries, GptMenu);
|
|
|
|
int res = 0;
|
|
|
|
while (1){
|
|
|
|
gfx_clearscreen();
|
|
|
|
gfx_printf((MMCType == MMC_CONN_EMMC) ? "-- Emmc --\n\n" : "-- Emummc --\n\n");
|
|
|
|
|
|
|
|
res = newMenu(&GptMenu, res, 40, 20, ALWAYSREDRAW | ENABLEB, GptMenu.count);
|
|
|
|
|
2020-12-31 11:55:26 +00:00
|
|
|
if (res < 1){
|
2020-12-27 22:33:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-12-31 11:55:26 +00:00
|
|
|
else if (res == 1){
|
|
|
|
gfx_clearscreen();
|
|
|
|
char *fileName = CpyStr(strrchr(TConf.srcCopy, '/') + 1);
|
|
|
|
|
|
|
|
gfx_printf("Are you sure you want to flash %s? ", fileName);
|
|
|
|
if (MakeYesNoHorzMenu(3, COLOR_DEFAULT)){
|
|
|
|
RESETCOLOR;
|
|
|
|
gfx_printf("\nFlashing %s... ", fileName);
|
|
|
|
ErrCode_t a = DumpOrWriteEmmcPart(TConf.srcCopy, fileName, 1, 0);
|
|
|
|
if (a.err){
|
|
|
|
if (a.err == TE_WARN_FILE_TOO_SMALL_FOR_DEST){
|
|
|
|
gfx_printf("\r%s is too small for the destination. Flash anyway? ", fileName);
|
|
|
|
if (MakeYesNoHorzMenu(3, COLOR_DEFAULT)){
|
|
|
|
RESETCOLOR;
|
|
|
|
gfx_printf("\nFlashing %s... ", fileName);
|
|
|
|
a = DumpOrWriteEmmcPart(TConf.srcCopy, fileName, 1, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
a.err = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DrawError(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(fileName);
|
|
|
|
}
|
2020-12-27 22:33:23 +00:00
|
|
|
else if (entries[res].icon == 127){
|
|
|
|
unmountMMCPart();
|
2021-05-23 22:57:58 +01:00
|
|
|
ErrCode_t err = (TConf.keysDumped) ? mountMMCPart(entries[res].name) : newErrCode(TE_ERR_KEYDUMP_FAIL);
|
2020-12-27 22:33:23 +00:00
|
|
|
if (err.err){
|
|
|
|
DrawError(err);
|
|
|
|
}
|
|
|
|
else {
|
2021-05-23 22:57:58 +01:00
|
|
|
if (TConf.curExplorerLoc > LOC_SD)
|
|
|
|
ResetCopyParams();
|
2020-12-28 01:29:58 +00:00
|
|
|
|
2021-05-23 22:57:58 +01:00
|
|
|
TConf.curExplorerLoc = LOC_EMMC;
|
|
|
|
FileExplorer("bis:/");
|
2020-12-27 22:33:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-12-30 21:51:07 +00:00
|
|
|
if (!sd_mount())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gfx_clearscreen();
|
|
|
|
gfx_printf("Do you want to dump %s? ", entries[res].name);
|
|
|
|
if (MakeYesNoHorzMenu(3, COLOR_DEFAULT)){
|
|
|
|
gfx_putc('\n');
|
|
|
|
RESETCOLOR;
|
|
|
|
gfx_printf("Dumping %s... ", entries[res].name);
|
|
|
|
|
|
|
|
f_mkdir("sd:/tegraexplorer");
|
|
|
|
f_mkdir("sd:/tegraexplorer/Dumps");
|
|
|
|
|
|
|
|
char *path = CombinePaths("sd:/tegraexplorer/Dumps", entries[res].name);
|
|
|
|
|
2020-12-31 11:55:26 +00:00
|
|
|
ErrCode_t a = DumpOrWriteEmmcPart(path, entries[res].name, 0, 0);
|
|
|
|
if (a.err){
|
|
|
|
if (a.err == TE_WARN_FILE_EXISTS){
|
|
|
|
gfx_printf("\rDest file for %s exists already. Overwrite? ", entries[res].name);
|
|
|
|
if (MakeYesNoHorzMenu(3, COLOR_DEFAULT)){
|
|
|
|
RESETCOLOR;
|
|
|
|
gfx_printf("\nDumping %s... ", entries[res].name);
|
|
|
|
a = DumpOrWriteEmmcPart(path, entries[res].name, 0, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
a.err = 0;
|
|
|
|
}
|
|
|
|
}
|
2020-12-30 21:51:07 +00:00
|
|
|
DrawError(a);
|
2020-12-31 11:55:26 +00:00
|
|
|
}
|
2020-12-30 21:51:07 +00:00
|
|
|
}
|
2020-12-27 22:33:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(GptMenu.data);
|
|
|
|
}
|