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,52 +2610,93 @@ 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;
FRESULT res;
DIR dir;
UINT i;
static FILINFO fno;
count = 1; //TODO: is there a better way we can count the entries perhaps a hashtable?
dir_t buf; res = f_opendir(&dir, path); /* Open the directory */
if (res == FR_OK) {
//load the directory-entry for (;;) {
resp = fatLoadDirByName("/ED64/CFG"); 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 */
int dsize = dir->size; if (!fno.fattrib & !AM_DIR) {
dsize++;
char toplist[dsize][256]; }
}
for (int i = 0; i < dir->size; i++) f_closedir(&dir);
{
rec = dir->rec[i];
u8 rom_cfg_file[128];
//set rom_cfg
sprintf(rom_cfg_file, "/ED64/CFG/%s", rec->name);
static uint8_t cfg_file_data[512] = {0};
resp = fatOpenFileByName(rom_cfg_file, 0); //512 bytes fix one cluster
resp = fatReadFile(&cfg_file_data, 1);
toplist[i][0] = (char)cfg_file_data[5]; //quality
strcpy(toplist[i] + 1, cfg_file_data + 32); //fullpath
} }
qsort(toplist, dsize, 256, compare_int_reverse); res = f_opendir(&dir, path); /* Open the directory */
if (res == FR_OK) {
char toplist[dsize][256];
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) { /* 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];
//set rom_cfg
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};
if (dsize > 15) int fsize = f_size(&file);
list_size = 15;
else result =
list_size = dsize; 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
strcpy(toplist[i] + 1, cfg_file_data + 32); //fullpath
i++;
}
}
}
f_closedir(&dir);
for (int c = 0; c < list_size; c++) qsort(toplist, dsize, 256, compare_int_reverse);
strcpy(toplist15[c], toplist[c]);
list_pos_backup[2] = list_size; if (dsize > 15)
list_size = 15;
else
list_size = dsize;
for (int c = 0; c < list_size; c++)
strcpy(toplist15[c], toplist[c]);
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);
} }