mirror of
https://github.com/Fledge68/WiiFlow_Lite.git
synced 2025-01-11 19:39:09 +01:00
-removed a few unneeded lines of code
This commit is contained in:
parent
f7929f2838
commit
39e8ceb842
@ -1,7 +1,6 @@
|
||||
#include "cache.hpp"
|
||||
|
||||
template <typename T>
|
||||
CCache<T>::CCache(T &tmp, string path, u32 index, CMode mode) /* Load/Save One */
|
||||
CCache::CCache(dir_discHdr &tmp, string path, u32 index, CMode mode) /* Load/Save One */
|
||||
{
|
||||
filename = path;
|
||||
//gprintf("Openning DB: %s\n", filename.c_str());
|
||||
@ -22,8 +21,7 @@ CCache<T>::CCache(T &tmp, string path, u32 index, CMode mode) /* Load/Save One *
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
CCache<T>::CCache(vector<T> &list, string path , CMode mode) /* Load/Save All */
|
||||
CCache::CCache(vector<dir_discHdr> &list, string path , CMode mode) /* Load/Save All */
|
||||
{
|
||||
filename = path;
|
||||
//gprintf("Opening DB: %s\n", filename.c_str());
|
||||
@ -44,8 +42,7 @@ CCache<T>::CCache(vector<T> &list, string path , CMode mode) /* Load/Save All */
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
CCache<T>::CCache(vector<T> &list, string path, T tmp, CMode mode) /* Add One */
|
||||
CCache::CCache(vector<dir_discHdr> &list, string path, dir_discHdr tmp, CMode mode) /* Add One */
|
||||
{
|
||||
filename = path;
|
||||
//gprintf("Openning DB: %s\n", filename.c_str());
|
||||
@ -63,8 +60,7 @@ CCache<T>::CCache(vector<T> &list, string path, T tmp, CMode mode) /* Add One */
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
CCache<T>::CCache(vector<T> &list, string path, u32 index, CMode mode) /* Remove One */
|
||||
CCache::CCache(vector<dir_discHdr> &list, string path, u32 index, CMode mode) /* Remove One */
|
||||
{
|
||||
filename = path;
|
||||
//gprintf("Openning DB: %s\n", filename.c_str());
|
||||
@ -82,44 +78,40 @@ CCache<T>::CCache(vector<T> &list, string path, u32 index, CMode mode) /* Remov
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
CCache<T>::~CCache()
|
||||
CCache::~CCache()
|
||||
{
|
||||
//gprintf("Closing DB: %s\n", filename.c_str());
|
||||
if(cache) fclose(cache);
|
||||
cache = NULL;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void CCache<T>::SaveAll(vector<T> list)
|
||||
void CCache::SaveAll(vector<dir_discHdr> list)
|
||||
{
|
||||
//gprintf("Updating DB: %s\n", filename.c_str());
|
||||
if(!cache) return;
|
||||
fwrite((void *)&list[0], 1, list.size() * sizeof(T), cache);
|
||||
fwrite((void *)&list[0], 1, list.size() * sizeof(dir_discHdr), cache);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void CCache<T>::SaveOne(T tmp, u32 index)
|
||||
void CCache::SaveOne(dir_discHdr tmp, u32 index)
|
||||
{
|
||||
//gprintf("Updating Item number %u in DB: %s\n", index, filename.c_str());
|
||||
if(!cache) return;
|
||||
fseek(cache, index * sizeof(T), SEEK_SET);
|
||||
fwrite((void *)&tmp, 1, sizeof(T), cache);
|
||||
fseek(cache, index * sizeof(dir_discHdr), SEEK_SET);
|
||||
fwrite((void *)&tmp, 1, sizeof(dir_discHdr), cache);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void CCache<T>::LoadAll(vector<T> &list)
|
||||
void CCache::LoadAll(vector<dir_discHdr> &list)
|
||||
{
|
||||
if(!cache) return;
|
||||
|
||||
//gprintf("Loading DB: %s\n", filename.c_str());
|
||||
|
||||
T tmp;
|
||||
dir_discHdr tmp;
|
||||
fseek(cache, 0, SEEK_END);
|
||||
u64 fileSize = ftell(cache);
|
||||
fseek(cache, 0, SEEK_SET);
|
||||
|
||||
u32 count = (u32)(fileSize / sizeof(T));
|
||||
u32 count = (u32)(fileSize / sizeof(dir_discHdr));
|
||||
|
||||
list.reserve(count + list.size());
|
||||
for(u32 i = 0; i < count; i++)
|
||||
@ -129,34 +121,28 @@ void CCache<T>::LoadAll(vector<T> &list)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void CCache<T>::LoadOne(T &tmp, u32 index)
|
||||
void CCache::LoadOne(dir_discHdr &tmp, u32 index)
|
||||
{
|
||||
if(!cache) return;
|
||||
|
||||
//gprintf("Fetching Item number %u in DB: %s\n", index, filename.c_str());
|
||||
fseek(cache, index * sizeof(T), SEEK_SET);
|
||||
fread((void *)&tmp, 1, sizeof(T), cache);
|
||||
fseek(cache, index * sizeof(dir_discHdr), SEEK_SET);
|
||||
fread((void *)&tmp, 1, sizeof(dir_discHdr), cache);
|
||||
//gprintf("Path %s\n", tmp.path);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void CCache<T>::AddOne(vector<T> &list, T tmp)
|
||||
void CCache::AddOne(vector<dir_discHdr> &list, dir_discHdr tmp)
|
||||
{
|
||||
//gprintf("Adding Item number %u in DB: %s\n", list.size()+1, filename.c_str());
|
||||
list.push_back(tmp);
|
||||
|
||||
if(!cache) return;
|
||||
fwrite((void *)&tmp, 1, sizeof(T), cache); // FILE* is opened as "ab+" so its always written to the EOF.
|
||||
fwrite((void *)&tmp, 1, sizeof(dir_discHdr), cache); // FILE* is opened as "ab+" so its always written to the EOF.
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void CCache<T>::RemoveOne(vector<T> &list, u32 index)
|
||||
void CCache::RemoveOne(vector<dir_discHdr> &list, u32 index)
|
||||
{
|
||||
//gprintf("Removing Item number %u in DB: %s\n", index, filename.c_str());
|
||||
list.erase(list.begin() + index);
|
||||
SaveAll(list);
|
||||
}
|
||||
|
||||
template class CCache<dir_discHdr>;
|
@ -25,23 +25,22 @@ enum CMode
|
||||
REMOVE
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class CCache
|
||||
{
|
||||
public:
|
||||
CCache(T &tmp, string path, u32 index, CMode mode); /* Load/Save One */
|
||||
CCache(vector<T> &list, string path, CMode mode); /* Load/Save All */
|
||||
CCache(vector<T> &list, string path, T tmp, CMode mode); /* Add One */
|
||||
CCache(vector<T> &list, string path, u32 index, CMode mode); /* Remove One */
|
||||
CCache(dir_discHdr &tmp, string path, u32 index, CMode mode); /* Load/Save One */
|
||||
CCache(vector<dir_discHdr> &list, string path, CMode mode); /* Load/Save All */
|
||||
CCache(vector<dir_discHdr> &list, string path, dir_discHdr tmp, CMode mode); /* Add One */
|
||||
CCache(vector<dir_discHdr> &list, string path, u32 index, CMode mode); /* Remove One */
|
||||
~CCache();
|
||||
private:
|
||||
void SaveAll(vector<T> list);
|
||||
void SaveOne(T tmp, u32 index);
|
||||
void LoadAll(vector<T> &list);
|
||||
void LoadOne(T &tmp, u32 index);
|
||||
void SaveAll(vector<dir_discHdr> list);
|
||||
void SaveOne(dir_discHdr tmp, u32 index);
|
||||
void LoadAll(vector<dir_discHdr> &list);
|
||||
void LoadOne(dir_discHdr &tmp, u32 index);
|
||||
|
||||
void AddOne(vector<T> &list, T tmp);
|
||||
void RemoveOne(vector<T> &list, u32 index);
|
||||
void AddOne(vector<dir_discHdr> &list, dir_discHdr tmp);
|
||||
void RemoveOne(vector<dir_discHdr> &list, u32 index);
|
||||
|
||||
FILE *cache;
|
||||
string filename;
|
||||
|
@ -1,8 +1,7 @@
|
||||
#include "cachedlist.hpp"
|
||||
#include <typeinfo>
|
||||
|
||||
template <class T>
|
||||
void CachedList<T>::Load(string path, string containing, string m_lastLanguage, Config &m_plugin) /* Load All */
|
||||
void CachedList::Load(string path, string containing, string m_lastLanguage, Config &m_plugin) /* Load All */
|
||||
{
|
||||
gprintf("\nLoading files containing %s in %s\n", containing.c_str(), path.c_str());
|
||||
m_loaded = false;
|
||||
@ -16,10 +15,7 @@ void CachedList<T>::Load(string path, string containing, string m_lastLanguage,
|
||||
bool update_emu = false;
|
||||
|
||||
bool ditimes = false;
|
||||
bool music = typeid(T) == typeid(std::string);
|
||||
if(music)
|
||||
gprintf("Loading music list from path: %s\n", path.c_str());
|
||||
else if(!m_wbfsFS)
|
||||
if(!m_wbfsFS)
|
||||
{
|
||||
gprintf("Database file: %s\n", m_database.c_str());
|
||||
|
||||
@ -56,7 +52,7 @@ void CachedList<T>::Load(string path, string containing, string m_lastLanguage,
|
||||
if(mtimes || ditimes)
|
||||
gprintf("The WBFS folder was modified!\nCache date: %i\nFolder date: %i\n", cache.st_mtime, filestat.st_mtime);
|
||||
|
||||
if(m_extcheck && !m_update && !music)
|
||||
if(m_extcheck && !m_update)
|
||||
{
|
||||
bool m_chupdate = false;
|
||||
DIR *dir = opendir(path.c_str());
|
||||
@ -80,12 +76,12 @@ void CachedList<T>::Load(string path, string containing, string m_lastLanguage,
|
||||
if(update_dml)
|
||||
force_update[COVERFLOW_DML] = false;
|
||||
|
||||
if(m_update || m_wbfsFS || music)
|
||||
if(m_update || m_wbfsFS)
|
||||
{
|
||||
gprintf("Calling list to update filelist\n");
|
||||
|
||||
vector<string> pathlist;
|
||||
list.GetPaths(pathlist, containing, path, m_wbfsFS, (update_dml || (m_update && strcasestr(path.c_str(), ":/games") != NULL)), (!update_emu && !music));
|
||||
list.GetPaths(pathlist, containing, path, m_wbfsFS, (update_dml || (m_update && strcasestr(path.c_str(), ":/games") != NULL)), !update_emu);
|
||||
list.GetHeaders(pathlist, *this, m_settingsDir, m_curLanguage, m_DMLgameDir, m_plugin);
|
||||
|
||||
path.append("/touch.db");
|
||||
@ -96,19 +92,18 @@ void CachedList<T>::Load(string path, string containing, string m_lastLanguage,
|
||||
m_loaded = true;
|
||||
m_update = false;
|
||||
|
||||
if(!music && pathlist.size() > 0)
|
||||
if(pathlist.size() > 0)
|
||||
Save();
|
||||
pathlist.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
CCache<T>(*this, m_database, LOAD);
|
||||
CCache(*this, m_database, LOAD);
|
||||
m_loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void CachedList<dir_discHdr>::LoadChannels(string path, u32 channelType, string m_lastLanguage) /* Load All */
|
||||
void CachedList::LoadChannels(string path, u32 channelType, string m_lastLanguage) /* Load All */
|
||||
{
|
||||
m_loaded = false;
|
||||
m_update = true;
|
||||
@ -148,13 +143,12 @@ void CachedList<dir_discHdr>::LoadChannels(string path, u32 channelType, string
|
||||
if(this->size() > 0 && emu) Save();
|
||||
}
|
||||
else
|
||||
CCache<dir_discHdr>(*this, m_database, LOAD);
|
||||
CCache(*this, m_database, LOAD);
|
||||
|
||||
m_loaded = true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
string CachedList<T>::make_db_name(string path)
|
||||
string CachedList::make_db_name(string path)
|
||||
{
|
||||
string buffer = path;
|
||||
size_t find = buffer.find(":/");
|
||||
@ -170,5 +164,3 @@ string CachedList<T>::make_db_name(string path)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
template class CachedList<string>;
|
||||
template class CachedList<dir_discHdr>;
|
||||
|
@ -17,8 +17,7 @@ enum {
|
||||
COVERFLOW_MAX
|
||||
};
|
||||
|
||||
template <typename T = dir_discHdr>
|
||||
class CachedList : public vector<T>
|
||||
class CachedList : public vector<dir_discHdr>
|
||||
{
|
||||
public:
|
||||
void Init(string cachedir, string settingsDir, string curLanguage, string DMLgameDir, bool extcheck) /* Initialize Private Variables */
|
||||
@ -54,13 +53,13 @@ class CachedList : public vector<T>
|
||||
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 */
|
||||
void Save() {if(m_loaded) CCache(*this, m_database, SAVE);} /* Save All */
|
||||
|
||||
void Get(T tmp, u32 index) {if(m_loaded) CCache<T>(tmp, m_database, index, LOAD);} /* Load One */
|
||||
void Set(T tmp, u32 index) {if(m_loaded) CCache<T>(tmp, m_database, index, SAVE);} /* Save One */
|
||||
void Get(dir_discHdr tmp, u32 index) {if(m_loaded) CCache(tmp, m_database, index, LOAD);} /* Load One */
|
||||
void Set(dir_discHdr tmp, u32 index) {if(m_loaded) CCache(tmp, m_database, index, SAVE);} /* Save One */
|
||||
|
||||
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 Add(dir_discHdr tmp) {if(m_loaded) CCache(*this, m_database, tmp, ADD);} /* Add One */
|
||||
void Remove(u32 index) {if(m_loaded) CCache(*this, m_database, index, REMOVE);} /* Remove One */
|
||||
|
||||
void SetLanguage(string curLanguage) { m_curLanguage = curLanguage; }
|
||||
private:
|
||||
@ -71,7 +70,7 @@ class CachedList : public vector<T>
|
||||
bool m_wbfsFS;
|
||||
bool m_extcheck;
|
||||
u8 force_update[COVERFLOW_MAX];
|
||||
CList<T> list;
|
||||
CList<dir_discHdr> list;
|
||||
string m_database;
|
||||
string m_cacheDir;
|
||||
string m_settingsDir;
|
||||
|
@ -59,7 +59,7 @@ private:
|
||||
CButtonsMgr m_btnMgr;
|
||||
CCoverFlow m_cf;
|
||||
CFanart m_fa;
|
||||
CachedList<dir_discHdr> m_gameList;
|
||||
CachedList m_gameList;
|
||||
Config m_cfg;
|
||||
Config m_loc;
|
||||
Config m_cat;
|
||||
|
Loading…
x
Reference in New Issue
Block a user