mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-22 03:09:15 +01:00
*Moved GameStatistics (FavoriteRank/PlayCount) out of cfg.c and into an own class. All settings are now separated. Old rankings and playcounts will be reseted due to a new format.
*Fixed loading of game settings *Moved NTFS cache to mem2 as well
This commit is contained in:
parent
137c2331c6
commit
48a40172d0
@ -2,8 +2,8 @@
|
||||
<app version="1">
|
||||
<name> USB Loader GX</name>
|
||||
<coder>USB Loader GX Team</coder>
|
||||
<version>1.0 r974</version>
|
||||
<release_date>201009250702</release_date>
|
||||
<version>1.0 r975</version>
|
||||
<release_date>201009250708</release_date>
|
||||
<short_description>Loads games from USB-devices</short_description>
|
||||
<long_description>USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times.
|
||||
The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller.
|
||||
|
File diff suppressed because one or more lines are too long
@ -23,24 +23,21 @@
|
||||
#define _MEM_ALLOCATE_H
|
||||
|
||||
#include <malloc.h>
|
||||
#include "memory/mem2.h"
|
||||
|
||||
static inline void* ntfs_alloc(size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
return MEM2_alloc(size);
|
||||
}
|
||||
|
||||
static inline void* ntfs_align(size_t size)
|
||||
{
|
||||
#ifdef __wii__
|
||||
return memalign(32, size);
|
||||
#else
|
||||
return malloc(size);
|
||||
#endif
|
||||
return MEM2_alloc(size);
|
||||
}
|
||||
|
||||
static inline void ntfs_free(void* mem)
|
||||
{
|
||||
free(mem);
|
||||
MEM2_free(mem);
|
||||
}
|
||||
|
||||
#endif /* _MEM_ALLOCATE_H */
|
||||
|
@ -9,14 +9,16 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void MEM2_init(unsigned int mem2Size);
|
||||
void MEM2_cleanup(void);
|
||||
void MEM2_takeBigOnes(bool b);
|
||||
void *MEM2_alloc(unsigned int s);
|
||||
void *MEM2_realloc(void *p, unsigned int s);
|
||||
void MEM2_free(void *p);
|
||||
unsigned int MEM2_usableSize(void *p);
|
||||
unsigned int MEM2_freesize();
|
||||
#include <gctypes.h>
|
||||
|
||||
void MEM2_init(unsigned int mem2Size);
|
||||
void MEM2_cleanup(void);
|
||||
void MEM2_takeBigOnes(bool b);
|
||||
void *MEM2_alloc(unsigned int s);
|
||||
void *MEM2_realloc(void *p, unsigned int s);
|
||||
void MEM2_free(void *p);
|
||||
unsigned int MEM2_usableSize(void *p);
|
||||
unsigned int MEM2_freesize();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "prompts/TitleBrowser.h"
|
||||
#include "settings/Settings.h"
|
||||
#include "settings/CGameSettings.h"
|
||||
#include "settings/CGameStatistics.h"
|
||||
#include "themes/CTheme.h"
|
||||
#include "wpad.h"
|
||||
#include "sys.h"
|
||||
@ -1515,7 +1516,7 @@ int MenuDiscList()
|
||||
GameCFG* game_cfg = GameSettings.GetGameCFG(header->id);
|
||||
u8 alternatedol;
|
||||
u8 ocarinaChoice;
|
||||
|
||||
|
||||
if (game_cfg)
|
||||
{
|
||||
alternatedol = game_cfg->loadalternatedol;
|
||||
@ -1569,23 +1570,11 @@ int MenuDiscList()
|
||||
if (isInserted(bootDevice))
|
||||
{
|
||||
//////////save game play count////////////////
|
||||
struct Game_NUM* game_num = CFG_get_game_num(header->id);
|
||||
GameStatistics.SetPlayCount(header->id, GameStatistics.GetPlayCount(header->id)+1);
|
||||
GameStatistics.Save();
|
||||
|
||||
if (game_num)
|
||||
{
|
||||
favoritevar = game_num->favorite;
|
||||
playcount = game_num->count;
|
||||
}
|
||||
else
|
||||
{
|
||||
favoritevar = 0;
|
||||
playcount = 0;
|
||||
}
|
||||
playcount += 1;
|
||||
|
||||
CFG_save_game_num(header->id);
|
||||
gprintf("\n\tplaycount for %c%c%c%c%c%c raised to %i", header->id[0], header->id[1], header->id[2],
|
||||
header->id[3], header->id[4], header->id[5], playcount);
|
||||
header->id[3], header->id[4], header->id[5], GameStatistics.GetPlayCount(header->id));
|
||||
|
||||
}
|
||||
menu = MENU_EXIT;
|
||||
@ -1742,7 +1731,7 @@ int MenuDiscList()
|
||||
}
|
||||
covertOld = covert;
|
||||
}
|
||||
|
||||
|
||||
HaltGui();
|
||||
mainWindow->RemoveAll();
|
||||
mainWindow->Append(bgImg);
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "libwiigui/gui.h"
|
||||
#include "libwiigui/gui_diskcover.h"
|
||||
#include "libwiigui/Text.hpp"
|
||||
#include "settings/CGameStatistics.h"
|
||||
#include "network/networkops.h"
|
||||
#include "network/http.h"
|
||||
#include "prompts/PromptWindows.h"
|
||||
@ -1143,25 +1144,19 @@ void SetupFavoriteButton(GuiButton *btnFavorite, int xPos, GuiImage *img, GuiSou
|
||||
u8 SetFavorite(GuiButton *fav1, GuiButton *fav2, GuiButton *fav3, GuiButton *fav4, GuiButton *fav5, u8* gameId,
|
||||
u8 favorite)
|
||||
{
|
||||
struct Game_NUM * game_num = CFG_get_game_num(gameId);
|
||||
if (game_num)
|
||||
{
|
||||
favoritevar = game_num->favorite;
|
||||
playcount = game_num->count;
|
||||
}
|
||||
else
|
||||
{
|
||||
favoritevar = 0;
|
||||
playcount = 0;
|
||||
}
|
||||
favoritevar = (favorite == favoritevar) ? 0 : favorite; // Press the current rank to reset the rank
|
||||
CFG_save_game_num(gameId);
|
||||
return favoritevar;
|
||||
int FavoriteRank = (favorite == GameStatistics.GetFavoriteRank(gameId)) ? 0 : favorite; // Press the current rank to reset the rank
|
||||
|
||||
GameStatistics.SetFavoriteRank(gameId, FavoriteRank);
|
||||
GameStatistics.Save();
|
||||
|
||||
return FavoriteRank;
|
||||
}
|
||||
|
||||
void SetFavoriteImages(GuiImage *b1, GuiImage *b2, GuiImage *b3, GuiImage *b4, GuiImage *b5, GuiImageData *on,
|
||||
void SetFavoriteImages(const u8 * gameid, GuiImage *b1, GuiImage *b2, GuiImage *b3, GuiImage *b4, GuiImage *b5, GuiImageData *on,
|
||||
GuiImageData *off)
|
||||
{
|
||||
int favoritevar = GameStatistics.GetFavoriteRank(gameid);
|
||||
|
||||
b1->SetImage(favoritevar >= 1 ? on : off);
|
||||
b2->SetImage(favoritevar >= 2 ? on : off);
|
||||
b3->SetImage(favoritevar >= 3 ? on : off);
|
||||
@ -1516,20 +1511,8 @@ int GameWindowPrompt()
|
||||
}
|
||||
|
||||
nameTxt.SetText(get_title(header));
|
||||
|
||||
struct Game_NUM* game_num = CFG_get_game_num(header->id);
|
||||
if (game_num)
|
||||
{
|
||||
playcount = game_num->count;
|
||||
favoritevar = game_num->favorite;
|
||||
}
|
||||
else
|
||||
{
|
||||
playcount = 0;
|
||||
favoritevar = 0;
|
||||
}
|
||||
playcntTxt.SetTextf("%s: %i", tr( "Play Count" ), playcount);
|
||||
SetFavoriteImages(&btnFavoriteImg1, &btnFavoriteImg2, &btnFavoriteImg3, &btnFavoriteImg4, &btnFavoriteImg5,
|
||||
playcntTxt.SetTextf("%s: %i", tr( "Play Count" ), GameStatistics.GetPlayCount(header));
|
||||
SetFavoriteImages(header->id, &btnFavoriteImg1, &btnFavoriteImg2, &btnFavoriteImg3, &btnFavoriteImg4, &btnFavoriteImg5,
|
||||
&imgFavorite, &imgNotFavorite);
|
||||
|
||||
nameTxt.SetPosition(0, 1);
|
||||
@ -1576,23 +1559,8 @@ int GameWindowPrompt()
|
||||
|
||||
if (btn1.GetState() == STATE_CLICKED)
|
||||
{
|
||||
//playcounter
|
||||
struct Game_NUM* game_num = CFG_get_game_num(header->id);
|
||||
if (game_num)
|
||||
{
|
||||
favoritevar = game_num->favorite;
|
||||
playcount = game_num->count;
|
||||
}
|
||||
else
|
||||
{
|
||||
favoritevar = 0;
|
||||
playcount = 0;
|
||||
}
|
||||
playcount += 1;
|
||||
if (isInserted(bootDevice))
|
||||
{
|
||||
CFG_save_game_num(header->id);
|
||||
}
|
||||
GameStatistics.SetPlayCount(header->id, GameStatistics.GetPlayCount(header->id)+1);
|
||||
GameStatistics.Save();
|
||||
|
||||
choice = 1;
|
||||
}
|
||||
@ -1622,7 +1590,7 @@ int GameWindowPrompt()
|
||||
{
|
||||
SetFavorite(&btnFavorite1, &btnFavorite2, &btnFavorite3, &btnFavorite4, &btnFavorite5, header->id,
|
||||
1);
|
||||
SetFavoriteImages(&btnFavoriteImg1, &btnFavoriteImg2, &btnFavoriteImg3, &btnFavoriteImg4,
|
||||
SetFavoriteImages(header->id, &btnFavoriteImg1, &btnFavoriteImg2, &btnFavoriteImg3, &btnFavoriteImg4,
|
||||
&btnFavoriteImg5, &imgFavorite, &imgNotFavorite);
|
||||
}
|
||||
btnFavorite1.ResetState();
|
||||
@ -1633,7 +1601,7 @@ int GameWindowPrompt()
|
||||
{
|
||||
SetFavorite(&btnFavorite1, &btnFavorite2, &btnFavorite3, &btnFavorite4, &btnFavorite5, header->id,
|
||||
2);
|
||||
SetFavoriteImages(&btnFavoriteImg1, &btnFavoriteImg2, &btnFavoriteImg3, &btnFavoriteImg4,
|
||||
SetFavoriteImages(header->id, &btnFavoriteImg1, &btnFavoriteImg2, &btnFavoriteImg3, &btnFavoriteImg4,
|
||||
&btnFavoriteImg5, &imgFavorite, &imgNotFavorite);
|
||||
}
|
||||
btnFavorite2.ResetState();
|
||||
@ -1644,7 +1612,7 @@ int GameWindowPrompt()
|
||||
{
|
||||
SetFavorite(&btnFavorite1, &btnFavorite2, &btnFavorite3, &btnFavorite4, &btnFavorite5, header->id,
|
||||
3);
|
||||
SetFavoriteImages(&btnFavoriteImg1, &btnFavoriteImg2, &btnFavoriteImg3, &btnFavoriteImg4,
|
||||
SetFavoriteImages(header->id, &btnFavoriteImg1, &btnFavoriteImg2, &btnFavoriteImg3, &btnFavoriteImg4,
|
||||
&btnFavoriteImg5, &imgFavorite, &imgNotFavorite);
|
||||
}
|
||||
btnFavorite3.ResetState();
|
||||
@ -1655,7 +1623,7 @@ int GameWindowPrompt()
|
||||
{
|
||||
SetFavorite(&btnFavorite1, &btnFavorite2, &btnFavorite3, &btnFavorite4, &btnFavorite5, header->id,
|
||||
4);
|
||||
SetFavoriteImages(&btnFavoriteImg1, &btnFavoriteImg2, &btnFavoriteImg3, &btnFavoriteImg4,
|
||||
SetFavoriteImages(header->id, &btnFavoriteImg1, &btnFavoriteImg2, &btnFavoriteImg3, &btnFavoriteImg4,
|
||||
&btnFavoriteImg5, &imgFavorite, &imgNotFavorite);
|
||||
}
|
||||
btnFavorite4.ResetState();
|
||||
@ -1666,7 +1634,7 @@ int GameWindowPrompt()
|
||||
{
|
||||
SetFavorite(&btnFavorite1, &btnFavorite2, &btnFavorite3, &btnFavorite4, &btnFavorite5, header->id,
|
||||
5);
|
||||
SetFavoriteImages(&btnFavoriteImg1, &btnFavoriteImg2, &btnFavoriteImg3, &btnFavoriteImg4,
|
||||
SetFavoriteImages(header->id, &btnFavoriteImg1, &btnFavoriteImg2, &btnFavoriteImg3, &btnFavoriteImg4,
|
||||
&btnFavoriteImg5, &imgFavorite, &imgNotFavorite);
|
||||
}
|
||||
btnFavorite5.ResetState();
|
||||
|
@ -83,21 +83,18 @@ GameCFG * CGameSettings::GetGameCFG(const char * id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CGameSettings::AddGame(const GameCFG * NewGame)
|
||||
bool CGameSettings::AddGame(const GameCFG & NewGame)
|
||||
{
|
||||
if(!NewGame)
|
||||
return false;
|
||||
|
||||
for(u32 i = 0; i < GameList.size(); ++i)
|
||||
{
|
||||
if(strncmp(NewGame->id, GameList[i].id, 6) == 0)
|
||||
if(strncmp(NewGame.id, GameList[i].id, 6) == 0)
|
||||
{
|
||||
memcpy(&GameList[i], NewGame, sizeof(GameCFG));
|
||||
memcpy(&GameList[i], &NewGame, sizeof(GameCFG));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
GameList.push_back(*NewGame);
|
||||
GameList.push_back(NewGame);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -341,6 +338,9 @@ void CGameSettings::ParseLine(char *line)
|
||||
if(!ReadGameID(line, GameID, 6))
|
||||
return;
|
||||
|
||||
if(strlen(GameID) != 6)
|
||||
return;
|
||||
|
||||
GameCFG NewCFG;
|
||||
memset(&NewCFG, 0, sizeof(GameCFG));
|
||||
|
||||
@ -354,7 +354,7 @@ void CGameSettings::ParseLine(char *line)
|
||||
|
||||
char * eq = strchr(LinePtr, ':');
|
||||
|
||||
if (!eq) return;
|
||||
if (!eq) break;
|
||||
|
||||
this->TrimLine(name, LinePtr, sizeof(name));
|
||||
this->TrimLine(value, eq + 1, sizeof(value));
|
||||
@ -364,7 +364,7 @@ void CGameSettings::ParseLine(char *line)
|
||||
LinePtr = strchr(LinePtr, ';');
|
||||
}
|
||||
|
||||
AddGame(&NewCFG);
|
||||
AddGame(NewCFG);
|
||||
}
|
||||
|
||||
void CGameSettings::TrimLine(char *dest, const char *src, int size)
|
||||
@ -376,7 +376,7 @@ void CGameSettings::TrimLine(char *dest, const char *src, int size)
|
||||
|
||||
for(i = 0; i < size; i++, src++)
|
||||
{
|
||||
if(*src == ';' || *src == '\n' ||
|
||||
if(*src == ':' || *src == ';' || *src == '\n' ||
|
||||
*src == '\r' || *src == '\0')
|
||||
break;
|
||||
|
||||
|
@ -37,7 +37,7 @@ class CGameSettings
|
||||
//!Save
|
||||
bool Save();
|
||||
//!AddGame
|
||||
bool AddGame(const GameCFG * NewGame);
|
||||
bool AddGame(const GameCFG & NewGame);
|
||||
//!Reset
|
||||
bool RemoveAll();
|
||||
//!Overload Reset for one Game
|
||||
|
293
source/settings/CGameStatistics.cpp
Normal file
293
source/settings/CGameStatistics.cpp
Normal file
@ -0,0 +1,293 @@
|
||||
#include <ogcsys.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "CGameStatistics.h"
|
||||
#include "FileOperations/fileops.h"
|
||||
|
||||
CGameStatistics GameStatistics;
|
||||
|
||||
|
||||
CGameStatistics::CGameStatistics()
|
||||
{
|
||||
}
|
||||
|
||||
CGameStatistics::~CGameStatistics()
|
||||
{
|
||||
}
|
||||
|
||||
GameStatus * CGameStatistics::GetGameStatus(const char * id)
|
||||
{
|
||||
if(!id)
|
||||
return NULL;
|
||||
|
||||
for(u32 i = 0; i < GameList.size(); ++i)
|
||||
{
|
||||
if(strncmp(id, GameList[i].id, 6) == 0)
|
||||
{
|
||||
return &GameList[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CGameStatistics::AddGame(const GameStatus & NewGame)
|
||||
{
|
||||
for(u32 i = 0; i < GameList.size(); ++i)
|
||||
{
|
||||
if(strncmp(NewGame.id, GameList[i].id, 6) == 0)
|
||||
{
|
||||
memcpy(&GameList[i], &NewGame, sizeof(GameStatus));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
GameList.push_back(NewGame);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CGameStatistics::RemoveAll()
|
||||
{
|
||||
GameList.clear();
|
||||
std::vector<GameStatus>().swap(GameList);
|
||||
|
||||
return Save();
|
||||
}
|
||||
|
||||
bool CGameStatistics::Remove(const char * id)
|
||||
{
|
||||
if(!id)
|
||||
return false;
|
||||
|
||||
for(u32 i = 0; i < GameList.size(); ++i)
|
||||
{
|
||||
if(strncmp(id, GameList[i].id, 6) == 0)
|
||||
{
|
||||
GameList.erase(GameList.begin()+i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CGameStatistics::Load(const char * path)
|
||||
{
|
||||
char line[1024];
|
||||
char filepath[300];
|
||||
snprintf(filepath, sizeof(filepath), "%sGXGameStatistics.cfg", path);
|
||||
|
||||
ConfigPath = filepath;
|
||||
|
||||
FILE *file = fopen(filepath, "r");
|
||||
if (!file) return false;
|
||||
|
||||
while (fgets(line, sizeof(line), file))
|
||||
{
|
||||
if (line[0] == '#')
|
||||
continue;
|
||||
|
||||
this->ParseLine(line);
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CGameStatistics::Save()
|
||||
{
|
||||
char filepath[300];
|
||||
strcpy(filepath, ConfigPath.c_str());
|
||||
|
||||
char * ptr = strrchr(filepath, '/');
|
||||
if(ptr)
|
||||
ptr[0] = 0;
|
||||
|
||||
if(!CreateSubfolder(filepath))
|
||||
return false;
|
||||
|
||||
FILE * f = fopen(ConfigPath.c_str(), "w");
|
||||
if (!f) return false;
|
||||
|
||||
fprintf(f, "# USB Loader settings file\n");
|
||||
fprintf(f, "# note: this file is automatically generated\n");
|
||||
fprintf(f, "# Num Games: %d\n", GameList.size());
|
||||
for (u32 i = 0; i < GameList.size(); i++)
|
||||
{
|
||||
fprintf(f, "game:%s = ", GameList[i].id);
|
||||
fprintf(f, "FavoriteRank:%d; ", GameList[i].FavoriteRank);
|
||||
fprintf(f, "PlayCount:%d;\n", GameList[i].PlayCount);
|
||||
}
|
||||
fprintf(f, "# END\n");
|
||||
fclose(f);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CGameStatistics::SetSetting(GameStatus & game, char *name, char *value)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if(strcmp(name, "FavoriteRank") == 0)
|
||||
{
|
||||
if (sscanf(value, "%d", &i) == 1)
|
||||
{
|
||||
game.FavoriteRank = i;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(strcmp(name, "PlayCount") == 0)
|
||||
{
|
||||
if (sscanf(value, "%d", &i) == 1)
|
||||
{
|
||||
game.PlayCount = i;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CGameStatistics::ReadGameID(const char * src, char * GameID, int size)
|
||||
{
|
||||
if(strncasecmp(src, "game:", 5) != 0)
|
||||
return false;
|
||||
|
||||
char * ptr = strchr(src, ':');
|
||||
if(!ptr)
|
||||
return false;
|
||||
|
||||
ptr++;
|
||||
|
||||
int i = 0;
|
||||
|
||||
for(i = 0; i < size; i++, ptr++)
|
||||
{
|
||||
if(*ptr == ' ' || *ptr == '\0')
|
||||
break;
|
||||
|
||||
GameID[i] = *ptr;
|
||||
}
|
||||
|
||||
GameID[i] = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
#include "gecko.h"
|
||||
void CGameStatistics::ParseLine(char *line)
|
||||
{
|
||||
char name[1024], value[1024];
|
||||
char GameID[8];
|
||||
|
||||
if(!ReadGameID(line, GameID, 6))
|
||||
return;
|
||||
|
||||
if(strlen(GameID) != 6)
|
||||
return;
|
||||
|
||||
GameStatus NewGame;
|
||||
memset(&NewGame, 0, sizeof(GameStatus));
|
||||
|
||||
snprintf(NewGame.id, sizeof(NewGame.id), GameID);
|
||||
|
||||
char * LinePtr = strchr(line, '=');
|
||||
|
||||
while(LinePtr != NULL)
|
||||
{
|
||||
LinePtr++;
|
||||
|
||||
char * eq = strchr(LinePtr, ':');
|
||||
|
||||
if (!eq) break;
|
||||
|
||||
this->TrimLine(name, LinePtr, sizeof(name));
|
||||
this->TrimLine(value, eq + 1, sizeof(value));
|
||||
|
||||
gprintf("\nID: %s, Name = %s, Value = %s\n", GameID, name, value);
|
||||
SetSetting(NewGame, name, value);
|
||||
|
||||
LinePtr = strchr(LinePtr, ';');
|
||||
}
|
||||
|
||||
AddGame(NewGame);
|
||||
}
|
||||
|
||||
void CGameStatistics::TrimLine(char *dest, const char *src, int size)
|
||||
{
|
||||
while (*src == ' ')
|
||||
src++;
|
||||
|
||||
int i = 0;
|
||||
|
||||
for(i = 0; i < size; i++, src++)
|
||||
{
|
||||
if(*src == ';' || *src == ':' || *src == '\n' ||
|
||||
*src == '\r' || *src == '\0')
|
||||
break;
|
||||
|
||||
dest[i] = *src;
|
||||
}
|
||||
|
||||
dest[i] = '\0';
|
||||
}
|
||||
|
||||
void CGameStatistics::SetPlayCount(const char * id, int count)
|
||||
{
|
||||
if(!id)
|
||||
return;
|
||||
|
||||
GameStatus NewStatus;
|
||||
snprintf(NewStatus.id, sizeof(NewStatus.id), id);
|
||||
NewStatus.FavoriteRank = 0;
|
||||
NewStatus.PlayCount = count;
|
||||
|
||||
GameStatus * game = GetGameStatus(id);
|
||||
if(game)
|
||||
NewStatus.FavoriteRank = game->FavoriteRank;
|
||||
|
||||
AddGame(NewStatus);
|
||||
}
|
||||
|
||||
void CGameStatistics::SetFavoriteRank(const char * id, int rank)
|
||||
{
|
||||
if(!id)
|
||||
return;
|
||||
|
||||
GameStatus NewStatus;
|
||||
snprintf(NewStatus.id, sizeof(NewStatus.id), id);
|
||||
NewStatus.FavoriteRank = rank;
|
||||
NewStatus.PlayCount = 0;
|
||||
|
||||
GameStatus * game = GetGameStatus(id);
|
||||
if(game)
|
||||
NewStatus.FavoriteRank = game->FavoriteRank;
|
||||
|
||||
AddGame(NewStatus);
|
||||
}
|
||||
|
||||
int CGameStatistics::GetPlayCount(const char * id)
|
||||
{
|
||||
if(!id)
|
||||
return 0;
|
||||
|
||||
GameStatus * game = GetGameStatus(id);
|
||||
if(game)
|
||||
return game->PlayCount;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CGameStatistics::GetFavoriteRank(const char * id)
|
||||
{
|
||||
if(!id)
|
||||
return 0;
|
||||
|
||||
GameStatus * game = GetGameStatus(id);
|
||||
if(game)
|
||||
return game->FavoriteRank;
|
||||
|
||||
return 0;
|
||||
}
|
71
source/settings/CGameStatistics.h
Normal file
71
source/settings/CGameStatistics.h
Normal file
@ -0,0 +1,71 @@
|
||||
#ifndef _GAME_STATISTICS_H_
|
||||
#define _GAME_STATISTICS_H_
|
||||
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <gctypes.h>
|
||||
#include <vector>
|
||||
#include "usbloader/disc.h"
|
||||
|
||||
typedef struct _Stats
|
||||
{
|
||||
char id[7];
|
||||
u8 FavoriteRank;
|
||||
u8 PlayCount;
|
||||
} GameStatus;
|
||||
|
||||
class CGameStatistics
|
||||
{
|
||||
public:
|
||||
//!Constructor
|
||||
CGameStatistics();
|
||||
//!Destructor
|
||||
~CGameStatistics();
|
||||
//!Load
|
||||
bool Load(const char * path);
|
||||
//!Save
|
||||
bool Save();
|
||||
//!AddGame
|
||||
bool AddGame(const GameStatus & NewGame);
|
||||
//!Reset
|
||||
bool RemoveAll();
|
||||
//!Overload for removing one game out of the list
|
||||
bool Remove(const char * id);
|
||||
bool Remove(const u8 * id) { return Remove((const char *) id); };
|
||||
bool Remove(const struct discHdr * game) { if(!game) return false; else return Remove(game->id); };
|
||||
//!Overloads for set playcount
|
||||
void SetPlayCount(const char * id, int count);
|
||||
void SetPlayCount(const u8 * id, int count) { SetPlayCount((const char *) id, count); };
|
||||
void SetPlayCount(const struct discHdr * game, int count) { if(!game) return; SetPlayCount(game->id, count); };
|
||||
//!Overloads for get playcount
|
||||
int GetPlayCount(const char * id);
|
||||
int GetPlayCount(const u8 * id) { return GetPlayCount((const char *) id); };
|
||||
int GetPlayCount(const struct discHdr * game) { if(!game) return 0; else return GetPlayCount(game->id); };
|
||||
//!Overloads for set FavoriteRank
|
||||
void SetFavoriteRank(const char * id, int rank);
|
||||
void SetFavoriteRank(const u8 * id, int rank) { SetFavoriteRank((const char *) id, rank); };
|
||||
void SetFavoriteRank(const struct discHdr * game, int rank) { if(!game) return; SetFavoriteRank(game->id, rank); };
|
||||
//!Overloads for get FavoriteRank
|
||||
int GetFavoriteRank(const char * id);
|
||||
int GetFavoriteRank(const u8 * id) { return GetFavoriteRank((const char *) id); };
|
||||
int GetFavoriteRank(const struct discHdr * game) { if(!game) return 0; else return GetFavoriteRank(game->id); };
|
||||
//!Get GameStatus
|
||||
GameStatus * GetGameStatus(const char * id);
|
||||
//!Overload
|
||||
GameStatus * GetGameStatus(const u8 * id) { return GetGameStatus((const char *) id); };
|
||||
//!Overload
|
||||
GameStatus * GetGameStatus(const struct discHdr * game) { if(!game) return NULL; else return GetGameStatus(game->id); };
|
||||
|
||||
protected:
|
||||
bool ReadGameID(const char * src, char * GameID, int size);
|
||||
bool SetSetting(GameStatus & game, char *name, char *value);
|
||||
|
||||
void ParseLine(char *line);
|
||||
void TrimLine(char *dest, const char *src, int size);
|
||||
std::string ConfigPath;
|
||||
std::vector<GameStatus> GameList;
|
||||
};
|
||||
|
||||
extern CGameStatistics GameStatistics;
|
||||
|
||||
#endif
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include "CSettings.h"
|
||||
#include "CGameSettings.h"
|
||||
#include "CGameStatistics.h"
|
||||
#include "language/gettext.h"
|
||||
#include "themes/CTheme.h"
|
||||
#include "FileOperations/fileops.h"
|
||||
@ -144,13 +145,12 @@ bool CSettings::Load()
|
||||
fclose(file);
|
||||
|
||||
//!The following needs to be moved later
|
||||
CFG_LoadGameNum();
|
||||
|
||||
char GameSetPath[200];
|
||||
snprintf(GameSetPath, sizeof(GameSetPath), ConfigPath);
|
||||
char * ptr = strrchr(GameSetPath, '/');
|
||||
if(ptr) ptr[1] = 0;
|
||||
|
||||
|
||||
GameStatistics.Load(GameSetPath);
|
||||
GameSettings.Load(GameSetPath);
|
||||
Theme.Load(theme_path);
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "prompts/DiscBrowser.h"
|
||||
#include "settings/SettingsPrompts.h"
|
||||
#include "settings/CGameSettings.h"
|
||||
#include "settings/CGameStatistics.h"
|
||||
#include "prompts/filebrowser.h"
|
||||
#include "cheats/cheatmenu.h"
|
||||
#include "themes/CTheme.h"
|
||||
@ -2602,7 +2603,7 @@ int MenuGameSettings(struct discHdr * header)
|
||||
|
||||
else if (saveBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
if (GameSettings.AddGame(&game_cfg) && GameSettings.Save())
|
||||
if (GameSettings.AddGame(game_cfg) && GameSettings.Save())
|
||||
{
|
||||
WindowPrompt(tr( "Successfully Saved" ), 0, tr( "OK" ));
|
||||
}
|
||||
@ -2906,7 +2907,8 @@ int MenuGameSettings(struct discHdr * header)
|
||||
{
|
||||
GameSettings.Remove(header->id);
|
||||
GameSettings.Save();
|
||||
CFG_forget_game_num(header->id);
|
||||
GameStatistics.Remove(header->id);
|
||||
GameStatistics.Save();
|
||||
ret = WBFS_RemoveGame(header->id);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -2932,19 +2934,8 @@ int MenuGameSettings(struct discHdr * header)
|
||||
{
|
||||
if (isInserted(bootDevice))
|
||||
{
|
||||
struct Game_NUM* game_num = CFG_get_game_num(header->id);
|
||||
if (game_num)
|
||||
{
|
||||
favoritevar = game_num->favorite;
|
||||
playcount = game_num->count;
|
||||
}
|
||||
else
|
||||
{
|
||||
favoritevar = 0;
|
||||
playcount = 0;
|
||||
}
|
||||
playcount = 0;
|
||||
CFG_save_game_num(header->id);
|
||||
GameStatistics.SetPlayCount(header->id, 0);
|
||||
GameStatistics.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,6 @@ u8 fave = 0;
|
||||
u8 qboot = 0;
|
||||
u8 wsprompt = 0;
|
||||
u8 keyset = 0;
|
||||
u8 favoritevar = 0;
|
||||
u16 playcount = 0;
|
||||
u8 listDisplay = 0;
|
||||
u8 partition = -1;
|
||||
char alternatedname[40];
|
||||
@ -55,10 +53,6 @@ struct ID_Title *cfg_title = NULL;
|
||||
int num_control = 0;
|
||||
struct ID_Control *cfg_control = NULL;
|
||||
|
||||
#define MAX_SAVED_GAME_NUM 1000
|
||||
int num_saved_game_num = 0;
|
||||
struct Game_NUM cfg_game_num[MAX_SAVED_GAME_NUM];
|
||||
|
||||
char *cfg_get_title(u8 *id)
|
||||
{
|
||||
if (!id) return NULL;
|
||||
@ -295,175 +289,6 @@ bool cfg_parsetitlefile(char *fname, void(*set_func)(char*, char*, u8))
|
||||
return true;
|
||||
}
|
||||
|
||||
struct Game_NUM* cfg_get_game_num(u8 *id)
|
||||
{
|
||||
struct Game_NUM *game = CFG_get_game_num(id);
|
||||
if (game) return game;
|
||||
if (num_saved_game_num >= MAX_SAVED_GAME_NUM) return NULL;
|
||||
game = &cfg_game_num[num_saved_game_num];
|
||||
num_saved_game_num++;
|
||||
return game;
|
||||
}
|
||||
|
||||
// current options to game
|
||||
void cfg_set_game_num(struct Game_NUM *game, u8 *id)
|
||||
{
|
||||
strncpy((char*) game->id, (char*) id, 6);
|
||||
game->id[6] = 0;
|
||||
game->favorite = favoritevar;
|
||||
game->count = playcount;
|
||||
}
|
||||
|
||||
void game_set_num(char *name, char *val)
|
||||
{
|
||||
u8 id[8];
|
||||
struct Game_NUM *game;
|
||||
if (strncmp(name, "game:", 5) != 0) return;
|
||||
trimcopy((char*) id, name + 5, sizeof(id));
|
||||
game = cfg_get_game_num(id);
|
||||
|
||||
cfg_set_game_num(game, id);
|
||||
|
||||
// parse val
|
||||
// first split options by ;
|
||||
char opt[200], *p, *np;
|
||||
p = val;
|
||||
|
||||
while (p)
|
||||
{
|
||||
np = strchr(p, ';');
|
||||
if (np)
|
||||
trim_n_copy(opt, p, np - p, sizeof(opt));
|
||||
else trimcopy(opt, p, sizeof(opt));
|
||||
|
||||
char opt_name[200], opt_val[200];
|
||||
if (trimsplit(opt, opt_name, opt_val, ':', sizeof(opt_name)))
|
||||
{
|
||||
|
||||
short opt_c;
|
||||
if (strcmp("favorite", opt_name) == 0)
|
||||
{
|
||||
if (sscanf(opt_val, "%hd", &opt_c) == 1)
|
||||
{
|
||||
game->favorite = opt_c;
|
||||
}
|
||||
}
|
||||
if (strcmp("count", opt_name) == 0)
|
||||
{
|
||||
if (sscanf(opt_val, "%hd", &opt_c) == 1)
|
||||
{
|
||||
game->count = opt_c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (np)
|
||||
p = np + 1;
|
||||
else p = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool cfg_load_game_num()
|
||||
{
|
||||
char GXGameFavorites_cfg[100];
|
||||
sprintf(GXGameFavorites_cfg, "%s/config/GXGameFavorites.cfg", bootDevice);
|
||||
return cfg_parsefile(GXGameFavorites_cfg, &game_set_num);
|
||||
}
|
||||
|
||||
bool cfg_save_game_num()
|
||||
{
|
||||
FILE *f;
|
||||
int i;
|
||||
char GXGameFavorites_cfg[100];
|
||||
sprintf(GXGameFavorites_cfg, "%s/config", bootDevice);
|
||||
CreateSubfolder(GXGameFavorites_cfg);
|
||||
|
||||
sprintf(GXGameFavorites_cfg, "%s/config/GXGameFavorites.cfg", bootDevice);
|
||||
f = fopen(GXGameFavorites_cfg, "w");
|
||||
if (!f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
fprintf(f, "# USB Loader settings file\n");
|
||||
fprintf(f, "# note: this file is automatically generated\n");
|
||||
fprintf(f, "# Num Games: %d\n", num_saved_game_num);
|
||||
for (i = 0; i < num_saved_game_num; i++)
|
||||
{
|
||||
fprintf(f, "game:%s = ", cfg_game_num[i].id);
|
||||
fprintf(f, "favorite:%d; ", cfg_game_num[i].favorite);
|
||||
fprintf(f, "count:%d;\n", cfg_game_num[i].count);
|
||||
}
|
||||
fprintf(f, "# END\n");
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFG_reset_all_playcounters()
|
||||
{
|
||||
FILE *f;
|
||||
int i;
|
||||
char GXGameFavorites_cfg[100];
|
||||
sprintf(GXGameFavorites_cfg, "%s/config/GXGameFavorites.cfg", bootDevice);
|
||||
f = fopen(GXGameFavorites_cfg, "w");
|
||||
if (!f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
fprintf(f, "# USB Loader settings file\n");
|
||||
fprintf(f, "# note: this file is automatically generated\n");
|
||||
fprintf(f, "# Num Games: %d\n", num_saved_game_num);
|
||||
for (i = 0; i < num_saved_game_num; i++)
|
||||
{
|
||||
fprintf(f, "game:%s = ", cfg_game_num[i].id);
|
||||
fprintf(f, "favorite:%d; ", cfg_game_num[i].favorite);
|
||||
fprintf(f, "count:0;\n");
|
||||
}
|
||||
fprintf(f, "# END\n");
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
struct Game_NUM* CFG_get_game_num(const u8 *id)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < num_saved_game_num; i++)
|
||||
{
|
||||
if (memcmp(id, cfg_game_num[i].id, 6) == 0)
|
||||
{
|
||||
return &cfg_game_num[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool CFG_save_game_num(u8 *id)
|
||||
{
|
||||
struct Game_NUM *game = cfg_get_game_num(id);
|
||||
if (!game) return false;
|
||||
cfg_set_game_num(game, id);
|
||||
return cfg_save_game_num();
|
||||
}
|
||||
|
||||
bool CFG_forget_game_num(u8 *id)
|
||||
{
|
||||
struct Game_NUM *game = CFG_get_game_num(id);
|
||||
int i;
|
||||
if (!game) return true;
|
||||
// move entries down
|
||||
num_saved_game_num--;
|
||||
for (i = game - cfg_game_num; i < num_saved_game_num; i++)
|
||||
{
|
||||
cfg_game_num[i] = cfg_game_num[i + 1];
|
||||
}
|
||||
memset(&cfg_game_num[num_saved_game_num], 0, sizeof(struct Game_NUM));
|
||||
return cfg_save_game_num();
|
||||
}
|
||||
|
||||
void CFG_LoadGameNum()
|
||||
{
|
||||
cfg_load_game_num();
|
||||
}
|
||||
|
||||
void CFG_Cleanup(void)
|
||||
{
|
||||
int i = 0;
|
||||
|
@ -57,8 +57,6 @@ extern "C"
|
||||
// extern u8 wsprompt;
|
||||
// extern u8 keyset;
|
||||
// extern u8 gameDisplay;
|
||||
extern u16 playcount;
|
||||
extern u8 favoritevar;
|
||||
extern char alternatedname[40];
|
||||
// extern u8 returnToLoaderGV;
|
||||
|
||||
@ -68,18 +66,7 @@ extern "C"
|
||||
// always the last entry
|
||||
};
|
||||
|
||||
struct Game_NUM
|
||||
{
|
||||
u8 id[8];
|
||||
u8 favorite;
|
||||
u16 count;
|
||||
};
|
||||
|
||||
void CFG_LoadGameNum(); // -1 = non forced mode
|
||||
struct Game_NUM* CFG_get_game_num(const u8 *id);
|
||||
bool CFG_save_game_num(u8 *id);
|
||||
bool CFG_reset_all_playcounters();
|
||||
bool CFG_forget_game_num(u8 *id);
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "CSettings.h"
|
||||
#include "settings/CGameStatistics.h"
|
||||
#include "newtitles.h"
|
||||
|
||||
#define NEW_SECONDS 24 * 60 * 60
|
||||
@ -145,8 +146,8 @@ bool NewTitles::IsNew(u8 *titleid)
|
||||
if ((time(NULL) - t->timestamp) < NEW_SECONDS)
|
||||
{
|
||||
// Only count the game as new when it's never been played through GX
|
||||
Game_NUM *gnum = CFG_get_game_num(titleid);
|
||||
return gnum == NULL || gnum->count == 0;
|
||||
GameStatus *gnum = GameStatistics.GetGameStatus(titleid);
|
||||
return gnum == NULL || gnum->PlayCount == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "usbloader/wbfs.h"
|
||||
#include "settings/newtitles.h"
|
||||
#include "settings/CSettings.h"
|
||||
#include "settings/CGameStatistics.h"
|
||||
#include "xml/xml.h"
|
||||
#include "FreeTypeGX.h"
|
||||
#include "GameList.h"
|
||||
@ -118,8 +119,8 @@ int GameList::FilterList(const wchar_t * gameFilter)
|
||||
/* Filters */
|
||||
if (Settings.fave)
|
||||
{
|
||||
struct Game_NUM* game_num = CFG_get_game_num(header->id);
|
||||
if (!game_num || game_num->favorite == 0) continue;
|
||||
GameStatus * GameStats = GameStatistics.GetGameStatus(header->id);
|
||||
if (!GameStats || GameStats->FavoriteRank == 0) continue;
|
||||
}
|
||||
|
||||
//ignore uLoader cfg "iso". i was told it is "__CFG_" but not confirmed
|
||||
@ -237,12 +238,8 @@ bool GameList::NameSortCallback(const struct discHdr *a, const struct discHdr *b
|
||||
|
||||
bool GameList::PlaycountSortCallback(const struct discHdr *a, const struct discHdr *b)
|
||||
{
|
||||
struct Game_NUM* game_num1 = CFG_get_game_num(a->id);
|
||||
struct Game_NUM* game_num2 = CFG_get_game_num(b->id);
|
||||
int count1 = 0, count2 = 0;
|
||||
|
||||
if (game_num1) count1 = game_num1->count;
|
||||
if (game_num2) count2 = game_num2->count;
|
||||
int count1 = GameStatistics.GetPlayCount(a->id);
|
||||
int count2 = GameStatistics.GetPlayCount(b->id);
|
||||
|
||||
if (count1 == count2) return NameSortCallback(a, b);
|
||||
|
||||
@ -251,12 +248,8 @@ bool GameList::PlaycountSortCallback(const struct discHdr *a, const struct discH
|
||||
|
||||
bool GameList::FavoriteSortCallback(const struct discHdr *a, const struct discHdr *b)
|
||||
{
|
||||
struct Game_NUM* game_num1 = CFG_get_game_num(a->id);
|
||||
struct Game_NUM* game_num2 = CFG_get_game_num(b->id);
|
||||
int fav1 = 0, fav2 = 0;
|
||||
|
||||
if (game_num1) fav1 = game_num1->favorite;
|
||||
if (game_num2) fav2 = game_num2->favorite;
|
||||
int fav1 = GameStatistics.GetFavoriteRank(a->id);
|
||||
int fav2 = GameStatistics.GetFavoriteRank(b->id);
|
||||
|
||||
if (fav1 == fav2) return NameSortCallback(a, b);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user