2012-01-21 21:57:41 +01:00
|
|
|
#include "cachedlist.hpp"
|
|
|
|
#include <typeinfo>
|
|
|
|
|
2012-08-16 16:09:02 +02:00
|
|
|
void CachedList::Load(string path, string containing, string m_lastLanguage, Config &m_plugin) /* Load All */
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-09-23 14:10:25 +02:00
|
|
|
//gprintf("\nLoading files containing %s in %s\n", containing.c_str(), path.c_str());
|
2012-01-21 21:57:41 +01:00
|
|
|
m_loaded = false;
|
|
|
|
m_database = sfmt("%s/%s.db", m_cacheDir.c_str(), (make_db_name(path)).c_str());
|
2012-03-08 13:52:01 +01:00
|
|
|
|
2012-09-22 15:47:52 +02:00
|
|
|
m_wbfsFS = strncasecmp(DeviceHandle.PathToFSName(path.c_str()), "WBFS", 4) == 0;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
bool update_games = false;
|
|
|
|
bool update_homebrew = false;
|
2012-02-01 00:44:54 +01:00
|
|
|
bool update_dml = false;
|
2012-04-10 15:37:57 +02:00
|
|
|
bool update_emu = false;
|
|
|
|
|
2012-02-02 02:46:01 +01:00
|
|
|
bool ditimes = false;
|
2012-08-16 16:09:02 +02:00
|
|
|
if(!m_wbfsFS)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-09-23 14:10:25 +02:00
|
|
|
//gprintf("Database file: %s\n", m_database.c_str());
|
2012-02-18 14:51:55 +01:00
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
update_games = strcasestr(path.c_str(), "wbfs") != NULL && force_update[COVERFLOW_USB];
|
|
|
|
update_homebrew = strcasestr(path.c_str(), "apps") != NULL && force_update[COVERFLOW_HOMEBREW];
|
2012-05-22 20:06:43 +02:00
|
|
|
update_emu = strcasestr(path.c_str(), m_plugin.getString("PLUGIN","romDir","").c_str()) != NULL && force_update[COVERFLOW_EMU];
|
2012-03-08 13:52:01 +01:00
|
|
|
|
2012-09-22 15:47:52 +02:00
|
|
|
const char* partition = DeviceName[DeviceHandle.PathToDriveType(path.c_str())];
|
2012-05-04 14:30:43 +02:00
|
|
|
update_dml = strcasestr(path.c_str(), fmt(strncmp(partition, "sd", 2) != 0 ? m_DMLgameDir.c_str() : "%s:/games", partition)) != NULL && force_update[COVERFLOW_DML];
|
2012-03-08 13:52:01 +01:00
|
|
|
|
2012-09-23 14:10:25 +02:00
|
|
|
//gprintf("update_games=%d update_homebrew=%d update_dml=%d, update_emu=%d\n", update_games, update_homebrew, update_dml, update_emu);
|
2012-04-08 17:54:34 +02:00
|
|
|
if(update_games || update_homebrew || update_dml || update_emu)
|
2012-01-21 21:57:41 +01:00
|
|
|
remove(m_database.c_str());
|
|
|
|
|
2012-02-02 02:46:01 +01:00
|
|
|
m_discinf = sfmt("%s/disc.info", path.c_str());
|
|
|
|
struct stat filestat, discinfo, cache;
|
2012-09-23 14:10:25 +02:00
|
|
|
//gprintf("%s\n", path.c_str());
|
2012-06-07 02:34:47 +02:00
|
|
|
if(stat(path.c_str(), &filestat) == -1)
|
2012-07-26 00:12:17 +02:00
|
|
|
return;
|
2012-08-22 07:21:15 +02:00
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
bool update_lang = m_lastLanguage != m_curLanguage;
|
|
|
|
bool noDB = stat(m_database.c_str(), &cache) == -1;
|
|
|
|
bool mtimes = filestat.st_mtime > cache.st_mtime;
|
2012-02-02 02:46:01 +01:00
|
|
|
if(strcasestr(m_discinf.c_str(), "wbfs") != NULL && stat(m_discinf.c_str(), &discinfo) != -1)
|
2012-07-26 00:12:17 +02:00
|
|
|
ditimes = discinfo.st_mtime > cache.st_mtime;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-08-22 07:21:15 +02:00
|
|
|
m_update = update_lang || noDB || (!m_skipcheck && (mtimes || ditimes));
|
2012-09-23 14:10:25 +02:00
|
|
|
/*if(m_update)
|
2012-06-07 02:34:47 +02:00
|
|
|
gprintf("Cache of %s is being updated because:\n", 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");
|
2012-08-22 07:21:15 +02:00
|
|
|
if(!m_skipcheck && (mtimes || ditimes))
|
2012-06-07 02:34:47 +02:00
|
|
|
gprintf("The WBFS folder was modified!\nCache date: %i\nFolder date: %i\n", cache.st_mtime, filestat.st_mtime);
|
2012-09-23 14:10:25 +02:00
|
|
|
*/
|
2012-08-22 07:21:15 +02:00
|
|
|
if(m_extcheck && !m_update && !m_skipcheck)
|
2012-04-05 13:00:05 +02:00
|
|
|
{
|
|
|
|
bool m_chupdate = false;
|
|
|
|
DIR *dir = opendir(path.c_str());
|
|
|
|
struct dirent *entry;
|
|
|
|
while((entry = readdir(dir)) != NULL)
|
|
|
|
{
|
|
|
|
m_discinf = sfmt("%s/%s", path.c_str(), entry->d_name);
|
|
|
|
if(stat(m_discinf.c_str(), &discinfo) != -1)
|
|
|
|
m_chupdate = discinfo.st_mtime > cache.st_mtime;
|
|
|
|
if(m_chupdate)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
m_update = m_chupdate;
|
2012-08-22 07:21:15 +02:00
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-06-07 02:34:47 +02:00
|
|
|
if(update_games)
|
|
|
|
force_update[COVERFLOW_USB] = false;
|
|
|
|
if(update_homebrew)
|
|
|
|
force_update[COVERFLOW_HOMEBREW] = false;
|
|
|
|
if(update_dml)
|
|
|
|
force_update[COVERFLOW_DML] = false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-08-16 16:09:02 +02:00
|
|
|
if(m_update || m_wbfsFS)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-09-23 14:10:25 +02:00
|
|
|
gprintf("Updating Cache\n");
|
|
|
|
|
2012-05-06 14:03:43 +02:00
|
|
|
vector<string> pathlist;
|
2012-08-16 16:09:02 +02:00
|
|
|
list.GetPaths(pathlist, containing, path, m_wbfsFS, (update_dml || (m_update && strcasestr(path.c_str(), ":/games") != NULL)), !update_emu);
|
2012-04-10 01:19:08 +02:00
|
|
|
list.GetHeaders(pathlist, *this, m_settingsDir, m_curLanguage, m_DMLgameDir, m_plugin);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
path.append("/touch.db");
|
|
|
|
FILE *file = fopen(path.c_str(), "wb");
|
|
|
|
fclose(file);
|
|
|
|
remove(path.c_str());
|
|
|
|
|
2012-01-30 00:55:49 +01:00
|
|
|
m_loaded = true;
|
2012-07-26 00:12:17 +02:00
|
|
|
m_update = false;
|
2012-01-25 01:11:28 +01:00
|
|
|
|
2012-08-16 16:09:02 +02:00
|
|
|
if(pathlist.size() > 0)
|
2012-01-21 21:57:41 +01:00
|
|
|
Save();
|
2012-08-05 15:48:15 +02:00
|
|
|
pathlist.clear();
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
else
|
2012-07-26 00:12:17 +02:00
|
|
|
{
|
2012-08-16 16:09:02 +02:00
|
|
|
CCache(*this, m_database, LOAD);
|
2012-01-30 00:55:49 +01:00
|
|
|
m_loaded = true;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-08-16 16:09:02 +02:00
|
|
|
void CachedList::LoadChannels(string path, u32 channelType, string m_lastLanguage) /* Load All */
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
m_loaded = false;
|
|
|
|
m_update = true;
|
|
|
|
|
|
|
|
bool emu = !path.empty();
|
|
|
|
if(emu)
|
|
|
|
{
|
|
|
|
m_database = sfmt("%s/%s.db", m_cacheDir.c_str(), make_db_name(sfmt("%s/emu", path.c_str())).c_str());
|
|
|
|
|
|
|
|
size_t find = m_database.find("//");
|
|
|
|
if(find != string::npos)
|
|
|
|
m_database.replace(find, 2, "/");
|
|
|
|
|
|
|
|
if(force_update[COVERFLOW_CHANNEL])
|
|
|
|
remove(m_database.c_str());
|
|
|
|
|
|
|
|
//gprintf("%s\n", m_database.c_str());
|
|
|
|
struct stat filestat, cache;
|
|
|
|
|
2012-09-10 00:38:42 +02:00
|
|
|
/*** Removed that stupid check overhere! ***/
|
|
|
|
/*** Will replace it soon with something better!! ***/
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-02-03 04:00:13 +01:00
|
|
|
m_update = force_update[COVERFLOW_CHANNEL] || m_lastLanguage != m_curLanguage || stat(m_database.c_str(), &cache) == -1 || filestat.st_mtime > cache.st_mtime;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
force_update[COVERFLOW_CHANNEL] = false;
|
|
|
|
|
|
|
|
if(m_update)
|
|
|
|
{
|
2012-09-23 14:10:25 +02:00
|
|
|
//gprintf("Updating channels\n");
|
2012-02-03 04:00:13 +01:00
|
|
|
list.GetChannels(*this, m_settingsDir, channelType, m_curLanguage);
|
2012-09-23 14:10:25 +02:00
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
m_loaded = true;
|
|
|
|
m_update = false;
|
|
|
|
|
|
|
|
if(this->size() > 0 && emu) Save();
|
|
|
|
}
|
|
|
|
else
|
2012-08-16 16:09:02 +02:00
|
|
|
CCache(*this, m_database, LOAD);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
m_loaded = true;
|
|
|
|
}
|
|
|
|
|
2012-08-16 16:09:02 +02:00
|
|
|
string CachedList::make_db_name(string path)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
string buffer = path;
|
|
|
|
size_t find = buffer.find(":/");
|
|
|
|
if(find != string::npos)
|
|
|
|
buffer.replace(find, 2, "_");
|
|
|
|
|
|
|
|
find = buffer.find("/");
|
|
|
|
while(find != string::npos)
|
|
|
|
{
|
|
|
|
buffer[find] = '_';
|
|
|
|
find = buffer.find("/");
|
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|