-changed plugin code, also fixed a bug in it

This commit is contained in:
fix94.1 2012-05-04 18:05:41 +00:00
parent d2b6a29018
commit 20c2e948e7
2 changed files with 28 additions and 25 deletions

View File

@ -14,6 +14,7 @@
#include "gecko/gecko.h" #include "gecko/gecko.h"
static const std::string emptyString; static const std::string emptyString;
static char* emptyChar = (char*)" ";
void Plugin::init(string m_pluginsDir) void Plugin::init(string m_pluginsDir)
{ {
@ -29,11 +30,11 @@ void Plugin::EndAdd()
void Plugin::Cleanup() void Plugin::Cleanup()
{ {
for(banner_pos = 0; banner_pos < Plugins.size(); banner_pos++) for(u8 pos = 0; pos < Plugins.size(); pos++)
MEM2_free(Plugins[banner_pos].BannerSound); {
Plugins.clear(); if(Plugins[pos].BannerSound != NULL)
banner_pos = 0; MEM2_free(Plugins[pos].BannerSound);
pluginsDir.erase(0, pluginsDir.size()); }
} }
bool Plugin::AddPlugin(Config &plugin) bool Plugin::AddPlugin(Config &plugin)
@ -74,50 +75,50 @@ bool Plugin::AddPlugin(Config &plugin)
return false; return false;
} }
bool Plugin::UseReturnLoader(u32 magic) s8 Plugin::GetPluginPosition(u32 magic)
{ {
for(u8 pos = 0; pos < Plugins.size(); pos++) for(u8 pos = 0; pos < Plugins.size(); pos++)
{ {
if(magic == Plugins[pos].magicWord) if(magic == Plugins[pos].magicWord)
return Plugins[pos].ReturnLoader; return pos;
} }
return -1;
}
bool Plugin::UseReturnLoader(u32 magic)
{
if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
return Plugins[Plugin_Pos].ReturnLoader;
return false; return false;
} }
u8* Plugin::GetBannerSound(u32 magic) u8* Plugin::GetBannerSound(u32 magic)
{ {
for(banner_pos = 0; banner_pos < Plugins.size(); banner_pos++) if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
{ return Plugins[Plugin_Pos].BannerSound;
if(magic == Plugins[banner_pos].magicWord)
return Plugins[banner_pos].BannerSound;
}
return NULL; return NULL;
} }
u32 Plugin::GetBannerSoundSize() u32 Plugin::GetBannerSoundSize()
{ {
//We call that directly after GetBannerSound, so no need to search for the magic again //We call that directly after GetBannerSound, so no need to search for the magic again
if(Plugins[banner_pos].BannerSoundSize > 0) if(Plugin_Pos >= 0)
return Plugins[banner_pos].BannerSoundSize; return Plugins[Plugin_Pos].BannerSoundSize;
return 0; return 0;
} }
char* Plugin::GetDolName(u32 magic) char* Plugin::GetDolName(u32 magic)
{ {
char *null = (char*)" "; if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
for(u8 pos = 0; pos < Plugins.size(); pos++) return (char*)Plugins[Plugin_Pos].DolName.c_str();
if(magic == Plugins[pos].magicWord) return emptyChar;
return (char*)Plugins[pos].DolName.c_str();
return null;
} }
char* Plugin::GetCoverFolderName(u32 magic) char* Plugin::GetCoverFolderName(u32 magic)
{ {
char *null = (char*)" "; if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
for(u8 pos = 0; pos < Plugins.size(); pos++) return (char*)Plugins[Plugin_Pos].coverFolder.c_str();
if(magic == Plugins[pos].magicWord) return emptyChar;
return (char*)Plugins[pos].coverFolder.c_str();
return null;
} }
safe_vector<dir_discHdr> Plugin::ParseScummvmINI(Config &ini, string Device) safe_vector<dir_discHdr> Plugin::ParseScummvmINI(Config &ini, string Device)

View File

@ -42,8 +42,10 @@ public:
void EndAdd(); void EndAdd();
safe_vector<dir_discHdr> ParseScummvmINI(Config &ini, string Device); safe_vector<dir_discHdr> ParseScummvmINI(Config &ini, string Device);
private: private:
s8 GetPluginPosition(u32 magic);
safe_vector<PluginOptions> Plugins; safe_vector<PluginOptions> Plugins;
u8 banner_pos; s8 Plugin_Pos;
string pluginsDir; string pluginsDir;
bool adding; bool adding;
}; };