Subversion Repositories spk

Rev

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

Rev 50 Rev 51
Line 166... Line 166...
166
	return NULL;
166
	return NULL;
167
}
167
}
168
 
168
 
169
int CBaseFile::CheckFile ( CyString filename, float *version )
169
int CBaseFile::CheckFile ( CyString filename, float *version )
170
{
170
{
171
	FILE *id = fopen ( filename.c_str(), "rb" );
171
	std::fstream File(filename.ToString().c_str(), std::ios::in | std::ios::binary);
172
	if ( !id )
172
	if ( !File.is_open() ) return 0;
173
		return false;
-
 
174
 
173
 
175
	CyString line = GetEndOfLine ( id, NULL, false );
174
	Utils::String line = CBaseFile::readEndOfLine(File, NULL, false);
176
	CyString type = line.GetToken ( 1, ';' );
175
	Utils::String type = line.token(";", 1);
177
	fclose ( id );
176
	File.close();
178
 
177
 
179
	// check for old version
178
	// check for old version
180
	if ( line.Left(3) == "HiP" )
179
	if ( line.left(3) == "HiP" ) return SPKFILE_OLD;
181
		return SPKFILE_OLD;
-
 
182
 
180
 
183
	// check for format
181
	// check for format
184
	if ( version )
-
 
185
		*version = line.GetToken ( 2, ';' ).ToFloat();
182
	if ( version ) *version = line.token(";", 2);
186
 
183
 
187
	if ( type == "BaseCycrow" )
184
	if ( type == "BaseCycrow" )	return SPKFILE_BASE;
188
		return SPKFILE_BASE;
-
 
189
	if ( type == "SPKCycrow" )
185
	if ( type == "SPKCycrow" )	return SPKFILE_SINGLE;
190
		return SPKFILE_SINGLE;
-
 
191
	if ( type == "XSPCycrow" )
-
 
192
		return SPKFILE_SINGLESHIP;
186
	if ( type == "XSPCycrow" )	return SPKFILE_SINGLESHIP;
193
	if ( type == "MSPKCycrow" )
187
	if ( type == "MSPKCycrow" )	return SPKFILE_MULTI;
194
		return SPKFILE_MULTI;
-
 
195
	return SPKFILE_INVALID;
188
	return SPKFILE_INVALID;
196
}
189
}
197
 
190
 
198
void CBaseFile::ClearFileData()
191
void CBaseFile::ClearFileData()
199
{
192
{
Line 525... Line 518...
525
 
518
 
526
	return fullsize;
519
	return fullsize;
527
}
520
}
528
 
521
 
529
 
522
 
-
 
523
Utils::String CBaseFile::readEndOfLine(std::fstream &stream, int *line, bool upper )
-
 
524
{
-
 
525
	Utils::String str;
-
 
526
	std::getline(stream, str, '\n');
-
 
527
	if ( line ) ++(*line);
-
 
528
	if ( upper ) return str.upper();
-
 
529
	return str;
-
 
530
}
530
/*
531
/*
531
	Func:   GetEndOfLine
532
	Func:   GetEndOfLine
532
	Input:  id - The file id for the current file to read from
533
	Input:  id - The file id for the current file to read from
533
	        line - Pointed to hold the line number thats read
534
	        line - Pointed to hold the line number thats read
534
			upper - true if it converts to uppercase
535
			upper - true if it converts to uppercase
Line 722... Line 723...
722
{
723
{
723
	// no file to read from
724
	// no file to read from
724
	if ( this->filename().empty() ) return;
725
	if ( this->filename().empty() ) return;
725
 
726
 
726
	// now open the file
727
	// now open the file
727
	FILE *id = fopen ( this->filename().c_str(), "rb" );
728
	std::fstream File(this->filename(), std::ios::in | std::ios::binary);
728
	if ( !id )
729
	if ( !File.is_open() ) return;
729
		return;
-
 
730
 
730
 
731
	// read the header
731
	// read the header
732
	GetEndOfLine ( id, NULL, false );
732
	CBaseFile::readEndOfLine(File);
733
	// skip past values
733
	// skip past values
734
	fseek ( id, 4, SEEK_CUR );
-
 
735
	fseek ( id, m_SHeader.lValueCompressSize, SEEK_CUR );
734
	File.seekg(4 + m_SHeader.lValueCompressSize, std::ios::cur);
736
 
735
 
737
	// read the next header
736
	// read the next header
738
	GetEndOfLine ( id, NULL, false );
737
	CBaseFile::readEndOfLine(File);
739
	// skip past files
738
	// skip past files
740
	fseek ( id, 4, SEEK_CUR );
-
 
741
	fseek ( id, m_SHeader2.lSize, SEEK_CUR );
739
	File.seekg(4 + m_SHeader2.lSize, std::ios::cur);
742
 
740
 
743
	if ( m_pIconFile )
741
	if ( m_pIconFile )
744
	{
742
	{
745
		if ( (!m_pIconFile->GetData()) && (!m_pIconFile->Skip()) )
743
		if ( (!m_pIconFile->GetData()) && (!m_pIconFile->Skip()) )
746
			m_pIconFile->ReadFromFile ( id, m_pIconFile->GetDataSize() );
744
			m_pIconFile->readFromFile(File, m_pIconFile->GetDataSize());
747
		else
745
		else
748
		{
-
 
749
			fseek ( id, 4, SEEK_CUR );
-
 
750
			fseek ( id, m_pIconFile->GetDataSize(), SEEK_CUR );
746
			File.seekg(4 + m_pIconFile->GetDataSize(), std::ios::cur);
751
		}
-
 
752
	}
747
	}
753
 
748
 
754
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
749
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
755
	{
750
	{
756
		C_File *fit = node->Data();
751
		C_File *fit = node->Data();
757
		if ( (!fit->GetData()) && (!fit->Skip()) )
752
		if ( (!fit->GetData()) && (!fit->Skip()) )
758
			fit->ReadFromFile ( id, fit->GetDataSize() );
753
			fit->readFromFile(File, fit->GetDataSize());
759
		else
754
		else
760
		{
-
 
761
			fseek ( id, 4, SEEK_CUR );
-
 
762
			fseek ( id, fit->GetDataSize(), SEEK_CUR );
755
			File.seekg(4 + fit->GetDataSize(), std::ios::cur);
763
		}
-
 
764
	}
756
	}
765
 
757
 
766
	fclose ( id );
758
	File.close();
767
}
759
}
768
 
760
 
769
bool CBaseFile::ReadFileToMemory(C_File *f)
761
bool CBaseFile::ReadFileToMemory(C_File *f)
770
{
762
{
771
	if ( f->GetData() && f->GetDataSize() )
763
	if ( f->GetData() && f->GetDataSize() ) return true;	// already loaded the data
772
		return true;
-
 
773
	// no file to read from
-
 
774
	if ( this->filename().empty() || !f )
764
	if ( this->filename().empty() || !f ) return false;		// no filename to load from
775
		return false;
-
 
776
 
-
 
777
	// check the file is part of the package
-
 
778
	if ( !m_lFiles.FindData(f) )
765
	if ( !m_lFiles.FindData(f) ) return false;				// unable to find file entry
779
		return false;
-
 
780
 
766
 
781
	// now open the file
767
	// now open the file
782
	FILE *id = fopen ( this->filename().c_str(), "rb" );
768
	std::fstream File(this->filename(), std::ios::in | std::ios::binary);
783
	if ( !id )
-
 
784
		return false;
769
	if ( !File.is_open() ) return false;
785
 
770
 
786
	// read the header
771
	// read the header
787
	GetEndOfLine ( id, NULL, false );
772
	CBaseFile::readEndOfLine(File, NULL, false);
788
	// skip past values
773
	// skip past values
789
	fseek ( id, 4, SEEK_CUR );
-
 
790
	fseek ( id, m_SHeader.lValueCompressSize, SEEK_CUR );
774
	File.seekg(4 + m_SHeader.lValueCompressSize, std::ios::cur);
791
 
775
 
792
	// read the next header
776
	// read the next header
793
	GetEndOfLine ( id, NULL, false );
777
	CBaseFile::readEndOfLine(File, NULL, false);
794
	// skip past files
778
	// skip past files
795
	fseek ( id, 4, SEEK_CUR );
-
 
796
	fseek ( id, m_SHeader2.lSize, SEEK_CUR );
779
	File.seekg(4 + m_SHeader2.lSize, std::ios::cur);
797
 
780
 
798
	if ( m_pIconFile )
-
 
799
	{
-
 
800
		fseek ( id, 4, SEEK_CUR );
-
 
801
		fseek ( id, m_pIconFile->GetDataSize(), SEEK_CUR );
781
	if ( m_pIconFile ) File.seekg(4 + m_pIconFile->GetDataSize(), std::ios::cur);
802
	}
-
 
803
 
-
 
804
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
782
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
805
	{
-
 
806
		C_File *fit = node->Data();
783
		C_File *fit = node->Data();
807
		if (fit == f )
784
		if (fit == f ) {
808
		{
-
 
809
			fit->ReadFromFile ( id, fit->GetDataSize() );
785
			fit->readFromFile(File, fit->GetDataSize());
810
			break;
786
			break;
811
		}
787
		}
812
		else
-
 
813
		{
-
 
814
			fseek ( id, 4, SEEK_CUR );
-
 
815
			fseek ( id, fit->GetDataSize(), SEEK_CUR );
788
		else File.seekg(4 + fit->GetDataSize(), std::ios::cur);
816
		}
-
 
817
	}
789
	}
818
 
790
 
819
 
-
 
820
	fclose(id);
791
	File.close();
821
	return true;
792
	return true;
822
}
793
}
823
 
794
 
824
void CBaseFile::ReadIconFileToMemory ()
795
void CBaseFile::ReadIconFileToMemory ()
825
{
796
{
Line 829... Line 800...
829
 
800
 
830
	if ( !m_pIconFile )
801
	if ( !m_pIconFile )
831
		return;
802
		return;
832
 
803
 
833
	// now open the file
804
	// now open the file
834
	FILE *id = fopen ( this->filename().c_str(), "rb" );
805
	std::fstream stream(this->filename(), std::ios::in | std::ios::binary);
835
	if ( !id )
806
	if ( !stream.is_open() ) return;
836
		return;
-
 
837
 
807
 
838
	// read the header
808
	// read the header
839
	GetEndOfLine ( id, NULL, false );
809
	CBaseFile::readEndOfLine(stream, NULL, false);
840
	// skip past values
810
	// skip past values
841
	fseek ( id, 4, SEEK_CUR );
-
 
842
	fseek ( id, m_SHeader.lValueCompressSize, SEEK_CUR );
811
	stream.seekg(4 + m_SHeader.lValueCompressSize, std::ios::cur);
843
 
812
 
844
	// read the next header
813
	// read the next header
845
	GetEndOfLine ( id, NULL, false );
814
	CBaseFile::readEndOfLine(stream, NULL, false);
846
	// skip past files
815
	// skip past files
847
	fseek ( id, 4, SEEK_CUR );
-
 
848
	fseek ( id, m_SHeader2.lSize, SEEK_CUR );
816
	stream.seekg(4 + m_SHeader2.lSize, std::ios::cur);
849
 
817
 
850
	if ( m_pIconFile )
818
	if ( m_pIconFile ) {
851
	{
-
 
852
		if ( (!m_pIconFile->GetData()) && (!m_pIconFile->Skip()) )
819
		if ( (!m_pIconFile->GetData()) && (!m_pIconFile->Skip()) )
853
			m_pIconFile->ReadFromFile ( id, m_pIconFile->GetDataSize() );
820
			m_pIconFile->readFromFile(stream, m_pIconFile->GetDataSize() );
854
		else
821
		else
855
		{
-
 
856
			fseek ( id, 4, SEEK_CUR );
-
 
857
			fseek ( id, m_pIconFile->GetDataSize(), SEEK_CUR );
822
			stream.seekg(4 + m_pIconFile->GetDataSize(), std::ios::cur);
858
		}
-
 
859
	}
823
	}
860
 
824
 
861
	fclose ( id );
825
	stream.close();
862
}
826
}
863
 
827
 
864
void CBaseFile::_install_adjustFakePatches(CPackages *pPackages)
828
void CBaseFile::_install_adjustFakePatches(CPackages *pPackages)
865
{
829
{
866
	CyStringList lPatches;
830
	CyStringList lPatches;
Line 1102... Line 1066...
1102
		if ( errorStr ) errorStr->PushBack(pCheckFile->GetNameDirectory(this), ERRORLOG(SPKINSTALL_ENABLEFILE));
1066
		if ( errorStr ) errorStr->PushBack(pCheckFile->GetNameDirectory(this), ERRORLOG(SPKINSTALL_ENABLEFILE));
1103
	}
1067
	}
1104
 
1068
 
1105
	return true;
1069
	return true;
1106
}
1070
}
-
 
1071
 
-
 
1072
bool CBaseFile::_install_createDirectory(CDirIO &Dir, const Utils::String &sTo, C_File *pFile, CyStringList *errorStr)
-
 
1073
{
-
 
1074
	m_sLastError = sTo;
-
 
1075
	if ( !sTo.isin ( "::" ) )
-
 
1076
	{
-
 
1077
		if ( !Dir.Exists(sTo) )
-
 
1078
		{
-
 
1079
			CLog::logf(CLog::Log_Install, 2, "Creating directory to install file into, %s", sTo.c_str());
-
 
1080
			if ( !Dir.Create(sTo) )
-
 
1081
			{
-
 
1082
				if ( errorStr )
-
 
1083
					errorStr->PushBack(CyString(sTo), ERRORLOG(SPKINSTALL_CREATEDIRECTORY_FAIL));
-
 
1084
				return false;
-
 
1085
			}
-
 
1086
			if ( errorStr )
-
 
1087
				errorStr->PushBack(CyString(sTo), ERRORLOG(SPKINSTALL_CREATEDIRECTORY));
-
 
1088
		}
-
 
1089
	}
-
 
1090
	else {
-
 
1091
		CLog::logf(CLog::Log_Install, 2, "Adjusting file extension for file in mod, %s => %s", pFile->GetFilePointer().c_str(), CCatFile::PckChangeExtension(pFile->GetFilePointer()).c_str());
-
 
1092
		pFile->SetFilename(CCatFile::PckChangeExtension(pFile->GetFilePointer()));
-
 
1093
	}
-
 
1094
 
-
 
1095
	return true;
-
 
1096
}
-
 
1097
 
-
 
1098
void CBaseFile::_install_writeFile(C_File *pFile, const Utils::String &sDestination, CyStringList *errorStr)
-
 
1099
{
-
 
1100
	m_iLastError = SPKERR_WRITEFILE;
-
 
1101
	m_sLastError = pFile->GetFilePointer();
-
 
1102
	CyString sInstalledFile = pFile->GetNameDirectory(this);
-
 
1103
	if ( pFile->IsDisabled() )
-
 
1104
	{
-
 
1105
		sInstalledFile = pFile->GetFilePointer().Remove(sDestination);
-
 
1106
		if ( sInstalledFile[0] == '/' || sInstalledFile[0] == '\\' )
-
 
1107
			sInstalledFile.Erase(0, 1);
-
 
1108
	}
-
 
1109
 
-
 
1110
	if ( !pFile->WriteFilePointer() )
-
 
1111
	{
-
 
1112
		CLog::log(CLog::Log_Install, 1, "Failed to write the file");
-
 
1113
		if ( errorStr )
-
 
1114
			errorStr->PushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE_FAIL));
-
 
1115
	}
-
 
1116
	else
-
 
1117
	{
-
 
1118
		CLog::log(CLog::Log_Install, 1, "File written successfully");
-
 
1119
		CLog::log(CLog::Log_Install, 2, "Checking signed status of the file");
-
 
1120
		pFile->UpdateSigned();
-
 
1121
		if ( errorStr )
-
 
1122
			errorStr->PushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE));
-
 
1123
 
-
 
1124
		switch(pFile->GetFileType())
-
 
1125
		{
-
 
1126
			case FILETYPE_SCRIPT:
-
 
1127
			case FILETYPE_UNINSTALL:
-
 
1128
				CLog::log(CLog::Log_Install, 2, "Updating file signature");
-
 
1129
				pFile->UpdateSignature();
-
 
1130
				break;
-
 
1131
		}
-
 
1132
	}
-
 
1133
}
-
 
1134
 
1107
bool CBaseFile::InstallFiles ( CyString destdir, CProgressInfo *progress, CLinkList<C_File> *filelist, CyStringList *errorStr, bool enabled, CPackages *packages )
1135
bool CBaseFile::InstallFiles ( CyString destdir, CProgressInfo *progress, CLinkList<C_File> *filelist, CyStringList *errorStr, bool enabled, CPackages *packages )
1108
{
1136
{
1109
	//TODO: add errorStr and progress as member variables
1137
	//TODO: add errorStr and progress as member variables
1110
	if ( enabled ) {
1138
	if ( enabled ) {
1111
		this->_install_adjustFakePatches(packages);
1139
		this->_install_adjustFakePatches(packages);
Line 1162... Line 1190...
1162
			// no matching file found, adding to main list
1190
			// no matching file found, adding to main list
1163
			if ( !cFile ) filelist->push_back ( fit );
1191
			if ( !cFile ) filelist->push_back ( fit );
1164
			else
1192
			else
1165
			{
1193
			{
1166
				// if the file is not enabled, we need to check for any that might be enabled
1194
				// if the file is not enabled, we need to check for any that might be enabled
1167
				if ( !fileEnabled ) //_install_checkDisabled(cFile, errorStr);
1195
				if ( !fileEnabled ) //_install_checkDisabled(cFile, destdir, errorStr);
1168
				{
1196
				{
1169
					//TODO: check what this is actually doing
1197
					//TODO: check what this is actually doing
1170
					if ( !cFile->GetUsed() )
1198
					if ( !cFile->GetUsed() )
1171
					{
1199
					{
1172
						CFileIO rFile(cFile->GetFilePointer());
1200
						CFileIO rFile(cFile->GetFilePointer());
Line 1183... Line 1211...
1183
						cFile->SetFilename(fit->GetFilePointer());
1211
						cFile->SetFilename(fit->GetFilePointer());
1184
						cFile->SetDisabled(true);
1212
						cFile->SetDisabled(true);
1185
					}
1213
					}
1186
					else
1214
					else
1187
					{
1215
					{
1188
						cFile->SetFullDir ( CyString(sFilename) + fit->GetDirectory(this) );
1216
						fit->SetFullDir ( CyString(sFilename) + fit->GetDirectory(this) );
1189
						cFile->SetDisabled(false);
1217
						fit->SetDisabled(false);
1190
					}
1218
					}
1191
				}
1219
				}
1192
				// move it to enabled
1220
				// move it to enabled
1193
				else {
1221
				else {
1194
					if ( !this->_install_checkFileEnable(cFile, fit, destdir.ToString(), fileEnabled, errorStr) ) {
1222
					if ( !this->_install_checkFileEnable(cFile, fit, destdir.ToString(), fileEnabled, errorStr) ) {
Line 1207... Line 1235...
1207
			// uncompressed to file, rename and move
1235
			// uncompressed to file, rename and move
1208
			if ( uncomprToFile )
1236
			if ( uncomprToFile )
1209
			{
1237
			{
1210
				m_iLastError = SPKERR_WRITEFILE;
1238
				m_iLastError = SPKERR_WRITEFILE;
1211
				CyString to = fit->GetDirectory(this);
1239
				CyString to = fit->GetDirectory(this);
1212
				//to = to.GetToken ( 1, to.NumToken ('/') - 1, '/' );
-
 
1213
				if ( !fileEnabled )
-
 
1214
					to = CyString("PluginManager/Disabled/") + to;
1240
				if ( !fileEnabled )	to = CyString("PluginManager/Disabled/") + to;
1215
 
1241
 
1216
				CDirIO Dir(destdir);
-
 
1217
				if ( !Dir.Exists(to) )
-
 
1218
				{
-
 
1219
					if ( !Dir.Create ( to ) )
1242
				if ( !_install_createDirectory(Dir, to.ToString(), fit, errorStr) ) {
1220
					{
-
 
1221
						if ( errorStr )
1243
					bFailed = true;
1222
							errorStr->PushBack(to, ERRORLOG(SPKINSTALL_CREATEDIRECTORY_FAIL));
-
 
1223
						return false;
1244
					continue;
1224
					}
-
 
1225
					if ( errorStr )
-
 
1226
						errorStr->PushBack(to, ERRORLOG(SPKINSTALL_CREATEDIRECTORY));
-
 
1227
				}
1245
				}
1228
 
1246
 
1229
				int err = 1;
1247
				int err = 1;
1230
				m_sLastError = to;
1248
				m_sLastError = to;
1231
				if ( !fit->GetTempFile ().Empty() )
-
 
1232
					err = rename ( fit->GetTempFile().c_str(), to.c_str() );
1249
				if ( !fit->GetTempFile ().Empty() )	err = rename ( fit->GetTempFile().c_str(), to.c_str() );
1233
				if ( err )
1250
				if ( err ) {
-
 
1251
					bFailed = true;
1234
					return false;
1252
					continue;
-
 
1253
				}
1235
			}
1254
			}
1236
			//otherwise, just extract the file
1255
			//otherwise, just extract the file
1237
			else
1256
			else
1238
			{
1257
			{
1239
				// old file is found in list, switch to using new one
1258
				// old file is found in list, switch to using new one
Line 1245... Line 1264...
1245
				CyString fpointer = fit->GetFilePointer();
1264
				CyString fpointer = fit->GetFilePointer();
1246
				m_iLastError = SPKERR_CREATEDIRECTORY;
1265
				m_iLastError = SPKERR_CREATEDIRECTORY;
1247
				CyString dir = fit->GetFilePointer().GetToken ( "/", 1, fit->GetFilePointer().NumToken("/") - 1 );
1266
				CyString dir = fit->GetFilePointer().GetToken ( "/", 1, fit->GetFilePointer().NumToken("/") - 1 );
1248
 
1267
 
1249
				dir = dir.Remove(destdir);
1268
				dir = dir.Remove(destdir);
1250
				if ( dir[0] == '/' || dir[0] == '\\' )
1269
				if ( dir[0] == '/' || dir[0] == '\\' ) dir.Erase(0, 1);
1251
					dir.Erase(0, 1);
-
 
1252
 
1270
 
1253
				m_sLastError = dir;
-
 
1254
				if ( !dir.IsIn ( "::" ) )
-
 
1255
				{
-
 
1256
					if ( !Dir.Exists(dir) )
-
 
1257
					{
-
 
1258
						CLog::logf(CLog::Log_Install, 2, "Creating directory to install file into, %s", dir.c_str());
1271
				if ( !_install_createDirectory(Dir, dir.ToString(), fit, errorStr) ) {
1259
						if ( !Dir.Create(dir) )
-
 
1260
						{
-
 
1261
							if ( errorStr )
1272
					bFailed = true;
1262
								errorStr->PushBack(dir, ERRORLOG(SPKINSTALL_CREATEDIRECTORY_FAIL));
-
 
1263
							return false;
1273
					continue;
1264
						}
-
 
1265
						if ( errorStr )
-
 
1266
							errorStr->PushBack(dir, ERRORLOG(SPKINSTALL_CREATEDIRECTORY));
-
 
1267
					}
-
 
1268
				}
-
 
1269
				else {
-
 
1270
					CLog::logf(CLog::Log_Install, 2, "Adjusting file extension for file in mod, %s => %s", fit->GetFilePointer().c_str(), CCatFile::PckChangeExtension(fit->GetFilePointer()).c_str());
-
 
1271
					fit->SetFilename(CCatFile::PckChangeExtension(fit->GetFilePointer()));
-
 
1272
				}
1274
				}
1273
 
1275
 
1274
				m_iLastError = SPKERR_WRITEFILE;
-
 
1275
				m_sLastError = fit->GetFilePointer();
-
 
1276
				CyString sInstalledFile = fit->GetNameDirectory(this);
-
 
1277
				if ( fit->IsDisabled() )
-
 
1278
				{
-
 
1279
					sInstalledFile = fit->GetFilePointer().Remove(destdir);
1276
				_install_writeFile(fit, destdir.ToString(), errorStr);
1280
					if ( sInstalledFile[0] == '/' || sInstalledFile[0] == '\\' )
-
 
1281
						sInstalledFile.Erase(0, 1);
-
 
1282
				}
-
 
1283
 
-
 
1284
				if ( !fit->WriteFilePointer() )
-
 
1285
				{
-
 
1286
					CLog::log(CLog::Log_Install, 1, "Failed to write the file");
-
 
1287
					if ( errorStr )
-
 
1288
						errorStr->PushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE_FAIL));
-
 
1289
				}
-
 
1290
				else
-
 
1291
				{
-
 
1292
					CLog::log(CLog::Log_Install, 1, "File written successfully");
-
 
1293
					CLog::log(CLog::Log_Install, 2, "Checking signed status of the file");
-
 
1294
					fit->UpdateSigned();
-
 
1295
					if ( errorStr )
-
 
1296
						errorStr->PushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE));
-
 
1297
 
-
 
1298
					switch(fit->GetFileType())
-
 
1299
					{
-
 
1300
						case FILETYPE_SCRIPT:
-
 
1301
						case FILETYPE_UNINSTALL:
-
 
1302
							CLog::log(CLog::Log_Install, 2, "Updating file signature");
-
 
1303
							fit->UpdateSignature();
-
 
1304
							break;
-
 
1305
					}
-
 
1306
				}
-
 
1307
			}
1277
			}
1308
			ClearError ();
1278
			ClearError ();
1309
		}
1279
		}
1310
 
1280
 
1311
		if ( adjustPointer )
1281
		if ( adjustPointer )
Line 1318... Line 1288...
1318
		CLog::log(CLog::Log_Install, 1, "File installation completed");
1288
		CLog::log(CLog::Log_Install, 1, "File installation completed");
1319
	}
1289
	}
1320
 
1290
 
1321
	// now clear or data memory
1291
	// now clear or data memory
1322
	CLog::log(CLog::Log_Install, 2, "Delting temporary file data from memory");
1292
	CLog::log(CLog::Log_Install, 2, "Delting temporary file data from memory");
1323
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
1293
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) node->Data()->DeleteData();
1324
	{
-
 
1325
		// add plugin manager file to identify fake patches
-
 
1326
		/*
-
 
1327
		if ( fit->IsFakePatch() && fit->CheckFileExt ("cat") )
-
 
1328
		{
-
 
1329
			CFileIO plugin("pluginmanager.txt");
-
 
1330
			std::vector<CyString> lines;
-
 
1331
			CyString version;
-
 
1332
			version.FromFloat(GetLibraryVersion(), 2);
-
 
1333
			SStringList *strList = lPatches.FindData(fit->GetBaseName());
-
 
1334
 
-
 
1335
			CyString baseName;
-
 
1336
			if ( strList )
-
 
1337
				baseName = strList->str;
-
 
1338
			else
-
 
1339
				baseName = fit->GetBaseName();
-
 
1340
 
-
 
1341
			lines.push_back(CyString("FakePatch:") + baseName);
-
 
1342
			lines.push_back(CyString("spklibrary:") + version);
-
 
1343
			lines.push_back(CyString("Package:") + m_sName);
-
 
1344
			lines.push_back(CyString("Author:") + m_sAuthor);
-
 
1345
			lines.push_back(CyString("OriginalFile:") + fit->GetOriginalName());
-
 
1346
			if ( plugin.WriteFile(&lines) )
-
 
1347
			{
-
 
1348
				CCatFile cat;
-
 
1349
				if ( cat.Open(fit->GetFilePointer(), CATREAD_DAT, false) == CATERR_NONE )
-
 
1350
				{
-
 
1351
					cat.AppendFile(plugin.GetFilename(), plugin.GetFilename(), true);
-
 
1352
					cat.WriteCatFile();
-
 
1353
				}
-
 
1354
				plugin.Remove();
-
 
1355
			}
-
 
1356
		}
-
 
1357
*/
-
 
1358
		node->Data()->DeleteData();
-
 
1359
	}
-
 
1360
 
-
 
1361
 
-
 
1362
 
1294
 
1363
	return !bFailed;
1295
	return !bFailed;
1364
}
1296
}
1365
 
1297
 
1366
 
-
 
1367
 
-
 
1368
/*######################################################################################################*/
1298
/*######################################################################################################*/
1369
 
1299
 
1370
 
1300
 
1371
/*
1301
/*
1372
	Func:   ParseHeader
1302
	Func:   ParseHeader
Line 1641... Line 1571...
1641
	Return: boolean - return ture if acceptable format
1571
	Return: boolean - return ture if acceptable format
1642
	Desc:   Opens and reads the spk file and loads all data into class
1572
	Desc:   Opens and reads the spk file and loads all data into class
1643
*/
1573
*/
1644
bool CBaseFile::ReadFile ( CyString filename, int readtype, CProgressInfo *progress )
1574
bool CBaseFile::ReadFile ( CyString filename, int readtype, CProgressInfo *progress )
1645
{
1575
{
1646
	FILE *id = fopen ( filename.c_str(), "rb" );
1576
	std::fstream stream(filename.ToString().c_str(), std::ios::in | std::ios::binary);
1647
	if ( !id )
-
 
1648
		return false;
1577
	if ( !stream.is_open() ) return false;
1649
 
1578
 
1650
	bool ret = ReadFile ( id, readtype, progress );
1579
	bool ret = this->readFile(stream, readtype, progress);
1651
	if ( ret ) this->setFilename(filename.ToString());
1580
	if ( ret ) this->setFilename(filename.ToString());
1652
 
1581
 
1653
	fclose ( id );
1582
	stream.close();
1654
 
-
 
1655
	return ret;
1583
	return ret;
1656
}
1584
}
1657
bool CBaseFile::ReadFile ( FILE *id, int readtype, CProgressInfo *progress )
-
 
1658
{
-
 
1659
	ClearError ();
-
 
1660
 
1585
 
1661
	// first read the header
-
 
1662
	if ( !ParseHeader ( GetEndOfLine ( id, NULL, false ) ) )
1586
int CBaseFile::_read_Header(std::fstream &stream, int iReadType, int iMaxProgress, CProgressInfo *pProgress)
-
 
1587
{
1663
		return false;
1588
	int doneLen = 0;
1664
 
1589
 
1665
	if ( readtype == SPKREAD_HEADER )
1590
	// read data to memory
-
 
1591
	unsigned char *readData;
-
 
1592
	try {
-
 
1593
		readData = new unsigned char[m_SHeader.lValueCompressSize];
-
 
1594
	}
-
 
1595
	catch (std::exception &e) {
-
 
1596
		CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_Header() unable to malloc [header], %d (%s)", m_SHeader.lValueCompressSize, e.what());
1666
		return true;
1597
		return -1;
-
 
1598
	}
1667
 
1599
 
1668
	// update the progress for each section
1600
	unsigned char size[4];
1669
	int maxProgress = (readtype == SPKREAD_VALUES) ? 3 : 6;
-
 
1670
	if ( readtype != SPKREAD_ALL && progress )
1601
	stream.read((char *)size, 4);
1671
		progress->UpdateProgress(1, maxProgress);
1602
	stream.read((char *)readData, m_SHeader.lValueCompressSize);
1672
 
1603
 
1673
	long doneLen = 0;
-
 
1674
	// next read the data values for the spk files
-
 
1675
	if ( m_SHeader.lValueCompressSize )
-
 
1676
	{
-
 
1677
		// read data to memory
-
 
1678
		unsigned char *readData = new unsigned char[m_SHeader.lValueCompressSize];
-
 
1679
		unsigned char size[4];
-
 
1680
		fread ( size, 4, 1, id );
-
 
1681
		fread ( readData, sizeof(unsigned char), m_SHeader.lValueCompressSize, id );
-
 
1682
		unsigned long uncomprLen = (size[0] << 24) + (size[1] << 16) + (size[2] << 8) + size[3];
1604
	unsigned long uncomprLen = (size[0] << 24) + (size[1] << 16) + (size[2] << 8) + size[3];
1683
 
1605
 
1684
		// check for zlib compression
1606
	// check for zlib compression
1685
		if ( m_SHeader.iValueCompression == SPKCOMPRESS_ZLIB )
1607
	if ( m_SHeader.iValueCompression == SPKCOMPRESS_ZLIB ) {
1686
		{
-
 
1687
			// uncomress the data
1608
		// uncomress the data
-
 
1609
		try {
1688
			unsigned char *uncompr = new unsigned char[uncomprLen];
1610
			unsigned char *uncompr = new unsigned char[uncomprLen];
1689
 
-
 
1690
			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader.lValueCompressSize );
1611
			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader.lValueCompressSize );
1691
			// update the progress for each section
1612
			// update the progress for each section
1692
			if ( readtype != SPKREAD_ALL && progress )
-
 
1693
				progress->UpdateProgress(2, maxProgress);
1613
			if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
1694
			if ( err == Z_OK )
-
 
1695
				ReadValues ( CyString ((char *)uncompr) );
1614
			if ( err == Z_OK ) this->ReadValues ( CyString ((char *)uncompr) );
1696
			doneLen = uncomprLen;
1615
			doneLen = uncomprLen;
1697
			delete uncompr;
1616
			delete uncompr;
1698
		}
1617
		}
1699
		else if ( m_SHeader.iValueCompression == SPKCOMPRESS_7ZIP )
-
 
1700
		{
-
 
1701
			long len = uncomprLen;
1618
		catch (std::exception &e) {
1702
			unsigned char *compr = LZMADecode_C ( readData, m_SHeader.lValueCompressSize, (size_t*)&len, NULL );
1619
			CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_Header() unable to malloc [uncompr], %d (%s)", uncomprLen, e.what());
1703
			// update the progress for each section
-
 
1704
			if ( readtype != SPKREAD_ALL && progress )
-
 
1705
				progress->UpdateProgress(2, maxProgress);
-
 
1706
 
-
 
1707
			if ( compr )
1620
			return -1;
1708
				ReadValues ( CyString ((char *)compr) );
-
 
1709
		}
1621
		}
1710
		// no compression
-
 
1711
		else
-
 
1712
			ReadValues ( CyString ((char *)readData) );
-
 
1713
 
-
 
1714
		delete readData;
-
 
1715
	}
1622
	}
-
 
1623
	else if ( m_SHeader.iValueCompression == SPKCOMPRESS_7ZIP ) {
-
 
1624
		long len = uncomprLen;
-
 
1625
		unsigned char *compr = LZMADecode_C ( readData, m_SHeader.lValueCompressSize, (size_t*)&len, NULL );
-
 
1626
		// update the progress for each section
-
 
1627
		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
1716
 
1628
 
1717
	// update the progress for each section
1629
		if ( compr ) ReadValues ( CyString ((char *)compr) );
-
 
1630
	}
1718
	if ( readtype != SPKREAD_ALL && progress )
1631
	// no compression
-
 
1632
	else
1719
		progress->UpdateProgress(3, maxProgress);
1633
		ReadValues ( CyString ((char *)readData) );
1720
 
1634
 
1721
	if ( readtype == SPKREAD_VALUES )
-
 
1722
		return true;
1635
	delete readData;
1723
 
1636
 
1724
	// next should be the next header
-
 
1725
	if ( !ParseFileHeader ( GetEndOfLine (id, NULL, false) ) )
-
 
1726
		return false;
1637
	return doneLen;
-
 
1638
}
1727
 
1639
 
-
 
1640
int CBaseFile::_read_FileHeader(std::fstream &stream, int iReadType, int iMaxProgress, int iDoneLen, CProgressInfo *pProgress)
-
 
1641
{
1728
	// clear the current file list
1642
	unsigned char *readData;
-
 
1643
	try {
-
 
1644
		readData = new unsigned char[m_SHeader2.lSize];
-
 
1645
	}
1729
	m_lFiles.clear(true);
1646
	catch (std::exception &e) {
-
 
1647
		CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_FileHeader() unable to malloc [header], %d (%s)", m_SHeader2.lSize, e.what());
-
 
1648
		return -1;
-
 
1649
	}
1730
 
1650
 
1731
	// update the progress for each section
1651
	unsigned char size[4];
1732
	if ( readtype != SPKREAD_ALL && progress )
1652
	stream.read((char *)size, 4);
1733
		progress->UpdateProgress(4, maxProgress);
1653
	stream.read((char *)readData, m_SHeader2.lSize);
1734
 
1654
 
1735
	if ( m_SHeader2.lSize )
-
 
1736
	{
-
 
1737
		unsigned char *readData = new unsigned char[m_SHeader2.lSize];
-
 
1738
		unsigned char size[4];
-
 
1739
		fread ( size, 4, 1, id );
-
 
1740
		fread ( readData, sizeof(char), m_SHeader2.lSize, id );
-
 
1741
 
-
 
1742
		unsigned long uncomprLen = (size[0] << 24) + (size[1] << 16) + (size[2] << 8) + size[3];
1655
	unsigned long uncomprLen = (size[0] << 24) + (size[1] << 16) + (size[2] << 8) + size[3];
1743
		// check for zlib compression
-
 
1744
		if ( m_SHeader.iValueCompression == SPKCOMPRESS_ZLIB )
-
 
1745
		{
-
 
1746
 
1656
 
-
 
1657
	// check for zlib compression
1747
			if ( uncomprLen < (unsigned long)doneLen )
1658
	if ( m_SHeader.iValueCompression == SPKCOMPRESS_ZLIB ) {
1748
				uncomprLen = doneLen;
1659
		if ( uncomprLen < (unsigned long)iDoneLen ) uncomprLen = iDoneLen;
1749
 
1660
 
-
 
1661
		try {
1750
			unsigned char *uncompr = new unsigned char[uncomprLen];
1662
			unsigned char *uncompr = new unsigned char[uncomprLen];
1751
			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader2.lSize );
1663
			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader2.lSize );
1752
			// update the progress for each section
1664
			// update the progress for each section
1753
			if ( readtype != SPKREAD_ALL && progress )
-
 
1754
				progress->UpdateProgress(5, maxProgress);
1665
			if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(5, iMaxProgress);
1755
			if ( err == Z_OK )
-
 
1756
				ReadFiles ( CyString ((char *)uncompr) );
1666
			if ( err == Z_OK ) ReadFiles ( CyString ((char *)uncompr) );
1757
			delete uncompr;
1667
			delete uncompr;
1758
		}
1668
		}
1759
		else if ( m_SHeader.iValueCompression == SPKCOMPRESS_7ZIP )
-
 
1760
		{
-
 
1761
			long len = uncomprLen;
1669
		catch (std::exception &e) {
1762
			unsigned char *compr = LZMADecode_C ( readData, m_SHeader2.lSize, (size_t*)&len, NULL );
1670
			CLog::logf(CLog::Log_IO, 2, "CBaseFile::_read_FileHeader() unable to malloc [uncompr], %d (%s)", uncomprLen, e.what());
1763
			// update the progress for each section
-
 
1764
			if ( readtype != SPKREAD_ALL && progress )
-
 
1765
				progress->UpdateProgress(5, maxProgress);
-
 
1766
			if ( compr )
1671
			return -1;
1767
				ReadFiles ( CyString ((char *)compr) );
-
 
1768
		}
1672
		}
1769
		else
-
 
1770
			ReadFiles ( CyString ((char *)readData) );
-
 
1771
 
1673
 
1772
		delete readData;
-
 
1773
	}
1674
	}
-
 
1675
	else if ( m_SHeader.iValueCompression == SPKCOMPRESS_7ZIP )
-
 
1676
	{
-
 
1677
		long len = uncomprLen;
-
 
1678
		unsigned char *compr = LZMADecode_C ( readData, m_SHeader2.lSize, (size_t*)&len, NULL );
-
 
1679
		// update the progress for each section
-
 
1680
		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(5, iMaxProgress);
-
 
1681
		if ( compr ) ReadFiles ( CyString ((char *)compr) );
-
 
1682
	}
-
 
1683
	else
-
 
1684
		ReadFiles ( CyString ((char *)readData) );
-
 
1685
 
-
 
1686
	delete readData;
-
 
1687
	return true;
-
 
1688
}
-
 
1689
 
-
 
1690
bool CBaseFile::readFile(std::fstream &stream, int readtype, CProgressInfo *progress)
-
 
1691
{
-
 
1692
	ClearError ();
-
 
1693
 
-
 
1694
	// first read the header
-
 
1695
	if ( !ParseHeader(CBaseFile::readEndOfLine(stream, NULL, false)) ) return false;
-
 
1696
	if ( readtype == SPKREAD_HEADER ) return true;
-
 
1697
 
-
 
1698
	// update the progress for each section
-
 
1699
	int maxProgress = (readtype == SPKREAD_VALUES) ? 3 : 6;
-
 
1700
	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(1, maxProgress);
-
 
1701
 
-
 
1702
	long doneLen = 0;
-
 
1703
	// next read the data values for the spk files
-
 
1704
	if ( m_SHeader.lValueCompressSize ) doneLen = this->_read_Header(stream, readtype, maxProgress, progress);
-
 
1705
 
-
 
1706
	// update the progress for each section
-
 
1707
	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(3, maxProgress);
-
 
1708
	if ( readtype == SPKREAD_VALUES ) return true;
-
 
1709
 
-
 
1710
	// next should be the next header
-
 
1711
	if ( !ParseFileHeader(CBaseFile::readEndOfLine(stream, NULL, false)) ) return false;
-
 
1712
 
-
 
1713
	// clear the current file list
-
 
1714
	m_lFiles.clear(true);
-
 
1715
 
-
 
1716
	// update the progress for each section
-
 
1717
	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(4, maxProgress);
-
 
1718
 
-
 
1719
	if ( m_SHeader2.lSize ) this->_read_FileHeader(stream, readtype, maxProgress, doneLen, progress);
1774
 
1720
 
1775
	// file mismatch
1721
	// file mismatch
1776
	long numfiles = m_lFiles.size();
1722
	long numfiles = m_lFiles.size();
1777
	if ( m_pIconFile )
1723
	if ( m_pIconFile ) ++numfiles;
1778
		++numfiles;
-
 
1779
	if ( m_SHeader2.iNumFiles != numfiles )
1724
	if ( m_SHeader2.iNumFiles != numfiles ) {
1780
	{
-
 
1781
		m_iLastError = SPKERR_FILEMISMATCH;
1725
		m_iLastError = SPKERR_FILEMISMATCH;
1782
		return false;
1726
		return false;
1783
	}
1727
	}
1784
 
1728
 
1785
	// update the progress for each section
1729
	// update the progress for each section
1786
	if ( readtype != SPKREAD_ALL && progress )
-
 
1787
		progress->UpdateProgress(6, maxProgress);
1730
	if ( readtype != SPKREAD_ALL && progress )	progress->UpdateProgress(6, maxProgress);
1788
 
1731
 
1789
	if ( readtype == SPKREAD_ALL )
1732
	if ( readtype == SPKREAD_ALL ) {
1790
	{
-
 
1791
		int fileCount = 2;
1733
		int fileCount = 2;
1792
		if ( m_pIconFile )
-
 
1793
			m_pIconFile->ReadFromFile ( id, m_pIconFile->GetDataSize() );
1734
		if ( m_pIconFile ) m_pIconFile->readFromFile(stream, m_pIconFile->GetDataSize() );
1794
 
1735
 
1795
		// ok finally we need to read all the files
1736
		// ok finally we need to read all the file
1796
 
-
 
1797
		for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
1737
		for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
1798
		{
-
 
1799
			node->Data()->ReadFromFile ( id, node->Data()->GetDataSize() );
1738
			node->Data()->readFromFile(stream, node->Data()->GetDataSize() );
1800
			if ( progress )
-
 
1801
				progress->UpdateProgress(fileCount++, m_lFiles.size() + 2);
1739
			if ( progress )	progress->UpdateProgress(fileCount++, m_lFiles.size() + 2);
1802
		}
1740
		}
1803
 
1741
 
1804
		m_bFullyLoaded = true;
1742
		m_bFullyLoaded = true;
1805
	}
1743
	}
1806
 
1744