Subversion Repositories spk

Rev

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

Rev 43 Rev 45
Line 970... Line 970...
970
}
970
}
971
 
971
 
972
bool C_File::UncompressData ( CProgressInfo *progress )
972
bool C_File::UncompressData ( CProgressInfo *progress )
973
{
973
{
974
	// no data to try to uncompress
974
	// no data to try to uncompress
975
	if ( (!m_sData) || (!m_lDataSize) )
975
	if ( (!m_sData) || (!m_lDataSize) ) {
976
		return false;
976
		return (m_lSize) ? false : true;
-
 
977
	}
977
 
978
 
978
	if ( m_bCompressedToFile )
979
	if ( m_bCompressedToFile )
979
		return false;
980
		return false;
980
 
981
 
981
	// if comopression is set to none, dont bother
982
	// if comopression is set to none, dont bother
982
	if ( m_iDataCompression == SPKCOMPRESS_NONE )
983
	if ( m_iDataCompression == SPKCOMPRESS_NONE )
983
		return true;
984
		return true;
984
 
985
 
985
	if ( m_iDataCompression == SPKCOMPRESS_ZLIB )
986
	if ( m_iDataCompression == SPKCOMPRESS_ZLIB )
Line 991... Line 992...
991
		{
992
		{
992
			DeleteData ();
993
			DeleteData ();
993
			m_iDataCompression = SPKCOMPRESS_NONE;
994
			m_iDataCompression = SPKCOMPRESS_NONE;
994
			m_lDataSize = uncomprLen;
995
			m_lDataSize = uncomprLen;
995
			m_sData = uncompr;
996
			m_sData = uncompr;
996
			return true;
997
			return true;
997
		}
998
		}
998
 
999
 
999
		if ( uncompr )
1000
		if ( uncompr )
1000
			delete [] uncompr;
1001
			delete [] uncompr;
1001
	}
1002
	}
1002
	else if ( m_iDataCompression == SPKCOMPRESS_LZMA )
1003
	else if ( m_iDataCompression == SPKCOMPRESS_LZMA )
1003
	{
1004
	{
1004
		size_t uncomprLen = m_lUncomprDataSize;
1005
		size_t uncomprLen = m_lUncomprDataSize;
1005
		unsigned char *uncompr = new unsigned char[m_lUncomprDataSize];
1006
		unsigned char *uncompr = new unsigned char[m_lUncomprDataSize];
1006
		SRes res = Lzma86_Decode(uncompr, &uncomprLen, m_sData, (size_t*)&m_lDataSize);
1007
		SRes res = Lzma86_Decode(uncompr, &uncomprLen, m_sData, (size_t*)&m_lDataSize);
1007
		if ( res == SZ_OK )
1008
		if ( res == SZ_OK )
Line 1050... Line 1051...
1050
		*size = m_lDataSize;
1051
		*size = m_lDataSize;
1051
		return m_sData;
1052
		return m_sData;
1052
	}
1053
	}
1053
 
1054
 
1054
	if ( m_iDataCompression == SPKCOMPRESS_ZLIB )
1055
	if ( m_iDataCompression == SPKCOMPRESS_ZLIB )
1055
	{
1056
	{
1056
		unsigned long uncomprLen = m_lUncomprDataSize;
1057
		unsigned long uncomprLen = m_lUncomprDataSize;
1057
		unsigned char *uncompr = new unsigned char[m_lUncomprDataSize];
1058
		unsigned char *uncompr = new unsigned char[m_lUncomprDataSize];
1058
		int err = uncompress ( uncompr, &uncomprLen, (const unsigned char *)m_sData, m_lDataSize );
1059
		int err = uncompress ( uncompr, &uncomprLen, (const unsigned char *)m_sData, m_lDataSize );
1059
		if ( err == Z_OK )
1060
		if ( err == Z_OK )
1060
		{
1061
		{
Line 1104... Line 1105...
1104
		FILE *id = fopen ( m_sTmpFile.c_str(), "rb" );
1105
		FILE *id = fopen ( m_sTmpFile.c_str(), "rb" );
1105
		if ( id )
1106
		if ( id )
1106
		{
1107
		{
1107
			fclose ( id );
1108
			fclose ( id );
1108
			return true;
1109
			return true;
1109
		}
1110
		}
1110
		m_sTmpFile = "";
1111
		m_sTmpFile = "";
1111
	}
1112
	}
1112
 
1113
 
1113
	// now uncompress to the file
1114
	// now uncompress to the file
1114
	CyString file = toFile;
1115
	CyString file = toFile;
Line 1158... Line 1159...
1158
	if ( (!len) || (!data) )
1159
	if ( (!len) || (!data) )
1159
	{
1160
	{
1160
		len = m_lDataSize;
1161
		len = m_lDataSize;
1161
		data = m_sData;
1162
		data = m_sData;
1162
	}
1163
	}
1163
 
1164
 
1164
	if ( (!len) || (!data) )
1165
	if ( (!len) || (!data) ) {
1165
		return false;
1166
		if ( m_lSize ) return false;
-
 
1167
	}
1166
 
1168
 
1167
	// check for cat file
1169
	// check for cat file
1168
	if ( filename.IsIn ( "::" ) )
1170
	if ( filename.IsIn ( "::" ) )
1169
	{
1171
	{
1170
		CyString catfile = filename.GetToken ( "::", 1, 1 );
1172
		CyString catfile = filename.GetToken ( "::", 1, 1 );
Line 1175... Line 1177...
1175
	}
1177
	}
1176
	else
1178
	else
1177
	{
1179
	{
1178
		CyString filen = filename.FindReplace ( "/", "\\" );
1180
		CyString filen = filename.FindReplace ( "/", "\\" );
1179
		filen = filen.FindReplace ( "\\\\", "\\" );
1181
		filen = filen.FindReplace ( "\\\\", "\\" );
1180
 
1182
 
1181
		FILE *id = fopen ( filen.c_str(), "wb" );
1183
		FILE *id = fopen ( filen.c_str(), "wb" );
1182
		if ( !id )
1184
		if ( !id )
1183
			return false;
1185
			return false;
1184
 
-
 
1185
		fwrite ( data, sizeof(unsigned char), len, id );
-
 
1186
 
1186
 
1187
		bool ret = true;
1187
		bool ret = true;
1188
		if ( ferror(id) )
1188
		if ( len && data ) {
1189
			ret = false;
1189
			fwrite ( data, sizeof(unsigned char), len, id );
1190
 
1190
 
1191
		fclose ( id );
1191
			if ( ferror(id) )
-
 
1192
				ret = false;
1192
 
1193
 
-
 
1194
			fclose ( id );
-
 
1195
		}
1193
		return ret;
1196
		return ret;
1194
	}
1197
	}
1195
 
1198
 
1196
	return false;
1199
	return false;
1197
}
1200
}