diff --git a/out/boot.dol b/out/boot.dol index 16b7d312..2338487a 100644 Binary files a/out/boot.dol and b/out/boot.dol differ diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index eafe7b8e..ea4ec601 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -75,7 +75,6 @@ CMenu::CMenu() m_init_network = false; m_use_source = true; m_sourceflow = false; - m_numPlugins = 0; m_clearCats = false; m_getFavs = true; m_catStartPage = 1; @@ -103,13 +102,6 @@ CMenu::CMenu() m_source_autoboot = false; } -static vector INI_List; -static void GrabINIFiles(char *FullPath) -{ - //Just push back - INI_List.push_back(FullPath); -} - bool CMenu::init(bool usb_mounted) { SoundHandle.Init(); @@ -327,28 +319,29 @@ bool CMenu::init(bool usb_mounted) m_coverflow.load(fmt("%s/default.ini", m_coverflowsDir.c_str())); m_platform.load(fmt("%s/platform.ini", m_pluginDataDir.c_str())); - /* Get plugin ini files */ + /* Init plugins */ m_plugin.init(m_pluginsDir); - INI_List.clear(); - GetFiles(m_pluginsDir.c_str(), stringToVector(".ini", '|'), GrabINIFiles, false, 3); - - if(INI_List.size() > 0) + vector magics = m_cfg.getStrings(PLUGIN_DOMAIN, "enabled_plugins", ','); + if(magics.size() > 0) { - Config m_plugin_cfg; - for(vector::const_iterator iniFile = INI_List.begin(); iniFile != INI_List.end(); ++iniFile) + enabledPluginsCount = 0; + string enabledMagics; + for(u8 i = 0; i < magics.size(); i++) { - if(iniFile->find("scummvm.ini") != string::npos) - continue; - m_plugin_cfg.load(iniFile->c_str()); - if(m_plugin_cfg.loaded()) + u8 pos = m_plugin.GetPluginPosition(strtoul(magics[i].c_str(), NULL, 16)); + if(pos < 255) { - m_plugin.AddPlugin(m_plugin_cfg); - m_numPlugins++; + enabledPluginsCount++; + m_plugin.SetEnablePlugin(pos, 2); + if(i == 0) + enabledMagics = magics[0]; + else + enabledMagics.append(',' + magics[i]); } - m_plugin_cfg.unload(); } + m_cfg.setString(PLUGIN_DOMAIN, "enabled_plugins", enabledMagics); + magics.clear(); } - m_plugin.EndAdd(); /* Set wiiflow language */ const char *defLang = "Default"; @@ -2146,7 +2139,7 @@ void CMenu::_initCF(void) dump.setWString(domain, id, hdr->title); } - if(hdr->type == TYPE_PLUGIN && m_plugin.GetEnableStatus(m_cfg, hdr->settings[0])) + if(hdr->type == TYPE_PLUGIN && m_plugin.GetEnabledStatus(m_plugin.GetPluginPosition(hdr->settings[0]))) CoverFlow.addItem(&(*hdr), 0, 0); else { @@ -2187,10 +2180,9 @@ void CMenu::_initCF(void) } else if(m_current_view == COVERFLOW_PLUGIN) { - m_plugin.GetEnabledPlugins(m_cfg, &enabledPluginsCount); if(enabledPluginsCount == 1)// only one plugin enabled { - if(m_cfg.getBool(PLUGIN_ENABLED, "48425257"))// homebrew plugin + if(m_plugin.GetEnabledStatus(m_plugin.GetPluginPosition(strtoul("48425257", NULL, 16))))// homebrew plugin { CoverFlow.setBoxMode(m_cfg.getBool(HOMEBREW_DOMAIN, "box_mode", true)); CoverFlow.setSmallBoxMode(m_cfg.getBool(HOMEBREW_DOMAIN, "smallbox", false)); @@ -2198,9 +2190,9 @@ void CMenu::_initCF(void) else { s8 bm = -1; - for(u8 i = 0; m_plugin.PluginExist(i); ++i)// get plugins box mode value + for(u8 i = 0; m_plugin.PluginExist(i); ++i) { - if(m_plugin.GetEnableStatus(m_cfg, m_plugin.getPluginMagic(i))) + if(m_plugin.GetEnabledStatus(i)) { bm = m_plugin.GetBoxMode(i); break; @@ -2217,31 +2209,33 @@ void CMenu::_initCF(void) { s8 bm1 = -1; s8 bm2 = -1; - u8 i; - for(i = 0; m_plugin.PluginExist(i); ++i)// get first enabled plugins box mode + bool all_same = true; + for(u8 i = 0; m_plugin.PluginExist(i); ++i) { - if(m_plugin.GetEnableStatus(m_cfg, m_plugin.getPluginMagic(i))) + if(m_plugin.GetEnabledStatus(i)) { - bm1 = m_plugin.GetBoxMode(i); - if(bm1 < 0) - bm1 = m_cfg.getBool("GENERAL", "box_mode", true); - break; + if(bm1 == -1) + { + bm1 = m_plugin.GetBoxMode(i); + if(bm1 < 0) + bm1 = m_cfg.getBool("GENERAL", "box_mode", true) ? 1 : 0; + } + else + { + bm2 = m_plugin.GetBoxMode(i); + if(bm2 < 0) + bm2 = m_cfg.getBool("GENERAL", "box_mode", true) ? 1 : 0; + if(bm2 != bm1) + { + all_same = false; + break; + } + } } } - for(i = 0; m_plugin.PluginExist(i); ++i)// check all other enabled are the same - { - if(m_plugin.GetEnableStatus(m_cfg, m_plugin.getPluginMagic(i))) - { - bm2 = m_plugin.GetBoxMode(i); - if(bm2 < 0) - bm2 = m_cfg.getBool("GENERAL", "box_mode", true); - if(bm2 != bm1) - break; - } - } - if(m_plugin.PluginExist(i))// broke out of loop because not all the same so use default + if(!all_same) CoverFlow.setBoxMode(m_cfg.getBool("GENERAL", "box_mode", true)); - else // made it thru loop so they all match + else CoverFlow.setBoxMode(bm1 == 0 ? false : true); CoverFlow.setSmallBoxMode(false); } @@ -2271,18 +2265,20 @@ void CMenu::_initCF(void) u32 sourceNumber = 0; if(m_current_view == COVERFLOW_PLUGIN && !m_sourceflow) { - strncpy(m_plugin.PluginMagicWord, m_cfg.getString(PLUGIN_DOMAIN, "cur_magic").c_str(), 8); - if(!m_cfg.getBool("PLUGINS_ENABLED", m_plugin.PluginMagicWord, false)) + if(!m_plugin.GetEnabledStatus(m_plugin.GetPluginPosition(strtoul(m_cfg.getString(PLUGIN_DOMAIN, "cur_magic", "00000000").c_str(), NULL, 16)))) { for(u8 i = 0; m_plugin.PluginExist(i); ++i) { - if(m_plugin.GetEnableStatus(m_cfg, m_plugin.getPluginMagic(i)))// sets m_plugin.PluginMagicWord + if(m_plugin.GetEnabledStatus(i)) { - m_cfg.setString(PLUGIN_DOMAIN, "cur_magic", m_plugin.PluginMagicWord); + m_cfg.setString(PLUGIN_DOMAIN, "cur_magic", sfmt("%08x", m_plugin.GetPluginMagic(i))); break; } } } + + strncpy(m_plugin.PluginMagicWord, m_cfg.getString(PLUGIN_DOMAIN, "cur_magic").c_str(), 8); + if(strncasecmp(m_plugin.PluginMagicWord, "4E47434D", 8) == 0)//NGCM ID = m_cfg.getString("plugin_item", m_plugin.PluginMagicWord, ""); else if(strncasecmp(m_plugin.PluginMagicWord, "4E574949", 8) == 0)//NWII @@ -2468,8 +2464,7 @@ bool CMenu::_loadPluginList() gprintf("Adding plugins list\n"); for(u8 i = 0; m_plugin.PluginExist(i); ++i) { - u32 Magic = m_plugin.getPluginMagic(i); - if(!m_plugin.GetEnableStatus(m_cfg, Magic))// m_plugin.PluginMagicWord is set here. + if(!m_plugin.GetEnabledStatus(i)) continue; int romsPartition = m_plugin.GetRomPartition(i); if(romsPartition < 0) @@ -2477,6 +2472,7 @@ bool CMenu::_loadPluginList() currentPartition = romsPartition; if(!DeviceHandle.IsInserted(currentPartition)) continue; + strncpy(m_plugin.PluginMagicWord, fmt("%08x", m_plugin.GetPluginMagic(i)), 8); const char *romDir = m_plugin.GetRomDir(i); if(strcasecmp(romDir, "scummvm.ini") != 0) { @@ -2519,7 +2515,7 @@ bool CMenu::_loadPluginList() bool preCachedList = fsop_FileExist(cachedListFile.c_str()); vector FileTypes = stringToVector(m_plugin.GetFileTypes(i), '|'); m_cacheList.Color = m_plugin.GetCaseColor(i); - m_cacheList.Magic = Magic; + m_cacheList.Magic = m_plugin.GetPluginMagic(i); m_cacheList.usePluginDBTitles = m_cfg.getBool(PLUGIN_DOMAIN, "database_titles", true); m_cacheList.CreateRomList(m_platform, romsDir, FileTypes, cachedListFile, updateCache); for(vector::iterator tmp_itr = m_cacheList.begin(); tmp_itr != m_cacheList.end(); tmp_itr++) @@ -2543,7 +2539,7 @@ bool CMenu::_loadPluginList() if(m_platform.loaded())/* convert plugin magic to platform name */ platformName = m_platform.getString("PLUGINS", m_plugin.PluginMagicWord); m_cacheList.Color = m_plugin.GetCaseColor(i); - m_cacheList.Magic = Magic; + m_cacheList.Magic = m_plugin.GetPluginMagic(i); m_cacheList.ParseScummvmINI(scummvm, DeviceName[currentPartition], m_pluginDataDir.c_str(), platformName.c_str(), cachedListFile, updateCache); for(vector::iterator tmp_itr = m_cacheList.begin(); tmp_itr != m_cacheList.end(); tmp_itr++) m_gameList.push_back(*tmp_itr); diff --git a/source/menu/menu.hpp b/source/menu/menu.hpp index e8689e6f..630a271f 100644 --- a/source/menu/menu.hpp +++ b/source/menu/menu.hpp @@ -102,7 +102,6 @@ private: u8 *m_buffer; u8 m_aa; u8 m_numCFVersions; - u8 m_numPlugins; u8 m_max_source_btn; u8 curCustBg; char cf_domain[16]; diff --git a/source/menu/menu_categories.cpp b/source/menu/menu_categories.cpp index e0fed060..fa386ef0 100644 --- a/source/menu/menu_categories.cpp +++ b/source/menu/menu_categories.cpp @@ -75,8 +75,9 @@ void CMenu::_setCatGenDomain() { for(u8 i = 0; m_plugin.PluginExist(i); ++i)// only set "PLUGINS" for real plugins { - if(m_plugin.GetEnableStatus(m_cfg, m_plugin.getPluginMagic(i))) + if(m_plugin.GetEnabledStatus(i)) { + strncpy(m_plugin.PluginMagicWord, fmt("%08x", m_plugin.GetPluginMagic(i)), 8); if(strncasecmp(m_plugin.PluginMagicWord, "4E47434D", 8) == 0)//NGCM continue; else if(strncasecmp(m_plugin.PluginMagicWord, "4E574949", 8) == 0)//NWII @@ -88,7 +89,10 @@ void CMenu::_setCatGenDomain() else if(strncasecmp(m_plugin.PluginMagicWord, "48425257", 8) == 0)//HBRW continue; else + { genDomain = "PLUGINS"; + break; + } } } } diff --git a/source/menu/menu_home.cpp b/source/menu/menu_home.cpp index eecf875d..ec8c8ee6 100644 --- a/source/menu/menu_home.cpp +++ b/source/menu/menu_home.cpp @@ -537,8 +537,7 @@ int CMenu::_cacheCovers() smallBox = m_cfg.getBool(SOURCEFLOW_DOMAIN, "smallbox", false); else if(m_current_view == COVERFLOW_PLUGIN && !m_sourceflow) { - m_plugin.GetEnabledPlugins(m_cfg, &enabledPluginsCount); - if(enabledPluginsCount == 1 && m_cfg.getBool(PLUGIN_ENABLED, "48425257")) + if(enabledPluginsCount == 1 && m_plugin.GetEnabledStatus(m_plugin.GetPluginPosition(strtoul("48425257", NULL, 16)))) smallBox = m_cfg.getBool(HOMEBREW_DOMAIN, "smallbox", false); } diff --git a/source/menu/menu_main.cpp b/source/menu/menu_main.cpp index 1ee4e93a..b6d13815 100644 --- a/source/menu/menu_main.cpp +++ b/source/menu/menu_main.cpp @@ -52,6 +52,8 @@ void CMenu::_getCustomBgTex() string fn = ""; if(m_platform.loaded()) { + m_plugin.PluginMagicWord[0] = '\0'; + u8 i = 0; switch(m_current_view) { case COVERFLOW_CHANNEL: @@ -67,19 +69,15 @@ void CMenu::_getCustomBgTex() strncpy(m_plugin.PluginMagicWord, "4E47434D", 9); break; case COVERFLOW_PLUGIN: - for(u8 i = 0; m_plugin.PluginExist(i); ++i) - { - if(m_plugin.GetEnableStatus(m_cfg, m_plugin.getPluginMagic(i))) - { - strncpy(m_plugin.PluginMagicWord, fmt("%08x", m_plugin.getPluginMagic(i)), 8); - break; - } - } + while(m_plugin.PluginExist(i) && !m_plugin.GetEnabledStatus(i)) { ++i; } + if(m_plugin.PluginExist(i)) + strncpy(m_plugin.PluginMagicWord, fmt("%08x", m_plugin.GetPluginMagic(i)), 8); break; default:// wii strncpy(m_plugin.PluginMagicWord, "4E574949", 9); } - fn = m_platform.getString("PLUGINS", m_plugin.PluginMagicWord, ""); + if(strlen(m_plugin.PluginMagicWord) == 8) + fn = m_platform.getString("PLUGINS", m_plugin.PluginMagicWord, ""); } if(fn.length() > 0) { @@ -171,7 +169,6 @@ void CMenu::_showCF(bool refreshList) break; case COVERFLOW_PLUGIN: Pth = ""; - m_plugin.GetEnabledPlugins(m_cfg, &enabledPluginsCount); if(enabledPluginsCount == 0) Msg = _t("main6", L"No plugins selected."); else if(enabledPluginsCount > 1) @@ -179,17 +176,13 @@ void CMenu::_showCF(bool refreshList) else { Msg = _t("main2", L"No games found in "); - for(u8 i = 0; m_plugin.PluginExist(i); ++i) - { - if(m_plugin.GetEnableStatus(m_cfg, m_plugin.getPluginMagic(i))) - { - int romsPartition = m_plugin.GetRomPartition(i); - if(romsPartition < 0) - romsPartition = m_cfg.getInt(PLUGIN_DOMAIN, "partition", 0); - Pth = wstringEx(fmt("%s:/%s", DeviceName[romsPartition], m_plugin.GetRomDir(i))); - break; - } - } + u8 i = 0; + while(m_plugin.PluginExist(i) && !m_plugin.GetEnabledStatus(i)){ ++i; } + int romsPartition = m_plugin.GetRomPartition(i); + if(romsPartition < 0) + romsPartition = m_cfg.getInt(PLUGIN_DOMAIN, "partition", 0); + Pth = wstringEx(fmt("%s:/%s", DeviceName[romsPartition], m_plugin.GetRomDir(i))); + break; } break; } @@ -301,47 +294,33 @@ void CMenu::_showCF(bool refreshList) strcpy(cf_domain, "_SMALLFLOW"); if(m_current_view == COVERFLOW_PLUGIN && !m_sourceflow) { - m_plugin.GetEnabledPlugins(m_cfg, &enabledPluginsCount); /* check if homebrew plugin */ - if(enabledPluginsCount == 1 && m_cfg.getBool(PLUGIN_ENABLED, "48425257") && m_cfg.getBool(HOMEBREW_DOMAIN, "smallbox")) + if(enabledPluginsCount == 1 && m_plugin.GetEnabledStatus(m_plugin.GetPluginPosition(strtoul("48425257", NULL, 16))) && m_cfg.getBool(HOMEBREW_DOMAIN, "smallbox")) strcpy(cf_domain, "_SMALLFLOW"); - else if(enabledPluginsCount > 0) + else if(enabledPluginsCount > 0 && m_platform.loaded()) { - /* check if platform.ini is loaded */ - if(m_platform.loaded()) + /* get first plugin flow domain */ + u8 i = 0; + while(m_plugin.PluginExist(i) && !m_plugin.GetEnabledStatus(i)){ ++i; } + string flow_domain = m_platform.getString("FLOWS", m_platform.getString("PLUGINS", sfmt("%08x", m_plugin.GetPluginMagic(i)), ""), "_COVERFLOW"); + + /* check if all plugin flow domains match */ + bool match = true; + i++; + while(m_plugin.PluginExist(i)) { - /* get first plugin flow domain */ - string flow_domain; - for(u8 i = 0; m_plugin.PluginExist(i); ++i) + if(m_plugin.GetEnabledStatus(i) && + flow_domain != m_platform.getString("FLOWS", m_platform.getString("PLUGINS", sfmt("%08x", m_plugin.GetPluginMagic(i)), ""), "_COVERFLOW")) { - if(m_plugin.GetEnableStatus(m_cfg, m_plugin.getPluginMagic(i))) - { - strncpy(m_plugin.PluginMagicWord, fmt("%08x", m_plugin.getPluginMagic(i)), 8); - flow_domain = m_platform.getString("FLOWS", m_platform.getString("PLUGINS", m_plugin.PluginMagicWord)); - break; - } - } - /* check if all plugin flow domains match */ - if(!flow_domain.empty()) - { - bool match = true; - for(u8 i = 0; m_plugin.PluginExist(i); ++i) - { - if(m_plugin.GetEnableStatus(m_cfg, m_plugin.getPluginMagic(i))) - { - strncpy(m_plugin.PluginMagicWord, fmt("%08x", m_plugin.getPluginMagic(i)), 8); - if(flow_domain != m_platform.getString("FLOWS", m_platform.getString("PLUGINS", m_plugin.PluginMagicWord))) - { - match = false; - break; - } - } - } - /* if all match we use that flow domain */ - if(match) - snprintf(cf_domain, sizeof(cf_domain), "%s", flow_domain.c_str()); + match = false; + break; } + i++; } + + /* if all match we use that flow domain */ + if(match) + snprintf(cf_domain, sizeof(cf_domain), "%s", flow_domain.c_str()); } } @@ -1273,12 +1252,16 @@ int CMenu::_getCFVersion() int first = 0; for(u8 i = 0; m_plugin.PluginExist(i); ++i) { - if(m_plugin.GetEnableStatus(m_cfg, m_plugin.getPluginMagic(i)) && m_cfg.has("PLUGIN_CFVERSION", m_plugin.PluginMagicWord)) + if(m_plugin.GetEnabledStatus(i)) { - if(first > 0 && m_cfg.getInt("PLUGIN_CFVERSION", m_plugin.PluginMagicWord, 1) != first) - return m_cfg.getInt(_domainFromView(), "last_cf_mode", 1); - else if(first == 0) - first = m_cfg.getInt("PLUGIN_CFVERSION", m_plugin.PluginMagicWord, 1); + string magic = sfmt("%08x", m_plugin.GetPluginMagic(i)); + if(m_cfg.has("PLUGIN_CFVERSION", magic)) + { + if(first > 0 && m_cfg.getInt("PLUGIN_CFVERSION", magic, 1) != first) + return m_cfg.getInt(_domainFromView(), "last_cf_mode", 1); + else if(first == 0) + first = m_cfg.getInt("PLUGIN_CFVERSION", magic, 1); + } } } if(first == 0) @@ -1297,21 +1280,25 @@ void CMenu::_setCFVersion(int version) int first = 0; for(u8 i = 0; m_plugin.PluginExist(i); ++i) { - if(m_plugin.GetEnableStatus(m_cfg, m_plugin.getPluginMagic(i)) && m_cfg.has("PLUGIN_CFVERSION", m_plugin.PluginMagicWord)) + if(m_plugin.GetEnabledStatus(i)) { - if(first > 0 && m_cfg.getInt("PLUGIN_CFVERSION", m_plugin.PluginMagicWord, 1) != first) + string magic = sfmt("%08x", m_plugin.GetPluginMagic(i)); + if(m_cfg.has("PLUGIN_CFVERSION", magic)) { - m_cfg.setInt(_domainFromView(), "last_cf_mode", version); - return; + if(first > 0 && m_cfg.getInt("PLUGIN_CFVERSION", magic, 1) != first) + { + m_cfg.setInt(_domainFromView(), "last_cf_mode", version); + return; + } + else if(first == 0) + first = m_cfg.getInt("PLUGIN_CFVERSION", magic, 1); } - else if(first == 0) - first = m_cfg.getInt("PLUGIN_CFVERSION", m_plugin.PluginMagicWord, 1); } } for(u8 i = 0; m_plugin.PluginExist(i); ++i) { - if(m_plugin.GetEnableStatus(m_cfg, m_plugin.getPluginMagic(i))) - m_cfg.setInt("PLUGIN_CFVERSION", m_plugin.PluginMagicWord, version); + if(m_plugin.GetEnabledStatus(i)) + m_cfg.setInt("PLUGIN_CFVERSION", sfmt("%08x", m_plugin.GetPluginMagic(i)), version); } } else diff --git a/source/menu/menu_plugin.cpp b/source/menu/menu_plugin.cpp index 04f91df4..9de15485 100644 --- a/source/menu/menu_plugin.cpp +++ b/source/menu/menu_plugin.cpp @@ -72,7 +72,7 @@ void CMenu::_updatePluginCheckboxes(void) m_btnMgr.hide(m_pluginBtn[i]); m_btnMgr.hide(m_pluginLblCat[i]); } - const vector &EnabledPlugins = m_plugin.GetEnabledPlugins(m_cfg, &enabledPluginsCount); + const vector &EnabledPlugins = m_plugin.GetEnabledPlugins(&enabledPluginsCount); /* ALL Button */ if(EnabledPlugins.size() == 0) m_pluginBtn[0] = m_pluginBtnCats[0]; @@ -99,10 +99,8 @@ void CMenu::_PluginSettings() while(m_plugin.PluginExist(i)) i++; Plugin_Pages = static_cast(ceil(static_cast(i)/static_cast(10))); m_max_plugins = i; - //gprintf("Plugins found: %i, Pages: %i\n", m_max_plugins, Plugin_Pages); - if(Plugin_Pages == 0) + if(Plugin_Pages == 0)// Only use Plugin Settings if Plugins are found return; - /* Only use Plugin Settings if Plugins are found */ SetupInput(); Plugin_curPage = 1; _showPluginSettings(); @@ -112,7 +110,6 @@ void CMenu::_PluginSettings() _mainLoopCommon(); if(BTN_HOME_PRESSED || BTN_B_PRESSED || (BTN_A_PRESSED && m_btnMgr.selected(m_pluginBtnBack))) { - //m_cfg.save(); break; } else if(BTN_UP_PRESSED) @@ -149,18 +146,17 @@ void CMenu::_PluginSettings() { /* clear all plugins */ for(u8 j = 0; m_plugin.PluginExist(j); j++) - m_plugin.SetEnablePlugin(m_cfg, j, 1); + m_plugin.SetEnablePlugin(j, 1); m_current_view = COVERFLOW_PLUGIN; } if(i == 0)// all button to clear all or set all { - m_plugin.GetEnabledPlugins(m_cfg, &enabledPluginsCount);// get enabled plugins count // if all clear then set(2) them else clear(1) them all for(u8 j = 0; m_plugin.PluginExist(j); j++) - m_plugin.SetEnablePlugin(m_cfg, j, (enabledPluginsCount == 0) ? 2 : 1); + m_plugin.SetEnablePlugin(j, (enabledPluginsCount == 0) ? 2 : 1); } else - m_plugin.SetEnablePlugin(m_cfg, i+IteratorHelp-1);// switch plugin from off to on or vice versa + m_plugin.SetEnablePlugin(i+IteratorHelp-1);// switch plugin from off to on or vice versa _updatePluginCheckboxes(); m_btnMgr.setSelected(m_pluginBtn[i]); break; @@ -169,7 +165,20 @@ void CMenu::_PluginSettings() } } _hidePluginSettings(); - m_plugin.GetEnabledPlugins(m_cfg, &enabledPluginsCount); + string enabledMagics; + for(u8 i = 0; m_plugin.PluginExist(i); i++) + { + if(m_plugin.GetEnabledStatus(i)) + { + string magic = sfmt("%08x", m_plugin.GetPluginMagic(i)); + if(i == 0) + enabledMagics = magic; + else + enabledMagics.append(',' + magic); + } + } + m_cfg.setString(PLUGIN_DOMAIN, "enabled_plugins", enabledMagics); + if(m_refreshGameList && enabledPluginsCount > 0) { m_cfg.setUInt("GENERAL", "sources", m_current_view); diff --git a/source/menu/menu_source.cpp b/source/menu/menu_source.cpp index f545c6b4..bbe980eb 100644 --- a/source/menu/menu_source.cpp +++ b/source/menu/menu_source.cpp @@ -14,7 +14,7 @@ TexData m_sourceBg; string source; bool exitSource = false; -static u8 i, j, k; +static u8 i, j; int curPage; int numPages; vector magicNums; @@ -73,15 +73,25 @@ void CMenu::_sourceFlow() magicNums = m_source.getStrings(btn_selected, "magic", ','); if(magicNums.size() > 0) { - m_current_view = COVERFLOW_PLUGIN; - for(k = 0; k < m_numPlugins; ++k) - m_plugin.SetEnablePlugin(m_cfg, k, 1); // force disable all - for(vector::iterator itr = magicNums.begin(); itr != magicNums.end(); itr++) + for(u8 pos = 0; m_plugin.PluginExist(pos); pos++) + m_plugin.SetEnablePlugin(pos, 1); // force disable all + enabledPluginsCount = 0; + string enabledMagics; + for(i = 0; i < magicNums.size(); i++) { - s16 exist = m_plugin.GetPluginPosition(strtoul(itr->c_str(), NULL, 16)); - if(exist >= 0) - m_plugin.SetEnablePlugin(m_cfg, exist, 2); + u8 pos = m_plugin.GetPluginPosition(strtoul(magicNums[i].c_str(), NULL, 16)); + if(pos < 255) + { + enabledPluginsCount++; + m_plugin.SetEnablePlugin(pos, 2); + if(i == 0) + enabledMagics = magicNums[0]; + else + enabledMagics.append(',' + magicNums[i]); + } } + m_cfg.setString(PLUGIN_DOMAIN, "enabled_plugins", enabledMagics); + m_current_view = COVERFLOW_PLUGIN; } } else if(source =="new_source") @@ -425,24 +435,31 @@ bool CMenu::_Source() } else if(source == "plugin") { - m_current_view = COVERFLOW_PLUGIN; - _setSrcOptions(); - for(k = 0; k < m_numPlugins; ++k) - m_plugin.SetEnablePlugin(m_cfg, k, 1); /* force disable */ magicNums.clear(); magicNums = m_source.getStrings(btn_selected, "magic", ','); if(magicNums.size() > 0) { - for(vector::iterator itr = magicNums.begin(); itr != magicNums.end(); itr++) + for(u8 pos = 0; m_plugin.PluginExist(pos); pos++) + m_plugin.SetEnablePlugin(pos, 1); // force disable all + enabledPluginsCount = 0; + string enabledMagics; + for(i = 0; i < magicNums.size(); i++) { - s16 exist = m_plugin.GetPluginPosition(strtoul(itr->c_str(), NULL, 16));// make sure magic# is valid - if(exist >= 0) - m_plugin.SetEnablePlugin(m_cfg, exist, 2); + u8 pos = m_plugin.GetPluginPosition(strtoul(magicNums[i].c_str(), NULL, 16)); + if(pos < 255) + { + enabledPluginsCount++; + m_plugin.SetEnablePlugin(pos, 2); + if(i == 0) + enabledMagics = magicNums[0]; + else + enabledMagics.append(',' + magicNums[i]); + } } + m_cfg.setString(PLUGIN_DOMAIN, "enabled_plugins", enabledMagics); + m_current_view = COVERFLOW_PLUGIN; + _setSrcOptions(); } - m_plugin.GetEnabledPlugins(m_cfg, &enabledPluginsCount); - if(enabledPluginsCount == 0) // no magic #'s or invalid ones so default to first plugin in list - m_plugin.SetEnablePlugin(m_cfg, 0, 2); } else if(source =="new_source") { diff --git a/source/plugin/plugin.cpp b/source/plugin/plugin.cpp index a4da35bb..96371b8a 100644 --- a/source/plugin/plugin.cpp +++ b/source/plugin/plugin.cpp @@ -26,6 +26,7 @@ #include "gecko/gecko.hpp" #include "devicemounter/PartitionHandle.h" #include "devicemounter/DeviceHandler.hpp" +#include "list/ListGenerator.hpp" #include "types.h" #include "crc32.h" @@ -36,15 +37,6 @@ #define MODETEST_VAL 0xffffff00 #endif -Plugin m_plugin; -void Plugin::init(const string& m_pluginsDir) -{ - PluginMagicWord[8] = '\0'; - pluginsDir = m_pluginsDir; - Plugins.clear(); - adding = true; -} - static bool PluginOptions_cmp(PluginOptions lhs, PluginOptions rhs) { const wchar_t *first = lhs.DisplayName.c_str(); @@ -52,23 +44,48 @@ static bool PluginOptions_cmp(PluginOptions lhs, PluginOptions rhs) return wchar_cmp(first, second, wcslen(first), wcslen(second)); } -void Plugin::EndAdd() +static vector INI_List; +static void GrabINIFiles(char *FullPath) { + //Just push back + INI_List.push_back(FullPath); +} + +Plugin m_plugin; +void Plugin::init(const string& m_pluginsDir) +{ + PluginMagicWord[8] = '\0'; + pluginsDir = m_pluginsDir; + Plugins.clear(); + + INI_List.clear(); + GetFiles(m_pluginsDir.c_str(), stringToVector(".ini", '|'), GrabINIFiles, false, 3); + + if(INI_List.size() > 0) + { + Config m_plugin_cfg; + for(vector::const_iterator iniFile = INI_List.begin(); iniFile != INI_List.end(); ++iniFile) + { + if(iniFile->find("scummvm.ini") != string::npos) + continue; + m_plugin_cfg.load(iniFile->c_str()); + if(m_plugin_cfg.loaded()) + { + m_plugin.AddPlugin(m_plugin_cfg); + } + m_plugin_cfg.unload(); + } + } std::sort(Plugins.begin(), Plugins.end(), PluginOptions_cmp); - adding = false; } void Plugin::Cleanup() { Plugins.clear(); - adding = true; } -bool Plugin::AddPlugin(Config &plugin) +void Plugin::AddPlugin(Config &plugin) { - if(!adding) - return false; - PluginOptions NewPlugin; NewPlugin.DolName = plugin.getString(PLUGIN, "dolFile"); NewPlugin.coverFolder = plugin.getString(PLUGIN, "coverFolder"); @@ -79,6 +96,7 @@ bool Plugin::AddPlugin(Config &plugin) NewPlugin.fileTypes = plugin.getString(PLUGIN, "fileTypes"); NewPlugin.Args = plugin.getStrings(PLUGIN, "arguments", '|'); NewPlugin.boxMode = plugin.getInt(PLUGIN, "boxmode", -1); + NewPlugin.state = false; string PluginName = plugin.getString(PLUGIN, "displayname"); if(PluginName.size() < 2) { @@ -93,27 +111,26 @@ bool Plugin::AddPlugin(Config &plugin) if(NewPlugin.BannerSoundSize > 0) NewPlugin.BannerSound = bannerfilepath; Plugins.push_back(NewPlugin); - return false; } -s16 Plugin::GetPluginPosition(u32 magic) +u8 Plugin::GetPluginPosition(u32 magic) { for(u8 pos = 0; pos < Plugins.size(); pos++) { if(magic == Plugins[pos].magic) return (s16)pos; } - return -1; + return 255; } -u32 Plugin::getPluginMagic(u8 pos) +u32 Plugin::GetPluginMagic(u8 pos) { return Plugins[pos].magic; } u8* Plugin::GetBannerSound(u32 magic) { - if((Plugin_Pos = GetPluginPosition(magic)) >= 0) + if((Plugin_Pos = GetPluginPosition(magic)) < 255) { u32 size = 0; return fsop_ReadFile(Plugins[Plugin_Pos].BannerSound.c_str(), &size); @@ -131,21 +148,23 @@ u32 Plugin::GetBannerSoundSize() const char *Plugin::GetDolName(u32 magic) { - if((Plugin_Pos = GetPluginPosition(magic)) >= 0) + if((Plugin_Pos = GetPluginPosition(magic)) < 255) return Plugins[Plugin_Pos].DolName.c_str(); return NULL; } const char *Plugin::GetCoverFolderName(u32 magic) { - if((Plugin_Pos = GetPluginPosition(magic)) >= 0) + if((Plugin_Pos = GetPluginPosition(magic)) < 255) return Plugins[Plugin_Pos].coverFolder.c_str(); return NULL; } int Plugin::GetRomPartition(u8 pos) { - return Plugins[pos].romPartition; + if(pos < Plugins.size()) + return Plugins[pos].romPartition; + return -1; } const char *Plugin::GetRomDir(u8 pos) @@ -153,7 +172,7 @@ const char *Plugin::GetRomDir(u8 pos) return Plugins[pos].romDir.c_str(); } -const string& Plugin::GetFileTypes(s16 pos) +const string& Plugin::GetFileTypes(u8 pos) { return Plugins[pos].fileTypes; } @@ -180,44 +199,36 @@ bool Plugin::PluginExist(u8 pos) return false; } -void Plugin::SetEnablePlugin(Config &cfg, u8 pos, u8 ForceMode) +void Plugin::SetEnablePlugin(u8 pos, u8 ForceMode) { if(pos < Plugins.size()) { - strncpy(PluginMagicWord, fmt("%08x", Plugins[pos].magic), 8); if(ForceMode == 1) - cfg.setBool(PLUGIN_ENABLED, PluginMagicWord, false); + Plugins[pos].state = false; else if(ForceMode == 2) - cfg.setBool(PLUGIN_ENABLED, PluginMagicWord, true); + Plugins[pos].state = true; else - cfg.setBool(PLUGIN_ENABLED, PluginMagicWord, cfg.getBool(PLUGIN_ENABLED, PluginMagicWord) ? false : true); + Plugins[pos].state = Plugins[pos].state ? false : true; } } -bool Plugin::GetEnableStatus(Config &cfg, u32 magic) +bool Plugin::GetEnabledStatus(u8 pos) { - if((Plugin_Pos = GetPluginPosition(magic)) >= 0) - { - strncpy(PluginMagicWord, fmt("%08x", magic), 8); - return cfg.getBool(PLUGIN_ENABLED, PluginMagicWord, true); - } + if(pos < Plugins.size()) + return Plugins[pos].state; return false; } -const vector &Plugin::GetEnabledPlugins(Config &cfg, u8 *num) +const vector &Plugin::GetEnabledPlugins(u8 *num) { enabledPlugins.clear(); u8 enabledPluginsNumber = 0; for(u8 i = 0; i < Plugins.size(); i++) { - strncpy(PluginMagicWord, fmt("%08x", Plugins[i].magic), 8); - if(cfg.getBool(PLUGIN_ENABLED, PluginMagicWord, true)) - { + enabledPlugins.push_back(GetEnabledStatus(i)); + if(GetEnabledStatus(i)) enabledPluginsNumber++; - enabledPlugins.push_back(true); - } - else - enabledPlugins.push_back(false); + } if(enabledPluginsNumber == Plugins.size()) enabledPlugins.clear(); @@ -231,7 +242,7 @@ vector Plugin::CreateArgs(const char *device, const char *path, { vector args; Plugin_Pos = GetPluginPosition(magic); - if(Plugin_Pos < 0) + if(Plugin_Pos == 255) return args; for(vector::const_iterator arg = Plugins[Plugin_Pos].Args.begin(); arg != Plugins[Plugin_Pos].Args.end(); ++arg) @@ -466,7 +477,7 @@ string Plugin::GetRomId(char *romPath, u32 Magic, Config &m_crc, const char *dat } else if(!strcasecmp(platform, "ATARIST")) { - s16 pos = m_plugin.GetPluginPosition(Magic); + u8 pos = m_plugin.GetPluginPosition(Magic); string FileTypes = m_plugin.GetFileTypes(pos); string path; @@ -507,7 +518,7 @@ string Plugin::GetRomId(char *romPath, u32 Magic, Config &m_crc, const char *dat } else if(!strcasecmp(platform, "DOS")) { - s16 pos = m_plugin.GetPluginPosition(Magic); + u8 pos = m_plugin.GetPluginPosition(Magic); string FileTypes = m_plugin.GetFileTypes(pos); if(strcasestr(FileTypes.c_str(), ".conf")) diff --git a/source/plugin/plugin.hpp b/source/plugin/plugin.hpp index 7e59c2dd..ac35ef34 100644 --- a/source/plugin/plugin.hpp +++ b/source/plugin/plugin.hpp @@ -54,6 +54,7 @@ struct PluginOptions vector Args; wstringEx DisplayName; s8 boxMode; + bool state; }; class Plugin @@ -68,19 +69,18 @@ public: string GetRomName(const char *FullPath); string GetRomId(char *romPath, u32 Magic, Config &m_crc, const char *datadir, const char *platform, const char *name); int GetRomPartition(u8 pos); - const string& GetFileTypes(s16 pos); + const string& GetFileTypes(u8 pos); wstringEx GetPluginName(u8 pos); - u32 getPluginMagic(u8 pos); - s16 GetPluginPosition(u32 magic); + u32 GetPluginMagic(u8 pos); + u8 GetPluginPosition(u32 magic); s8 GetBoxMode(u8 pos); void init(const string& m_pluginsDir); - bool AddPlugin(Config &plugin); + void AddPlugin(Config &plugin); void Cleanup(); - void EndAdd(); - bool GetEnableStatus(Config &cfg, u32 magic); - void SetEnablePlugin(Config &cfg, u8 pos, u8 ForceMode = 0); - const vector &GetEnabledPlugins(Config &cfg, u8 *num); + bool GetEnabledStatus(u8 pos); + void SetEnablePlugin(u8 pos, u8 ForceMode = 0); + const vector &GetEnabledPlugins(u8 *num); bool PluginExist(u8 pos); vector CreateArgs(const char *device, const char *path, @@ -93,7 +93,6 @@ private: vector enabledPlugins; s16 Plugin_Pos; string pluginsDir; - bool adding; }; extern Plugin m_plugin;