Subversion Repositories spk

Rev

Rev 49 | Rev 170 | 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)
{
        _setDefaults();
}

CCorePackage::~CCorePackage(void)
{
        delete _pInstallText;
        delete _pUninstallText;
}

void CCorePackage::_setDefaults()
{
        _iRecommended = -1;
        _iGameChanging = -1;
        _iEaseOfUse = -1;

        delete _pInstallText;
        delete _pUninstallText;

        _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("&quot;", "\"");
        _sDescription = _sDescription.findReplace("&gt;", ">");
        _sDescription = _sDescription.findReplace("&lt;", "<");
        _sDescription = _sDescription.findReplace("&amp;", "&");
        _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();
}

///////////////////////////////////////////////////////////////////////////////////////////////
//      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