Skip to content

Commit

Permalink
get game size at info page switch
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito committed Dec 20, 2024
1 parent ae2679a commit 8b98862
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 29 deletions.
2 changes: 2 additions & 0 deletions include/iosupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ typedef struct _item_list_t

config_set_t *(*itemGetConfig)(item_list_t *itemList, int id);

int (*itemGetSize)(item_list_t *itemList, int id);

int (*itemGetImage)(item_list_t *itemList, char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm);

void (*itemCleanUp)(item_list_t *itemList, int exception);
Expand Down
1 change: 1 addition & 0 deletions include/supportbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void sbCreatePath(const base_game_info_t *game, char *path, const char *prefix,
void sbDelete(base_game_info_t **list, const char *prefix, const char *sep, int gamecount, int id);
void sbRename(base_game_info_t **list, const char *prefix, const char *sep, int gamecount, int id, char *newname);
config_set_t *sbPopulateConfig(base_game_info_t *game, const char *prefix, const char *sep);
int sbCalcGameSize(base_game_info_t *game, const char *prefix, const char *sep);
void sbCreateFolders(const char *path, int createDiscImgFolders);

// ISO9660 filesystem management functions.
Expand Down
7 changes: 6 additions & 1 deletion src/appsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ static config_set_t *appGetConfig(item_list_t *itemList, int id)
return config;
}

static int appGetSize(item_list_t *itemList, int id)
{
return 0;
}

static int appGetImage(item_list_t *itemList, char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm)
{
char device[8], *startup;
Expand Down Expand Up @@ -500,4 +505,4 @@ static void appShutdown(item_list_t *itemList)
static item_list_t appItemList = {
APP_MODE, -1, 0, MODE_FLAG_NO_COMPAT | MODE_FLAG_NO_UPDATE, MENU_MIN_INACTIVE_FRAMES, APP_MODE_UPDATE_DELAY, NULL, NULL, &appGetTextId, NULL, &appInit, &appNeedsUpdate, &appUpdateItemList,
&appGetItemCount, NULL, &appGetItemName, &appGetItemNameLength, &appGetItemStartup, &appDeleteItem, &appRenameItem, &appLaunchItem,
&appGetConfig, &appGetImage, &appCleanUp, &appShutdown, NULL, &appGetIconId};
&appGetConfig, &appGetSize, &appGetImage, &appCleanUp, &appShutdown, NULL, &appGetIconId};
8 changes: 7 additions & 1 deletion src/bdmsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,12 @@ static config_set_t *bdmGetConfig(item_list_t *itemList, int id)
return sbPopulateConfig(&pDeviceData->bdmGames[id], pDeviceData->bdmPrefix, "/");
}

static int bdmGetSize(item_list_t *itemList, int id)
{
bdm_device_data_t *pDeviceData = (bdm_device_data_t *)itemList->priv;
return sbCalcGameSize(&pDeviceData->bdmGames[id], pDeviceData->bdmPrefix, "/");
}

static int bdmGetImage(item_list_t *itemList, char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm)
{
char path[256];
Expand Down Expand Up @@ -701,7 +707,7 @@ static char *bdmGetPrefix(item_list_t *itemList)
static item_list_t bdmGameList = {
BDM_MODE, 2, 0, 0, MENU_MIN_INACTIVE_FRAMES, BDM_MODE_UPDATE_DELAY, NULL, NULL, &bdmGetTextId, &bdmGetPrefix, &bdmInit, &bdmNeedsUpdate,
&bdmUpdateGameList, &bdmGetGameCount, &bdmGetGame, &bdmGetGameName, &bdmGetGameNameLength, &bdmGetGameStartup, &bdmDeleteGame, &bdmRenameGame,
&bdmLaunchGame, &bdmGetConfig, &bdmGetImage, &bdmCleanUp, &bdmShutdown, &bdmCheckVMC, &bdmGetIconId};
&bdmLaunchGame, &bdmGetConfig, &bdmGetSize, &bdmGetImage, &bdmCleanUp, &bdmShutdown, &bdmCheckVMC, &bdmGetIconId};

void bdmInitSemaphore()
{
Expand Down
7 changes: 6 additions & 1 deletion src/ethsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,11 @@ static config_set_t *ethGetConfig(item_list_t *itemList, int id)
return sbPopulateConfig(&ethGames[id], ethPrefix, "\\");
}

static int ethGetSize(item_list_t *itemList, int id)
{
return sbCalcGameSize(&ethGames[id], ethPrefix, "\\");
}

static int ethGetImage(item_list_t *itemList, char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm)
{
char path[256];
Expand Down Expand Up @@ -789,7 +794,7 @@ static char *ethGetPrefix(item_list_t *itemList)
static item_list_t ethGameList = {
ETH_MODE, 1, 0, 0, MENU_MIN_INACTIVE_FRAMES, ETH_MODE_UPDATE_DELAY, NULL, NULL, &ethGetTextId, &ethGetPrefix, &ethInit, &ethNeedsUpdate,
&ethUpdateGameList, &ethGetGameCount, &ethGetGame, &ethGetGameName, &ethGetGameNameLength, &ethGetGameStartup, &ethDeleteGame, &ethRenameGame,
&ethLaunchGame, &ethGetConfig, &ethGetImage, &ethCleanUp, &ethShutdown, &ethCheckVMC, &ethGetIconId};
&ethLaunchGame, &ethGetConfig, &ethGetSize, &ethGetImage, &ethCleanUp, &ethShutdown, &ethCheckVMC, &ethGetIconId};

static int ethReadNetConfig(void)
{
Expand Down
7 changes: 6 additions & 1 deletion src/hddsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,11 @@ static config_set_t *hddGetConfig(item_list_t *itemList, int id)
return config;
}

static int hddGetSize(item_list_t *itemList, int id)
{
return 0;
}

static int hddGetImage(item_list_t *itemList, char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm)
{
char path[256];
Expand Down Expand Up @@ -837,4 +842,4 @@ static char *hddGetPrefix(item_list_t *itemList)
static item_list_t hddGameList = {
HDD_MODE, 0, 0, MODE_FLAG_COMPAT_DMA, MENU_MIN_INACTIVE_FRAMES, HDD_MODE_UPDATE_DELAY, NULL, NULL, &hddGetTextId, &hddGetPrefix, &hddInit, &hddNeedsUpdate, &hddUpdateGameList,
&hddGetGameCount, &hddGetGame, &hddGetGameName, &hddGetGameNameLength, &hddGetGameStartup, &hddDeleteGame, &hddRenameGame,
&hddLaunchGame, &hddGetConfig, &hddGetImage, &hddCleanUp, &hddShutdown, &hddCheckVMC, &hddGetIconId};
&hddLaunchGame, &hddGetConfig, &hddGetSize, &hddGetImage, &hddCleanUp, &hddShutdown, &hddCheckVMC, &hddGetIconId};
7 changes: 6 additions & 1 deletion src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,13 @@ static void itemExecCircle(struct menu_item *curMenu)

static void itemExecSquare(struct menu_item *curMenu)
{
if (curMenu->current && gTheme->infoElems.first)
if (curMenu->current && gTheme->infoElems.first) {
item_list_t *support = curMenu->userdata;
if (support->itemGetSize(support, curMenu->current->item.id))
menuLoadConfig();

guiSwitchScreen(GUI_SCREEN_INFO);
}
}

static void itemExecTriangle(struct menu_item *curMenu)
Expand Down
45 changes: 21 additions & 24 deletions src/supportbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ static int scanForISO(char *path, char type, struct game_list_t **glist)
int cacheLoaded = loadISOGameListCache(path, &cache) == 0;

if ((dir = opendir(path)) != NULL) {
//struct stat statbuf;

size_t base_path_len = strlen(path);
strcpy(fullpath, path);
fullpath[base_path_len] = '/';
Expand Down Expand Up @@ -363,12 +361,7 @@ static int scanForISO(char *path, char type, struct game_list_t **glist)
game->parts = 1;
game->media = type;
game->format = format;


/*if (stat(fullpath, &statbuf) == 0) {
game->sizeMB = statbuf.st_size >> 20;
} else {*/
game->sizeMB = 0;
game->sizeMB = 0; // Get size at cfg populate.. its only used for info page

count++;
}
Expand Down Expand Up @@ -778,22 +771,6 @@ config_set_t *sbPopulateConfig(base_game_info_t *game, const char *prefix, const
config_set_t *config = configAlloc(0, NULL, path);
configRead(config); // Does not matter if the config file could be loaded or not.

char gamepath[256];
// Get game size if not already set
if (game->sizeMB == 0) {
if (game->format == GAME_FORMAT_OLD_ISO)
snprintf(gamepath, sizeof(gamepath), "%s%s%s%s%s%s", prefix, sep, game->media == SCECdPS2CD ? "CD" : "DVD", sep, game->startup, game->extension);
else
snprintf(gamepath, sizeof(gamepath), "%s%s%s%s%s%s", prefix, sep, game->media == SCECdPS2CD ? "CD" : "DVD", sep, game->name, game->extension);

if (stat(gamepath, &st) == 0)
game->sizeMB = st.st_size >> 20;
else
game->sizeMB = 0;
}

LOG("GAMEPATH=%s\n", gamepath);

configSetStr(config, CONFIG_ITEM_NAME, game->name);
configSetInt(config, CONFIG_ITEM_SIZE, game->sizeMB);

Expand All @@ -811,6 +788,26 @@ config_set_t *sbPopulateConfig(base_game_info_t *game, const char *prefix, const
return config;
}

int sbCalcGameSize(base_game_info_t *game, const char *prefix, const char *sep)
{
if ((game->sizeMB == 0) && (game->format != GAME_FORMAT_OLD_ISO)) {
char gamepath[256];
struct stat st;

snprintf(gamepath, sizeof(gamepath), "%s%s%s%s%s%s", prefix, sep, game->media == SCECdPS2CD ? "CD" : "DVD", sep, game->name, game->extension);

if (stat(gamepath, &st) == 0) {
game->sizeMB = st.st_size >> 20;
return 1;
} else {
game->sizeMB = 0;
LOG("Failed to stat file: %s\n", gamepath);
}
}

return 0;
}

static void sbCreateFoldersFromList(const char *path, const char **folders)
{
int i;
Expand Down

0 comments on commit 8b98862

Please sign in to comment.