2009-06-05 00:13:39 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2009-06-13 02:24:36 +02:00
|
|
|
#include "settings/cfg.h"
|
|
|
|
#include "usbloader/wbfs.h"
|
2009-06-05 00:13:39 +02:00
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
|
2009-06-11 10:13:08 +02:00
|
|
|
|
2009-06-05 00:13:39 +02:00
|
|
|
struct discHdr * gameList;
|
|
|
|
u32 gameCnt;
|
|
|
|
s32 gameSelected, gameStart;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* EntryCmp
|
|
|
|
***************************************************************************/
|
|
|
|
s32 __Menu_EntryCmp(const void *a, const void *b)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
struct discHdr *hdr1 = (struct discHdr *)a;
|
2009-06-05 00:13:39 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
struct discHdr *hdr2 = (struct discHdr *)b;
|
2009-06-05 00:13:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Compare strings */
|
2009-06-05 00:13:39 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
return stricmp(get_title(hdr1), get_title(hdr2));
|
2009-06-05 00:13:39 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 __Menu_EntryCmpCount(const void *a, const void *b) {
|
|
|
|
s32 ret;
|
2009-06-05 00:13:39 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
struct discHdr *hdr1 = (struct discHdr *)a;
|
2009-06-05 00:13:39 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
struct discHdr *hdr2 = (struct discHdr *)b;
|
2009-06-05 00:13:39 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Compare Play Count */
|
|
|
|
u16 count1 = 0;
|
|
|
|
u16 count2 = 0;
|
|
|
|
struct Game_NUM* game_num1 = CFG_get_game_num(hdr1->id);
|
|
|
|
struct Game_NUM* game_num2 = CFG_get_game_num(hdr2->id);
|
2009-06-05 00:13:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
if (game_num1) count1 = game_num1->count;
|
|
|
|
if (game_num2) count2 = game_num2->count;
|
2009-06-05 00:13:39 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
ret = (s32) (count2-count1);
|
|
|
|
if (ret == 0) return stricmp(get_title(hdr1), get_title(hdr2));
|
2009-06-05 00:13:39 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
return ret;
|
2009-06-05 00:13:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Get Gamelist
|
|
|
|
***************************************************************************/
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
int __Menu_GetEntries(int t) {
|
|
|
|
struct discHdr *buffer = NULL;
|
|
|
|
struct discHdr *buffer2 = NULL;
|
|
|
|
struct discHdr *header = NULL;
|
|
|
|
|
|
|
|
u32 cnt, len;
|
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
/* Get list length */
|
|
|
|
ret = WBFS_GetCount(&cnt);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Buffer length */
|
|
|
|
len = sizeof(struct discHdr) * cnt;
|
|
|
|
|
|
|
|
/* Allocate memory */
|
|
|
|
buffer = (struct discHdr *)memalign(32, len);
|
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Clear buffer */
|
|
|
|
memset(buffer, 0, len);
|
|
|
|
|
|
|
|
/* Get header list */
|
|
|
|
ret = WBFS_GetHeaders(buffer, cnt, sizeof(struct discHdr));
|
|
|
|
if (ret < 0) {
|
|
|
|
if (buffer) free(buffer);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Filters */
|
|
|
|
if (Settings.fave && t==0) {
|
|
|
|
u32 cnt2 = 0;
|
|
|
|
|
|
|
|
for (u32 i = 0; i < cnt; i++) {
|
|
|
|
header = &buffer[i];
|
|
|
|
u8 favorite = 0;
|
|
|
|
struct Game_NUM* game_num = CFG_get_game_num(header->id);
|
|
|
|
if (game_num) {
|
|
|
|
favorite = game_num->favorite;
|
|
|
|
}
|
|
|
|
if (favorite==1) {
|
|
|
|
buffer2 = (discHdr *) realloc(buffer2, (cnt2+1) * sizeof(struct discHdr));
|
|
|
|
if (!buffer2) {
|
|
|
|
free(buffer);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy((buffer2 + cnt2), (buffer + i), sizeof(struct discHdr));
|
|
|
|
cnt2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (buffer2) {
|
|
|
|
free(buffer);
|
|
|
|
buffer = buffer2;
|
|
|
|
buffer2 = NULL;
|
|
|
|
} else {
|
|
|
|
memset(buffer, 0, len);
|
|
|
|
}
|
|
|
|
cnt = cnt2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Settings.parentalcontrol && !Settings.godmode && t==0) {
|
|
|
|
u32 cnt2 = 0;
|
|
|
|
|
|
|
|
for (u32 i = 0; i < cnt; i++) {
|
|
|
|
header = &buffer[i];
|
|
|
|
if (get_block(header) < Settings.parentalcontrol) {
|
|
|
|
buffer2 = (discHdr *) realloc(buffer2, (cnt2+1) * sizeof(struct discHdr));
|
|
|
|
if (!buffer2) {
|
|
|
|
free(buffer);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy((buffer2 + cnt2), (buffer + i), sizeof(struct discHdr));
|
|
|
|
cnt2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (buffer2) {
|
|
|
|
free(buffer);
|
|
|
|
buffer = buffer2;
|
|
|
|
buffer2 = NULL;
|
|
|
|
} else {
|
|
|
|
memset(buffer, 0, len);
|
|
|
|
}
|
|
|
|
cnt = cnt2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Settings.sort==pcount) {
|
|
|
|
qsort(buffer, cnt, sizeof(struct discHdr), __Menu_EntryCmpCount);
|
|
|
|
} else {
|
|
|
|
qsort(buffer, cnt, sizeof(struct discHdr), __Menu_EntryCmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free memory */
|
|
|
|
if (gameList)
|
|
|
|
free(gameList);
|
|
|
|
|
|
|
|
/* Set values */
|
|
|
|
gameList = buffer;
|
|
|
|
buffer = NULL;
|
|
|
|
gameCnt = cnt;
|
|
|
|
|
|
|
|
/* Reset variables */
|
|
|
|
gameSelected = gameStart = 0;
|
|
|
|
|
|
|
|
return 0;
|
2009-06-05 00:13:39 +02:00
|
|
|
}
|