Subversion Repositories spk

Rev

Rev 48 | Rev 50 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
46 cycrow 1
 
2
#include "CorePackage.h"
3
 
4
#include <File.h>
5
#include "InstallText.h"
6
 
7
namespace SPK {
8
namespace Package {
9
 
48 cycrow 10
CCorePackage::CCorePackage(void) : _bChanged(false), _pInstallText(NULL), _pUninstallText(NULL)
46 cycrow 11
{
12
	_setDefaults();
13
}
14
 
15
CCorePackage::~CCorePackage(void)
16
{
17
	delete _pInstallText;
18
	delete _pUninstallText;
19
}
20
 
21
void CCorePackage::_setDefaults()
22
{
23
	_iRecommended = -1;
24
	_iGameChanging = -1;
25
	_iEaseOfUse = -1;
26
 
27
	delete _pInstallText;
28
	delete _pUninstallText;
29
 
30
	_pInstallText = new CInstallText;
31
	_pUninstallText = new CInstallText;
48 cycrow 32
 
33
	_iPluginType = PLUGIN_NORMAL;
46 cycrow 34
}
35
 
36
void CCorePackage::_setRatings(int iEase, int iChanging, int iRec)
37
{
38
	_iRecommended = iRec;
39
	_iGameChanging = iChanging;
40
	_iEaseOfUse = iEase;
41
}
42
 
48 cycrow 43
void CCorePackage::_parseDescription(const Utils::String &sDesc)
44
{
45
	_sDescription = sDesc;
46
	//_sDescription.RemoveFirstChar('\n');
47
	//_sDescription.RemoveFirstChar('\r');
48
	_sDescription.removeFirstSpace();
49
	_sDescription = _sDescription.findReplace("&quot;", "\"");
50
	_sDescription = _sDescription.findReplace("&gt;", ">");
51
	_sDescription = _sDescription.findReplace("&lt;", "<");
52
	_sDescription = _sDescription.findReplace("&amp;", "&");
53
	_sDescription = _sDescription.findReplace("<newline>", "\n");
54
	_sDescription = _sDescription.findReplace("<br>", "\n");
55
 
56
	if ( _sDescription.left(6).Compare("<html>") ) {
57
		int foundFirst = -1;
58
		int pos = 0;
59
		while ( foundFirst == -1 )
60
		{
61
			pos = _sDescription.findPos(">", pos);
62
 
63
			pos++;
64
			if ( pos >= (int)_sDescription.length() )
65
				break;
66
			char c = _sDescription[pos];
67
 
68
			if ( c != '<' )
69
				foundFirst = pos;
70
		}
71
 
72
		if ( foundFirst == -1 )
73
			_sDescription = "";
74
		else
75
		{
76
			Utils::String firstStr = _sDescription.left(foundFirst).findRemove("<br />").findRemove("<br/>");
77
			Utils::String lastStr = _sDescription.right(_sDescription.length() - foundFirst);
78
 
79
			_sDescription = firstStr + lastStr;
80
		}
81
	}
82
 
83
}
84
 
46 cycrow 85
void CCorePackage::_merge(CCorePackage *pPackage)
86
{
87
	_iRecommended	= pPackage->recommended();
88
	_iGameChanging	= pPackage->gameChanging();
89
	_iEaseOfUse		= pPackage->easeOfUse();
90
 
91
	_pInstallText->merge(pPackage->installText());
92
	_pUninstallText->merge(pPackage->uninstallText());
48 cycrow 93
 
94
	_iPluginType	= pPackage->pluginType();
95
	_sDescription	= pPackage->description();
49 cycrow 96
	_sWebSite		= pPackage->webSite();
97
	_sWebAddress	= pPackage->webAddress();
98
	_sEmail			= pPackage->email();
99
	_sForumLink		= pPackage->forumLink();
46 cycrow 100
}
101
 
102
///////////////////////////////////////////////////////////////////////////////////////////////
103
//	Install/Uninstall Texts
104
///////
105
 
106
Utils::String CCorePackage::installText(int iLang, bool bBefore, bool bIncludeDefault) const
107
{
108
	return _installText(iLang, bBefore, bIncludeDefault, _pInstallText);
109
}
110
 
111
Utils::String CCorePackage::uninstallText(int iLang, bool bBefore, bool bIncludeDefault) const
112
{
113
	return _installText(iLang, bBefore, bIncludeDefault, _pUninstallText);
114
}
115
 
116
void CCorePackage::addInstallText(int iLang, bool bBefore, const Utils::String &sText) 
117
{
118
	_addInstallText(iLang, bBefore, sText, _pInstallText);
119
}
120
 
121
void CCorePackage::addUninstallText(int iLang, bool bBefore, const Utils::String &sText)
122
{
123
	_addInstallText(iLang, bBefore, sText, _pUninstallText);
124
}
125
 
126
void CCorePackage::removeInstallText(int iLang, bool bInstall)
127
{
128
	if ( bInstall ) _pInstallText->remove(iLang);
129
	else			_pUninstallText->remove(iLang);
130
}
131
 
48 cycrow 132
Utils::String CCorePackage::_installText(int iLang, bool bBefore, bool bIncludeDefault, const CInstallText *pText) const
133
{
134
	return (bBefore) ? pText->getBefore(iLang, bIncludeDefault) : pText->getAfter(iLang, bIncludeDefault);
135
}
46 cycrow 136
 
137
void CCorePackage::_addInstallText(int iLang, bool bBefore, const Utils::String &sText, CInstallText *pText)
138
{
139
	if ( bBefore ) pText->addBefore(iLang, sText);
140
	else pText->addAfter(iLang, sText);
141
}
142
 
143
 
144
 
145
}}//NAMESPACE