* Fixed cache updates for each view when the language is changed

This commit is contained in:
overjoy.psm 2012-02-03 03:00:13 +00:00
parent 69c1094891
commit 28d10bbcdc
6 changed files with 31 additions and 24 deletions

View File

@ -2,7 +2,7 @@
#include <typeinfo>
template <class T>
void CachedList<T>::Load(string path, string containing) /* Load All */
void CachedList<T>::Load(string path, string containing, string m_lastLanguage) /* Load All */
{
gprintf("\nLoading files containing %s in %s\n", containing.c_str(), path.c_str());
m_loaded = false;
@ -37,7 +37,10 @@ void CachedList<T>::Load(string path, string containing) /* Load All
ditimes = discinfo.st_mtime > cache.st_mtime;
m_update = update_lang || noDB || mtimes || ditimes;
if(m_update) gprintf("Cache is being updated because %s\n", update_lang ? "languages are different!" : noDB ? "a database was not found!" : "the WBFS folder was modified!");
if(m_update) gprintf("Cache of %s is being updated because ", path.c_str());
if(update_lang) gprintf("languages are different!\nOld language string: %s\nNew language string: %s\n", m_lastLanguage.c_str(), m_curLanguage.c_str());
if(noDB) gprintf("a database was not found!\n");
if(mtimes || ditimes) gprintf("the WBFS folder was modified!");
}
if(update_games) force_update[COVERFLOW_USB] = false;
@ -59,7 +62,6 @@ void CachedList<T>::Load(string path, string containing) /* Load All
fclose(file);
remove(path.c_str());
m_lastLanguage = m_curLanguage;
m_loaded = true;
m_update = false;
@ -70,14 +72,14 @@ void CachedList<T>::Load(string path, string containing) /* Load All
}
}
else
{
{
CCache<T>(*this, m_database, LOAD);
m_loaded = true;
}
}
template<>
void CachedList<dir_discHdr>::LoadChannels(string path, u32 channelType) /* Load All */
void CachedList<dir_discHdr>::LoadChannels(string path, u32 channelType, string m_lastLanguage) /* Load All */
{
m_loaded = false;
m_update = true;
@ -101,7 +103,7 @@ void CachedList<dir_discHdr>::LoadChannels(string path, u32 channelType)
if(stat(newpath.c_str(), &filestat) == -1) return;
m_update = force_update[COVERFLOW_CHANNEL] || m_lastchannelLang != m_channelLang || stat(m_database.c_str(), &cache) == -1 || filestat.st_mtime > cache.st_mtime;
m_update = force_update[COVERFLOW_CHANNEL] || m_lastLanguage != m_curLanguage || stat(m_database.c_str(), &cache) == -1 || filestat.st_mtime > cache.st_mtime;
}
force_update[COVERFLOW_CHANNEL] = false;
@ -109,11 +111,10 @@ void CachedList<dir_discHdr>::LoadChannels(string path, u32 channelType)
if(m_update)
{
gprintf("Updating channels\n");
list.GetChannels(*this, m_settingsDir, channelType, m_channelLang);
list.GetChannels(*this, m_settingsDir, channelType, m_curLanguage);
m_loaded = true;
m_update = false;
m_lastchannelLang = m_channelLang;
if(this->size() > 0 && emu) Save();
}

View File

@ -24,8 +24,7 @@ class CachedList : public safe_vector<T>
{
m_cacheDir = cachedir;
m_settingsDir = settingsDir;
m_curLanguage = m_lastLanguage = curLanguage;
m_channelLang = m_lastchannelLang = curLanguage;
m_curLanguage = curLanguage;
m_loaded = false;
m_database = "";
m_update = false;
@ -48,8 +47,8 @@ class CachedList : public safe_vector<T>
}
}
void Load(string path, string containing);
void LoadChannels(string path, u32 channelType);
void Load(string path, string containing, string m_lastLanguage);
void LoadChannels(string path, u32 channelType, string m_lastLanguage);
void Unload(){if(m_loaded) {this->clear(); m_loaded = false; m_database = "";}};
void Save() {if(m_loaded) CCache<T>(*this, m_database, SAVE);} /* Save All */
@ -60,7 +59,7 @@ class CachedList : public safe_vector<T>
void Add(T tmp) {if(m_loaded) CCache<T>(*this, m_database, tmp, ADD);} /* Add One */
void Remove(u32 index) {if(m_loaded) CCache<T>(*this, m_database, index, REMOVE);} /* Remove One */
void SetLanguage(string curLanguage) { m_curLanguage = m_channelLang = curLanguage; }
void SetLanguage(string curLanguage) { m_curLanguage = curLanguage; }
private:
string make_db_name(string path);
@ -73,9 +72,6 @@ class CachedList : public safe_vector<T>
string m_cacheDir;
string m_settingsDir;
string m_curLanguage;
string m_lastLanguage;
string m_channelLang;
string m_lastchannelLang;
string m_discinf;
};

View File

@ -1534,7 +1534,12 @@ bool CMenu::_loadChannelList(void)
string nandpath = sfmt("%s:%s", DeviceName[currentPartition], path.empty() ? "/" : path.c_str());
gprintf("nandpath = %s\n", nandpath.c_str());
if(!failed) m_gameList.LoadChannels(disable_emu ? "" : nandpath, 0);
if(!failed)
{
m_gameList.LoadChannels(disable_emu ? "" : nandpath, 0, m_cfg.getString("NAND", "lastlanguage", "EN").c_str());
m_cfg.setString("NAND", "lastlanguage", m_loc.getString(m_curLanguage, "gametdb_code", "EN"));
m_cfg.save();
}
lastPartition = currentPartition;
last_emu_state = disable_emu;
@ -1585,7 +1590,9 @@ bool CMenu::_loadGameList(void)
gprintf("%s\n", DeviceName[currentPartition]);
DeviceHandler::Instance()->Open_WBFS(currentPartition);
m_gameList.Load(sfmt(GAMES_DIR, DeviceName[currentPartition]), ".wbfs|.iso");
m_gameList.Load(sfmt(GAMES_DIR, DeviceName[currentPartition]), ".wbfs|.iso", m_cfg.getString("GAMES", "lastlanguage", "EN").c_str());
m_cfg.setString("GAMES", "lastlanguage", m_loc.getString(m_curLanguage, "gametdb_code", "EN"));
m_cfg.save();
return m_gameList.size() > 0 ? true : false;
}
@ -1597,8 +1604,9 @@ bool CMenu::_loadHomebrewList()
gprintf("%s\n", DeviceName[currentPartition]);
DeviceHandler::Instance()->Open_WBFS(currentPartition);
m_gameList.Load(sfmt(HOMEBREW_DIR, DeviceName[currentPartition]), ".dol|.elf");
m_gameList.Load(sfmt(HOMEBREW_DIR, DeviceName[currentPartition]), ".dol|.elf", m_cfg.getString("HOMEBREW", "lastlanguage", "EN").c_str());
m_cfg.setString("HOMEBREW", "lastlanguage", m_loc.getString(m_curLanguage, "gametdb_code", "EN"));
m_cfg.save();
return m_gameList.size() > 0 ? true : false;
}
@ -1609,7 +1617,9 @@ bool CMenu::_loadDmlList()
gprintf("%s\n", DeviceName[SD]);
DeviceHandler::Instance()->Open_WBFS(SD);
m_gameList.Load(sfmt(DML_DIR, DeviceName[SD]), ".iso");
m_gameList.Load(sfmt(DML_DIR, DeviceName[SD]), ".iso", m_cfg.getString("DML", "lastlanguage", "EN").c_str());
m_cfg.setString("DML", "lastlanguage", m_loc.getString(m_curLanguage, "gametdb_code", "EN"));
m_cfg.save();
return m_gameList.size() > 0 ? true : false;
}

View File

@ -200,6 +200,7 @@ int CMenu::_configAdv(void)
{
if(lang_changed)
m_gameList.SetLanguage(m_loc.getString(m_curLanguage, "gametdb_code", "EN").c_str());
_loadList();
}
lang_changed = false;

View File

@ -194,7 +194,6 @@ int CMenu::main(void)
m_gametdb.CloseFile();
}
m_gameList.SetLanguage(m_loc.getString(m_curLanguage, "gametdb_code", "EN").c_str());
if (m_cfg.getBool("GENERAL", "update_cache", false))
{
UpdateCache();

View File

@ -34,10 +34,10 @@ void MusicPlayer::Init(Config &cfg, string musicDir, string themeMusicDir)
m_music_files.Init(cfg.getString("GENERAL", "dir_list_cache"), std::string(), std::string());
if (dir & THEME_MUSIC)
m_music_files.Load(themeMusicDir, ".ogg|.mp3"); //|.mod|.xm|.s3m|.wav|.aiff");
m_music_files.Load(themeMusicDir, ".ogg|.mp3", "EN"); //|.mod|.xm|.s3m|.wav|.aiff");
if (dir & NORMAL_MUSIC)
m_music_files.Load(musicDir, ".ogg|.mp3"); //|.mod|.xm|.s3m|.wav|.aiff");
m_music_files.Load(musicDir, ".ogg|.mp3", "EN"); //|.mod|.xm|.s3m|.wav|.aiff");
if (cfg.getBool("GENERAL", "randomize_music", false) && m_music_files.size() > 0)
{