mirror of
https://gitee.com/anod/open_agb_firm.git
synced 2025-05-09 23:34:11 +08:00
修改显示正确的页码
在文件目录过大的时候警示
This commit is contained in:
parent
e8c98d6d02
commit
9a9721f3c2
@ -68,7 +68,7 @@ const char *acf_put_text(int x, int y, int width, int height, int maxwidth, u8 c
|
||||
//---------------------------------------------------
|
||||
|
||||
#define CONTAINER_LEFTTOP_X 20
|
||||
#define CONTAINER_LEFTTOP_Y 15
|
||||
#define CONTAINER_LEFTTOP_Y 10
|
||||
#define CONTAINER_RECT_WIDTH 282
|
||||
#define CONTAINER_MAX_LINES 13
|
||||
#define WINDOW_WIDTH 320
|
||||
@ -189,7 +189,7 @@ static void set_paging( int top, int len )
|
||||
unsigned total = (len+CONTAINER_MAX_LINES-1) / CONTAINER_MAX_LINES;
|
||||
unsigned current = top / CONTAINER_MAX_LINES;
|
||||
char buf[PAGING_BUFSIZE+1];
|
||||
ee_snprintf( buf, PAGING_BUFSIZE, "页码:%d/%d", top, len );
|
||||
ee_snprintf( buf, PAGING_BUFSIZE, "页码:%d/%d", current+1, total );
|
||||
buf[PAGING_BUFSIZE] = '\0';
|
||||
atp_tips( buf, NULL );
|
||||
|
||||
|
@ -34,19 +34,11 @@
|
||||
// Notes on these settings:
|
||||
// MAX_ENT_BUF_SIZE should be big enough to hold the average file/dir name length * MAX_DIR_ENTRIES.
|
||||
#define MAX_ENT_BUF_SIZE (1024u * 196) // 196 KiB.
|
||||
#define MAX_DIR_ENTRIES (1000u)
|
||||
#define MAX_DIR_ENTRIES (999u)
|
||||
#define DIR_READ_BLOCKS (10u)
|
||||
|
||||
//#define SCREEN_COLS (53u - 1) // - 1 because the console inserts a newline after the last line otherwise.
|
||||
//#define SCREEN_ROWS (24u)
|
||||
#define SCREEN_COLS 19
|
||||
#define SCREEN_ROWS 14u
|
||||
|
||||
#define LINENO_TO_Y(y) 15+(y)*15
|
||||
#define CWIDTH 320u
|
||||
#define CHEIGHT 240u
|
||||
#define CLEFTMARGIN 20u
|
||||
#define CLINELIMIT 282u
|
||||
|
||||
#define ENT_TYPE_FILE (0)
|
||||
#define ENT_TYPE_DIR (1)
|
||||
@ -85,6 +77,7 @@ static Result scanDir(const char *const path, DirList *const dList, const char *
|
||||
|
||||
Result res;
|
||||
DHandle dh;
|
||||
u32 received;
|
||||
if((res = fOpenDir(&dh, path)) == RES_OK)
|
||||
{
|
||||
u32 read; // Number of entries read by fReadDir().
|
||||
@ -94,6 +87,7 @@ static Result scanDir(const char *const path, DirList *const dList, const char *
|
||||
do
|
||||
{
|
||||
if((res = fReadDir(dh, fis, DIR_READ_BLOCKS, &read)) != RES_OK) break;
|
||||
received = numEntries + read;
|
||||
read = (read <= MAX_DIR_ENTRIES - numEntries ? read : MAX_DIR_ENTRIES - numEntries);
|
||||
|
||||
for(u32 i = 0; i < read; i++)
|
||||
@ -139,16 +133,16 @@ scanEnd:
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
return received > MAX_DIR_ENTRIES ? RES_OUT_OF_RANGE : res;
|
||||
}
|
||||
|
||||
static atp_text_t folder_help[] = {
|
||||
"操 作 说 明",
|
||||
"~ ~ ~ ~ ~ ~ ~",
|
||||
"蓝色 文件夹",
|
||||
"白色 游戏文件",
|
||||
"蓝色 目录",
|
||||
"白色 游戏",
|
||||
"~ ~ ~ ~ ~ ~ ~",
|
||||
"A键 查看文件夹或运行游戏",
|
||||
"A键 查看目录或启动游戏",
|
||||
"B键 上层文件夹",
|
||||
"X键 金手指",
|
||||
"Y键 游戏设置",
|
||||
@ -167,13 +161,17 @@ static atp_error_t display_folder( atp_callerdata_t data, atp_counter_t index, a
|
||||
return ATP_SUCCESS;
|
||||
}
|
||||
|
||||
static atp_error_t display_empty( atp_callerdata_t, atp_counter_t, atp_linecfg_t *config )
|
||||
{
|
||||
config->text = "没有合适的文件";
|
||||
config->text_align = ATP_PLACEMENT_CENTER;
|
||||
config->text_color = ATP_COLOR_RED;
|
||||
return ATP_SUCCESS;
|
||||
}
|
||||
#define DECLARE_ERROR_PAGE(name, message) static atp_error_t name (atp_callerdata_t, atp_counter_t, atp_linecfg_t *c) \
|
||||
{ \
|
||||
c->text = message; \
|
||||
c->text_align = ATP_PLACEMENT_CENTER; \
|
||||
c->text_color = ATP_COLOR_RED; \
|
||||
return ATP_SUCCESS; \
|
||||
}
|
||||
|
||||
DECLARE_ERROR_PAGE( display_empty, "没有合适的文件" )
|
||||
DECLARE_ERROR_PAGE( display_toolong, "路径过长,改名或移动文件后再试" )
|
||||
DECLARE_ERROR_PAGE( display_pathfull, "游戏或目录过量,最多显示999个" )
|
||||
|
||||
static atp_error_t display_help( atp_callerdata_t table, atp_counter_t index, atp_linecfg_t *config )
|
||||
{
|
||||
@ -191,12 +189,15 @@ static void help_page( atp_text_t *wording, atp_counter_t length )
|
||||
}
|
||||
|
||||
#define DIRBUFFSIZE 512
|
||||
#define PATH_SAME 0
|
||||
#define PATH_PUSH 1
|
||||
#define PATH_POP 2
|
||||
#define DIRUP { \
|
||||
char *tmpPathPtr = curDir + pathLen; \
|
||||
while(*--tmpPathPtr != '/'); \
|
||||
if(*(tmpPathPtr - 1) == ':') tmpPathPtr++; \
|
||||
*tmpPathPtr = '\0'; \
|
||||
scan = 1; \
|
||||
path_recover = PATH_POP; \
|
||||
upFrom = tmpPathPtr + 1; \
|
||||
}
|
||||
Result browseFiles(const char *const basePath, char selected[512])
|
||||
@ -212,15 +213,21 @@ Result browseFiles(const char *const basePath, char selected[512])
|
||||
if(dList == NULL) return RES_OUT_OF_MEM;
|
||||
|
||||
Result res;
|
||||
if((res = scanDir(curDir, dList, ".gba", NULL, NULL)) != RES_OK) goto end;
|
||||
if((res = scanDir(curDir, dList, ".gba", NULL, NULL)) != RES_OK)
|
||||
{
|
||||
if( res == RES_OUT_OF_RANGE )
|
||||
atp_show(1, display_fullpath, NULL);
|
||||
|
||||
goto end;
|
||||
}
|
||||
|
||||
const char *upFrom = NULL;
|
||||
int selecting = 0;
|
||||
while( 1 )
|
||||
{
|
||||
atp_itemval_t value;
|
||||
atp_boolean_t scan = 0;
|
||||
atp_error_t error;
|
||||
int path_recover = PATH_SAME;
|
||||
const u32 count = dList->num;
|
||||
|
||||
u32 pathLen = strlen(curDir);
|
||||
@ -232,7 +239,6 @@ Result browseFiles(const char *const basePath, char selected[512])
|
||||
}
|
||||
else error = atp_show( 1, display_empty, NULL );
|
||||
|
||||
|
||||
if( error == ATP_POWER_OFF )
|
||||
{
|
||||
res = error;
|
||||
@ -250,8 +256,8 @@ Result browseFiles(const char *const basePath, char selected[512])
|
||||
u32 namelen = strlen( fname ) + 1;
|
||||
if( namelen + pathLen > DIRBUFFSIZE-1 )
|
||||
{
|
||||
res = RES_OUT_OF_MEM;
|
||||
break;
|
||||
atp_show( 1, display_toolong, NULL );
|
||||
continue;
|
||||
}
|
||||
curDir[pathLen++] = '/';
|
||||
safeStrcpy( curDir+pathLen, fname, DIRBUFFSIZE - namelen );
|
||||
@ -262,7 +268,7 @@ Result browseFiles(const char *const basePath, char selected[512])
|
||||
}
|
||||
else
|
||||
{
|
||||
scan = 1;
|
||||
path_recover = PATH_PUSH;
|
||||
selecting = 0;
|
||||
upFrom = NULL;
|
||||
}
|
||||
@ -279,10 +285,17 @@ Result browseFiles(const char *const basePath, char selected[512])
|
||||
else DIRUP;
|
||||
}
|
||||
|
||||
if( scan )
|
||||
if( path_recover )
|
||||
{
|
||||
if(RES_OK != (res = scanDir(curDir, dList, ".gba", upFrom, &selecting)) )
|
||||
break;
|
||||
{
|
||||
if( res == RES_OUT_OF_RANGE )
|
||||
{
|
||||
atp_show( 1, display_pathfull, NULL ); // give a warning for user, and keep show the list
|
||||
}
|
||||
else break;
|
||||
}
|
||||
path_recover = PATH_SAME;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user