Subversion Repositories spk

Rev

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

Rev 208 Rev 209
Line 1703... Line 1703...
1703
			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader.lValueCompressSize );
1703
			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader.lValueCompressSize );
1704
			// update the progress for each section
1704
			// update the progress for each section
1705
			if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
1705
			if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
1706
			if (err == Z_OK) 
1706
			if (err == Z_OK) 
1707
			{
1707
			{
-
 
1708
				if (m_SHeader.fVersion <= 4.3f)
-
 
1709
				{
1708
				std::string data((char*)uncompr);
1710
					std::string data((const char*)uncompr);
1709
				_readValues(std::wstring(data.begin(), data.end()));
1711
					_readValues(std::wstring(data.begin(), data.end()));
-
 
1712
				}
-
 
1713
				else
-
 
1714
				{
-
 
1715
					const wchar_t* data = (const wchar_t*)uncompr;
-
 
1716
					_readValues(Utils::WString(data));
-
 
1717
				}
1710
			}
1718
			}
1711
			doneLen = uncomprLen;
1719
			doneLen = uncomprLen;
1712
			delete []uncompr;
1720
			delete []uncompr;
1713
		}
1721
		}
1714
		catch (std::exception &e) {
1722
		catch (std::exception &e) {
1715
			CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_Header() unable to malloc [uncompr], %d (%s)", uncomprLen, e.what());
1723
			CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_Header() unable to malloc [uncompr], %d (%s)", uncomprLen, e.what());
1716
			delete []readData;
1724
			delete []readData;
1717
			return -1;
1725
			return -1;
1718
		}
1726
		}
1719
	}
1727
	}
1720
	else if ( m_SHeader.iValueCompression == SPKCOMPRESS_7ZIP ) {
1728
	else if ( m_SHeader.iValueCompression == SPKCOMPRESS_7ZIP ) {
1721
		long len = uncomprLen;
1729
		long len = uncomprLen;
1722
		unsigned char *compr = LZMADecode_C ( readData, m_SHeader.lValueCompressSize, (size_t*)&len, NULL );
1730
		unsigned char *compr = LZMADecode_C ( readData, m_SHeader.lValueCompressSize, (size_t*)&len, NULL );
1723
		// update the progress for each section
1731
		// update the progress for each section
1724
		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
1732
		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
1725
 
1733
 
1726
		if (compr) 
1734
		if (compr) 
1727
		{
1735
		{
-
 
1736
			if (m_SHeader.fVersion <= 4.3f)
-
 
1737
			{
1728
			std::string data((char*)compr);
1738
				std::string data((const char*)compr);
1729
			_readValues(std::wstring(data.begin(), data.end()));
1739
				_readValues(std::wstring(data.begin(), data.end()));
-
 
1740
			}
-
 
1741
			else
-
 
1742
			{
-
 
1743
				const wchar_t* data = (const wchar_t*)compr;
-
 
1744
				_readValues(Utils::WString(data));
-
 
1745
			}
1730
		}
1746
		}
1731
	}
1747
	}
1732
	// no compression
1748
	// no compression
1733
	else
1749
	else
1734
	{
1750
	{
-
 
1751
		if (m_SHeader.fVersion <= 4.3f)
-
 
1752
		{
1735
		std::string data((char*)readData);
1753
			std::string data((const char*)readData);
1736
		_readValues(std::wstring(data.begin(), data.end()));
1754
			_readValues(std::wstring(data.begin(), data.end()));
-
 
1755
		}
-
 
1756
		else
-
 
1757
		{
-
 
1758
			const wchar_t* data = (const wchar_t*)readData;
-
 
1759
			_readValues(Utils::WString(data));
-
 
1760
		}
1737
	}
1761
	}
1738
 
1762
 
1739
	delete []readData;
1763
	delete []readData;
1740
 
1764
 
1741
	return doneLen;
1765
	return doneLen;
Line 1980... Line 2004...
1980
	if ( fileheader == SPKCOMPRESS_7ZIP )
2004
	if ( fileheader == SPKCOMPRESS_7ZIP )
1981
		fileheader = SPKCOMPRESS_ZLIB;
2005
		fileheader = SPKCOMPRESS_ZLIB;
1982
 
2006
 
1983
	// get the script values
2007
	// get the script values
1984
	Utils::WString values = this->createValuesLine();
2008
	Utils::WString values = this->createValuesLine();
1985
	std::string sValues(values.begin(), values.end());
2009
	const char* data = (const char*)values.c_str();
1986
 
2010
 
1987
	// compress the values
2011
	// compress the values
1988
	int valueUncomprLen = (int)strlen(sValues.c_str());
2012
	int valueUncomprLen = (int)(wcslen(values.c_str()) * sizeof(wchar_t)) / sizeof(char);
1989
	unsigned long valueComprLen = 0;
2013
	unsigned long valueComprLen = 0;
1990
	unsigned char *valueCompr = NULL;
2014
	unsigned char *valueCompr = NULL;
1991
	bool compressed = false;
2015
	bool compressed = false;
1992
 
2016
 
1993
	if ( valueheader == SPKCOMPRESS_ZLIB )
2017
	if ( valueheader == SPKCOMPRESS_ZLIB )
Line 1997... Line 2021...
1997
			valueComprLen = 200;
2021
			valueComprLen = 200;
1998
		else if ( valueComprLen < 1000 )
2022
		else if ( valueComprLen < 1000 )
1999
			valueComprLen *= 2;
2023
			valueComprLen *= 2;
2000
 
2024
 
2001
		valueCompr = (unsigned char *)calloc((unsigned int)valueComprLen, 1);
2025
		valueCompr = (unsigned char *)calloc((unsigned int)valueComprLen, 1);
2002
		int err = compress ( (unsigned char *)valueCompr, &valueComprLen, (const unsigned char *)sValues.c_str(), (unsigned long)strlen(sValues.c_str()), 0 );
2026
		int err = compress ( (unsigned char *)valueCompr, &valueComprLen, (const unsigned char *)data, (unsigned long)valueUncomprLen, 0 );
2003
		if ( err == Z_OK )
2027
		if ( err == Z_OK )
2004
			compressed = true;
2028
			compressed = true;
2005
	}
2029
	}
2006
 
2030
 
2007
	if ( !compressed )
2031
	if ( !compressed )
2008
	{
2032
	{
2009
		valueComprLen = valueUncomprLen;
2033
		valueComprLen = valueUncomprLen;
2010
		valueCompr = (unsigned char *)calloc((unsigned int)valueComprLen, 1);
2034
		valueCompr = (unsigned char *)calloc((unsigned int)valueComprLen, 1);
2011
		memcpy ( valueCompr, sValues.c_str(), valueComprLen );
2035
		memcpy ( valueCompr, (const unsigned char *)data, valueComprLen );
2012
		valueheader = SPKCOMPRESS_NONE;
2036
		valueheader = SPKCOMPRESS_NONE;
2013
	}
2037
	}
2014
 
2038
 
2015
	// write the main header to the file
2039
	// write the main header to the file
2016
	if ( !this->writeHeader(file, valueheader, valueComprLen) )	return false;
2040
	if ( !this->writeHeader(file, valueheader, valueComprLen) )	return false;