Skip to content

Commit

Permalink
Improved error checking and cleaned up interface
Browse files Browse the repository at this point in the history
Thanks RandalHoffman/@lorilith for the file error check.
  • Loading branch information
zoogie authored and zoogie committed Oct 5, 2018
1 parent f3d8e2d commit 7790d92
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TOPDIR ?= $(CURDIR)
include $(DEVKITARM)/3ds_rules

APP_TITLE = Frogtool
APP_DESCRIPTION = Frogminer title manager
APP_DESCRIPTION = v1.1 - Frogminer title manager
APP_AUTHOR = zoogie

#---------------------------------------------------------------------------------
Expand Down
63 changes: 45 additions & 18 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
PrintConsole topScreen, bottomScreen;
AM_TWLPartitionInfo info;

const char *bkblack="\x1b[40;1m";
const char *green="\x1b[32;1m";
const char *yellow="\x1b[33;1m";
const char *bkyellow="\x1b[43;1m";
const char *blue="\x1b[34;1m";
const char *dblue="\x1b[34;0m";
const char *white="\x1b[37;1m";
const char *dwhite="\x1b[37;0m";

Result import(u64 tid, u8 op, u8 *workbuf, char *ext){
Handle handle;
Result res;
Expand All @@ -20,6 +29,11 @@ Result import(u64 tid, u8 op, u8 *workbuf, char *ext){

memset(fpath, 0, 64);
sprintf(fpath,"sdmc:/%08lX%s",(u32)tid, ext);
if(access(fpath, F_OK ) == -1 ) {
printf("%s missing on SD\n\n",fpath);
return 1;

}
memset(filepath16, 0, sizeof(filepath16));
units = utf8_to_utf16(filepath16, (u8*)(fpath+5), len);

Expand All @@ -30,6 +44,7 @@ Result import(u64 tid, u8 op, u8 *workbuf, char *ext){
printf("import:%d %s\n", op, fpath);
res = FSUSER_OpenFileDirectly(&handle, ARCHIVE_SDMC, archPath, filePath, FS_OPEN_READ, 0);
printf("fsopen: %08X\n",(int)res);
printf("importing dsiware...\n");
res = AM_ImportTwlBackup(handle, op, workbuf, 0x20000);
printf("twl import: %08X %s\n\n",(int)res, res ? "FAILED!" : "SUCCESS!");
FSFILE_Close(handle);
Expand All @@ -43,10 +58,10 @@ Result export(u64 tid, u8 op, u8 *workbuf, char *ext){
memset(fpath, 0, 128);
sprintf(fpath,"sdmc:/%08lX%s",(u32)tid, ext);
if(access(fpath, F_OK ) != -1 ) {
printf("DS dlp already exists on SD\n");
printf("DS dlp already exists on SD\n\n");
return 1;
}
printf("export:%d %016llX to %s\n", op, tid, fpath);
printf("exporting:%d %016llX to\n%s...\n", op, tid, fpath);
res = AM_ExportTwlBackup(tid, op, workbuf, 0x20000, fpath);
printf("twl export: %08X %s\n\n",(int)res, res ? "FAILED!" : "SUCCESS!");

Expand All @@ -55,37 +70,49 @@ Result export(u64 tid, u8 op, u8 *workbuf, char *ext){

Result menuUpdate(int cursor, int showinfo){
consoleClear();
printf("Frogtool v1.0 - zoogie\n\n");
printf("%sFrogtool v1.1 - zoogie%s\n\n", green, white);
char menu[menu_size][128] = {
"IMPORT patched DS Download Play",
"EXPORT clean DS Download Play",
"IMPORT patched DS Download Play",
"BOOT patched DS Download Play",
"RESTORE clean DS Download Play",
"BOOT patched DS Download Play"
};

for(int i=0;i<menu_size;i++){
printf("%s %s\n", cursor == i ? "->" : " ", menu[i]);
printf("%s %s%s\n", cursor == i ? bkyellow : bkblack, menu[i], bkblack);
}

printf("\nPress START to exit\n\n");
printf("\n%sPress START to exit%s\n\n", green, white);

if(!showinfo){
consoleSelect(&bottomScreen);
consoleClear();
printf("TWL PARTITION INFO\n");
printf(" Bytes Blocks\n");
printf("Capacity: 0x%08lX %04d\n",(u32)info.capacity,(int)info.capacity/0x20000);
printf("FreeSpace: 0x%08lX %04d\n",(u32)info.freeSpace,(int)info.freeSpace/0x20000);
printf("TitlesCapacity: 0x%08lX %04d\n",(u32)info.titlesCapacity,(int)info.titlesCapacity/0x20000);
printf("TitlesFreeSpace: 0x%08lX %04d\n",(u32)info.titlesFreeSpace,(int)info.titlesFreeSpace/0x20000);
printf("%sTWL PARTITION INFO Bytes Blocks%s", green, white);
printf("Capacity: 0x%08lX %04d\n",(u32)info.capacity,(int)info.capacity/0x20000);
printf("FreeSpace: 0x%08lX %04d\n",(u32)info.freeSpace,(int)info.freeSpace/0x20000);
printf("TitlesCapacity: 0x%08lX %04d\n",(u32)info.titlesCapacity,(int)info.titlesCapacity/0x20000);
printf("TitlesFreeSpace: 0x%08lX %04d\n\n\n\n",(u32)info.titlesFreeSpace,(int)info.titlesFreeSpace/0x20000);
printf("%s\n\n\n\n\n", green);
printf(" ** **\n");
printf(" * **** *\n");
printf(" * **** *\n");
printf(" ********\n");
printf(" **********\n");
printf(" ** **\n");
printf(" *** ***\n");
printf(" **** ****\n");
printf(" **** ****\n");
printf(" ************\n");
//printf(" Gero!\n");
printf("%s\n", white);
consoleSelect(&topScreen);
}

return 0;
}

Result waitKey(){
printf("\nTap bottom screen to continue ...\n");
printf("\nTap the %sFrog%s to continue ...\n", green, white);

while(1){
gspWaitForVBlank();
Expand Down Expand Up @@ -139,12 +166,12 @@ int main(int argc, char* argv[])
break; // break in order to return to hbmenu
if(kDown & KEY_A){
switch(cursor){
case 0: import(tid, op, buf, ".bin.patched"); break;
case 1: export(tid, op, buf, ".bin"); break;
case 2: import(tid, op, buf, ".bin"); break;
case 3: printf("Booting dlp now ...\n");
case 0: export(tid, op, buf, ".bin"); break;
case 1: import(tid, op, buf, ".bin.patched"); break;
case 2: printf("Booting dlp now ...\n");
NS_RebootToTitle(0, tid);
while(1)gspWaitForVBlank();
case 3: import(tid, op, buf, ".bin"); break;
default:;
}
waitKey();
Expand Down

0 comments on commit 7790d92

Please sign in to comment.