diff --git a/HBC/META.XML b/HBC/META.XML index 40d203b5..af011be0 100644 --- a/HBC/META.XML +++ b/HBC/META.XML @@ -2,8 +2,8 @@ USB Loader GX USB Loader GX Team - 1.0 r974 - 201009250702 + 1.0 r975 + 201009250708 Loads games from USB-devices 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. diff --git a/gui.pnproj b/gui.pnproj index 4230a764..d7934e45 100644 --- a/gui.pnproj +++ b/gui.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/source/libntfs/mem_allocate.h b/source/libntfs/mem_allocate.h index ca3dce70..92659cf5 100644 --- a/source/libntfs/mem_allocate.h +++ b/source/libntfs/mem_allocate.h @@ -23,24 +23,21 @@ #define _MEM_ALLOCATE_H #include +#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 */ diff --git a/source/memory/mem2.h b/source/memory/mem2.h index ceb1bab0..b8fa93cf 100644 --- a/source/memory/mem2.h +++ b/source/memory/mem2.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 + +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 } diff --git a/source/menu/menu_disclist.cpp b/source/menu/menu_disclist.cpp index cfa4b209..1bc92a4d 100644 --- a/source/menu/menu_disclist.cpp +++ b/source/menu/menu_disclist.cpp @@ -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); diff --git a/source/prompts/PromptWindows.cpp b/source/prompts/PromptWindows.cpp index 24066832..f034c4e7 100644 --- a/source/prompts/PromptWindows.cpp +++ b/source/prompts/PromptWindows.cpp @@ -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(); diff --git a/source/settings/CGameSettings.cpp b/source/settings/CGameSettings.cpp index 3c6eb82c..4b294dfe 100644 --- a/source/settings/CGameSettings.cpp +++ b/source/settings/CGameSettings.cpp @@ -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; diff --git a/source/settings/CGameSettings.h b/source/settings/CGameSettings.h index 096d44e6..16cf74c4 100644 --- a/source/settings/CGameSettings.h +++ b/source/settings/CGameSettings.h @@ -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 diff --git a/source/settings/CGameStatistics.cpp b/source/settings/CGameStatistics.cpp new file mode 100644 index 00000000..8aaed7ca --- /dev/null +++ b/source/settings/CGameStatistics.cpp @@ -0,0 +1,293 @@ +#include +#include +#include +#include + +#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().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; +} diff --git a/source/settings/CGameStatistics.h b/source/settings/CGameStatistics.h new file mode 100644 index 00000000..86bd5165 --- /dev/null +++ b/source/settings/CGameStatistics.h @@ -0,0 +1,71 @@ +#ifndef _GAME_STATISTICS_H_ +#define _GAME_STATISTICS_H_ + +#include +#include +#include +#include +#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 GameList; +}; + +extern CGameStatistics GameStatistics; + +#endif diff --git a/source/settings/CSettings.cpp b/source/settings/CSettings.cpp index 1f230e8b..4ec9fb9a 100644 --- a/source/settings/CSettings.cpp +++ b/source/settings/CSettings.cpp @@ -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); diff --git a/source/settings/Settings.cpp b/source/settings/Settings.cpp index 5f8834df..531e4cb2 100644 --- a/source/settings/Settings.cpp +++ b/source/settings/Settings.cpp @@ -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(); } } } diff --git a/source/settings/cfg.c b/source/settings/cfg.c index d4546d49..2512fd2b 100644 --- a/source/settings/cfg.c +++ b/source/settings/cfg.c @@ -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; diff --git a/source/settings/cfg.h b/source/settings/cfg.h index 5d7c44ed..72ee8467 100644 --- a/source/settings/cfg.h +++ b/source/settings/cfg.h @@ -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 { diff --git a/source/settings/newtitles.cpp b/source/settings/newtitles.cpp index 5810bbe8..2d2c5667 100644 --- a/source/settings/newtitles.cpp +++ b/source/settings/newtitles.cpp @@ -2,6 +2,7 @@ #include #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; } diff --git a/source/usbloader/GameList.cpp b/source/usbloader/GameList.cpp index 941fbe3c..3b22439f 100644 --- a/source/usbloader/GameList.cpp +++ b/source/usbloader/GameList.cpp @@ -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);