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