Rev 208 | 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)
{
_lNames = new Utils::CList<SNames>();
_setDefaults();
}
CCorePackage::~CCorePackage(void)
{
if (_lNames)
delete _lNames;
if(_pInstallText)
delete _pInstallText;
if(_pUninstallText)
delete _pUninstallText;
if (_pAutoExtract)
delete _pAutoExtract;
if (_pAutoExport)
delete _pAutoExport;
}
const Utils::WString& CCorePackage::name(int lang) const
{
if (lang == -1)
return _sName;
for(auto itr = _lNames->begin(); itr != _lNames->end(); itr++)
{
if ((*itr)->iLanguage == lang)
return (*itr)->sName;
}
return _sName;
}
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;
_lNames->deleteItems();
}
void CCorePackage::_setRatings(int iEase, int iChanging, int iRec)
{
_iRecommended = iRec;
_iGameChanging = iChanging;
_iEaseOfUse = iEase;
}
void CCorePackage::_parseDescription(const Utils::WString &sDesc)
{
_sDescription = sDesc;
//_sDescription.RemoveFirstChar('\n');
//_sDescription.RemoveFirstChar('\r');
_sDescription.removeFirstSpace();
_sDescription = _sDescription.findReplace(L""", L"\"");
_sDescription = _sDescription.findReplace(L">", L">");
_sDescription = _sDescription.findReplace(L"<", L"<");
_sDescription = _sDescription.findReplace(L"&", L"&");
_sDescription = _sDescription.findReplace(L"<newline>", L"\n");
_sDescription = _sDescription.findReplace(L"<br>", L"\n");
if ( _sDescription.left(6).Compare(L"<html>") ) {
int foundFirst = -1;
int pos = 0;
while ( foundFirst == -1 )
{
pos = _sDescription.findPos(L">", pos);
pos++;
if ( pos >= (int)_sDescription.length() )
break;
wchar_t c = _sDescription[pos];
if ( c != L'<' )
foundFirst = pos;
}
if ( foundFirst == -1 )
_sDescription = L"";
else
{
Utils::WString firstStr = _sDescription.left(foundFirst).findRemove(L"<br />").findRemove(L"<br/>");
Utils::WString 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::WString &dir)
{
if (!_pAutoExtract)
_pAutoExtract = new std::map<unsigned int, Utils::WString>();
(*_pAutoExtract)[game] = dir;
}
void CCorePackage::addAutoExport(unsigned int game, const Utils::WString &file)
{
if (!_pAutoExport)
_pAutoExport = new std::map<unsigned int, Utils::WString>();
(*_pAutoExport)[game] = file;
}
void CCorePackage::clearAutoExport()
{
if (_pAutoExport)
delete _pAutoExport;
_pAutoExport = NULL;
}
void CCorePackage::clearAutoExtract()
{
if (_pAutoExtract)
delete _pAutoExtract;
_pAutoExtract = NULL;
}
void CCorePackage::removeName(int lang)
{
auto itr = _lNames->begin();
while (itr != _lNames->end())
{
if ((*itr)->iLanguage == lang)
{
SNames* n = *itr;
itr = _lNames->remove(itr);
delete n;
_changed();
}
else
itr++;
}
}
void CCorePackage::clearNames()
{
_lNames->deleteItems();
}
void CCorePackage::addName(int lang, const Utils::WString& name)
{
for (auto n = _lNames->first(); n; n = _lNames->next())
{
if (n->iLanguage == lang)
{
n->sName = name;
_changed();
return;
}
}
// not found, add a new entry
SNames *n = new SNames;
n->iLanguage = lang;
n->sName = name;
_lNames->push_back(n);
_changed();
}
///////////////////////////////////////////////////////////////////////////////////////////////
// Install/Uninstall Texts
///////
Utils::WString CCorePackage::installText(int iLang, bool bBefore, bool bIncludeDefault) const
{
return _installText(iLang, bBefore, bIncludeDefault, _pInstallText);
}
Utils::WString CCorePackage::uninstallText(int iLang, bool bBefore, bool bIncludeDefault) const
{
return _installText(iLang, bBefore, bIncludeDefault, _pUninstallText);
}
void CCorePackage::addInstallText(int iLang, bool bBefore, const Utils::WString &sText)
{
_addInstallText(iLang, bBefore, sText, _pInstallText);
}
void CCorePackage::addUninstallText(int iLang, bool bBefore, const Utils::WString &sText)
{
_addInstallText(iLang, bBefore, sText, _pUninstallText);
}
void CCorePackage::removeInstallText(int iLang, bool bInstall)
{
if ( bInstall ) _pInstallText->remove(iLang);
else _pUninstallText->remove(iLang);
}
Utils::WString 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::WString &sText, CInstallText *pText)
{
if ( bBefore ) pText->addBefore(iLang, sText);
else pText->addAfter(iLang, sText);
}
void CCorePackage::addWebMirror(const Utils::WString& str)
{
if (!_lMirrors.contains(str))
{
_lMirrors.pushBack(str, L"");
_changed();
}
}
void CCorePackage::removeWebMirror(const Utils::WString& str)
{
_lMirrors.remove(str, true);
_changed();
}
}}//NAMESPACE