-removed plugin settings limit, you can now have as much as you want

-cleaned up and smalled down plugin code
This commit is contained in:
fix94.1 2012-10-04 14:35:08 +00:00
parent 4d4e987286
commit f365b1080c
7 changed files with 119 additions and 119 deletions

View File

@ -319,9 +319,10 @@ wstringEx Config::getWString(const string &domain, const string &key, const wstr
string Config::getString(const string &domain, const string &key, const string &defVal) string Config::getString(const string &domain, const string &key, const string &defVal)
{ {
if (domain.empty() || key.empty()) return defVal; if(domain.empty() || key.empty())
return defVal;
string &data = m_domains[upperCase(domain)][lowerCase(key)]; string &data = m_domains[upperCase(domain)][lowerCase(key)];
if (data.empty() || strncasecmp(data.c_str(), "usb:", 4) == 0) if(data.empty())
{ {
data = defVal; data = defVal;
m_changed = true; m_changed = true;

View File

@ -1520,7 +1520,7 @@ void CMenu::_initCF(void)
m_cf.clear(); m_cf.clear();
m_cf.reserve(m_gameList.size()); m_cf.reserve(m_gameList.size());
vector<bool> EnabledPlugins; const vector<bool> *EnabledPlugins;
if(m_current_view == COVERFLOW_PLUGIN) if(m_current_view == COVERFLOW_PLUGIN)
EnabledPlugins = m_plugin.GetEnabledPlugins(m_cfg); EnabledPlugins = m_plugin.GetEnabledPlugins(m_cfg);
@ -1546,10 +1546,10 @@ void CMenu::_initCF(void)
// check for single plugin selected // check for single plugin selected
u8 pos = 0; u8 pos = 0;
u8 enabledPluginsCount = 0; u8 enabledPluginsCount = 0;
if(m_current_view == COVERFLOW_PLUGIN && EnabledPlugins.size() != 0) if(m_current_view == COVERFLOW_PLUGIN && EnabledPlugins->size() != 0)
{ {
char PluginMagicWord[9]; char PluginMagicWord[9];
for(u8 i = 0; i < EnabledPlugins.size(); i++) for(u8 i = 0; i < EnabledPlugins->size(); i++)
{ {
snprintf(PluginMagicWord, sizeof(PluginMagicWord), "%08x", m_plugin.getPluginMagic(i)); snprintf(PluginMagicWord, sizeof(PluginMagicWord), "%08x", m_plugin.getPluginMagic(i));
if(m_cfg.getBool("PLUGIN", PluginMagicWord, true)) if(m_cfg.getBool("PLUGIN", PluginMagicWord, true))
@ -1785,7 +1785,7 @@ void CMenu::_initCF(void)
if(tempname.find_last_of("/") != string::npos) if(tempname.find_last_of("/") != string::npos)
tempname.assign(&tempname[tempname.find_last_of("/") + 1]); tempname.assign(&tempname[tempname.find_last_of("/") + 1]);
string coverFolder(m_plugin.GetCoverFolderName(m_gameList[i].settings[0])); string coverFolder(m_plugin.GetCoverFolderName(m_gameList[i].settings[0]));
if(EnabledPlugins.size() == 0) //all plugins if(EnabledPlugins->size() == 0) //all plugins
{ {
if(coverFolder.size() > 0) if(coverFolder.size() > 0)
m_cf.addItem(&m_gameList[i], fmt("%s/%s/%s.png", m_picDir.c_str(), coverFolder.c_str(), tempname.c_str()), fmt("%s/%s/%s.png", m_boxPicDir.c_str(), coverFolder.c_str(), tempname.c_str()), playcount, lastPlayed); m_cf.addItem(&m_gameList[i], fmt("%s/%s/%s.png", m_picDir.c_str(), coverFolder.c_str(), tempname.c_str()), fmt("%s/%s/%s.png", m_boxPicDir.c_str(), coverFolder.c_str(), tempname.c_str()), playcount, lastPlayed);
@ -1794,9 +1794,9 @@ void CMenu::_initCF(void)
} }
else else
{ {
for(u8 j = 0; j < EnabledPlugins.size(); j++) for(u8 j = 0; j < EnabledPlugins->size(); j++)
{ {
if(EnabledPlugins[j] == true && m_gameList[i].settings[0] == m_plugin.getPluginMagic(j)) if(EnabledPlugins->at(j) == true && m_gameList[i].settings[0] == m_plugin.getPluginMagic(j))
{ {
if(coverFolder.size() > 0) if(coverFolder.size() > 0)
m_cf.addItem(&m_gameList[i], fmt("%s/%s/%s.png", m_picDir.c_str(), coverFolder.c_str(), tempname.c_str()), fmt("%s/%s/%s.png", m_boxPicDir.c_str(), coverFolder.c_str(), tempname.c_str()), playcount, lastPlayed); m_cf.addItem(&m_gameList[i], fmt("%s/%s/%s.png", m_picDir.c_str(), coverFolder.c_str(), tempname.c_str()), fmt("%s/%s/%s.png", m_boxPicDir.c_str(), coverFolder.c_str(), tempname.c_str()), playcount, lastPlayed);
@ -2302,7 +2302,7 @@ bool CMenu::_loadEmuList()
Config scummvm; Config scummvm;
vector<dir_discHdr> scummvmList; vector<dir_discHdr> scummvmList;
scummvm.load(fmt("%s/%s", m_pluginsDir.c_str(), "scummvm.ini")); scummvm.load(fmt("%s/%s", m_pluginsDir.c_str(), "scummvm.ini"));
scummvmList = m_plugin.ParseScummvmINI(scummvm, string(DeviceName[currentPartition])); scummvmList = m_plugin.ParseScummvmINI(scummvm, DeviceName[currentPartition]);
for(vector<dir_discHdr>::iterator tmp_itr = scummvmList.begin(); tmp_itr != scummvmList.end(); tmp_itr++) for(vector<dir_discHdr>::iterator tmp_itr = scummvmList.begin(); tmp_itr != scummvmList.end(); tmp_itr++)
emuList.push_back(*tmp_itr); emuList.push_back(*tmp_itr);
} }

View File

@ -922,6 +922,7 @@ private:
void _showHome(void); void _showHome(void);
void _showExitTo(void); void _showExitTo(void);
void _updateSourceBtns(void); void _updateSourceBtns(void);
void _updatePluginText(void);
void _updatePluginCheckboxes(void); void _updatePluginCheckboxes(void);
void _updateCheckboxes(void); void _updateCheckboxes(void);
void _getIDCats(void); void _getIDCats(void);

View File

@ -149,15 +149,14 @@ void CMenu::_CategorySettings(bool fromGameSet)
catDomain = _domainFromView(); catDomain = _domainFromView();
u8 pos = 0; u8 pos = 0;
vector<bool> EnabledPlugins;
if(m_current_view == COVERFLOW_PLUGIN) if(m_current_view == COVERFLOW_PLUGIN)
{ {
EnabledPlugins = m_plugin.GetEnabledPlugins(m_cfg); const vector<bool> *EnabledPlugins = m_plugin.GetEnabledPlugins(m_cfg);
if(EnabledPlugins.size() != 0) if(EnabledPlugins->size() != 0)
{ {
char PluginMagicWord[9]; char PluginMagicWord[9];
u8 enabledPluginsCount = 0; u8 enabledPluginsCount = 0;
for(u8 i = 0; i < EnabledPlugins.size(); i++) for(u8 i = 0; i < EnabledPlugins->size(); i++)
{ {
snprintf(PluginMagicWord, sizeof(PluginMagicWord), "%08x", m_plugin.getPluginMagic(i)); snprintf(PluginMagicWord, sizeof(PluginMagicWord), "%08x", m_plugin.getPluginMagic(i));
if(m_cfg.getBool("PLUGIN", PluginMagicWord, true)) if(m_cfg.getBool("PLUGIN", PluginMagicWord, true))

View File

@ -3,7 +3,8 @@
#include <string.h> #include <string.h>
#include <gccore.h> #include <gccore.h>
u32 Plugin_curPage; u8 Plugin_curPage;
u8 Plugin_Pages;
u8 Plugin_lastBtn; u8 Plugin_lastBtn;
// Plugin menu // Plugin menu
@ -12,10 +13,10 @@ s16 m_pluginBtnPageM;
s16 m_pluginBtnPageP; s16 m_pluginBtnPageP;
s16 m_pluginBtnBack; s16 m_pluginBtnBack;
s16 m_pluginLblTitle; s16 m_pluginLblTitle;
s16 m_pluginLblCat[21]; s16 m_pluginLblCat[11];
s16 m_pluginBtn[21]; s16 m_pluginBtn[11];
s16 m_pluginBtnCat[21]; s16 m_pluginBtnCat[11];
s16 m_pluginBtnCats[21]; s16 m_pluginBtnCats[11];
s16 m_pluginLblUser[4]; s16 m_pluginLblUser[4];
u8 m_max_plugins; u8 m_max_plugins;
STexture m_pluginBg; STexture m_pluginBg;
@ -32,8 +33,7 @@ void CMenu::_hidePluginSettings(bool instant)
if(m_pluginLblUser[i] != -1) if(m_pluginLblUser[i] != -1)
m_btnMgr.hide(m_pluginLblUser[i], instant); m_btnMgr.hide(m_pluginLblUser[i], instant);
} }
for(u8 i = 0; i < 11; ++i)
for(int i = 0; i < 21; ++i)
{ {
m_btnMgr.hide(m_pluginLblCat[i]); m_btnMgr.hide(m_pluginLblCat[i]);
m_btnMgr.hide(m_pluginBtn[i]); m_btnMgr.hide(m_pluginBtn[i]);
@ -53,30 +53,40 @@ void CMenu::_showPluginSettings(void)
_updatePluginCheckboxes(); _updatePluginCheckboxes();
} }
void CMenu::_updatePluginText(void)
{
u32 IteratorHelp = (Plugin_curPage - 1) * 10;
for(u8 i = 1; i < min(IteratorHelp+10, (u32)m_max_plugins)-IteratorHelp+1; i++)
m_btnMgr.setText(m_pluginLblCat[i], m_plugin.GetPluginName(i+IteratorHelp-1));
}
void CMenu::_updatePluginCheckboxes(void) void CMenu::_updatePluginCheckboxes(void)
{ {
if(m_max_plugins > 10) if(m_max_plugins > 10)
{ {
m_btnMgr.setText(m_pluginLblPage, wfmt(L"%i / 2", Plugin_curPage)); m_btnMgr.setText(m_pluginLblPage, wfmt(L"%i / %i", Plugin_curPage, Plugin_Pages));
m_btnMgr.show(m_pluginLblPage); m_btnMgr.show(m_pluginLblPage);
m_btnMgr.show(m_pluginBtnPageM); m_btnMgr.show(m_pluginBtnPageM);
m_btnMgr.show(m_pluginBtnPageP); m_btnMgr.show(m_pluginBtnPageP);
} }
for(int i = 0; i < 21; ++i) for(int i = 0; i < 11; ++i)
{ {
m_btnMgr.hide(m_pluginBtn[i]); m_btnMgr.hide(m_pluginBtn[i]);
m_btnMgr.hide(m_pluginLblCat[i]); m_btnMgr.hide(m_pluginLblCat[i]);
} }
const vector<bool> *EnabledPlugins = m_plugin.GetEnabledPlugins(m_cfg);
vector<bool> EnabledPlugins = m_plugin.GetEnabledPlugins(m_cfg); /* ALL Button */
if(Plugin_curPage == 1) if(EnabledPlugins->size() == 0)
m_pluginBtn[0] = m_pluginBtnCats[0];
else
m_pluginBtn[0] = m_pluginBtnCat[0];
m_btnMgr.show(m_pluginBtn[0]);
m_btnMgr.show(m_pluginLblCat[0]);
/* Single Plugins */
u32 IteratorHelp = (Plugin_curPage - 1) * 10;
for(u8 i = 1; i < min(IteratorHelp+10, (u32)m_max_plugins)-IteratorHelp+1; ++i)
{ {
int j = 11; if(EnabledPlugins->size() == 0 || EnabledPlugins->at(i+IteratorHelp-1) == true)
if(m_max_plugins < 11)
j = m_max_plugins;
for(u8 i = 0; i < j; ++i)
{
if((EnabledPlugins.size() == 0) || (i != 0 && EnabledPlugins.size() >= i && EnabledPlugins[i - 1] == true))
m_pluginBtn[i] = m_pluginBtnCats[i]; m_pluginBtn[i] = m_pluginBtnCats[i];
else else
m_pluginBtn[i] = m_pluginBtnCat[i]; m_pluginBtn[i] = m_pluginBtnCat[i];
@ -84,23 +94,15 @@ void CMenu::_updatePluginCheckboxes(void)
m_btnMgr.show(m_pluginLblCat[i]); m_btnMgr.show(m_pluginLblCat[i]);
} }
} }
else
{
for(int i = 11; i < m_max_plugins; ++i)
{
m_pluginBtn[i] = m_pluginBtnCat[i];
m_btnMgr.show(m_pluginBtn[i]);
m_btnMgr.show(m_pluginLblCat[i]);
}
}
}
void CMenu::_PluginSettings() void CMenu::_PluginSettings()
{ {
SetupInput(); SetupInput();
Plugin_Pages = 1;
Plugin_curPage = 1; Plugin_curPage = 1;
_textPluginSettings(); _textPluginSettings();
_showPluginSettings(); _showPluginSettings();
_updatePluginText();
while(!m_exit) while(!m_exit)
{ {
_mainLoopCommon(); _mainLoopCommon();
@ -119,19 +121,23 @@ void CMenu::_PluginSettings()
{ {
Plugin_lastBtn = m_pluginBtnPageM; Plugin_lastBtn = m_pluginBtnPageM;
m_btnMgr.noHover(true); m_btnMgr.noHover(true);
Plugin_curPage = Plugin_curPage == 1 ? 2 : 1; Plugin_curPage--;
if(Plugin_curPage == 0) Plugin_curPage = Plugin_Pages;
if(BTN_LEFT_PRESSED || BTN_MINUS_PRESSED) if(BTN_LEFT_PRESSED || BTN_MINUS_PRESSED)
m_btnMgr.click(m_pluginBtnPageM); m_btnMgr.click(m_pluginBtnPageM);
_updatePluginCheckboxes(); _updatePluginCheckboxes();
_updatePluginText();
} }
else if(((BTN_PLUS_PRESSED || BTN_RIGHT_PRESSED)) || (BTN_A_PRESSED && m_btnMgr.selected(m_pluginBtnPageP))) else if(((BTN_PLUS_PRESSED || BTN_RIGHT_PRESSED)) || (BTN_A_PRESSED && m_btnMgr.selected(m_pluginBtnPageP)))
{ {
Plugin_lastBtn = m_pluginBtnPageP; Plugin_lastBtn = m_pluginBtnPageP;
m_btnMgr.noHover(true); m_btnMgr.noHover(true);
Plugin_curPage = Plugin_curPage == 1 ? 2 : 1; Plugin_curPage++;
if(Plugin_curPage > Plugin_Pages) Plugin_curPage = 1;
if(BTN_RIGHT_PRESSED || BTN_PLUS_PRESSED) if(BTN_RIGHT_PRESSED || BTN_PLUS_PRESSED)
m_btnMgr.click(m_pluginBtnPageP); m_btnMgr.click(m_pluginBtnPageP);
_updatePluginCheckboxes(); _updatePluginCheckboxes();
_updatePluginText();
} }
if(BTN_A_PRESSED) if(BTN_A_PRESSED)
{ {
@ -140,7 +146,8 @@ void CMenu::_PluginSettings()
m_cfg.save(); m_cfg.save();
break; break;
} }
for(int i = 0; i < 21; ++i) u32 IteratorHelp = (Plugin_curPage - 1) * 10;
for(u8 i = 1; i < min(IteratorHelp+10, (u32)m_max_plugins)-IteratorHelp+1; ++i)
{ {
if(m_btnMgr.selected(m_pluginBtn[i])) if(m_btnMgr.selected(m_pluginBtn[i]))
{ {
@ -149,18 +156,18 @@ void CMenu::_PluginSettings()
if(i == 0) if(i == 0)
{ {
int j = 0; int j = 0;
bool EnableAll = (m_plugin.GetEnabledPlugins(m_cfg).size()); bool EnableAll = (m_plugin.GetEnabledPlugins(m_cfg)->size());
while(true) while(true)
{ {
if(m_plugin.PluginExist(j)) if(m_plugin.PluginExist(j+IteratorHelp-1))
m_plugin.SetEnablePlugin(m_cfg, j, EnableAll ? 2 : 1); m_plugin.SetEnablePlugin(m_cfg, j+IteratorHelp-1, EnableAll ? 2 : 1);
else else
break; break;
j++; j++;
} }
} }
else else
m_plugin.SetEnablePlugin(m_cfg, i - 1); m_plugin.SetEnablePlugin(m_cfg, i+IteratorHelp-1);
_updatePluginCheckboxes(); _updatePluginCheckboxes();
break; break;
} }
@ -191,27 +198,21 @@ void CMenu::_initPluginSettingsMenu(CMenu::SThemeData &theme)
m_pluginBtnCat[i+5] = _addPicButton(theme, fmt("PLUGIN/PLUGIN_%i_BTN", i+5), theme.checkboxoff, theme.checkboxoffs, 325, (42+i*58), 44, 48); m_pluginBtnCat[i+5] = _addPicButton(theme, fmt("PLUGIN/PLUGIN_%i_BTN", i+5), theme.checkboxoff, theme.checkboxoffs, 325, (42+i*58), 44, 48);
m_pluginBtnCats[i+5] = _addPicButton(theme, fmt("PLUGIN/PLUGIN_%i_BTNS", i+5), theme.checkboxon, theme.checkboxons, 325, (42+i*58), 44, 48); m_pluginBtnCats[i+5] = _addPicButton(theme, fmt("PLUGIN/PLUGIN_%i_BTNS", i+5), theme.checkboxon, theme.checkboxons, 325, (42+i*58), 44, 48);
m_pluginLblCat[i+5] = _addLabel(theme, fmt("PLUGIN/PLUGIN_%i", i+5), theme.txtFont, L"", 380, (42+i*58), 230, 48, theme.lblFontColor, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_MIDDLE); m_pluginLblCat[i+5] = _addLabel(theme, fmt("PLUGIN/PLUGIN_%i", i+5), theme.txtFont, L"", 380, (42+i*58), 230, 48, theme.lblFontColor, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_MIDDLE);
// Page 2
m_pluginBtnCat[i+10] = _addPicButton(theme, fmt("PLUGIN/PLUGIN_%i_BTN", i+10), theme.checkboxoff, theme.checkboxoffs, 30, (42+i*58), 44, 48);
m_pluginBtnCats[i+10] = _addPicButton(theme, fmt("PLUGIN/PLUGIN_%i_BTNS", i+10), theme.checkboxon, theme.checkboxons, 30, (42+i*58), 44, 48);
m_pluginLblCat[i+10] = _addLabel(theme, fmt("PLUGIN/PLUGIN_%i", i+10), theme.lblFont, L"", 85, (42+i*58), 230, 48, theme.lblFontColor, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_MIDDLE);
// right half
m_pluginBtnCat[i+15] = _addPicButton(theme, fmt("PLUGIN/PLUGIN_%i_BTN", i+15), theme.checkboxoff, theme.checkboxoffs, 325, (42+i*58), 44, 48);
m_pluginBtnCats[i+15] = _addPicButton(theme, fmt("PLUGIN/PLUGIN_%i_BTNS", i+15), theme.checkboxon, theme.checkboxons, 325, (42+i*58), 44, 48);
m_pluginLblCat[i+15] = _addLabel(theme, fmt("PLUGIN/PLUGIN_%i", i+15), theme.txtFont, L"", 380, (42+i*58), 230, 48, theme.lblFontColor, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_MIDDLE);
} }
_setHideAnim(m_pluginLblTitle, "PLUGIN/TITLE", 0, 0, -2.f, 0.f); _setHideAnim(m_pluginLblTitle, "PLUGIN/TITLE", 0, 0, -2.f, 0.f);
_setHideAnim(m_pluginLblPage, "PLUGIN/PAGE_BTN", 0, 0, 1.f, -1.f); _setHideAnim(m_pluginLblPage, "PLUGIN/PAGE_BTN", 0, 0, 1.f, -1.f);
_setHideAnim(m_pluginBtnPageM, "PLUGIN/PAGE_MINUS", 0, 0, 1.f, -1.f); _setHideAnim(m_pluginBtnPageM, "PLUGIN/PAGE_MINUS", 0, 0, 1.f, -1.f);
_setHideAnim(m_pluginBtnPageP, "PLUGIN/PAGE_PLUS", 0, 0, 1.f, -1.f); _setHideAnim(m_pluginBtnPageP, "PLUGIN/PAGE_PLUS", 0, 0, 1.f, -1.f);
_setHideAnim(m_pluginBtnBack, "PLUGIN/BACK_BTN", 0, 0, 1.f, -1.f); _setHideAnim(m_pluginBtnBack, "PLUGIN/BACK_BTN", 0, 0, 1.f, -1.f);
for(u8 i = 0; i < 21; ++i) for(u8 i = 0; i < 11; ++i)
{ {
_setHideAnim(m_pluginBtnCat[i], fmt("PLUGIN/PLUGIN_%i_BTN", i), 0, 0, 1.f, 0.f); _setHideAnim(m_pluginBtnCat[i], fmt("PLUGIN/PLUGIN_%i_BTN", i), 0, 0, 1.f, 0.f);
_setHideAnim(m_pluginBtnCats[i], fmt("PLUGIN/PLUGIN_%i_BTNS", i), 0, 0, 1.f, 0.f); _setHideAnim(m_pluginBtnCats[i], fmt("PLUGIN/PLUGIN_%i_BTNS", i), 0, 0, 1.f, 0.f);
_setHideAnim(m_pluginLblCat[i], fmt("PLUGIN/PLUGIN_%i", i), 0, 0, 1.f, 0.f); _setHideAnim(m_pluginLblCat[i], fmt("PLUGIN/PLUGIN_%i", i), 0, 0, 1.f, 0.f);
m_pluginBtn[i] = m_pluginBtnCat[i]; m_pluginBtn[i] = m_pluginBtnCat[i];
} }
Plugin_curPage = 1;
Plugin_Pages = 1;
m_max_plugins = 0; m_max_plugins = 0;
_hidePluginSettings(true); _hidePluginSettings(true);
_textPluginSettings(); _textPluginSettings();
@ -228,10 +229,9 @@ void CMenu::_textPluginSettings(void)
m_btnMgr.setText(m_pluginLblCat[i], _t("dl25", L"All")); m_btnMgr.setText(m_pluginLblCat[i], _t("dl25", L"All"));
else else
{ {
if(m_plugin.PluginExist(i - 1)) if(!m_plugin.PluginExist(i - 1))
m_btnMgr.setText(m_pluginLblCat[i], m_plugin.GetPluginName(i - 1));
else
{ {
Plugin_Pages = (i-1)/10;
m_max_plugins = i; m_max_plugins = i;
break; break;
} }

View File

@ -28,11 +28,7 @@
#include "types.h" #include "types.h"
#include "crc32.h" #include "crc32.h"
static const string emptyString; void Plugin::init(const string& m_pluginsDir)
static const string emptyString2("/");
static char* emptyChar = (char*)" ";
void Plugin::init(string m_pluginsDir)
{ {
pluginsDir = m_pluginsDir; pluginsDir = m_pluginsDir;
//Ready to add plugins //Ready to add plugins
@ -56,21 +52,21 @@ bool Plugin::AddPlugin(Config &plugin)
return false; return false;
PluginOptions NewPlugin; PluginOptions NewPlugin;
NewPlugin.DolName = plugin.getString(PLUGIN_DOMAIN, "dolFile",emptyChar); NewPlugin.DolName = plugin.getString(PLUGIN_DOMAIN, "dolFile");
NewPlugin.coverFolder = plugin.getString(PLUGIN_DOMAIN, "coverFolder",emptyChar); NewPlugin.coverFolder = plugin.getString(PLUGIN_DOMAIN, "coverFolder");
NewPlugin.magicWord = strtoul(plugin.getString(PLUGIN_DOMAIN, "magic",emptyChar).c_str(), NULL, 16); NewPlugin.magicWord = strtoul(plugin.getString(PLUGIN_DOMAIN, "magic").c_str(), NULL, 16);
NewPlugin.caseColor = strtoul(plugin.getString(PLUGIN_DOMAIN, "coverColor",emptyChar).c_str(), NULL, 16); NewPlugin.caseColor = strtoul(plugin.getString(PLUGIN_DOMAIN, "coverColor").c_str(), NULL, 16);
NewPlugin.Args = plugin.getStrings(PLUGIN_DOMAIN, "arguments", '|'); NewPlugin.Args = plugin.getStrings(PLUGIN_DOMAIN, "arguments", '|');
string PluginName = plugin.getString(PLUGIN_DOMAIN, "displayname",emptyChar); string PluginName = plugin.getString(PLUGIN_DOMAIN, "displayname");
if(PluginName == emptyString || PluginName == emptyString2) if(PluginName.size() < 2)
{ {
PluginName = NewPlugin.DolName; PluginName = NewPlugin.DolName;
PluginName.erase(PluginName.end() - 4, PluginName.end()); PluginName.erase(PluginName.end() - 4, PluginName.end());
} }
NewPlugin.DisplayName.fromUTF8(PluginName.c_str()); NewPlugin.DisplayName.fromUTF8(PluginName.c_str());
NewPlugin.consoleCoverID = plugin.getString(PLUGIN_DOMAIN,"consoleCoverID",emptyChar); NewPlugin.consoleCoverID = plugin.getString(PLUGIN_DOMAIN,"consoleCoverID");
const char *bannerfilepath = fmt("%s/%s", pluginsDir.c_str(), plugin.getString(PLUGIN_DOMAIN,"bannerSound",emptyChar).c_str()); const char *bannerfilepath = fmt("%s/%s", pluginsDir.c_str(), plugin.getString(PLUGIN_DOMAIN,"bannerSound").c_str());
FILE *fp = fopen(bannerfilepath, "rb"); FILE *fp = fopen(bannerfilepath, "rb");
if(fp != NULL) if(fp != NULL)
{ {
@ -128,14 +124,14 @@ char* Plugin::GetDolName(u32 magic)
{ {
if((Plugin_Pos = GetPluginPosition(magic)) >= 0) if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
return (char*)Plugins[Plugin_Pos].DolName.c_str(); return (char*)Plugins[Plugin_Pos].DolName.c_str();
return emptyChar; return NULL;
} }
char* Plugin::GetCoverFolderName(u32 magic) char* Plugin::GetCoverFolderName(u32 magic)
{ {
if((Plugin_Pos = GetPluginPosition(magic)) >= 0) if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
return (char*)Plugins[Plugin_Pos].coverFolder.c_str(); return (char*)Plugins[Plugin_Pos].coverFolder.c_str();
return emptyChar; return NULL;
} }
bool Plugin::PluginExist(u8 pos) bool Plugin::PluginExist(u8 pos)
@ -155,7 +151,8 @@ void Plugin::SetEnablePlugin(Config &cfg, u8 pos, u8 ForceMode)
if(pos < Plugins.size()) if(pos < Plugins.size())
{ {
char PluginMagicWord[9]; char PluginMagicWord[9];
snprintf(PluginMagicWord, sizeof(PluginMagicWord), "%08x", Plugins[pos].magicWord); memset(PluginMagicWord, 0, sizeof(PluginMagicWord));
strncpy(PluginMagicWord, fmt("%08x", Plugins[pos].magicWord), 8);
if(ForceMode == 1) if(ForceMode == 1)
cfg.setBool(PLUGIN_DOMAIN, PluginMagicWord, false); cfg.setBool(PLUGIN_DOMAIN, PluginMagicWord, false);
else if(ForceMode == 2) else if(ForceMode == 2)
@ -165,14 +162,15 @@ void Plugin::SetEnablePlugin(Config &cfg, u8 pos, u8 ForceMode)
} }
} }
vector<bool> Plugin::GetEnabledPlugins(Config &cfg) const vector<bool> *Plugin::GetEnabledPlugins(Config &cfg)
{ {
vector<bool> enabledPlugins; enabledPlugins.clear();
char PluginMagicWord[9]; char PluginMagicWord[9];
u8 enabledPluginsNumber = 0; u8 enabledPluginsNumber = 0;
for(u8 i = 0; i < Plugins.size(); i++) for(u8 i = 0; i < Plugins.size(); i++)
{ {
snprintf(PluginMagicWord, sizeof(PluginMagicWord), "%08x", Plugins[i].magicWord); memset(PluginMagicWord, 0, sizeof(PluginMagicWord));
strncpy(PluginMagicWord, fmt("%08x", Plugins[i].magicWord), 8);
if(cfg.getBool(PLUGIN_DOMAIN, PluginMagicWord, true)) if(cfg.getBool(PLUGIN_DOMAIN, PluginMagicWord, true))
{ {
enabledPluginsNumber++; enabledPluginsNumber++;
@ -183,7 +181,7 @@ vector<bool> Plugin::GetEnabledPlugins(Config &cfg)
} }
if(enabledPluginsNumber == Plugins.size()) if(enabledPluginsNumber == Plugins.size())
enabledPlugins.clear(); enabledPlugins.clear();
return enabledPlugins; return &enabledPlugins;
} }
u32 Plugin::getPluginMagic(u8 pos) u32 Plugin::getPluginMagic(u8 pos)
@ -191,51 +189,48 @@ u32 Plugin::getPluginMagic(u8 pos)
return Plugins[pos].magicWord; return Plugins[pos].magicWord;
} }
vector<dir_discHdr> Plugin::ParseScummvmINI(Config &ini, string Device) vector<dir_discHdr> Plugin::ParseScummvmINI(Config &ini, const char *Device)
{ {
gprintf("Parsing scummvm.ini\n"); gprintf("Parsing scummvm.ini\n");
vector<dir_discHdr> gameHeader; vector<dir_discHdr> gameHeader;
if(!ini.loaded()) if(!ini.loaded())
return gameHeader; return gameHeader;
string game(ini.firstDomain()); const string *GameDomain = &ini.firstDomain();
string GameName; dir_discHdr ListElement;
dir_discHdr tmp;
while(1) while(1)
{ {
if(game == emptyString || game == emptyString2) if(GameDomain->size() < 2)
break; break;
GameName = ini.getString(game, "description"); const string &GameName = ini.getString(*GameDomain, "description");
if(GameName == emptyString || GameName == emptyString2 || if(GameName.size() < 2 || ini.getString(*GameDomain, "path").find(Device) == string::npos)
strncasecmp(ini.getWString(game, "path").toUTF8().c_str(), Device.c_str(), 2) != 0)
{ {
game = ini.nextDomain(); GameDomain = &ini.nextDomain();
continue; continue;
} }
memset(&tmp, 0, sizeof(dir_discHdr)); memset((void*)&ListElement, 0, sizeof(dir_discHdr));
strncpy((char*)tmp.id, PLUGIN_DOMAIN, sizeof(tmp.id)); strncpy((char*)ListElement.id, PLUGIN_DOMAIN, 6);
tmp.casecolor = Plugins.back().caseColor; ListElement.casecolor = Plugins.back().caseColor;
wstringEx tmpString; mbstowcs(ListElement.title, GameName.c_str(), 63);
tmpString.fromUTF8(GameName.c_str()); strncpy(ListElement.path, GameDomain->c_str(), sizeof(ListElement.path));
wcsncpy(tmp.title, tmpString.c_str(), 64); gprintf("Found: %s\n", GameDomain->c_str());
strncpy(tmp.path, game.c_str(), sizeof(tmp.path)); ListElement.settings[0] = Plugins.back().magicWord;
gprintf("Found: %ls\n", tmp.title); ListElement.type = TYPE_PLUGIN;
tmp.settings[0] = Plugins.back().magicWord; gameHeader.push_back(ListElement);
tmp.type = TYPE_PLUGIN; GameDomain = &ini.nextDomain();
gameHeader.push_back(tmp);
game = ini.nextDomain();
} }
return gameHeader; return gameHeader;
} }
vector<string> Plugin::CreateArgs(string device, string path, string title, string loader, u32 magic) vector<string> Plugin::CreateArgs(const string& device, const string& path,
const string& title, const string& loader, u32 magic)
{ {
vector<string> args; vector<string> args;
Plugin_Pos = GetPluginPosition(magic); Plugin_Pos = GetPluginPosition(magic);
if(Plugin_Pos < 0) if(Plugin_Pos < 0)
return args; return args;
for(vector<string>::iterator arg = Plugins[Plugin_Pos].Args.begin(); for(vector<string>::const_iterator arg = Plugins[Plugin_Pos].Args.begin();
arg != Plugins[Plugin_Pos].Args.end(); arg++) arg != Plugins[Plugin_Pos].Args.end(); ++arg)
{ {
string Argument(*arg); string Argument(*arg);
if(Argument.find(PLUGIN_DEV) != string::npos) if(Argument.find(PLUGIN_DEV) != string::npos)
@ -251,8 +246,9 @@ vector<string> Plugin::CreateArgs(string device, string path, string title, stri
return args; return args;
} }
string Plugin::GenerateCoverLink(dir_discHdr gameHeader, string url, Config &Checksums) string Plugin::GenerateCoverLink(dir_discHdr gameHeader, const string& constURL, Config &Checksums)
{ {
string url(constURL);
Plugin_Pos = GetPluginPosition(gameHeader.settings[0]); Plugin_Pos = GetPluginPosition(gameHeader.settings[0]);
if(url.find(TAG_LOC) != url.npos) if(url.find(TAG_LOC) != url.npos)
@ -266,12 +262,13 @@ string Plugin::GenerateCoverLink(dir_discHdr gameHeader, string url, Config &Che
strncpy(gamePath, &gameHeader.path[string(gameHeader.path).find_last_of("/")+1], sizeof(gamePath)); strncpy(gamePath, &gameHeader.path[string(gameHeader.path).find_last_of("/")+1], sizeof(gamePath));
else else
strncpy(gamePath, gameHeader.path, sizeof(gamePath)); strncpy(gamePath, gameHeader.path, sizeof(gamePath));
string cachedCRC = Checksums.getString("CHECKSUMS", gamePath, emptyString); const string& cachedCRC = Checksums.getString("CHECKSUMS", gamePath);
char crc_string[9]; char crc_string[9];
if(cachedCRC != emptyString) memset(crc_string, 0, sizeof(crc_string));
if(cachedCRC.size() > 1)
{ {
gprintf("CRC32 of %s is cached\n", gamePath); gprintf("CRC32 of %s is cached\n", gamePath);
snprintf(crc_string, sizeof(crc_string), "%s", cachedCRC.c_str()); strncpy(crc_string, cachedCRC.c_str(), 8);
} }
else else
{ {
@ -284,7 +281,7 @@ string Plugin::GenerateCoverLink(dir_discHdr gameHeader, string url, Config &Che
infile.seekg(0x0e, ios::beg); infile.seekg(0x0e, ios::beg);
infile.read((char*)&buffer, 8); infile.read((char*)&buffer, 8);
infile.close(); infile.close();
snprintf(crc_string, sizeof(crc_string), "%08x", (u32)__builtin_bswap32(buffer)); strncpy(crc_string, fmt("%08x", (u32)__builtin_bswap32(buffer)), 8);
} }
else if(strstr(gameHeader.path, ".7z") != NULL) else if(strstr(gameHeader.path, ".7z") != NULL)
{ {
@ -300,10 +297,10 @@ string Plugin::GenerateCoverLink(dir_discHdr gameHeader, string url, Config &Che
infile.seekg(-13, ios::cur); infile.seekg(-13, ios::cur);
infile.read((char*)&buffer, 8); infile.read((char*)&buffer, 8);
infile.close(); infile.close();
snprintf(crc_string, sizeof(crc_string), "%08x", (u32)__builtin_bswap32(buffer)); strncpy(crc_string, fmt("%08x", (u32)__builtin_bswap32(buffer)), 8);
} }
else else
snprintf(crc_string, sizeof(crc_string), "%08x", crc32file(gameHeader.path)); strncpy(crc_string, fmt("%08x", crc32file(gameHeader.path)), 8);
Checksums.setString("CHECKSUMS", gamePath, crc_string); Checksums.setString("CHECKSUMS", gamePath, crc_string);
Checksums.save(); Checksums.save();
} }

View File

@ -58,20 +58,22 @@ public:
u32 GetBannerSoundSize(); u32 GetBannerSoundSize();
char* GetDolName(u32 magic); char* GetDolName(u32 magic);
char* GetCoverFolderName(u32 magic); char* GetCoverFolderName(u32 magic);
string GenerateCoverLink(dir_discHdr gameHeader, string url, Config &Checksums); string GenerateCoverLink(dir_discHdr gameHeader, const string& constURL, Config &Checksums);
wstringEx GetPluginName(u8 pos); wstringEx GetPluginName(u8 pos);
u32 getPluginMagic(u8 pos); u32 getPluginMagic(u8 pos);
bool PluginExist(u8 pos); bool PluginExist(u8 pos);
void SetEnablePlugin(Config &cfg, u8 pos, u8 ForceMode = 0); void SetEnablePlugin(Config &cfg, u8 pos, u8 ForceMode = 0);
vector<bool> GetEnabledPlugins(Config &cfg); const vector<bool> *GetEnabledPlugins(Config &cfg);
vector<string> CreateArgs(string device, string path, string title, string loader, u32 magic); vector<string> CreateArgs(const string& device, const string& path,
void init(string); const string& title, const string& loader, u32 magic);
void init(const string& m_pluginsDir);
void Cleanup(); void Cleanup();
void EndAdd(); void EndAdd();
vector<dir_discHdr> ParseScummvmINI(Config &ini, string Device); vector<dir_discHdr> ParseScummvmINI(Config &ini, const char *Device);
private: private:
s8 GetPluginPosition(u32 magic); s8 GetPluginPosition(u32 magic);
vector<PluginOptions> Plugins; vector<PluginOptions> Plugins;
vector<bool> enabledPlugins;
s8 Plugin_Pos; s8 Plugin_Pos;
string pluginsDir; string pluginsDir;
bool adding; bool adding;