Subversion Repositories spk

Rev

Rev 207 | Rev 209 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 207 Rev 208
Line 1675... Line 1675...
1675
int CBaseFile::_read_Header(CFileIO &File, int iReadType, int iMaxProgress, CProgressInfo *pProgress)
1675
int CBaseFile::_read_Header(CFileIO &File, int iReadType, int iMaxProgress, CProgressInfo *pProgress)
1676
{
1676
{
1677
	int doneLen = 0;
1677
	int doneLen = 0;
1678
 
1678
 
1679
	// read data to memory
1679
	// read data to memory
1680
	unsigned char *readData;
1680
	unsigned char *readData = 0;
1681
	try {
1681
	try {
1682
		readData = new unsigned char[m_SHeader.lValueCompressSize];
1682
		readData = new unsigned char[m_SHeader.lValueCompressSize];
1683
	}
1683
	}
1684
	catch (std::exception &e) {
1684
	catch (std::exception &e) {
1685
		CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_Header() unable to malloc [header], %d (%s)", m_SHeader.lValueCompressSize, e.what());
1685
		CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_Header() unable to malloc [header], %d (%s)", m_SHeader.lValueCompressSize, e.what());
1686
		return -1;
1686
		return -1;
1687
	}
1687
	}
1688
 
1688
 
-
 
1689
	if (!readData)
-
 
1690
		return -1;
-
 
1691
 
1689
	unsigned char size[4];
1692
	unsigned char size[4];
1690
	File.read(size, 4);
1693
	File.read(size, 4);
1691
	File.read(readData, m_SHeader.lValueCompressSize);
1694
	File.read(readData, m_SHeader.lValueCompressSize);
1692
 
1695
 
1693
	unsigned long uncomprLen = (size[0] << 24) + (size[1] << 16) + (size[2] << 8) + size[3];
1696
	unsigned long uncomprLen = (size[0] << 24) + (size[1] << 16) + (size[2] << 8) + size[3];
Line 1698... Line 1701...
1698
		try {
1701
		try {
1699
			unsigned char *uncompr = new unsigned char[uncomprLen];
1702
			unsigned char *uncompr = new unsigned char[uncomprLen];
1700
			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader.lValueCompressSize );
1703
			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader.lValueCompressSize );
1701
			// update the progress for each section
1704
			// update the progress for each section
1702
			if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
1705
			if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
-
 
1706
			if (err == Z_OK) 
-
 
1707
			{
1703
			if ( err == Z_OK ) this->_readValues((char *)uncompr);
1708
				std::string data((char*)uncompr);
-
 
1709
				_readValues(std::wstring(data.begin(), data.end()));
-
 
1710
			}
1704
			doneLen = uncomprLen;
1711
			doneLen = uncomprLen;
1705
			delete uncompr;
1712
			delete []uncompr;
1706
		}
1713
		}
1707
		catch (std::exception &e) {
1714
		catch (std::exception &e) {
1708
			CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_Header() unable to malloc [uncompr], %d (%s)", uncomprLen, e.what());
1715
			CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_Header() unable to malloc [uncompr], %d (%s)", uncomprLen, e.what());
1709
			delete []readData;
1716
			delete []readData;
1710
			return -1;
1717
			return -1;
Line 1714... Line 1721...
1714
		long len = uncomprLen;
1721
		long len = uncomprLen;
1715
		unsigned char *compr = LZMADecode_C ( readData, m_SHeader.lValueCompressSize, (size_t*)&len, NULL );
1722
		unsigned char *compr = LZMADecode_C ( readData, m_SHeader.lValueCompressSize, (size_t*)&len, NULL );
1716
		// update the progress for each section
1723
		// update the progress for each section
1717
		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
1724
		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
1718
 
1725
 
-
 
1726
		if (compr) 
-
 
1727
		{
1719
		if ( compr ) _readValues((char *)compr);
1728
			std::string data((char*)compr);
-
 
1729
			_readValues(std::wstring(data.begin(), data.end()));
-
 
1730
		}
1720
	}
1731
	}
1721
	// no compression
1732
	// no compression
1722
	else
1733
	else
-
 
1734
	{
1723
		_readValues((char *)readData);
1735
		std::string data((char*)readData);
-
 
1736
		_readValues(std::wstring(data.begin(), data.end()));
-
 
1737
	}
1724
 
1738
 
1725
	delete []readData;
1739
	delete []readData;
1726
 
1740
 
1727
	return doneLen;
1741
	return doneLen;
1728
}
1742
}
Line 1882... Line 1896...
1882
	if ( !this->webAddress().empty() )	values += L"WebAddress: "	+ this->webAddress()	+ L"\n";
1896
	if ( !this->webAddress().empty() )	values += L"WebAddress: "	+ this->webAddress()	+ L"\n";
1883
	if ( !this->webSite().empty() )		values += L"WebSite: "		+ this->webSite()		+ L"\n";
1897
	if ( !this->webSite().empty() )		values += L"WebSite: "		+ this->webSite()		+ L"\n";
1884
	if ( !this->email().empty() )		values += L"Email: "		+ this->email()			+ L"\n";
1898
	if ( !this->email().empty() )		values += L"Email: "		+ this->email()			+ L"\n";
1885
	if ( !this->forumLink().empty() )	values += L"ForumLink: "	+ this->forumLink()		+ L"\n";
1899
	if ( !this->forumLink().empty() )	values += L"ForumLink: "	+ this->forumLink()		+ L"\n";
1886
 
1900
 
1887
	for(auto itr = _lMirrors.begin(); itr != _lMirrors.end(); itr++)
1901
	for(auto itr = webMirrors().begin(); itr != webMirrors().end(); itr++)
1888
		values += Utils::WString(L"WebMirror: ") + (*itr)->str.toWString() + L"\n";
1902
		values += Utils::WString(L"WebMirror: ") + (*itr)->str + L"\n";
1889
	if ( !this->description().empty() ) {
1903
	if ( !this->description().empty() ) {
1890
		Utils::WString desc = this->description();
1904
		Utils::WString desc = this->description();
1891
		desc = desc.findReplace(L"<newline>", L"<br>");
1905
		desc = desc.findReplace(L"<newline>", L"<br>");
1892
		desc = desc.findReplace(L"\n", "L<br>");
1906
		desc = desc.findReplace(L"\n", "L<br>");
1893
		desc.remove(L'\r');
1907
		desc.remove(L'\r');
Line 1966... Line 1980...
1966
	if ( fileheader == SPKCOMPRESS_7ZIP )
1980
	if ( fileheader == SPKCOMPRESS_7ZIP )
1967
		fileheader = SPKCOMPRESS_ZLIB;
1981
		fileheader = SPKCOMPRESS_ZLIB;
1968
 
1982
 
1969
	// get the script values
1983
	// get the script values
1970
	Utils::WString values = this->createValuesLine();
1984
	Utils::WString values = this->createValuesLine();
-
 
1985
	std::string sValues(values.begin(), values.end());
1971
 
1986
 
1972
	// compress the values
1987
	// compress the values
1973
	int valueUncomprLen = (int)values.length();
1988
	int valueUncomprLen = (int)strlen(sValues.c_str());
1974
	unsigned long valueComprLen = 0;
1989
	unsigned long valueComprLen = 0;
1975
	unsigned char *valueCompr = NULL;
1990
	unsigned char *valueCompr = NULL;
1976
	bool compressed = false;
1991
	bool compressed = false;
-
 
1992
 
1977
	if ( valueheader == SPKCOMPRESS_ZLIB )
1993
	if ( valueheader == SPKCOMPRESS_ZLIB )
1978
	{
1994
	{
1979
		valueComprLen = valueUncomprLen;
1995
		valueComprLen = valueUncomprLen;
1980
		if ( valueComprLen < 100 )
1996
		if ( valueComprLen < 100 )
1981
			valueComprLen = 200;
1997
			valueComprLen = 200;
1982
		else if ( valueComprLen < 1000 )
1998
		else if ( valueComprLen < 1000 )
1983
			valueComprLen *= 2;
1999
			valueComprLen *= 2;
1984
 
2000
 
1985
		valueCompr = (unsigned char *)calloc((unsigned int)valueComprLen, 1);
2001
		valueCompr = (unsigned char *)calloc((unsigned int)valueComprLen, 1);
1986
		int err = compress ( (unsigned char *)valueCompr, &valueComprLen, (const unsigned char *)values.c_str(), (unsigned long)values.length(), 0 );
2002
		int err = compress ( (unsigned char *)valueCompr, &valueComprLen, (const unsigned char *)sValues.c_str(), (unsigned long)strlen(sValues.c_str()), 0 );
1987
		if ( err == Z_OK )
2003
		if ( err == Z_OK )
1988
			compressed = true;
2004
			compressed = true;
1989
	}
2005
	}
1990
 
2006
 
1991
	if ( !compressed )
2007
	if ( !compressed )
1992
	{
2008
	{
1993
		valueComprLen = valueUncomprLen;
2009
		valueComprLen = valueUncomprLen;
1994
		valueCompr = (unsigned char *)calloc((unsigned int)valueComprLen, 1);
2010
		valueCompr = (unsigned char *)calloc((unsigned int)valueComprLen, 1);
1995
		memcpy ( valueCompr, values.c_str(), valueComprLen );
2011
		memcpy ( valueCompr, sValues.c_str(), valueComprLen );
1996
		valueheader = SPKCOMPRESS_NONE;
2012
		valueheader = SPKCOMPRESS_NONE;
1997
	}
2013
	}
1998
 
2014
 
1999
	// write the main header to the file
2015
	// write the main header to the file
2000
	if ( !this->writeHeader(file, valueheader, valueComprLen) )	return false;
2016
	if ( !this->writeHeader(file, valueheader, valueComprLen) )	return false;
Line 2476... Line 2492...
2476
		list->pushBack("# The email address of the author, to allow users to contract if needed");
2492
		list->pushBack("# The email address of the author, to allow users to contract if needed");
2477
		list->pushBack("Email: " + this->email().toString());
2493
		list->pushBack("Email: " + this->email().toString());
2478
		list->pushBack("");
2494
		list->pushBack("");
2479
	}
2495
	}
2480
 
2496
 
2481
	if (_lMirrors.size())
2497
	if (webMirrors().size())
2482
	{
2498
	{
2483
		list->pushBack("# A link to the mirror address for the update file, can have many of these");
2499
		list->pushBack("# A link to the mirror address for the update file, can have many of these");
2484
		for(auto itr = _lMirrors.begin(); itr != _lMirrors.end(); itr++)
2500
		for(auto itr = webMirrors().begin(); itr != webMirrors().end(); itr++)
2485
			list->pushBack(Utils::String("WebMirror: ") + (*itr)->str);
2501
			list->pushBack(Utils::String("WebMirror: ") + (*itr)->str.toString());
2486
		list->pushBack("");
2502
		list->pushBack("");
2487
	}
2503
	}
2488
 
2504
 
2489
	if ( m_bAutoGenerateUpdateFile )
2505
	if ( m_bAutoGenerateUpdateFile )
2490
	{
2506
	{
Line 3173... Line 3189...
3173
		f->renameScript(baseName);
3189
		f->renameScript(baseName);
3174
 
3190
 
3175
	f->changeBaseName(baseName);
3191
	f->changeBaseName(baseName);
3176
}
3192
}
3177
 
3193
 
3178
void CBaseFile::addWebMirror(const Utils::String& str) 
-
 
3179
{ 
-
 
3180
	if (!_lMirrors.contains(str))
-
 
3181
	{
-
 
3182
		_lMirrors.pushBack(str, "");
-
 
3183
		_changed();
-
 
3184
	}
-
 
3185
}
-
 
3186
 
-
 
3187
void CBaseFile::removeWebMirror(const Utils::String& str) 
-
 
3188
{ 
-
 
3189
	_lMirrors.remove(str, true); 
-
 
3190
	_changed(); 
-
 
3191
}
-
 
3192
 
-
 
3193
Utils::WString CBaseFile::createUpdateFile(const Utils::WString &dir) const
3194
Utils::WString CBaseFile::createUpdateFile(const Utils::WString &dir) const
3194
{
3195
{
3195
	Utils::WString file = this->getNameValidFile() + L"_" + this->author() + L".dat";
3196
	Utils::WString file = this->getNameValidFile() + L"_" + this->author() + L".dat";
3196
	file.removeChar(' ');
3197
	file.removeChar(' ');
3197
 
3198