From 527ad26d20f49686039b2ba09ab8fe5a1338e235 Mon Sep 17 00:00:00 2001 From: anod <182859762@qq.com> Date: Wed, 18 Jan 2023 13:44:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=8E=B7=E5=8F=96rom?= =?UTF-8?q?=E7=9A=84=E8=AF=86=E5=88=AB=E7=A0=81=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/arm11/filebrowser.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/source/arm11/filebrowser.c b/source/arm11/filebrowser.c index 215d25c..e88ab76 100644 --- a/source/arm11/filebrowser.c +++ b/source/arm11/filebrowser.c @@ -260,6 +260,7 @@ atp_error_t select_region( atp_callerdata_t data, atp_counter_t index, atp_itemc extern atp_error_t oaf_config_page(); +#define DIRBUFFSIZE 512 #define WAIT_ON_ACT( act ) ( ATP_POWER_OFF == (act) ) ? ATP_POWER_OFF : ATP_PAGE_REFRESH #define WAIT_ON_ERRPAGE( page ) WAIT_ON_ACT( atp_show(1, (page), NULL) ) @@ -277,18 +278,36 @@ static atp_pageopt_t serve_on_key( atp_callerdata_t data, atp_counter_t index, a else if( x ) { DirList const *dList = (DirList*)data; - const char *file = &dList->ptrs[index][1]; + char *path = (char*)(data+1); + const char *file = &dList->ptrs[index][1]; + int pathlen = strlen(path); + int filelen = strlen(file); + + if( pathlen + filelen > DIRBUFFSIZE - 1) + { + return WAIT_ON_ERRPAGE( display_toolong ); + } + else if( ENT_TYPE_DIR == dList->ptrs[index][0] ) + { + return WAIT_ON_ERRPAGE( display_empty ); + } + + path[pathlen] = '/'; + safeStrcpy( path+pathlen+1, file, DIRBUFFSIZE - filelen ); + +#define RECOVER_PATH path[pathlen] = '\0' // 确定game serial char serial[5]; - if( RES_OK != rom_get_serial(file, serial) ) + if( RES_OK != rom_get_serial(path, serial) ) { + RECOVER_PATH; return WAIT_ON_ERRPAGE( display_noserial ); } - serial[4] = '\0'; + else RECOVER_PATH; acl_count_t len; - if( RES_OK != acl_open_lib( file ) ) + if( RES_OK != acl_open_lib( "gba.acl" ) ) { return WAIT_ON_ERRPAGE( display_openlib ); } @@ -312,12 +331,11 @@ static atp_pageopt_t serve_on_key( atp_callerdata_t data, atp_counter_t index, a res = atp_select("选择一个金手指配置", len, select_region, NULL, type, 0, 0, &item ); acl_close_lib(); - return ATP_PAGE_REFRESH; + return WAIT_ON_ACT( res ); } return ATP_PAGE_NOOPTION; } -#define DIRBUFFSIZE 512 #define PATH_SAME 0 #define PATH_PUSH 1 #define PATH_POP 2 @@ -367,7 +385,8 @@ Result browseFiles(const char *const basePath, char selected[512]) GFX_waitForVBlank0(); hidScanInput(); atp_tips( NULL, "指引:按START" ); - error = atp_select( curDir, count, display_folder, serve_on_key, (atp_callerdata_t)dList, selecting, 0, &value ); + void *cust[] = {dList, curDir}; + error = atp_select( curDir, count, display_folder, serve_on_key, (atp_callerdata_t)cust, selecting, 0, &value ); } else error = atp_show( 1, display_empty, NULL );