2012-04-10 19:12:38 +02:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// Name : plugin.cpp
|
|
|
|
// Copyright : 2012 FIX94
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "plugin.hpp"
|
|
|
|
#include "memory/mem2.hpp"
|
|
|
|
#include "gui/text.hpp"
|
2012-04-12 00:01:41 +02:00
|
|
|
#include "gecko/gecko.h"
|
|
|
|
|
|
|
|
static const std::string emptyString;
|
2012-05-04 20:05:41 +02:00
|
|
|
static char* emptyChar = (char*)" ";
|
2012-04-10 19:12:38 +02:00
|
|
|
|
|
|
|
void Plugin::init(string m_pluginsDir)
|
|
|
|
{
|
|
|
|
pluginsDir = m_pluginsDir;
|
|
|
|
//Ready to add plugins
|
|
|
|
adding = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Plugin::EndAdd()
|
|
|
|
{
|
|
|
|
adding = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Plugin::Cleanup()
|
|
|
|
{
|
2012-05-04 20:05:41 +02:00
|
|
|
for(u8 pos = 0; pos < Plugins.size(); pos++)
|
|
|
|
{
|
|
|
|
if(Plugins[pos].BannerSound != NULL)
|
|
|
|
MEM2_free(Plugins[pos].BannerSound);
|
|
|
|
}
|
2012-04-10 19:12:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Plugin::AddPlugin(Config &plugin)
|
|
|
|
{
|
|
|
|
if(!adding)
|
|
|
|
return false;
|
2012-04-12 00:01:41 +02:00
|
|
|
|
2012-05-01 15:30:16 +02:00
|
|
|
PluginOptions NewPlugin;
|
|
|
|
NewPlugin.DolName = plugin.getString("PLUGIN","dolFile","");
|
|
|
|
NewPlugin.coverFolder = plugin.getString("PLUGIN","coverFolder","");
|
|
|
|
sscanf(plugin.getString("PLUGIN","magic","").c_str(), "%08x", &NewPlugin.magicWord);
|
|
|
|
sscanf(plugin.getString("PLUGIN","coverColor","").c_str(), "%08x", &NewPlugin.caseColor);
|
|
|
|
NewPlugin.ReturnLoader = plugin.getBool("PLUGIN","ReturnLoader");
|
2012-04-10 19:12:38 +02:00
|
|
|
|
|
|
|
string bannerfilepath = sfmt("%s/%s", pluginsDir.c_str(), plugin.getString("PLUGIN","bannerSound","").c_str());
|
|
|
|
ifstream infile;
|
|
|
|
infile.open(bannerfilepath.c_str(), ios::binary);
|
|
|
|
if(infile.is_open())
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
infile.seekg(0, ios::end);
|
|
|
|
size = infile.tellg();
|
|
|
|
infile.seekg(0, ios::beg);
|
|
|
|
//Don't free that, otherwise you would delete the sound
|
|
|
|
char* FileReadBuffer = (char*)MEM2_alloc(size);
|
|
|
|
infile.read(FileReadBuffer, size);
|
2012-05-01 15:30:16 +02:00
|
|
|
NewPlugin.BannerSound = (u8*)FileReadBuffer;
|
|
|
|
NewPlugin.BannerSoundSize = size;
|
|
|
|
Plugins.push_back(NewPlugin);
|
2012-04-10 19:12:38 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-01 15:30:16 +02:00
|
|
|
NewPlugin.BannerSound = 0;
|
|
|
|
NewPlugin.BannerSoundSize = 0;
|
|
|
|
Plugins.push_back(NewPlugin);
|
2012-04-10 19:12:38 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-04 20:05:41 +02:00
|
|
|
s8 Plugin::GetPluginPosition(u32 magic)
|
2012-04-14 21:43:37 +02:00
|
|
|
{
|
2012-05-01 15:30:16 +02:00
|
|
|
for(u8 pos = 0; pos < Plugins.size(); pos++)
|
2012-04-14 21:43:37 +02:00
|
|
|
{
|
2012-05-01 15:30:16 +02:00
|
|
|
if(magic == Plugins[pos].magicWord)
|
2012-05-04 20:05:41 +02:00
|
|
|
return pos;
|
2012-04-14 21:43:37 +02:00
|
|
|
}
|
2012-05-04 20:05:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Plugin::UseReturnLoader(u32 magic)
|
|
|
|
{
|
|
|
|
if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
|
|
|
|
return Plugins[Plugin_Pos].ReturnLoader;
|
2012-04-14 21:43:37 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-10 19:12:38 +02:00
|
|
|
u8* Plugin::GetBannerSound(u32 magic)
|
|
|
|
{
|
2012-05-04 20:05:41 +02:00
|
|
|
if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
|
|
|
|
return Plugins[Plugin_Pos].BannerSound;
|
2012-04-10 19:12:38 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 Plugin::GetBannerSoundSize()
|
|
|
|
{
|
|
|
|
//We call that directly after GetBannerSound, so no need to search for the magic again
|
2012-05-04 20:05:41 +02:00
|
|
|
if(Plugin_Pos >= 0)
|
|
|
|
return Plugins[Plugin_Pos].BannerSoundSize;
|
2012-04-10 19:12:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* Plugin::GetDolName(u32 magic)
|
|
|
|
{
|
2012-05-04 20:05:41 +02:00
|
|
|
if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
|
|
|
|
return (char*)Plugins[Plugin_Pos].DolName.c_str();
|
|
|
|
return emptyChar;
|
2012-05-01 15:30:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
char* Plugin::GetCoverFolderName(u32 magic)
|
|
|
|
{
|
2012-05-04 20:05:41 +02:00
|
|
|
if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
|
|
|
|
return (char*)Plugins[Plugin_Pos].coverFolder.c_str();
|
|
|
|
return emptyChar;
|
2012-04-10 19:12:38 +02:00
|
|
|
}
|
2012-04-12 00:01:41 +02:00
|
|
|
|
2012-05-05 22:07:54 +02:00
|
|
|
bool Plugin::PluginExist(u8 pos)
|
|
|
|
{
|
|
|
|
if(pos < Plugins.size())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wstringEx Plugin::GetPluginName(u8 pos)
|
|
|
|
{
|
|
|
|
wstringEx tmpString;
|
|
|
|
string PluginName(Plugins[pos].DolName);
|
|
|
|
PluginName.erase(PluginName.end() - 4, PluginName.end());
|
|
|
|
tmpString.fromUTF8(PluginName.c_str());
|
|
|
|
return tmpString;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Plugin::SetEnablePlugin(Config &cfg, u8 pos, u8 ForceMode)
|
|
|
|
{
|
|
|
|
if(pos < Plugins.size())
|
|
|
|
{
|
|
|
|
char PluginMagicWord[8];
|
|
|
|
snprintf(PluginMagicWord, sizeof(PluginMagicWord), "%08x", Plugins[pos].magicWord);
|
|
|
|
if(ForceMode == 1)
|
|
|
|
cfg.setBool("PLUGIN", PluginMagicWord, false);
|
|
|
|
else if(ForceMode == 2)
|
|
|
|
cfg.setBool("PLUGIN", PluginMagicWord, true);
|
|
|
|
else
|
|
|
|
cfg.setBool("PLUGIN", PluginMagicWord, cfg.getBool("PLUGIN", PluginMagicWord) ? false : true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
safe_vector<bool> Plugin::GetEnabledPlugins(Config &cfg)
|
|
|
|
{
|
|
|
|
safe_vector<bool> enabledPlugins;
|
|
|
|
char PluginMagicWord[8];
|
|
|
|
u8 enabledPluginsNumber = 0;
|
|
|
|
for(u8 i = 0; i < Plugins.size(); i++)
|
|
|
|
{
|
|
|
|
snprintf(PluginMagicWord, sizeof(PluginMagicWord), "%08x", Plugins[i].magicWord);
|
|
|
|
if(cfg.getBool("PLUGIN", PluginMagicWord, true))
|
|
|
|
{
|
|
|
|
enabledPluginsNumber++;
|
|
|
|
enabledPlugins.push_back(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
enabledPlugins.push_back(false);
|
|
|
|
}
|
|
|
|
if(enabledPluginsNumber == Plugins.size())
|
|
|
|
enabledPlugins.clear();
|
|
|
|
return enabledPlugins;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 Plugin::getPluginMagic(u8 pos)
|
|
|
|
{
|
|
|
|
return Plugins[pos].magicWord;
|
|
|
|
}
|
|
|
|
|
2012-04-16 06:58:17 +02:00
|
|
|
safe_vector<dir_discHdr> Plugin::ParseScummvmINI(Config &ini, string Device)
|
2012-04-12 00:01:41 +02:00
|
|
|
{
|
|
|
|
gprintf("Parsing scummvm.ini\n");
|
|
|
|
safe_vector<dir_discHdr> gameHeader;
|
2012-04-28 18:52:41 +02:00
|
|
|
if(!ini.loaded())
|
|
|
|
return gameHeader;
|
2012-05-04 14:30:43 +02:00
|
|
|
string game(ini.firstDomain());
|
2012-04-12 00:01:41 +02:00
|
|
|
dir_discHdr tmp;
|
|
|
|
while(1)
|
|
|
|
{
|
2012-04-21 17:41:18 +02:00
|
|
|
if(game == emptyString)
|
|
|
|
break;
|
|
|
|
if(strncasecmp(game.c_str(), "/", 1) == 0 ||
|
2012-04-29 14:33:24 +02:00
|
|
|
strncasecmp(ini.getString(game,"description").c_str(), "/", 1) == 0 ||
|
|
|
|
strncasecmp(ini.getWString(game, "path").toUTF8().c_str(), Device.c_str(), 3) != 0)
|
2012-04-12 00:01:41 +02:00
|
|
|
{
|
|
|
|
game = ini.nextDomain();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
memset(&tmp, 0, sizeof(dir_discHdr));
|
2012-05-01 15:30:16 +02:00
|
|
|
tmp.hdr.casecolor = Plugins.back().caseColor;
|
2012-04-28 18:52:41 +02:00
|
|
|
wstringEx tmpString;
|
|
|
|
tmpString.fromUTF8(ini.getString(game,"description").c_str());
|
|
|
|
wcsncpy(tmp.title, tmpString.c_str(), 64);
|
2012-04-12 00:01:41 +02:00
|
|
|
strncpy(tmp.path, game.c_str(), sizeof(tmp.path));
|
2012-04-29 14:33:24 +02:00
|
|
|
gprintf("Found: %ls\n", tmp.title);
|
2012-05-01 15:30:16 +02:00
|
|
|
tmp.hdr.magic = Plugins.back().magicWord;
|
2012-04-12 00:01:41 +02:00
|
|
|
tmp.hdr.gc_magic = 0x4c4f4c4f;
|
|
|
|
gameHeader.push_back(tmp);
|
|
|
|
game = ini.nextDomain();
|
|
|
|
}
|
|
|
|
return gameHeader;
|
|
|
|
}
|