Subversion Repositories spk

Rev

Rev 131 | Rev 171 | 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
 
131 cycrow 10
CCorePackage::CCorePackage(void) : 
11
	_bChanged(false),
12
	_pInstallText(NULL),
13
	_pUninstallText(NULL),
14
	_pAutoExtract(NULL),
15
	_pAutoExport(NULL)
46 cycrow 16
{
170 cycrow 17
	_lNames = new Utils::CList<SNames>();
46 cycrow 18
	_setDefaults();
19
}
20
 
21
CCorePackage::~CCorePackage(void)
22
{
170 cycrow 23
	if (_lNames)
24
		delete _lNames;
131 cycrow 25
	if(_pInstallText)
26
		delete _pInstallText;
27
	if(_pUninstallText)
28
		delete _pUninstallText;
29
	if (_pAutoExtract)
30
		delete _pAutoExtract;
31
	if (_pAutoExport)
32
		delete _pAutoExport;
46 cycrow 33
}
34
 
170 cycrow 35
const Utils::String& CCorePackage::name(int lang) const
36
{ 
37
	for(auto itr = _lNames->begin(); itr != _lNames->end(); itr++)
38
	{
39
		if ((*itr)->iLanguage == lang)
40
			return (*itr)->sName;
41
	}
42
	return _sName; 
43
}
44
 
46 cycrow 45
void CCorePackage::_setDefaults()
46
{
47
	_iRecommended = -1;
48
	_iGameChanging = -1;
49
	_iEaseOfUse = -1;
50
 
131 cycrow 51
	if(_pInstallText)
52
		delete _pInstallText;
53
	if(_pUninstallText)
54
		delete _pUninstallText;
55
	if (_pAutoExtract)
56
		delete _pAutoExtract;
57
	if (_pAutoExport)
58
		delete _pAutoExport;
46 cycrow 59
 
131 cycrow 60
	_pAutoExtract = NULL;
61
	_pAutoExport = NULL;
46 cycrow 62
	_pInstallText = new CInstallText;
63
	_pUninstallText = new CInstallText;
48 cycrow 64
 
65
	_iPluginType = PLUGIN_NORMAL;
170 cycrow 66
 
67
	_lNames->deleteItems();
46 cycrow 68
}
69
 
70
void CCorePackage::_setRatings(int iEase, int iChanging, int iRec)
71
{
72
	_iRecommended = iRec;
73
	_iGameChanging = iChanging;
74
	_iEaseOfUse = iEase;
75
}
76
 
48 cycrow 77
void CCorePackage::_parseDescription(const Utils::String &sDesc)
78
{
79
	_sDescription = sDesc;
80
	//_sDescription.RemoveFirstChar('\n');
81
	//_sDescription.RemoveFirstChar('\r');
82
	_sDescription.removeFirstSpace();
83
	_sDescription = _sDescription.findReplace("&quot;", "\"");
84
	_sDescription = _sDescription.findReplace("&gt;", ">");
85
	_sDescription = _sDescription.findReplace("&lt;", "<");
86
	_sDescription = _sDescription.findReplace("&amp;", "&");
87
	_sDescription = _sDescription.findReplace("<newline>", "\n");
88
	_sDescription = _sDescription.findReplace("<br>", "\n");
89
 
90
	if ( _sDescription.left(6).Compare("<html>") ) {
91
		int foundFirst = -1;
92
		int pos = 0;
93
		while ( foundFirst == -1 )
94
		{
95
			pos = _sDescription.findPos(">", pos);
96
 
97
			pos++;
98
			if ( pos >= (int)_sDescription.length() )
99
				break;
100
			char c = _sDescription[pos];
101
 
102
			if ( c != '<' )
103
				foundFirst = pos;
104
		}
105
 
106
		if ( foundFirst == -1 )
107
			_sDescription = "";
108
		else
109
		{
110
			Utils::String firstStr = _sDescription.left(foundFirst).findRemove("<br />").findRemove("<br/>");
111
			Utils::String lastStr = _sDescription.right(_sDescription.length() - foundFirst);
112
 
113
			_sDescription = firstStr + lastStr;
114
		}
115
	}
116
 
117
}
118
 
46 cycrow 119
void CCorePackage::_merge(CCorePackage *pPackage)
120
{
121
	_iRecommended	= pPackage->recommended();
122
	_iGameChanging	= pPackage->gameChanging();
123
	_iEaseOfUse		= pPackage->easeOfUse();
124
 
125
	_pInstallText->merge(pPackage->installText());
126
	_pUninstallText->merge(pPackage->uninstallText());
48 cycrow 127
 
128
	_iPluginType	= pPackage->pluginType();
129
	_sDescription	= pPackage->description();
49 cycrow 130
	_sWebSite		= pPackage->webSite();
131
	_sWebAddress	= pPackage->webAddress();
132
	_sEmail			= pPackage->email();
133
	_sForumLink		= pPackage->forumLink();
50 cycrow 134
	_sCreationDate	= pPackage->creationDate();
135
	_sVersion		= pPackage->version();
46 cycrow 136
}
137
 
131 cycrow 138
void CCorePackage::addAutoExtract(unsigned int game, const Utils::String &dir)
139
{
140
	if (!_pAutoExtract)
141
		_pAutoExtract = new std::map<unsigned int, Utils::String>();
142
	(*_pAutoExtract)[game] = dir;
143
}
144
 
145
void CCorePackage::addAutoExport(unsigned int game, const Utils::String &file)
146
{
147
	if (!_pAutoExport)
148
		_pAutoExport = new std::map<unsigned int, Utils::String>();
149
	(*_pAutoExport)[game] = file;
150
}
151
 
152
void CCorePackage::clearAutoExport()
153
{
154
	if (_pAutoExport)
155
		delete _pAutoExport;
156
	_pAutoExport = NULL;
157
}
158
 
159
void CCorePackage::clearAutoExtract()
160
{
161
	if (_pAutoExtract)
162
		delete _pAutoExtract;
163
	_pAutoExtract = NULL;
164
}
165
 
170 cycrow 166
 
167
void CCorePackage::removeName(int lang)
168
{
169
	auto itr = _lNames->begin();
170
	while (itr != _lNames->end())
171
	{
172
		if ((*itr)->iLanguage == lang)
173
		{
174
			SNames* n = *itr;
175
			itr = _lNames->remove(itr);
176
			delete n;
177
			_changed();
178
		}
179
		else 
180
			itr++;
181
	}
182
}
183
 
184
void CCorePackage::clearNames()
185
{
186
	_lNames->deleteItems();
187
}
188
 
189
void CCorePackage::addName(int lang, const Utils::String& name)
190
{
191
	for (auto n = _lNames->first(); n; n = _lNames->next())
192
	{
193
		if (n->iLanguage == lang)
194
		{
195
			n->sName = name;
196
			_changed();
197
			return;
198
		}
199
	}
200
 
201
	// not found, add a new entry
202
	SNames *n = new SNames;
203
	n->iLanguage = lang;
204
	n->sName = name;
205
	_lNames->push_back(n);
206
 
207
	_changed();
208
}
209
 
46 cycrow 210
///////////////////////////////////////////////////////////////////////////////////////////////
211
//	Install/Uninstall Texts
212
///////
213
 
214
Utils::String CCorePackage::installText(int iLang, bool bBefore, bool bIncludeDefault) const
215
{
216
	return _installText(iLang, bBefore, bIncludeDefault, _pInstallText);
217
}
218
 
219
Utils::String CCorePackage::uninstallText(int iLang, bool bBefore, bool bIncludeDefault) const
220
{
221
	return _installText(iLang, bBefore, bIncludeDefault, _pUninstallText);
222
}
223
 
224
void CCorePackage::addInstallText(int iLang, bool bBefore, const Utils::String &sText) 
225
{
226
	_addInstallText(iLang, bBefore, sText, _pInstallText);
227
}
228
 
229
void CCorePackage::addUninstallText(int iLang, bool bBefore, const Utils::String &sText)
230
{
231
	_addInstallText(iLang, bBefore, sText, _pUninstallText);
232
}
233
 
234
void CCorePackage::removeInstallText(int iLang, bool bInstall)
235
{
236
	if ( bInstall ) _pInstallText->remove(iLang);
237
	else			_pUninstallText->remove(iLang);
238
}
239
 
48 cycrow 240
Utils::String CCorePackage::_installText(int iLang, bool bBefore, bool bIncludeDefault, const CInstallText *pText) const
241
{
242
	return (bBefore) ? pText->getBefore(iLang, bIncludeDefault) : pText->getAfter(iLang, bIncludeDefault);
243
}
46 cycrow 244
 
245
void CCorePackage::_addInstallText(int iLang, bool bBefore, const Utils::String &sText, CInstallText *pText)
246
{
247
	if ( bBefore ) pText->addBefore(iLang, sText);
248
	else pText->addAfter(iLang, sText);
249
}
250
 
251
 
252
 
253
}}//NAMESPACE