2020-03-18 22:58:32 +00:00
# include <string.h>
# include "entrymenu.h"
# include "../common/common.h"
# include "../../libs/fatfs/ff.h"
# include "../../gfx/gfx.h"
# include "fsutils.h"
# include "fsactions.h"
# include "../utils/utils.h"
# include "../gfx/gfxutils.h"
# include "../../mem/heap.h"
# include "fsreader.h"
# include "../gfx/menu.h"
# include "../common/types.h"
# include "../../utils/sprintf.h"
2020-03-31 13:24:34 +01:00
# include "../script/parser.h"
2020-03-19 15:11:18 +00:00
# include "../emmc/emmcoperations.h"
2020-05-02 00:41:43 +01:00
# include "../../hid/hid.h"
2020-05-04 12:55:26 +01:00
# include "../utils/menuUtils.h"
2020-05-08 23:22:35 +01:00
# include "savesign.h"
2020-03-18 22:58:32 +00:00
extern char * currentpath ;
extern char * clipboard ;
extern u8 clipboardhelper ;
extern int launch_payload ( char * path ) ;
int delfile ( const char * path , const char * filename ) {
gfx_clearscreen ( ) ;
SWAPCOLOR ( COLOR_ORANGE ) ;
2020-05-02 13:06:56 +01:00
gfx_printf ( " Are you sure you want to delete: \n %s \n \n Press B to cancel \n " , filename ) ;
2020-05-03 01:00:04 +01:00
if ( gfx_makewaitmenu ( " Press A to delete " , 2 ) ) {
2020-03-18 22:58:32 +00:00
f_unlink ( path ) ;
fsreader_readfolder ( currentpath ) ;
return 0 ;
}
else
return - 1 ;
}
void viewbytes ( char * path ) {
FIL in ;
2020-05-02 15:40:40 +01:00
u8 * print ;
2020-03-18 22:58:32 +00:00
u32 size ;
QWORD offset = 0 ;
int res ;
2020-05-02 00:41:43 +01:00
Inputs * input = hidRead ( ) ;
2020-05-02 20:56:49 +01:00
while ( input - > buttons & ( KEY_POW | KEY_B ) )
hidRead ( ) ;
2020-03-18 22:58:32 +00:00
gfx_clearscreen ( ) ;
2020-05-02 15:40:40 +01:00
print = malloc ( 1024 ) ;
2020-05-02 00:41:43 +01:00
2020-03-18 22:58:32 +00:00
if ( ( res = f_open ( & in , path , FA_READ | FA_OPEN_EXISTING ) ) ) {
gfx_errDisplay ( " viewbytes " , res , 1 ) ;
return ;
}
while ( 1 ) {
f_lseek ( & in , offset * 16 ) ;
2020-05-02 15:40:40 +01:00
if ( ( res = f_read ( & in , print , 1024 * sizeof ( u8 ) , & size ) ) ) {
2020-03-18 22:58:32 +00:00
gfx_errDisplay ( " viewbytes " , res , 2 ) ;
return ;
}
gfx_con_setpos ( 0 , 31 ) ;
gfx_hexdump ( offset * 16 , print , size * sizeof ( u8 ) ) ;
2020-05-02 00:41:43 +01:00
input = hidRead ( ) ;
2020-03-18 22:58:32 +00:00
2020-05-02 00:41:43 +01:00
if ( ! ( input - > buttons ) )
input = hidWait ( ) ;
2020-03-18 22:58:32 +00:00
2020-05-02 00:41:43 +01:00
if ( input - > Ldown & & 1024 * sizeof ( u8 ) = = size )
2020-03-18 22:58:32 +00:00
offset + + ;
2020-05-02 00:41:43 +01:00
if ( input - > Lup & & offset > 0 )
2020-03-18 22:58:32 +00:00
offset - - ;
2020-05-02 00:41:43 +01:00
if ( input - > buttons & ( KEY_POW | KEY_B ) )
2020-03-18 22:58:32 +00:00
break ;
}
f_close ( & in ) ;
2020-05-02 15:40:40 +01:00
free ( print ) ;
2020-03-18 22:58:32 +00:00
}
void copyfile ( const char * src_in , const char * outfolder ) {
char * in , * out , * filename ;
int res ;
gfx_clearscreen ( ) ;
utils_copystring ( src_in , & in ) ;
utils_copystring ( strrchr ( in , ' / ' ) + 1 , & filename ) ;
utils_copystring ( fsutil_getnextloc ( outfolder , filename ) , & out ) ;
gfx_printf ( " Note: \n To stop the transfer hold Vol- \n \n %s \n Progress: " , filename ) ;
if ( ! strcmp ( in , out ) ) {
gfx_errDisplay ( " gfxcopy " , ERR_SAME_LOC , 1 ) ;
return ;
}
if ( clipboardhelper & OPERATIONMOVE ) {
if ( ( res = f_rename ( in , out ) ) ) {
gfx_errDisplay ( " gfxcopy " , res , 2 ) ;
return ;
}
}
else if ( clipboardhelper & OPERATIONCOPY ) {
if ( fsact_copy ( in , out , COPY_MODE_CANCEL | COPY_MODE_PRINT ) )
return ;
}
else {
gfx_errDisplay ( " gfxcopy " , ERR_EMPTY_CLIPBOARD , 3 ) ;
return ;
}
free ( in ) ;
free ( out ) ;
free ( filename ) ;
fsreader_readfolder ( currentpath ) ;
}
int filemenu ( menu_entry file ) {
int temp ;
2020-05-04 12:55:26 +01:00
char * tempchar ;
2020-03-18 22:58:32 +00:00
2020-05-04 12:55:26 +01:00
/*
for ( int i = 0 ; i < 2 ; i + + )
2020-03-18 22:58:32 +00:00
if ( fs_menu_file [ i ] . name ! = NULL )
free ( fs_menu_file [ i ] . name ) ;
utils_copystring ( file . name , & fs_menu_file [ 0 ] . name ) ;
2020-05-04 12:55:26 +01:00
*/
mu_copySingle ( file . name , fs_menu_file [ 0 ] . storage , fs_menu_file [ 0 ] . property , & fs_menu_file [ 0 ] ) ;
2020-03-18 22:58:32 +00:00
2020-05-04 12:55:26 +01:00
if ( fs_menu_file [ 1 ] . name ! = NULL )
free ( fs_menu_file [ 1 ] . name ) ;
fs_menu_file [ 1 ] . name = malloc ( 16 ) ;
sprintf ( fs_menu_file [ 1 ] . name , " \n Size: %d %s " , file . storage , gfx_file_size_names [ file . size ] ) ;
if ( ( tempchar = fsutil_formatFileAttribs ( fsutil_getnextloc ( currentpath , file . name ) ) ) = = NULL )
fs_menu_file [ 2 ] . isHide = 1 ;
2020-03-18 22:58:32 +00:00
else {
2020-05-04 12:55:26 +01:00
fs_menu_file [ 2 ] . isHide = 0 ;
mu_copySingle ( tempchar , fs_menu_file [ 2 ] . storage , fs_menu_file [ 2 ] . property , & fs_menu_file [ 2 ] ) ;
2020-03-18 22:58:32 +00:00
}
2020-05-04 12:55:26 +01:00
fs_menu_file [ 6 ] . isHide = ! hidConnected ( ) ;
fs_menu_file [ 8 ] . isHide = ( ! ( strstr ( file . name , " .bin " ) ! = NULL & & file . size = = 1 ) & & strstr ( file . name , " .rom " ) = = NULL ) ;
fs_menu_file [ 9 ] . isHide = ( strstr ( file . name , " .te " ) = = NULL ) ;
fs_menu_file [ 11 ] . isHide = ( strstr ( file . name , " .bis " ) = = NULL ) ;
2020-05-08 23:22:35 +01:00
fs_menu_file [ 12 ] . isHide = ( ! ! strcmp ( currentpath , " emmc:/save " ) ) ;
2020-05-04 12:55:26 +01:00
/*
2020-05-02 19:53:13 +01:00
SETBIT ( fs_menu_file [ 6 ] . property , ISHIDE , ! hidConnected ( ) ) ;
2020-05-04 12:55:26 +01:00
SETBIT ( fs_menu_file [ 8 ] . property , ISHIDE , ! ( strstr ( file . name , " .bin " ) ! = NULL & & file . size = = 1 ) & & strstr ( file . name , " .rom " ) = = NULL ) ;
2020-05-02 15:40:40 +01:00
SETBIT ( fs_menu_file [ 9 ] . property , ISHIDE , strstr ( file . name , " .te " ) = = NULL ) ;
SETBIT ( fs_menu_file [ 11 ] . property , ISHIDE , strstr ( file . name , " .bis " ) = = NULL ) ;
2020-05-04 12:55:26 +01:00
*/
2020-03-18 22:58:32 +00:00
2020-05-08 23:22:35 +01:00
temp = menu_make ( fs_menu_file , 13 , " -- File Menu -- " ) ;
2020-03-18 22:58:32 +00:00
switch ( temp ) {
case FILE_COPY :
fsreader_writeclipboard ( fsutil_getnextloc ( currentpath , file . name ) , OPERATIONCOPY ) ;
break ;
case FILE_MOVE :
fsreader_writeclipboard ( fsutil_getnextloc ( currentpath , file . name ) , OPERATIONMOVE ) ;
break ;
case FILE_DELETE :
delfile ( fsutil_getnextloc ( currentpath , file . name ) , file . name ) ;
break ;
2020-05-02 15:40:40 +01:00
case FILE_RENAME : ;
char * name , * curPath ;
gfx_clearscreen ( ) ;
gfx_printf ( " Renaming %s... \n \n " , file . name ) ;
2020-05-02 19:53:13 +01:00
name = utils_InputText ( file . name , 39 ) ;
2020-05-02 15:40:40 +01:00
if ( name = = NULL )
break ;
utils_copystring ( fsutil_getnextloc ( currentpath , file . name ) , & curPath ) ;
2020-05-02 16:31:00 +01:00
temp = f_rename ( curPath , fsutil_getnextloc ( currentpath , name ) ) ;
2020-05-02 15:40:40 +01:00
free ( curPath ) ;
free ( name ) ;
2020-05-02 16:31:00 +01:00
if ( temp ) {
gfx_errDisplay ( " fileMenu " , temp , 0 ) ;
break ;
}
2020-05-02 15:40:40 +01:00
break ;
2020-03-18 22:58:32 +00:00
case FILE_PAYLOAD :
launch_payload ( fsutil_getnextloc ( currentpath , file . name ) ) ;
break ;
case FILE_SCRIPT :
2020-03-30 19:15:07 +01:00
//ParseScript(fsutil_getnextloc(currentpath, file.name));
2020-05-02 23:30:05 +01:00
/*
2020-05-02 22:35:25 +01:00
gfx_printf ( " %kRelease any buttons if held! " , COLOR_RED ) ;
while ( hidRead ( ) - > buttons ) ;
2020-05-02 23:30:05 +01:00
*/
2020-05-02 22:35:25 +01:00
2020-04-01 15:48:36 +01:00
runScript ( fsutil_getnextloc ( currentpath , file . name ) ) ;
2020-03-18 22:58:32 +00:00
break ;
case FILE_HEXVIEW :
viewbytes ( fsutil_getnextloc ( currentpath , file . name ) ) ;
break ;
case FILE_DUMPBIS :
2020-03-19 15:11:18 +00:00
gfx_clearscreen ( ) ;
extract_bis_file ( fsutil_getnextloc ( currentpath , file . name ) , currentpath ) ;
2020-05-02 13:06:56 +01:00
hidWait ( ) ;
2020-05-08 23:22:35 +01:00
break ;
case FILE_SIGN :
if ( gfx_defaultWaitMenu ( " WARNING! \n \n This should only be used if you know what signing and a save is \n Do not do this if you don't know what this does \n \n Requires you to have a prod.keys located in the switch folder \n " , 5 ) ) {
gfx_clearscreen ( ) ;
gfx_printf ( " Signing save... \n " ) ;
if ( save_sign ( " sd:/switch/prod.keys " , fsutil_getnextloc ( currentpath , file . name ) ) ) {
gfx_printf ( " Done! \n Press any key to exit " ) ;
hidWait ( ) ;
}
}
2020-03-18 22:58:32 +00:00
break ;
2020-03-22 21:56:36 +00:00
case - 1 :
return - 1 ;
2020-03-18 22:58:32 +00:00
}
2020-05-19 16:54:21 +01:00
fsreader_readfolder ( currentpath ) ;
2020-03-18 22:58:32 +00:00
return 0 ;
}