Subversion Repositories spk

Rev

Rev 46 | Rev 49 | 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();
46 cycrow 96
}
97
 
98
///////////////////////////////////////////////////////////////////////////////////////////////
99
//	Install/Uninstall Texts
100
///////
101
 
102
Utils::String CCorePackage::installText(int iLang, bool bBefore, bool bIncludeDefault) const
103
{
104
	return _installText(iLang, bBefore, bIncludeDefault, _pInstallText);
105
}
106
 
107
Utils::String CCorePackage::uninstallText(int iLang, bool bBefore, bool bIncludeDefault) const
108
{
109
	return _installText(iLang, bBefore, bIncludeDefault, _pUninstallText);
110
}
111
 
112
void CCorePackage::addInstallText(int iLang, bool bBefore, const Utils::String &sText) 
113
{
114
	_addInstallText(iLang, bBefore, sText, _pInstallText);
115
}
116
 
117
void CCorePackage::addUninstallText(int iLang, bool bBefore, const Utils::String &sText)
118
{
119
	_addInstallText(iLang, bBefore, sText, _pUninstallText);
120
}
121
 
122
void CCorePackage::removeInstallText(int iLang, bool bInstall)
123
{
124
	if ( bInstall ) _pInstallText->remove(iLang);
125
	else			_pUninstallText->remove(iLang);
126
}
127
 
48 cycrow 128
Utils::String CCorePackage::_installText(int iLang, bool bBefore, bool bIncludeDefault, const CInstallText *pText) const
129
{
130
	return (bBefore) ? pText->getBefore(iLang, bIncludeDefault) : pText->getAfter(iLang, bIncludeDefault);
131
}
46 cycrow 132
 
133
void CCorePackage::_addInstallText(int iLang, bool bBefore, const Utils::String &sText, CInstallText *pText)
134
{
135
	if ( bBefore ) pText->addBefore(iLang, sText);
136
	else pText->addAfter(iLang, sText);
137
}
138
 
139
 
140
 
141
}}//NAMESPACE