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"
|
2012-05-23 18:27:55 +02:00
|
|
|
#include "devicemounter/PartitionHandle.h"
|
|
|
|
#include "devicemounter/DeviceHandler.hpp"
|
2012-05-24 20:48:26 +02:00
|
|
|
#include "defines.h"
|
2012-04-12 00:01:41 +02:00
|
|
|
|
2012-05-11 20:46:43 +02:00
|
|
|
static const string emptyString;
|
|
|
|
static const string emptyString2("/");
|
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
|
|
|
|
2012-05-11 20:46:43 +02:00
|
|
|
string PluginName = plugin.getString("PLUGIN","displayname","");
|
|
|
|
if(PluginName == emptyString || PluginName == emptyString2)
|
|
|
|
{
|
|
|
|
PluginName = NewPlugin.DolName;
|
|
|
|
PluginName.erase(PluginName.end() - 4, PluginName.end());
|
|
|
|
}
|
|
|
|
NewPlugin.DisplayName.fromUTF8(PluginName.c_str());
|
|
|
|
|
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)
|
|
|
|
{
|
2012-05-11 20:46:43 +02:00
|
|
|
return Plugins[pos].DisplayName;
|
2012-05-05 22:07:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-06 14:03:43 +02:00
|
|
|
vector<bool> Plugin::GetEnabledPlugins(Config &cfg)
|
2012-05-05 22:07:54 +02:00
|
|
|
{
|
2012-05-06 14:03:43 +02:00
|
|
|
vector<bool> enabledPlugins;
|
2012-05-05 22:07:54 +02:00
|
|
|
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-05-06 14:03:43 +02:00
|
|
|
vector<dir_discHdr> Plugin::ParseScummvmINI(Config &ini, string Device)
|
2012-04-12 00:01:41 +02:00
|
|
|
{
|
|
|
|
gprintf("Parsing scummvm.ini\n");
|
2012-05-06 14:03:43 +02:00
|
|
|
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-05-11 20:46:43 +02:00
|
|
|
string GameName;
|
2012-04-12 00:01:41 +02:00
|
|
|
dir_discHdr tmp;
|
|
|
|
while(1)
|
|
|
|
{
|
2012-05-11 20:46:43 +02:00
|
|
|
if(game == emptyString || game == emptyString2)
|
2012-04-21 17:41:18 +02:00
|
|
|
break;
|
2012-05-21 22:03:28 +02:00
|
|
|
GameName = ini.getString(game, "description");
|
2012-05-11 20:46:43 +02:00
|
|
|
if(GameName == emptyString || GameName == emptyString2 ||
|
2012-05-21 22:03:28 +02:00
|
|
|
strncasecmp(ini.getWString(game, "path").toUTF8().c_str(), Device.c_str(), 2) != 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;
|
2012-05-11 20:46:43 +02:00
|
|
|
tmpString.fromUTF8(GameName.c_str());
|
2012-04-28 18:52:41 +02:00
|
|
|
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-05-24 20:48:26 +02:00
|
|
|
tmp.hdr.gc_magic = EMU_MAGIC;
|
2012-04-12 00:01:41 +02:00
|
|
|
gameHeader.push_back(tmp);
|
|
|
|
game = ini.nextDomain();
|
|
|
|
}
|
|
|
|
return gameHeader;
|
|
|
|
}
|
2012-05-23 18:27:55 +02:00
|
|
|
|
|
|
|
/* Thanks to dimok for this */
|
|
|
|
vector<string> Plugin::CreateMplayerCEArguments(const char *filepath)
|
|
|
|
{
|
|
|
|
vector<string> args;
|
|
|
|
char dst[1024];
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
char device[10];
|
|
|
|
|
|
|
|
while(filepath[i] != ':')
|
|
|
|
{
|
|
|
|
device[i] = filepath[i];
|
|
|
|
device[i+1] = 0;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
char * ptr = (char *) &filepath[i];
|
|
|
|
|
|
|
|
while(ptr[0] != '/' || ptr[1] == '/')
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if(strncmp(DeviceHandler::PathToFSName(filepath), "NTF", 3) == 0)
|
|
|
|
{
|
|
|
|
sprintf(dst, "ntfs_usb:%s", ptr);
|
|
|
|
}
|
|
|
|
else if(strncmp(device, "usb", 3) == 0)
|
|
|
|
{
|
|
|
|
sprintf(dst, "usb:%s", ptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(dst, "%s:%s", device, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
args.push_back(dst);
|
|
|
|
args.push_back(string("-quiet"));
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Plugin::isMplayerCE(u32 magic)
|
|
|
|
{
|
|
|
|
if((Plugin_Pos = GetPluginPosition(magic)) >= 0)
|
|
|
|
return (Plugins[Plugin_Pos].magicWord == 0x4D504345);
|
|
|
|
return false;
|
|
|
|
}
|