Rev 50 | Rev 171 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include "CorePackage.h"
#include <File.h>
#include "InstallText.h"
namespace SPK {
namespace Package {
CCorePackage::CCorePackage(void) :
_bChanged(false),
_pInstallText(NULL),
_pUninstallText(NULL),
_pAutoExtract(NULL),
_pAutoExport(NULL)
{
_setDefaults();
}
CCorePackage::~CCorePackage(void)
{
if(_pInstallText)
delete _pInstallText;
if(_pUninstallText)
delete _pUninstallText;
if (_pAutoExtract)
delete _pAutoExtract;
if (_pAutoExport)
delete _pAutoExport;
}
void CCorePackage::_setDefaults()
{
_iRecommended = -1;
_iGameChanging = -1;
_iEaseOfUse = -1;
if(_pInstallText)
delete _pInstallText;
if(_pUninstallText)
delete _pUninstallText;
if (_pAutoExtract)
delete _pAutoExtract;
if (_pAutoExport)
delete _pAutoExport;
_pAutoExtract = NULL;
_pAutoExport = NULL;
_pInstallText = new CInstallText;
_pUninstallText = new CInstallText;
_iPluginType = PLUGIN_NORMAL;
}
void CCorePackage::_setRatings(int iEase, int iChanging, int iRec)
{
_iRecommended = iRec;
_iGameChanging = iChanging;
_iEaseOfUse = iEase;
}
void CCorePackage::_parseDescription(const Utils::String &sDesc)
{
_sDescription = sDesc;
//_sDescription.RemoveFirstChar('\n');
//_sDescription.RemoveFirstChar('\r');
_sDescription.removeFirstSpace();
_sDescription = _sDescription.findReplace(""", "\"");
_sDescription = _sDescription.findReplace(">", ">");
_sDescription = _sDescription.findReplace("<", "<");
_sDescription = _sDescription.findReplace("&", "&");
_sDescription = _sDescription.findReplace("<newline>", "\n");
_sDescription = _sDescription.findReplace("<br>", "\n");
if ( _sDescription.left(6).Compare("<html>") ) {
int foundFirst = -1;
int pos = 0;
while ( foundFirst == -1 )
{
pos = _sDescription.findPos(">", pos);
pos++;
if ( pos >= (int)_sDescription.length() )
break;
char c = _sDescription[pos];
if ( c != '<' )
foundFirst = pos;
}
if ( foundFirst == -1 )
_sDescription = "";
else
{
Utils::String firstStr = _sDescription.left(foundFirst).findRemove("<br />").findRemove("<br/>");
Utils::String lastStr = _sDescription.right(_sDescription.length() - foundFirst);
_sDescription = firstStr + lastStr;
}
}
}
void CCorePackage::_merge(CCorePackage *pPackage)
{
_iRecommended = pPackage->recommended();
_iGameChanging = pPackage->gameChanging();
_iEaseOfUse = pPackage->easeOfUse();
_pInstallText->merge(pPackage->installText());
_pUninstallText->merge(pPackage->uninstallText());
_iPluginType = pPackage->pluginType();
_sDescription = pPackage->description();
_sWebSite = pPackage->webSite();
_sWebAddress = pPackage->webAddress();
_sEmail = pPackage->email();
_sForumLink = pPackage->forumLink();
_sCreationDate = pPackage->creationDate();
_sVersion = pPackage->version();
}
void CCorePackage::addAutoExtract(unsigned int game, const Utils::String &dir)
{
if (!_pAutoExtract)
_pAutoExtract = new std::map<unsigned int, Utils::String>();
(*_pAutoExtract)[game] = dir;
}
void CCorePackage::addAutoExport(unsigned int game, const Utils::String &file)
{
if (!_pAutoExport)
_pAutoExport = new std::map<unsigned int, Utils::String>();
(*_pAutoExport)[game] = file;
}
void CCorePackage::clearAutoExport()
{
if (_pAutoExport)
delete _pAutoExport;
_pAutoExport = NULL;
}
void CCorePackage::clearAutoExtract()
{
if (_pAutoExtract)
delete _pAutoExtract;
_pAutoExtract = NULL;
}
///////////////////////////////////////////////////////////////////////////////////////////////
// Install/Uninstall Texts
///////
Utils::String CCorePackage::installText(int iLang, bool bBefore, bool bIncludeDefault) const
{
return _installText(iLang, bBefore, bIncludeDefault, _pInstallText);
}
Utils::String CCorePackage::uninstallText(int iLang, bool bBefore, bool bIncludeDefault) const
{
return _installText(iLang, bBefore, bIncludeDefault, _pUninstallText);
}
void CCorePackage::addInstallText(int iLang, bool bBefore, const Utils::String &sText)
{
_addInstallText(iLang, bBefore, sText, _pInstallText);
}
void CCorePackage::addUninstallText(int iLang, bool bBefore, const Utils::String &sText)
{
_addInstallText(iLang, bBefore, sText, _pUninstallText);
}
void CCorePackage::removeInstallText(int iLang, bool bInstall)
{
if ( bInstall ) _pInstallText->remove(iLang);
else _pUninstallText->remove(iLang);
}
Utils::String CCorePackage::_installText(int iLang, bool bBefore, bool bIncludeDefault, const CInstallText *pText) const
{
return (bBefore) ? pText->getBefore(iLang, bIncludeDefault) : pText->getAfter(iLang, bIncludeDefault);
}
void CCorePackage::_addInstallText(int iLang, bool bBefore, const Utils::String &sText, CInstallText *pText)
{
if ( bBefore ) pText->addBefore(iLang, sText);
else pText->addAfter(iLang, sText);
}
}}//NAMESPACE