Subversion Repositories spk

Rev

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