updated toplist

could do with a good refactor TBH
This commit is contained in:
Robin Jones 2017-10-18 17:44:13 +01:00
parent bb14fcd8c8
commit 8fd9f90522

View File

@ -821,8 +821,12 @@ static int configHandler(void *user, const char *section, const char *name, cons
void updateFirmware(char *filename) void updateFirmware(char *filename)
{ //check that firmware exists on the disk? mainly because it has to be ripped from the official image and may not have been. { //check that firmware exists on the disk? mainly because it has to be ripped from the official image and may not have been.
FatRecord rec_tmpf; FRESULT fr;
if (fatFindRecord(filename, &rec_tmpf, 0) == 0) FILINFO fno;
fr = f_stat(filename, &fno); //TODO: given this is on the ROM (not SD) does it even work??????
if (fr == FR_OK)
{ {
int fpf = dfs_open(filename); int fpf = dfs_open(filename);
firmware = malloc(dfs_size(fpf)); firmware = malloc(dfs_size(fpf));
@ -2606,40 +2610,80 @@ void drawToplistBox(display_context_t disp, int line)
{ {
list_pos_backup[0] = cursor; list_pos_backup[0] = cursor;
list_pos_backup[1] = page; list_pos_backup[1] = page;
int dsize = 0;
u8 list_size = 0; u8 list_size = 0;
if (line == 0) if (line == 0)
{ {
FatRecord *rec; char* path = "/ED64/CFG";
u8 resp = 0;
count = 1; FRESULT res;
dir_t buf; DIR dir;
UINT i;
static FILINFO fno;
//load the directory-entry //TODO: is there a better way we can count the entries perhaps a hashtable?
resp = fatLoadDirByName("/ED64/CFG"); res = f_opendir(&dir, path); /* Open the directory */
if (res == FR_OK) {
int dsize = dir->size; for (;;) {
res = f_readdir(&dir, &fno); /* Read a directory item */
if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
if (!fno.fattrib & !AM_DIR) {
dsize++;
}
}
f_closedir(&dir);
}
res = f_opendir(&dir, path); /* Open the directory */
if (res == FR_OK) {
char toplist[dsize][256]; char toplist[dsize][256];
for (int i = 0; i < dir->size; i++) for (;;) {
{ res = f_readdir(&dir, &fno); /* Read a directory item */
rec = dir->rec[i]; if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
if (fno.fattrib & AM_DIR) { /* It is a directory */
//i = strlen(path);
// sprintf(&path[i], "/%s", fno.fname);
// res = scan_files(path); /* Enter the directory */
// if (res != FR_OK) break;
// path[i] = 0;
} else { /* It is a file. */
u8 rom_cfg_file[128]; u8 rom_cfg_file[128];
//set rom_cfg //set rom_cfg
sprintf(rom_cfg_file, "/ED64/CFG/%s", rec->name); sprintf(rom_cfg_file, path, fno.fname);
FRESULT result;
FIL file;
UINT bytesread;
result = f_open(&file, rom_cfg_file, FA_READ);
if (result == FR_OK)
{
static uint8_t cfg_file_data[512] = {0}; static uint8_t cfg_file_data[512] = {0};
resp = fatOpenFileByName(rom_cfg_file, 0); //512 bytes fix one cluster int fsize = f_size(&file);
resp = fatReadFile(&cfg_file_data, 1);
result =
f_read (
&file, /* [IN] File object */
&cfg_file_data, /* [OUT] Buffer to store read data */
fsize, /* [IN] Number of bytes to read */
&bytesread /* [OUT] Number of bytes read */
);
result = f_close(&file);
toplist[i][0] = (char)cfg_file_data[5]; //quality toplist[i][0] = (char)cfg_file_data[5]; //quality
strcpy(toplist[i] + 1, cfg_file_data + 32); //fullpath strcpy(toplist[i] + 1, cfg_file_data + 32); //fullpath
i++;
} }
}
}
f_closedir(&dir);
qsort(toplist, dsize, 256, compare_int_reverse); qsort(toplist, dsize, 256, compare_int_reverse);
@ -2653,6 +2697,7 @@ void drawToplistBox(display_context_t disp, int line)
list_pos_backup[2] = list_size; list_pos_backup[2] = list_size;
} }
}
list_size = list_pos_backup[2]; list_size = list_pos_backup[2];
@ -4384,8 +4429,12 @@ int main(void)
char background_path[64]; char background_path[64];
sprintf(background_path, "/ED64/wallpaper/%s", background_image); sprintf(background_path, "/ED64/wallpaper/%s", background_image);
FatRecord rec_tmpf; FRESULT fr;
if (fatFindRecord(background_path, &rec_tmpf, 0) == 0) FILINFO fno;
fr = f_stat(background_path, &fno);
if (fr == FR_OK)
{ {
background = loadPng(background_path); background = loadPng(background_path);
} }