Subversion Repositories spk

Rev

Rev 50 | Rev 170 | 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
{
17
	_setDefaults();
18
}
19
 
20
CCorePackage::~CCorePackage(void)
21
{
131 cycrow 22
	if(_pInstallText)
23
		delete _pInstallText;
24
	if(_pUninstallText)
25
		delete _pUninstallText;
26
	if (_pAutoExtract)
27
		delete _pAutoExtract;
28
	if (_pAutoExport)
29
		delete _pAutoExport;
46 cycrow 30
}
31
 
32
void CCorePackage::_setDefaults()
33
{
34
	_iRecommended = -1;
35
	_iGameChanging = -1;
36
	_iEaseOfUse = -1;
37
 
131 cycrow 38
	if(_pInstallText)
39
		delete _pInstallText;
40
	if(_pUninstallText)
41
		delete _pUninstallText;
42
	if (_pAutoExtract)
43
		delete _pAutoExtract;
44
	if (_pAutoExport)
45
		delete _pAutoExport;
46 cycrow 46
 
131 cycrow 47
	_pAutoExtract = NULL;
48
	_pAutoExport = NULL;
46 cycrow 49
	_pInstallText = new CInstallText;
50
	_pUninstallText = new CInstallText;
48 cycrow 51
 
52
	_iPluginType = PLUGIN_NORMAL;
46 cycrow 53
}
54
 
55
void CCorePackage::_setRatings(int iEase, int iChanging, int iRec)
56
{
57
	_iRecommended = iRec;
58
	_iGameChanging = iChanging;
59
	_iEaseOfUse = iEase;
60
}
61
 
48 cycrow 62
void CCorePackage::_parseDescription(const Utils::String &sDesc)
63
{
64
	_sDescription = sDesc;
65
	//_sDescription.RemoveFirstChar('\n');
66
	//_sDescription.RemoveFirstChar('\r');
67
	_sDescription.removeFirstSpace();
68
	_sDescription = _sDescription.findReplace("&quot;", "\"");
69
	_sDescription = _sDescription.findReplace("&gt;", ">");
70
	_sDescription = _sDescription.findReplace("&lt;", "<");
71
	_sDescription = _sDescription.findReplace("&amp;", "&");
72
	_sDescription = _sDescription.findReplace("<newline>", "\n");
73
	_sDescription = _sDescription.findReplace("<br>", "\n");
74
 
75
	if ( _sDescription.left(6).Compare("<html>") ) {
76
		int foundFirst = -1;
77
		int pos = 0;
78
		while ( foundFirst == -1 )
79
		{
80
			pos = _sDescription.findPos(">", pos);
81
 
82
			pos++;
83
			if ( pos >= (int)_sDescription.length() )
84
				break;
85
			char c = _sDescription[pos];
86
 
87
			if ( c != '<' )
88
				foundFirst = pos;
89
		}
90
 
91
		if ( foundFirst == -1 )
92
			_sDescription = "";
93
		else
94
		{
95
			Utils::String firstStr = _sDescription.left(foundFirst).findRemove("<br />").findRemove("<br/>");
96
			Utils::String lastStr = _sDescription.right(_sDescription.length() - foundFirst);
97
 
98
			_sDescription = firstStr + lastStr;
99
		}
100
	}
101
 
102
}
103
 
46 cycrow 104
void CCorePackage::_merge(CCorePackage *pPackage)
105
{
106
	_iRecommended	= pPackage->recommended();
107
	_iGameChanging	= pPackage->gameChanging();
108
	_iEaseOfUse		= pPackage->easeOfUse();
109
 
110
	_pInstallText->merge(pPackage->installText());
111
	_pUninstallText->merge(pPackage->uninstallText());
48 cycrow 112
 
113
	_iPluginType	= pPackage->pluginType();
114
	_sDescription	= pPackage->description();
49 cycrow 115
	_sWebSite		= pPackage->webSite();
116
	_sWebAddress	= pPackage->webAddress();
117
	_sEmail			= pPackage->email();
118
	_sForumLink		= pPackage->forumLink();
50 cycrow 119
	_sCreationDate	= pPackage->creationDate();
120
	_sVersion		= pPackage->version();
46 cycrow 121
}
122
 
131 cycrow 123
void CCorePackage::addAutoExtract(unsigned int game, const Utils::String &dir)
124
{
125
	if (!_pAutoExtract)
126
		_pAutoExtract = new std::map<unsigned int, Utils::String>();
127
	(*_pAutoExtract)[game] = dir;
128
}
129
 
130
void CCorePackage::addAutoExport(unsigned int game, const Utils::String &file)
131
{
132
	if (!_pAutoExport)
133
		_pAutoExport = new std::map<unsigned int, Utils::String>();
134
	(*_pAutoExport)[game] = file;
135
}
136
 
137
void CCorePackage::clearAutoExport()
138
{
139
	if (_pAutoExport)
140
		delete _pAutoExport;
141
	_pAutoExport = NULL;
142
}
143
 
144
void CCorePackage::clearAutoExtract()
145
{
146
	if (_pAutoExtract)
147
		delete _pAutoExtract;
148
	_pAutoExtract = NULL;
149
}
150
 
46 cycrow 151
///////////////////////////////////////////////////////////////////////////////////////////////
152
//	Install/Uninstall Texts
153
///////
154
 
155
Utils::String CCorePackage::installText(int iLang, bool bBefore, bool bIncludeDefault) const
156
{
157
	return _installText(iLang, bBefore, bIncludeDefault, _pInstallText);
158
}
159
 
160
Utils::String CCorePackage::uninstallText(int iLang, bool bBefore, bool bIncludeDefault) const
161
{
162
	return _installText(iLang, bBefore, bIncludeDefault, _pUninstallText);
163
}
164
 
165
void CCorePackage::addInstallText(int iLang, bool bBefore, const Utils::String &sText) 
166
{
167
	_addInstallText(iLang, bBefore, sText, _pInstallText);
168
}
169
 
170
void CCorePackage::addUninstallText(int iLang, bool bBefore, const Utils::String &sText)
171
{
172
	_addInstallText(iLang, bBefore, sText, _pUninstallText);
173
}
174
 
175
void CCorePackage::removeInstallText(int iLang, bool bInstall)
176
{
177
	if ( bInstall ) _pInstallText->remove(iLang);
178
	else			_pUninstallText->remove(iLang);
179
}
180
 
48 cycrow 181
Utils::String CCorePackage::_installText(int iLang, bool bBefore, bool bIncludeDefault, const CInstallText *pText) const
182
{
183
	return (bBefore) ? pText->getBefore(iLang, bIncludeDefault) : pText->getAfter(iLang, bIncludeDefault);
184
}
46 cycrow 185
 
186
void CCorePackage::_addInstallText(int iLang, bool bBefore, const Utils::String &sText, CInstallText *pText)
187
{
188
	if ( bBefore ) pText->addBefore(iLang, sText);
189
	else pText->addAfter(iLang, sText);
190
}
191
 
192
 
193
 
194
}}//NAMESPACE