From cbdd8d7ec85b8c9bc3e951eae02aee53aa5c7b44 Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Thu, 4 Oct 2012 15:16:04 +0000 Subject: [PATCH] -added some security checks to list generator (should fix wbfs partitions) -removed some other unneeded stuff -fixed some wrong code in return to --- source/channel/channels.cpp | 2 ++ source/channel/channels.h | 2 ++ source/list/ListGenerator.cpp | 52 +++++++++++++++++++---------------- source/list/ListGenerator.hpp | 2 +- source/menu/menu.cpp | 6 ++-- source/menu/menu_config4.cpp | 23 ++++++---------- source/menu/menu_game.cpp | 5 ++-- 7 files changed, 47 insertions(+), 45 deletions(-) diff --git a/source/channel/channels.cpp b/source/channel/channels.cpp index b687b3c5..f98258e4 100644 --- a/source/channel/channels.cpp +++ b/source/channel/channels.cpp @@ -44,6 +44,8 @@ #define RF_NEWS_CHANNEL 0x48414741 #define RF_FORECAST_CHANNEL 0x48414641 +Channels ChannelHandle; + Channels::Channels() { } diff --git a/source/channel/channels.h b/source/channel/channels.h index 398a757e..08be6795 100644 --- a/source/channel/channels.h +++ b/source/channel/channels.h @@ -80,4 +80,6 @@ class Channels }; +extern Channels ChannelHandle; + #endif diff --git a/source/list/ListGenerator.cpp b/source/list/ListGenerator.cpp index 640565ce..7a64e1b9 100644 --- a/source/list/ListGenerator.cpp +++ b/source/list/ListGenerator.cpp @@ -27,14 +27,18 @@ ListGenerator m_gameList; void ListGenerator::Init(const char *settingsDir, const char *Language) { - gameTDB_Path = fmt("%s/wiitdb.xml", settingsDir); - CustomTitlesPath = fmt("%s/" CTITLES_FILENAME, settingsDir); - gameTDB_Language = Language; + if(settingsDir != NULL) + { + gameTDB_Path = fmt("%s/wiitdb.xml", settingsDir); + CustomTitlesPath = fmt("%s/" CTITLES_FILENAME, settingsDir); + } + if(Language != NULL) gameTDB_Language = Language; } void ListGenerator::Cleanup() { this->clear(); //clear gamelist + InternalList.clear(); //clear pathlist } void ListGenerator::OpenConfigs() @@ -53,21 +57,21 @@ void ListGenerator::CloseConfigs() CustomTitles.unload(); } -void ListGenerator::CreateList(u32 Flow, u32 Device, const string& Path, -const vector& FileTypes, const string& DBName, bool UpdateCache, u32 Color, u32 Magic) +void ListGenerator::CreateList(u32 Flow, u32 Device, const string& Path, const vector& FileTypes, + const string& DBName, bool UpdateCache, u32 Color, u32 Magic) { Cleanup(); - if(UpdateCache) + if(!DBName.empty()) { - gprintf("Force Update Cache\n"); - fsop_deleteFile(DBName.c_str()); - } - else - { - CCache(*this, DBName, LOAD); - if(!this->empty()) - return; - fsop_deleteFile(DBName.c_str()); + if(UpdateCache) + fsop_deleteFile(DBName.c_str()); + else + { + CCache(*this, DBName, LOAD); + if(!this->empty()) + return; + fsop_deleteFile(DBName.c_str()); + } } OpenConfigs(); if(Flow == COVERFLOW_USB) @@ -78,7 +82,7 @@ const vector& FileTypes, const string& DBName, bool UpdateCache, u32 Col Create_Wii_EXT_List(Path, FileTypes); } else if(Flow == COVERFLOW_CHANNEL) - CreateChannelList(); + Create_Channel_List(); else if(DeviceHandle.GetFSType(Device) != PART_FS_WBFS) { if(Flow == COVERFLOW_DML) @@ -89,7 +93,7 @@ const vector& FileTypes, const string& DBName, bool UpdateCache, u32 Col Create_Homebrew_List(Path, FileTypes); } CloseConfigs(); - if(!this->empty()) /* Write a new Cache */ + if(!this->empty() && !DBName.empty()) /* Write a new Cache */ CCache(*this, DBName, SAVE); } @@ -136,7 +140,6 @@ void ListGenerator::Create_GC_List(const string& Path, const vector& Fil { Name->erase(Name->begin() + Name->find("root"), Name->end()); Name->append("sys/boot.bin"); - gprintf("FST Name: %s\n", Name->c_str()); fp = fopen(Name->c_str(), "rb"); } if(fp) @@ -178,7 +181,7 @@ void ListGenerator::Create_Plugin_List(const string& Path, const vector& void ListGenerator::Create_Homebrew_List(const string& Path, const vector& FileTypes) { dir_discHdr ListElement; - GetFiles(Path.c_str(), FileTypes, InternalList, false, 4); + GetFiles(Path.c_str(), FileTypes, InternalList, false); for(vector::iterator Name = InternalList.begin(); Name != InternalList.end(); Name++) { if(Name->find("boot.") == string::npos) @@ -202,12 +205,12 @@ void ListGenerator::Create_Homebrew_List(const string& Path, const vectorpush_back(ListElement); continue; } + InternalList.clear(); } -void ListGenerator::CreateChannelList() +void ListGenerator::Create_Channel_List() { u32 GameColor = 1; - Channels ChannelHandle; dir_discHdr ListElement; ChannelHandle.Init(0, gameTDB_Language, true); for(int i = 0; i < ChannelHandle.Count(); i++) @@ -238,6 +241,7 @@ void ListGenerator::CreateChannelList() ListElement.type = TYPE_CHANNEL; this->push_back(ListElement); } + InternalList.clear(); } void ListGenerator::AddISO(const char *GameID, const char *GameTitle, const char *GamePath, u32 GameColor, u8 Type) @@ -245,8 +249,8 @@ void ListGenerator::AddISO(const char *GameID, const char *GameTitle, const char dir_discHdr ListElement; memset((void*)&ListElement, 0, sizeof(dir_discHdr)); ListElement.index = this->size(); - strncpy(ListElement.id, GameID, 6); - strncpy(ListElement.path, GamePath, sizeof(ListElement.path)); + if(GameID != NULL) strncpy(ListElement.id, GameID, 6); + if(GamePath != NULL) strncpy(ListElement.path, GamePath, sizeof(ListElement.path)); ListElement.casecolor = CustomTitles.getColor("COVERS", ListElement.id, GameColor).intVal(); string CustomTitle = CustomTitles.getString("TITLES", ListElement.id); if(gameTDB.IsLoaded()) @@ -260,7 +264,7 @@ void ListGenerator::AddISO(const char *GameID, const char *GameTitle, const char } if(CustomTitle.size() > 0) mbstowcs(ListElement.title, CustomTitle.c_str(), 63); - else + else if(GameTitle != NULL) mbstowcs(ListElement.title, GameTitle, 63); Asciify(ListElement.title); diff --git a/source/list/ListGenerator.hpp b/source/list/ListGenerator.hpp index 32c58511..96268529 100644 --- a/source/list/ListGenerator.hpp +++ b/source/list/ListGenerator.hpp @@ -45,7 +45,7 @@ private: void Create_Plugin_List(const string& Path, const vector& FileTypes, u32 Color, u32 Magic); void Create_Homebrew_List(const string& Path, const vector& FileTypes); - void CreateChannelList(); + void Create_Channel_List(); void AddISO(const char *GameID, const char *GameTitle, const char *GamePath, u32 GameColor, u8 Type); bool IsFileSupported(const char *File, const vector& FileTypes); void OpenConfigs(); diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index c42ff6c0..1073b5d2 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -2169,8 +2169,10 @@ bool CMenu::_loadChannelList(void) if(Nand::Instance()->EmulationEnabled() || disable_emu) { - string cacheDir(fmt("%s/%s_channels.db", m_cacheDir.c_str(), disable_emu ? "nand" : DeviceName[currentPartition])); - bool updateCache = disable_emu ? true : m_cfg.getBool(_domainFromView(), "update_cache"); + string cacheDir; + if(!disable_emu) + cacheDir = fmt("%s/%s_channels.db", m_cacheDir.c_str(), DeviceName[currentPartition]); + bool updateCache = m_cfg.getBool(_domainFromView(), "update_cache"); vector NullVector; m_gameList.CreateList(m_current_view, currentPartition, std::string(), NullVector, cacheDir, updateCache); diff --git a/source/menu/menu_config4.cpp b/source/menu/menu_config4.cpp index 4ace310d..708a67fc 100644 --- a/source/menu/menu_config4.cpp +++ b/source/menu/menu_config4.cpp @@ -18,8 +18,6 @@ static inline int loopNum(int i, int s) int currentChannelIndex = -1; int amountOfChannels = -1; -Channels m_channels; - const CMenu::SOption CMenu::_exitTo[5] = { { "def", L"Default" }, { "menu", L"System Menu" }, @@ -78,29 +76,22 @@ void CMenu::_showConfig4(void) wstringEx channelName = m_loc.getWString(m_curLanguage, "disabled", L"Disabled"); - string langCode = m_loc.getString(m_curLanguage, "gametdb_code", "EN"); - Nand::Instance()->Disable_Emu(); - - m_channels.Init(0x00010001, langCode, true); - amountOfChannels = m_channels.Count(); + ChannelHandle.Init(0, m_loc.getString(m_curLanguage, "gametdb_code", "EN"), true); + amountOfChannels = ChannelHandle.Count(); string currentChanId = m_cfg.getString("GENERAL", "returnto" ); if (currentChanId.size() > 0) { for (int i = 0; i < amountOfChannels; i++) { - if (currentChanId == m_channels.GetId(i)) + if (currentChanId == ChannelHandle.GetId(i)) { - channelName = custom_titles.getWString("TITLES", currentChanId, titles.getWString("TITLES", currentChanId, m_channels.GetName(i))); + channelName = custom_titles.getWString("TITLES", currentChanId, titles.getWString("TITLES", currentChanId, ChannelHandle.GetName(i))); break; } } } - - if(!neek2o() && m_current_view == COVERFLOW_CHANNEL && m_cfg.getInt("NAND", "emulation", 0) > 0) - Nand::Instance()->Enable_Emu(); - m_btnMgr.setText(m_config4LblReturnToVal, channelName); } @@ -139,7 +130,7 @@ int CMenu::_config4(void) if (currentChannelIndex == -1) m_cfg.remove("GENERAL", "returnto"); else - m_cfg.setString("GENERAL", "returnto", m_channels.GetId(currentChannelIndex)); + m_cfg.setString("GENERAL", "returnto", ChannelHandle.GetId(currentChannelIndex)); _showConfig4(); } else if (m_btnMgr.selected(m_config4BtnReturnToM)) @@ -149,11 +140,13 @@ int CMenu::_config4(void) if (currentChannelIndex == -1) m_cfg.remove("GENERAL", "returnto"); else - m_cfg.setString("GENERAL", "returnto", m_channels.GetId(currentChannelIndex)); + m_cfg.setString("GENERAL", "returnto", ChannelHandle.GetId(currentChannelIndex)); _showConfig4(); } } } + if(!neek2o() && m_current_view == COVERFLOW_CHANNEL && m_cfg.getBool("NAND", "disable", true) == false) + Nand::Instance()->Enable_Emu(); _hideConfig4(); return change; } diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index f28a1385..5cebf5b3 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -258,7 +258,7 @@ static void _extractBannerTitle(Banner *bnr, int language) static Banner *_extractChannelBnr(const u64 chantitle) { - return Channels::GetBanner(chantitle); + return ChannelHandle.GetBanner(chantitle); } static Banner *_extractBnr(dir_discHdr *hdr) @@ -1027,7 +1027,6 @@ static const char systems[11] = { 'C', 'E', 'F', 'J', 'L', 'M', 'N', 'P', 'Q', ' void CMenu::_launchChannel(dir_discHdr *hdr) { - Channels channel; u32 gameIOS = 0; string id = string(hdr->id); @@ -1122,7 +1121,7 @@ void CMenu::_launchChannel(dir_discHdr *hdr) Nand::Instance()->Init(emuPath.c_str(), emuPartition, false); Nand::Instance()->Enable_Emu(); } - gameIOS = channel.GetRequestedIOS(gameTitle); + gameIOS = ChannelHandle.GetRequestedIOS(gameTitle); if(!emu_disabled) Nand::Instance()->Disable_Emu(); if(_loadIOS(gameIOS, userIOS, id) == LOAD_IOS_FAILED)