Subversion Repositories spk

Rev

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

Rev 49 Rev 50
Line 41... Line 41...
41
	m_bAutoGenerateUpdateFile = false;
41
	m_bAutoGenerateUpdateFile = false;
42
	m_SHeader.iValueCompression = SPKCOMPRESS_ZLIB;
42
	m_SHeader.iValueCompression = SPKCOMPRESS_ZLIB;
43
	m_SHeader2.iFileCompression = SPKCOMPRESS_ZLIB;
43
	m_SHeader2.iFileCompression = SPKCOMPRESS_ZLIB;
44
	m_SHeader2.iDataCompression = SPKCOMPRESS_LZMA;
44
	m_SHeader2.iDataCompression = SPKCOMPRESS_LZMA;
45
	m_pParent = NULL;
45
	m_pParent = NULL;
46
	m_bChanged = false;
46
	_changed();
47
	m_bUpdate = false;
47
	m_bUpdate = false;
48
 
48
 
49
	ClearError();
49
	ClearError();
50
 
50
 
51
	m_iLoadError = 0;
51
	m_iLoadError = 0;
Line 84... Line 84...
84
	{
84
	{
85
		SNames *n = node->Data();
85
		SNames *n = node->Data();
86
		if ( n->iLanguage == lang )
86
		if ( n->iLanguage == lang )
87
			return n->sName;
87
			return n->sName;
88
	}
88
	}
89
	return m_sName;
89
	return this->name();
90
}
90
}
91
 
91
 
92
 
92
 
93
/*
93
/*
94
##########################################################################################
94
##########################################################################################
Line 203... Line 203...
203
	}
203
	}
204
}
204
}
205
 
205
 
206
CyString CBaseFile::GetNameValidFile ()
206
CyString CBaseFile::GetNameValidFile ()
207
{
207
{
208
	CyString name = m_sName;
208
	CyString name = this->name();
209
	name.RemoveChar ( ':' );
209
	name.RemoveChar ( ':' );
210
	name.RemoveChar ( '/' );
210
	name.RemoveChar ( '/' );
211
	name.RemoveChar ( '\\' );
211
	name.RemoveChar ( '\\' );
212
	name.RemoveChar ( '*' );
212
	name.RemoveChar ( '*' );
213
	name.RemoveChar ( '?' );
213
	name.RemoveChar ( '?' );
Line 260... Line 260...
260
		m_lFiles.remove(node, true);
260
		m_lFiles.remove(node, true);
261
		break;
261
		break;
262
	}
262
	}
263
 
263
 
264
	file->UpdateSigned();
264
	file->UpdateSigned();
265
	m_bChanged = true;
265
	_changed();
266
	m_lFiles.push_back ( file );
266
	m_lFiles.push_back ( file );
267
}
267
}
268
 
268
 
269
C_File *CBaseFile::AddFile ( CyString file, CyString dir, int type, int game )
269
C_File *CBaseFile::AddFile ( CyString file, CyString dir, int type, int game )
270
{
270
{
Line 289... Line 289...
289
		// must already exist, delete this one
289
		// must already exist, delete this one
290
		m_lFiles.remove(node, true);
290
		m_lFiles.remove(node, true);
291
		break;
291
		break;
292
	}
292
	}
293
 
293
 
294
	m_bChanged = true;
294
	_changed();
295
	newfile->UpdateSigned();
295
	newfile->UpdateSigned();
296
	m_lFiles.push_back ( newfile );
296
	m_lFiles.push_back ( newfile );
297
 
297
 
298
	return newfile;
298
	return newfile;
299
}
299
}
Line 407... Line 407...
407
	m_lFiles.erase ( pos + 1 );
407
	m_lFiles.erase ( pos + 1 );
408
 
408
 
409
	if ( file )
409
	if ( file )
410
		delete file;
410
		delete file;
411
 
411
 
412
	m_bChanged = true;
412
	_changed();
413
 
413
 
414
	return true;
414
	return true;
415
}
415
}
416
 
416
 
417
 
417
 
Line 430... Line 430...
430
			node->DeleteData();
430
			node->DeleteData();
431
	}
431
	}
432
 
432
 
433
	m_lFiles.RemoveEmpty();
433
	m_lFiles.RemoveEmpty();
434
 
434
 
435
	m_bChanged = true;
435
	_changed();
436
}
436
}
437
 
437
 
438
void CBaseFile::RecompressAllFiles ( int type, CProgressInfo *progress )
438
void CBaseFile::RecompressAllFiles ( int type, CProgressInfo *progress )
439
{
439
{
440
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
440
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
Line 583... Line 583...
583
	{
583
	{
584
		if ( n->iLanguage == lang )
584
		if ( n->iLanguage == lang )
585
		{
585
		{
586
			m_lNames.RemoveCurrent();
586
			m_lNames.RemoveCurrent();
587
			delete n;
587
			delete n;
588
			m_bChanged = true;
588
			_changed();
589
		}
589
		}
590
	}
590
	}
591
}
591
}
592
 
592
 
593
void CBaseFile::AddLanguageName ( int lang, const Utils::String &name )
593
void CBaseFile::AddLanguageName ( int lang, const Utils::String &name )
Line 607... Line 607...
607
	n = new SNames;
607
	n = new SNames;
608
	n->iLanguage = lang;
608
	n->iLanguage = lang;
609
	n->sName = name;
609
	n->sName = name;
610
	m_lNames.push_back ( n );
610
	m_lNames.push_back ( n );
611
 
611
 
612
	m_bChanged = true;
612
	_changed();
613
}
613
}
614
 
614
 
615
CyString CBaseFile::GetFullPackageName(CyString format, int lang)
615
CyString CBaseFile::GetFullPackageName(CyString format, int lang)
616
{
616
{
617
	if ( format.Empty() )
617
	if ( format.Empty() )
618
		return GetFullPackageName(lang);
618
		return GetFullPackageName(lang);
619
 
619
 
620
	CyString args[3] = { this->GetLanguageName(lang), this->GetVersion(), this->GetAuthor() };
620
	CyString args[3] = { this->GetLanguageName(lang), this->version(), this->author() };
621
	return format.Args(args, 3);
621
	return format.Args(args, 3);
622
}
622
}
623
 
623
 
624
/*
624
/*
625
	Func:   CreateFilesLine
625
	Func:   CreateFilesLine
Line 719... Line 719...
719
*/
719
*/
720
 
720
 
721
void CBaseFile::ReadAllFilesToMemory ()
721
void CBaseFile::ReadAllFilesToMemory ()
722
{
722
{
723
	// no file to read from
723
	// no file to read from
724
	if ( m_sFilename.Empty() )
724
	if ( this->filename().empty() ) return;
725
		return;
-
 
726
 
725
 
727
	// now open the file
726
	// now open the file
728
	FILE *id = fopen ( m_sFilename.c_str(), "rb" );
727
	FILE *id = fopen ( this->filename().c_str(), "rb" );
729
	if ( !id )
728
	if ( !id )
730
		return;
729
		return;
731
 
730
 
732
	// read the header
731
	// read the header
733
	GetEndOfLine ( id, NULL, false );
732
	GetEndOfLine ( id, NULL, false );
Line 770... Line 769...
770
bool CBaseFile::ReadFileToMemory(C_File *f)
769
bool CBaseFile::ReadFileToMemory(C_File *f)
771
{
770
{
772
	if ( f->GetData() && f->GetDataSize() )
771
	if ( f->GetData() && f->GetDataSize() )
773
		return true;
772
		return true;
774
	// no file to read from
773
	// no file to read from
775
	if ( m_sFilename.Empty() || !f )
774
	if ( this->filename().empty() || !f )
776
		return false;
775
		return false;
777
 
776
 
778
	// check the file is part of the package
777
	// check the file is part of the package
779
	if ( !m_lFiles.FindData(f) )
778
	if ( !m_lFiles.FindData(f) )
780
		return false;
779
		return false;
781
 
780
 
782
	// now open the file
781
	// now open the file
783
	FILE *id = fopen ( m_sFilename.c_str(), "rb" );
782
	FILE *id = fopen ( this->filename().c_str(), "rb" );
784
	if ( !id )
783
	if ( !id )
785
		return false;
784
		return false;
786
 
785
 
787
	// read the header
786
	// read the header
788
	GetEndOfLine ( id, NULL, false );
787
	GetEndOfLine ( id, NULL, false );
Line 823... Line 822...
823
}
822
}
824
 
823
 
825
void CBaseFile::ReadIconFileToMemory ()
824
void CBaseFile::ReadIconFileToMemory ()
826
{
825
{
827
	// no file to read from
826
	// no file to read from
828
	if ( m_sFilename.Empty() )
827
	if ( this->filename().empty() )
829
		return;
828
		return;
830
 
829
 
831
	if ( !m_pIconFile )
830
	if ( !m_pIconFile )
832
		return;
831
		return;
833
 
832
 
834
	// now open the file
833
	// now open the file
835
	FILE *id = fopen ( m_sFilename.c_str(), "rb" );
834
	FILE *id = fopen ( this->filename().c_str(), "rb" );
836
	if ( !id )
835
	if ( !id )
837
		return;
836
		return;
838
 
837
 
839
	// read the header
838
	// read the header
840
	GetEndOfLine ( id, NULL, false );
839
	GetEndOfLine ( id, NULL, false );
Line 889... Line 888...
889
			lPatches.PushBack(fit->GetBaseName(), newname);
888
			lPatches.PushBack(fit->GetBaseName(), newname);
890
		}
889
		}
891
 
890
 
892
		// rename the file
891
		// rename the file
893
		fit->FixOriginalName();
892
		fit->FixOriginalName();
-
 
893
		CLog::logf(CLog::Log_Install, 2, "Adjusting fake patch number, %s => %s", fit->GetNameDirectory(this).c_str(), (newname + "." + fit->GetFileExt()).c_str());
894
		fit->SetName ( newname + "." + fit->GetFileExt() );
894
		fit->SetName ( newname + "." + fit->GetFileExt() );
895
 
895
 
896
		// find the next gap
896
		// find the next gap
897
		if ( !opposite ) {
897
		if ( !opposite ) {
898
			startfake = pPackages->FindNextFakePatch(startfake + 1);
898
			startfake = pPackages->FindNextFakePatch(startfake + 1);
Line 909... Line 909...
909
		if ( !fit->IsAutoTextFile() )
909
		if ( !fit->IsAutoTextFile() )
910
			continue;
910
			continue;
911
 
911
 
912
		CyString newname = SPK::FormatTextName(starttext, pPackages->GetLanguage(), (pPackages->GetCurrentGameFlags() & EXEFLAG_TCTEXT));
912
		CyString newname = SPK::FormatTextName(starttext, pPackages->GetLanguage(), (pPackages->GetCurrentGameFlags() & EXEFLAG_TCTEXT));
913
		fit->FixOriginalName();
913
		fit->FixOriginalName();
-
 
914
		CLog::logf(CLog::Log_Install, 2, "Adjusting text file, %s => %s", fit->GetNameDirectory(this).c_str(), (newname + "." + fit->GetFileExt()).c_str());
914
		fit->SetName ( newname + "." + fit->GetFileExt() );
915
		fit->SetName ( newname + "." + fit->GetFileExt() );
915
 
916
 
916
		++starttext;
917
		++starttext;
917
	}
918
	}
918
}
919
}
919
 
920
 
-
 
921
bool CBaseFile::_install_setEnabled(bool bEnable, C_File *fit)
-
 
922
{
-
 
923
	if ( !bEnable )
-
 
924
	{
-
 
925
		if ( (fit->GetFileType() == FILETYPE_UNINSTALL) || (fit->GetFileType() == FILETYPE_README) || (fit->GetFileType() == FILETYPE_ADVERT) )
-
 
926
			bEnable = true;
-
 
927
		else if ( (fit->GetFileType() == FILETYPE_EXTRA) && (fit->GetDir().Left(7).ToLower() == "Extras/") )
-
 
928
			bEnable = true;
-
 
929
		else if ( (IsPatch()) && (fit->GetFileType() == FILETYPE_MOD) && (!fit->IsFakePatch()) )
-
 
930
			bEnable = true;
-
 
931
 
-
 
932
		if ( bEnable ) CLog::logf(CLog::Log_Install, 3, "Filetype(%d) is always enabled, setting enabled flag", fit->GetFileType());
-
 
933
	}
-
 
934
 
-
 
935
	return bEnable;
-
 
936
}
-
 
937
 
-
 
938
bool CBaseFile::_install_uncompress(C_File *fit, CProgressInfo *progress, CyStringList *errorStr, bool *uncomprToFile)
-
 
939
{
-
 
940
	*uncomprToFile = false;
-
 
941
	m_sLastError = fit->GetNameDirectory(this);
-
 
942
	m_iLastError = SPKERR_UNCOMPRESS;
-
 
943
	if ( !fit->UncompressData ( progress ) )
-
 
944
	{
-
 
945
		CLog::log(CLog::Log_Install, 2, "Failed to uncompress data, attempting file decompression");
-
 
946
		if ( fit->GetCompressionType() == SPKCOMPRESS_7ZIP )
-
 
947
		{
-
 
948
			if ( fit->UncompressToFile ( NullString, this, false, progress ) )
-
 
949
				*uncomprToFile = true;
-
 
950
		}
-
 
951
 
-
 
952
		if ( !uncomprToFile )
-
 
953
		{
-
 
954
			if ( errorStr )
-
 
955
				errorStr->PushBack(m_sLastError, ERRORLOG(SPKINSTALL_UNCOMPRESS_FAIL));
-
 
956
			CLog::log(CLog::Log_Install, 1, "Unable to decompress file, skipping");
-
 
957
			return false;
-
 
958
		}
-
 
959
	}
-
 
960
	ClearError ();
-
 
961
 
-
 
962
	return true;
-
 
963
}
-
 
964
 
-
 
965
bool CBaseFile::_install_checkVersion(C_File *pFile, const Utils::String &sDestination)
-
 
966
{
-
 
967
	// new check if we should install the file
-
 
968
	// first get the version
-
 
969
	if ( !m_bOverrideFiles && pFile->ReadScriptVersion() )
-
 
970
	{
-
 
971
		CLog::log(CLog::Log_Install, 2, "Checking for existing file version");
-
 
972
		C_File checkfile;
-
 
973
		CyString checkfilename = sDestination;
-
 
974
		if ( !checkfilename.Empty() ) checkfilename += "/";
-
 
975
		checkfilename += pFile->GetNameDirectory(this);
-
 
976
		checkfile.SetFilename ( checkfilename );
-
 
977
		checkfile.SetFileType ( pFile->GetFileType() );
-
 
978
		if ( checkfile.CheckValidFilePointer() ) {
-
 
979
			if ( checkfile.ReadScriptVersion() > pFile->GetVersion() ) {
-
 
980
				CLog::log(CLog::Log_Install, 1, "Newer version of the file found in directory, skipping");
-
 
981
				return false;
-
 
982
			}
-
 
983
		}
-
 
984
	}
-
 
985
 
-
 
986
	return true;
-
 
987
}
-
 
988
 
-
 
989
Utils::String CBaseFile::_install_adjustFilepointer(C_File *pFile, bool bEnabled, const Utils::String &sDestination)
-
 
990
{
-
 
991
	CyString filename = sDestination;
-
 
992
	if ( !filename.Empty() ) filename += "/";
-
 
993
 
-
 
994
	if ( (IsPatch()) && (pFile->GetFileType() == FILETYPE_MOD) )
-
 
995
		pFile->SetDir ( CyString("Patch") );
-
 
996
 
-
 
997
	if ( pFile->IsInMod() )
-
 
998
	{
-
 
999
		if ( bEnabled )
-
 
1000
			pFile->SetFilename(filename + pFile->GetInMod() + "::" + pFile->GetNameDirectory(this));
-
 
1001
		else
-
 
1002
			pFile->SetFilename(filename + "PluginManager/DisabledFiles.cat::" + pFile->GetNameDirectory(this));
-
 
1003
	}
-
 
1004
	else
-
 
1005
		pFile->SetFilename ( filename + pFile->GetNameDirectory(this) );
-
 
1006
 
-
 
1007
	if ( !bEnabled )
-
 
1008
	{
-
 
1009
		if ( !pFile->IsInMod() )
-
 
1010
		{
-
 
1011
			if ( pFile->IsFakePatch() )
-
 
1012
				pFile->SetFilename ( filename + "PluginManager/Disabled/FakePatches/FakePatch_" + this->GetNameValidFile() + "_" + this->author() + "_" + pFile->GetName() );
-
 
1013
			else if ( pFile->IsAutoTextFile() )
-
 
1014
				pFile->SetFilename ( filename + "PluginManager/Disabled/TextFiles/Text_" + this->GetNameValidFile() + "_" + this->author() + "_" + pFile->GetName() );
-
 
1015
			else
-
 
1016
				pFile->SetFullDir ( filename + "PluginManager/Disabled/" + pFile->GetDirectory(this) );
-
 
1017
		}
-
 
1018
		pFile->SetDisabled(true);
-
 
1019
	}
-
 
1020
 
-
 
1021
	CLog::logf(CLog::Log_Install, 2, "Adjusting the file pointer to correct install destintation, %s", pFile->GetFilePointer().c_str());
-
 
1022
 
-
 
1023
	return filename.ToString();
-
 
1024
}
-
 
1025
 
-
 
1026
C_File *CBaseFile::_install_checkFile(C_File *pFile, CyStringList *errorStr, bool *bDoFile, CLinkList<C_File> *pFileList)
-
 
1027
{
-
 
1028
	if ( !pFile->IsFakePatch() && pFile->GetFileType() != FILETYPE_README )
-
 
1029
	{
-
 
1030
		C_File *cFile;
-
 
1031
		for ( cFile = pFileList->First(); cFile; cFile = pFileList->Next() )
-
 
1032
		{
-
 
1033
			if ( !cFile->MatchFile(pFile) ) continue;
-
 
1034
 
-
 
1035
			if ( !m_bOverrideFiles && !cFile->CompareNew(pFile) ) {
-
 
1036
				if ( errorStr ) errorStr->PushBack(pFile->GetNameDirectory(this), ERRORLOG(SPKINSTALL_SKIPFILE));
-
 
1037
				CLog::log(CLog::Log_Install, 1, "Newer version of the file already installed, skipping");
-
 
1038
				*bDoFile = false;
-
 
1039
			}
-
 
1040
			break;
-
 
1041
		}
-
 
1042
 
-
 
1043
		return cFile;
-
 
1044
	}
-
 
1045
 
-
 
1046
	return NULL;
-
 
1047
}
-
 
1048
 
-
 
1049
bool CBaseFile::_install_checkFileEnable(C_File *pCheckFile, C_File *fit, const Utils::String &sDestination, bool bEnabled, CyStringList *errorStr)
-
 
1050
{
-
 
1051
	// found a file, check if its in the disabled directory
-
 
1052
	CyString dir = pCheckFile->GetFilePointer();
-
 
1053
	dir = dir.GetToken ( 1, dir.NumToken ('/') - 1, '/' );
-
 
1054
	CyString lastDir = dir.GetToken ( dir.NumToken('/'), '/' ).ToLower();
-
 
1055
 
-
 
1056
	// if its disabled, rename it so its enabled
-
 
1057
	if ( ((pCheckFile->IsDisabled()) || (lastDir == "disabled") || (dir.ToLower().IsIn ("/disabled/"))) && (bEnabled) )
-
 
1058
	{
-
 
1059
		CLog::logf(CLog::Log_Install, 2, "Existing file, %s, is disabled, re-enabling it", pCheckFile->GetFilePointer().c_str());
-
 
1060
		// first check if the directory exists
-
 
1061
		if ( pCheckFile->IsInMod() ) {
-
 
1062
			CyString tofile = pCheckFile->GetFilePointer().GetToken("::", 2, 2);
-
 
1063
 
-
 
1064
			CCatFile tocat;
-
 
1065
			int err = tocat.Open ( fit->GetFilePointer().GetToken("::", 1, 1), "", CATREAD_CATDECRYPT, true );
-
 
1066
			if ( (err == CATERR_NONE) || (err == CATERR_CREATED) ) {
-
 
1067
				tocat.AppendFile ( pCheckFile->GetFilePointer(), tofile );
-
 
1068
				CLog::logf(CLog::Log_Install, 2, "Adding existing file into new mod File, %s => %s", fit->GetFilePointer().GetToken("::", 1, 1).c_str(), tofile.c_str());
-
 
1069
			}
-
 
1070
 
-
 
1071
			CCatFile fromcat;
-
 
1072
			err = fromcat.Open ( pCheckFile->GetFilePointer().GetToken("::", 1, 1), "", CATREAD_CATDECRYPT, false );
-
 
1073
			if ( err == CATERR_NONE ) {
-
 
1074
				fromcat.RemoveFile(tofile);
-
 
1075
				CLog::logf(CLog::Log_Install, 2, "Removing file from existing mod, %s::%s", pCheckFile->GetFilePointer().GetToken("::", 1, 1).c_str(), tofile.c_str());
-
 
1076
			}
-
 
1077
 
-
 
1078
			CLog::logf(CLog::Log_Install, 1, "Adjusting existing file name %s => %s", pCheckFile->GetFilePointer().c_str(), fit->GetFilePointer().c_str());
-
 
1079
			pCheckFile->SetFilename ( fit->GetFilePointer() );
-
 
1080
			CLog::logf(CLog::Log_Install, 2, "Adjusting In Mod setting, %s => %s", pCheckFile->GetInMod().c_str(), fit->GetInMod().c_str());
-
 
1081
			pCheckFile->SetInMod(fit->GetInMod());
-
 
1082
		}
-
 
1083
		else {
-
 
1084
			CyString to = pCheckFile->GetDirectory(this);
-
 
1085
			CDirIO Dir(sDestination);
-
 
1086
			if ( !Dir.Exists(to) ) {
-
 
1087
				if ( !Dir.Create ( to ) ) {
-
 
1088
					if ( errorStr )	errorStr->PushBack(to, ERRORLOG(SPKINSTALL_CREATEDIRECTORY_FAIL));
-
 
1089
					return false;
-
 
1090
				}
-
 
1091
				if ( errorStr )	errorStr->PushBack(to, ERRORLOG(SPKINSTALL_CREATEDIRECTORY));
-
 
1092
			}
-
 
1093
 
-
 
1094
			CyString destfile = CyString(sDestination) + "/" + pCheckFile->GetNameDirectory(this);
-
 
1095
			if ( CFileIO(destfile).Exists() ) CFileIO(destfile).Remove();
-
 
1096
			CLog::logf(CLog::Log_Install, 1, "Adjusting existing filename, %s => %s", pCheckFile->GetFilePointer().c_str(), destfile.c_str());
-
 
1097
			rename ( pCheckFile->GetFilePointer().c_str(), destfile.c_str() );
-
 
1098
			pCheckFile->SetFilename ( CyString(sDestination) + "/" + pCheckFile->GetNameDirectory(this) );
-
 
1099
		}
-
 
1100
		pCheckFile->SetDisabled(false);
-
 
1101
 
-
 
1102
		if ( errorStr ) errorStr->PushBack(pCheckFile->GetNameDirectory(this), ERRORLOG(SPKINSTALL_ENABLEFILE));
-
 
1103
	}
-
 
1104
 
-
 
1105
	return true;
-
 
1106
}
920
bool CBaseFile::InstallFiles ( CyString destdir, CProgressInfo *progress, CLinkList<C_File> *filelist, CyStringList *errorStr, bool enabled, CPackages *packages )
1107
bool CBaseFile::InstallFiles ( CyString destdir, CProgressInfo *progress, CLinkList<C_File> *filelist, CyStringList *errorStr, bool enabled, CPackages *packages )
921
{
1108
{
-
 
1109
	//TODO: add errorStr and progress as member variables
922
	if ( enabled ) {
1110
	if ( enabled ) {
923
		this->_install_adjustFakePatches(packages);
1111
		this->_install_adjustFakePatches(packages);
924
		if ( packages ) this->_install_renameText(packages);
1112
		if ( packages ) this->_install_renameText(packages);
925
	}
1113
	}
926
 
1114
 
-
 
1115
	bool bFailed = false;
-
 
1116
 
927
	CDirIO Dir(destdir);
1117
	CDirIO Dir(destdir);
928
	int fileCount = 0;
1118
	int fileCount = 0;
929
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
1119
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
930
	{
1120
	{
931
		C_File *fit = node->Data();
1121
		C_File *fit = node->Data();
932
		bool fileEnabled = enabled;
-
 
933
		if ( !fileEnabled )
-
 
934
		{
-
 
935
			if ( (fit->GetFileType() == FILETYPE_UNINSTALL) || (fit->GetFileType() == FILETYPE_README) || (fit->GetFileType() == FILETYPE_ADVERT) )
-
 
936
				fileEnabled = true;
-
 
937
			else if ( (fit->GetFileType() == FILETYPE_EXTRA) && (fit->GetDir().Left(7).ToLower() == "Extras/") )
-
 
938
				fileEnabled = true;
-
 
939
			else if ( (IsPatch()) && (fit->GetFileType() == FILETYPE_MOD) && (!fit->IsFakePatch()) )
-
 
940
				fileEnabled = true;
-
 
941
		}
-
 
942
 
1122
 
-
 
1123
		// start the install process, check if we need to the file enabled or disabled
-
 
1124
		CLog::logf(CLog::Log_Install, 1, "Preparing to install file: %s", fit->GetNameDirectory(this).c_str());
-
 
1125
		bool fileEnabled = _install_setEnabled(enabled, fit);
-
 
1126
 
-
 
1127
		// check if the file is for the correct game version
943
		if ( fit->GetGame() && packages->GetGame() ) {
1128
		if ( fit->GetGame() && packages->GetGame() ) {
944
			if ( fit->GetGame() != packages->GetGame() )
1129
			if ( fit->GetGame() != packages->GetGame() ) {
-
 
1130
				CLog::logf(CLog::Log_Install, 1, "File didn't match game version, skipping, %d != %d", fit->GetGame(), packages->GetGame());
945
				continue;
1131
				continue;
-
 
1132
			}
946
		}
1133
		}
947
 
1134
 
-
 
1135
		// update the progress display to show we are processing this file
948
		if ( progress )
1136
		if ( progress ) {
949
		{
-
 
950
			if ( progress->IsSecond() )
1137
			if ( progress->IsSecond() ) progress->SwitchSecond();
951
				progress->SwitchSecond();
-
 
952
			progress->UpdateFile ( fit );
1138
			progress->UpdateFile ( fit );
953
			progress->UpdateProgress(fileCount++, m_lFiles.size());
1139
			progress->UpdateProgress(fileCount++, m_lFiles.size());
954
			progress->SwitchSecond();
1140
			progress->SwitchSecond();
955
		}
1141
		}
956
 
1142
 
957
		// first uncompress the file
1143
		// first uncompress the file
958
		bool uncomprToFile = false;
1144
		//TODO: add this flag to C_File
959
		m_sLastError = fit->GetNameDirectory(this);
-
 
960
		m_iLastError = SPKERR_UNCOMPRESS;
-
 
961
		if ( !fit->UncompressData ( progress ) )
-
 
962
		{
-
 
963
			if ( fit->GetCompressionType() == SPKCOMPRESS_7ZIP )
-
 
964
			{
-
 
965
				if ( fit->UncompressToFile ( NullString, this, false, progress ) )
-
 
966
					uncomprToFile = true;
-
 
967
			}
-
 
968
 
-
 
969
			if ( !uncomprToFile )
1145
		bool uncomprToFile;
970
			{
-
 
971
				if ( errorStr )
-
 
972
					errorStr->PushBack(m_sLastError, ERRORLOG(SPKINSTALL_UNCOMPRESS_FAIL));
1146
		if ( !this->_install_uncompress(fit, progress, errorStr, &uncomprToFile) ) {
973
				return false;
1147
			bFailed = true;
974
			}
1148
			continue;
975
		}
1149
		}
976
		ClearError ();
-
 
977
		bool dofile = true;
-
 
978
 
1150
 
979
		// new check if we should install the file
-
 
980
		// first get the version
-
 
981
		if ( !m_bOverrideFiles && fit->ReadScriptVersion() )
-
 
982
		{
-
 
983
			C_File checkfile;
-
 
984
			CyString checkfilename = destdir;
-
 
985
			if ( !checkfilename.Empty() )
-
 
986
				checkfilename += "/";
-
 
987
			checkfilename += fit->GetNameDirectory(this);
-
 
988
			checkfile.SetFilename ( checkfilename );
-
 
989
			checkfile.SetFileType ( fit->GetFileType() );
-
 
990
			if ( checkfile.CheckValidFilePointer() )
-
 
991
			{
-
 
992
				if ( checkfile.ReadScriptVersion() > fit->GetVersion() )
1151
		bool dofile = _install_checkVersion(fit, destdir.ToString());
993
					dofile = false;
-
 
994
			}
-
 
995
		}
-
 
996
 
1152
 
997
		// change file pointer
1153
		// change file pointer
998
		CyString filename = destdir;
-
 
999
		if ( !filename.Empty() )
-
 
1000
			filename += "/";
-
 
1001
		if ( (IsPatch()) && (fit->GetFileType() == FILETYPE_MOD) )
-
 
1002
			fit->SetDir ( CyString("Patch") );
-
 
1003
 
-
 
1004
		if ( fit->IsInMod() )
-
 
1005
		{
-
 
1006
			if ( fileEnabled )
-
 
1007
				fit->SetFilename(filename + fit->GetInMod() + "::" + fit->GetNameDirectory(this));
1154
		Utils::String sFilename = _install_adjustFilepointer(fit, fileEnabled, destdir.ToString());
1008
			else
-
 
1009
				fit->SetFilename(filename + "PluginManager/DisabledFiles.cat::" + fit->GetNameDirectory(this));
-
 
1010
		}
-
 
1011
		else
-
 
1012
			fit->SetFilename ( filename + fit->GetNameDirectory(this) );
-
 
1013
 
-
 
1014
		if ( !fileEnabled )
-
 
1015
		{
-
 
1016
			if ( !fit->IsInMod() )
-
 
1017
			{
-
 
1018
				if ( fit->IsFakePatch() )
-
 
1019
					fit->SetFilename ( filename + "PluginManager/Disabled/FakePatches/FakePatch_" + this->GetNameValidFile() + "_" + m_sAuthor + "_" + fit->GetName() );
-
 
1020
				else if ( fit->IsAutoTextFile() )
-
 
1021
					fit->SetFilename ( filename + "PluginManager/Disabled/TextFiles/Text_" + this->GetNameValidFile() + "_" + m_sAuthor + "_" + fit->GetName() );
-
 
1022
				else
-
 
1023
					fit->SetFullDir ( filename + "PluginManager/Disabled/" + fit->GetDirectory(this) );
-
 
1024
			}
-
 
1025
			fit->SetDisabled(true);
-
 
1026
		}
-
 
1027
 
1155
 
1028
		C_File *adjustPointer = NULL;
1156
		C_File *adjustPointer = NULL;
1029
 
1157
 
1030
		bool checkFile = dofile;
1158
		bool checkFile = dofile;
1031
		if ( filelist )
1159
		if ( filelist ) {
1032
		{
-
 
1033
			C_File *cFile = NULL;
-
 
1034
			if ( checkFile )
-
 
1035
			{
-
 
1036
				if ( !fit->IsFakePatch() && fit->GetFileType() != FILETYPE_README )
-
 
1037
				{
-
 
1038
					for ( cFile = filelist->First(); cFile; cFile = filelist->Next() )
1160
			C_File *cFile = (checkFile) ? _install_checkFile(fit, errorStr, &dofile, filelist) : NULL;
1039
					{
-
 
1040
						if ( !cFile->MatchFile ( fit ) )
-
 
1041
							continue;
-
 
1042
 
-
 
1043
						if ( !m_bOverrideFiles && !cFile->CompareNew ( fit ) )
-
 
1044
						{
-
 
1045
							if ( errorStr )
-
 
1046
								errorStr->PushBack(fit->GetNameDirectory(this), ERRORLOG(SPKINSTALL_SKIPFILE));
-
 
1047
							dofile = false;
-
 
1048
						}
-
 
1049
						break;
-
 
1050
					}
-
 
1051
				}
-
 
1052
			}
-
 
1053
 
1161
 
1054
			// no matching file found, adding to main list
1162
			// no matching file found, adding to main list
1055
			if ( !cFile )
-
 
1056
				filelist->push_back ( fit );
1163
			if ( !cFile ) filelist->push_back ( fit );
1057
			else
1164
			else
1058
			{
1165
			{
1059
				// if the file is not enabled, we need to check for any that might be enabled
1166
				// if the file is not enabled, we need to check for any that might be enabled
1060
				if ( !fileEnabled )
1167
				if ( !fileEnabled ) //_install_checkDisabled(cFile, errorStr);
1061
				{
1168
				{
-
 
1169
					//TODO: check what this is actually doing
1062
					if ( !cFile->GetUsed() )
1170
					if ( !cFile->GetUsed() )
1063
					{
1171
					{
1064
						CFileIO rFile(cFile->GetFilePointer());
1172
						CFileIO rFile(cFile->GetFilePointer());
1065
						if ( rFile.Exists() )
1173
						if ( rFile.Exists() )
1066
						{
1174
						{
Line 1075... Line 1183...
1075
						cFile->SetFilename(fit->GetFilePointer());
1183
						cFile->SetFilename(fit->GetFilePointer());
1076
						cFile->SetDisabled(true);
1184
						cFile->SetDisabled(true);
1077
					}
1185
					}
1078
					else
1186
					else
1079
					{
1187
					{
1080
						fit->SetFullDir ( filename + fit->GetDirectory(this) );
1188
						cFile->SetFullDir ( CyString(sFilename) + fit->GetDirectory(this) );
1081
						fit->SetDisabled(false);
1189
						cFile->SetDisabled(false);
1082
					}
1190
					}
1083
				}
1191
				}
1084
				else
-
 
1085
				// move it to enabled
1192
				// move it to enabled
1086
				{
1193
				else {
1087
					// found a file, check if its in the disabled directory
-
 
1088
					CyString dir = cFile->GetFilePointer();
-
 
1089
					dir = dir.GetToken ( 1, dir.NumToken ('/') - 1, '/' );
-
 
1090
					CyString lastDir = dir.GetToken ( dir.NumToken('/'), '/' ).ToLower();
-
 
1091
 
-
 
1092
					// if its disabled, rename it so its enabled
-
 
1093
					if ( ((cFile->IsDisabled()) || (lastDir == "disabled") || (dir.ToLower().IsIn ("/disabled/"))) && (enabled) )
1194
					if ( !this->_install_checkFileEnable(cFile, fit, destdir.ToString(), fileEnabled, errorStr) ) {
1094
					{
-
 
1095
						// first check if the directory exists
-
 
1096
						if ( cFile->IsInMod() )
-
 
1097
						{
-
 
1098
							CyString tofile = cFile->GetFilePointer().GetToken("::", 2, 2);
-
 
1099
 
-
 
1100
							CCatFile tocat;
1195
						bFailed = true;
1101
							int err = tocat.Open ( fit->GetFilePointer().GetToken("::", 1, 1), "", CATREAD_CATDECRYPT, true );
-
 
1102
							if ( (err == CATERR_NONE) || (err == CATERR_CREATED) )
-
 
1103
							{
-
 
1104
								tocat.AppendFile ( cFile->GetFilePointer(), tofile );
-
 
1105
							}
-
 
1106
 
-
 
1107
							CCatFile fromcat;
-
 
1108
							err = fromcat.Open ( cFile->GetFilePointer().GetToken("::", 1, 1), "", CATREAD_CATDECRYPT, false );
-
 
1109
							if ( err == CATERR_NONE )
-
 
1110
							{
-
 
1111
								fromcat.RemoveFile(tofile);
-
 
1112
							}
-
 
1113
 
-
 
1114
							cFile->SetFilename ( fit->GetFilePointer() );
-
 
1115
							cFile->SetInMod(fit->GetInMod());
-
 
1116
						}
-
 
1117
						else
1196
						continue;
1118
						{
-
 
1119
							CyString to = cFile->GetDirectory(this);
-
 
1120
							CDirIO Dir(destdir);
-
 
1121
							if ( !Dir.Exists(to) )
-
 
1122
							{
-
 
1123
								if ( !Dir.Create ( to ) )
-
 
1124
								{
-
 
1125
									if ( errorStr )
-
 
1126
										errorStr->PushBack(to, ERRORLOG(SPKINSTALL_CREATEDIRECTORY_FAIL));
-
 
1127
									return false;
-
 
1128
								}
-
 
1129
								if ( errorStr )
-
 
1130
									errorStr->PushBack(to, ERRORLOG(SPKINSTALL_CREATEDIRECTORY));
-
 
1131
							}
-
 
1132
 
-
 
1133
							CyString destfile = destdir + "/" + cFile->GetNameDirectory(this);
-
 
1134
							if ( CFileIO(destfile).Exists() )
-
 
1135
								CFileIO(destfile).Remove();
-
 
1136
							rename ( cFile->GetFilePointer().c_str(), destfile.c_str() );
-
 
1137
							cFile->SetFilename ( destdir + "/" + cFile->GetNameDirectory(this) );
-
 
1138
						}
-
 
1139
						cFile->SetDisabled(false);
-
 
1140
 
-
 
1141
						if ( !dofile && errorStr )
-
 
1142
							errorStr->PushBack(cFile->GetNameDirectory(this), ERRORLOG(SPKINSTALL_ENABLEFILE));
-
 
1143
					}
1197
					}
1144
				}
1198
				}
1145
 
1199
 
1146
				adjustPointer = cFile;
1200
				adjustPointer = cFile;
1147
				if ( dofile )
-
 
1148
					adjustPointer->SetCreationTime ( fit->GetCreationTime() );
1201
				if ( dofile ) adjustPointer->SetCreationTime(fit->GetCreationTime());
1149
			}
1202
			}
1150
		}
1203
		}
1151
 
1204
 
1152
		if ( dofile )
1205
		if ( dofile )
1153
		{
1206
		{
Line 1182... Line 1235...
1182
			}
1235
			}
1183
			//otherwise, just extract the file
1236
			//otherwise, just extract the file
1184
			else
1237
			else
1185
			{
1238
			{
1186
				// old file is found in list, switch to using new one
1239
				// old file is found in list, switch to using new one
1187
				if ( (filelist) && (adjustPointer) )
1240
				if ( (filelist) && (adjustPointer) ) {
1188
					adjustPointer->CopyData(fit, false);
1241
					adjustPointer->CopyData(fit, false);
-
 
1242
					CLog::log(CLog::Log_Install, 2, "Copying data into existing file");
-
 
1243
				}
1189
 
1244
 
1190
				CyString fpointer = fit->GetFilePointer();
1245
				CyString fpointer = fit->GetFilePointer();
1191
				m_iLastError = SPKERR_CREATEDIRECTORY;
1246
				m_iLastError = SPKERR_CREATEDIRECTORY;
1192
				CyString dir = fit->GetFilePointer().GetToken ( "/", 1, fit->GetFilePointer().NumToken("/") - 1 );
1247
				CyString dir = fit->GetFilePointer().GetToken ( "/", 1, fit->GetFilePointer().NumToken("/") - 1 );
1193
 
1248
 
Line 1198... Line 1253...
1198
				m_sLastError = dir;
1253
				m_sLastError = dir;
1199
				if ( !dir.IsIn ( "::" ) )
1254
				if ( !dir.IsIn ( "::" ) )
1200
				{
1255
				{
1201
					if ( !Dir.Exists(dir) )
1256
					if ( !Dir.Exists(dir) )
1202
					{
1257
					{
-
 
1258
						CLog::logf(CLog::Log_Install, 2, "Creating directory to install file into, %s", dir.c_str());
1203
						if ( !Dir.Create(dir) )
1259
						if ( !Dir.Create(dir) )
1204
						{
1260
						{
1205
							if ( errorStr )
1261
							if ( errorStr )
1206
								errorStr->PushBack(dir, ERRORLOG(SPKINSTALL_CREATEDIRECTORY_FAIL));
1262
								errorStr->PushBack(dir, ERRORLOG(SPKINSTALL_CREATEDIRECTORY_FAIL));
1207
							return false;
1263
							return false;
1208
						}
1264
						}
1209
						if ( errorStr )
1265
						if ( errorStr )
1210
							errorStr->PushBack(dir, ERRORLOG(SPKINSTALL_CREATEDIRECTORY));
1266
							errorStr->PushBack(dir, ERRORLOG(SPKINSTALL_CREATEDIRECTORY));
1211
					}
1267
					}
1212
				}
1268
				}
1213
				else
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());
1214
					fit->SetFilename(CCatFile::PckChangeExtension(fit->GetFilePointer()));
1271
					fit->SetFilename(CCatFile::PckChangeExtension(fit->GetFilePointer()));
-
 
1272
				}
1215
 
1273
 
1216
				m_iLastError = SPKERR_WRITEFILE;
1274
				m_iLastError = SPKERR_WRITEFILE;
1217
				m_sLastError = fit->GetFilePointer();
1275
				m_sLastError = fit->GetFilePointer();
1218
				CyString sInstalledFile = fit->GetNameDirectory(this);
1276
				CyString sInstalledFile = fit->GetNameDirectory(this);
1219
				if ( fit->IsDisabled() )
1277
				if ( fit->IsDisabled() )
Line 1223... Line 1281...
1223
						sInstalledFile.Erase(0, 1);
1281
						sInstalledFile.Erase(0, 1);
1224
				}
1282
				}
1225
 
1283
 
1226
				if ( !fit->WriteFilePointer() )
1284
				if ( !fit->WriteFilePointer() )
1227
				{
1285
				{
-
 
1286
					CLog::log(CLog::Log_Install, 1, "Failed to write the file");
1228
					if ( errorStr )
1287
					if ( errorStr )
1229
						errorStr->PushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE_FAIL));
1288
						errorStr->PushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE_FAIL));
1230
				}
1289
				}
1231
				else
1290
				else
1232
				{
1291
				{
-
 
1292
					CLog::log(CLog::Log_Install, 1, "File written successfully");
-
 
1293
					CLog::log(CLog::Log_Install, 2, "Checking signed status of the file");
1233
					fit->UpdateSigned();
1294
					fit->UpdateSigned();
1234
					if ( errorStr )
1295
					if ( errorStr )
1235
						errorStr->PushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE));
1296
						errorStr->PushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE));
1236
 
1297
 
1237
					switch(fit->GetFileType())
1298
					switch(fit->GetFileType())
1238
					{
1299
					{
1239
						case FILETYPE_SCRIPT:
1300
						case FILETYPE_SCRIPT:
1240
						case FILETYPE_UNINSTALL:
1301
						case FILETYPE_UNINSTALL:
-
 
1302
							CLog::log(CLog::Log_Install, 2, "Updating file signature");
1241
							fit->UpdateSignature();
1303
							fit->UpdateSignature();
1242
							break;
1304
							break;
1243
					}
1305
					}
1244
				}
1306
				}
1245
			}
1307
			}
1246
			ClearError ();
1308
			ClearError ();
1247
		}
1309
		}
1248
 
1310
 
1249
		if ( adjustPointer )
1311
		if ( adjustPointer )
1250
		{
1312
		{
-
 
1313
			CLog::log(CLog::Log_Install, 2, "Adjusting pointers to existing file and deleting new file pointer");
1251
			node->ChangeData(adjustPointer);
1314
			node->ChangeData(adjustPointer);
1252
			delete fit;
1315
			delete fit;
1253
		}
1316
		}
-
 
1317
 
-
 
1318
		CLog::log(CLog::Log_Install, 1, "File installation completed");
1254
	}
1319
	}
1255
 
1320
 
1256
	// now clear or data memory
1321
	// now clear or data memory
-
 
1322
	CLog::log(CLog::Log_Install, 2, "Delting temporary file data from memory");
1257
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
1323
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
1258
	{
1324
	{
1259
		// add plugin manager file to identify fake patches
1325
		// add plugin manager file to identify fake patches
1260
		/*
1326
		/*
1261
		if ( fit->IsFakePatch() && fit->CheckFileExt ("cat") )
1327
		if ( fit->IsFakePatch() && fit->CheckFileExt ("cat") )
Line 1290... Line 1356...
1290
		}
1356
		}
1291
*/
1357
*/
1292
		node->Data()->DeleteData();
1358
		node->Data()->DeleteData();
1293
	}
1359
	}
1294
 
1360
 
-
 
1361
 
-
 
1362
 
1295
	return true;
1363
	return !bFailed;
1296
}
1364
}
1297
 
1365
 
1298
 
1366
 
1299
 
1367
 
1300
/*######################################################################################################*/
1368
/*######################################################################################################*/
Line 1358... Line 1426...
1358
bool CBaseFile::ParseValueLine(const Utils::String &sLine)
1426
bool CBaseFile::ParseValueLine(const Utils::String &sLine)
1359
{
1427
{
1360
	Utils::String first = sLine.token(" ", 1);
1428
	Utils::String first = sLine.token(" ", 1);
1361
	Utils::String rest  = sLine.tokens(" ", 2);
1429
	Utils::String rest  = sLine.tokens(" ", 2);
1362
 
1430
 
1363
	if ( first.Compare("Name:") )
1431
	if ( first.Compare("Name:") )					this->setName(rest);
1364
		m_sName = rest;
-
 
1365
	else if ( first.Compare("Author:") )
1432
	else if ( first.Compare("Author:") )			this->setAuthor(rest);
1366
		m_sAuthor = rest;
-
 
1367
	else if ( first.Compare("Version:") )
1433
	else if ( first.Compare("Version:") )			this->setVersion(rest);
1368
		m_sVersion = rest;
-
 
1369
	else if ( first.Compare("fGameVersion:") ) {
1434
	else if ( first.Compare("fGameVersion:") ) {
1370
		if ( m_lGames.Back() ) {
1435
		if ( m_lGames.Back() ) {
1371
			m_lGames.Back()->Data()->sVersion = rest;
1436
			m_lGames.Back()->Data()->sVersion = rest;
1372
		}
1437
		}
1373
	}
1438
	}
Line 1380... Line 1445...
1380
		this->AddGameCompatability(rest, "");
1445
		this->AddGameCompatability(rest, "");
1381
	else if ( first.Compare("GameCompat:") )
1446
	else if ( first.Compare("GameCompat:") )
1382
		this->AddGameCompatability(rest.token(" ", 1), rest.tokens(" ", 2));
1447
		this->AddGameCompatability(rest.token(" ", 1), rest.tokens(" ", 2));
1383
	else if ( first.Compare("GameCompatExact:") )
1448
	else if ( first.Compare("GameCompatExact:") )
1384
		this->AddGameCompatability(rest.token(" ", 1), rest.tokens(" ", 2));
1449
		this->AddGameCompatability(rest.token(" ", 1), rest.tokens(" ", 2));
1385
	else if ( first.Compare("Date:") )
1450
	else if ( first.Compare("Date:") )				this->setCreationDate(rest);
1386
		m_sCreationDate = rest;
-
 
1387
	else if ( first.Compare("WebAddress:") )		this->setWebAddress(rest);
1451
	else if ( first.Compare("WebAddress:") )		this->setWebAddress(rest);
1388
	else if ( first.Compare("WebSite:") )			this->setWebSite(rest);
1452
	else if ( first.Compare("WebSite:") )			this->setWebSite(rest);
1389
	else if ( first.Compare("Email:") )				this->setEmail(rest);
1453
	else if ( first.Compare("Email:") )				this->setEmail(rest);
1390
	else if ( first.Compare("WebMirror1:") || first.Compare("Mirror1:") || first.Compare("WebMirror:") )
1454
	else if ( first.Compare("WebMirror1:") || first.Compare("Mirror1:") || first.Compare("WebMirror:") )
1391
		this->AddWebMirror(rest);
1455
		this->AddWebMirror(rest);
Line 1582... Line 1646...
1582
	FILE *id = fopen ( filename.c_str(), "rb" );
1646
	FILE *id = fopen ( filename.c_str(), "rb" );
1583
	if ( !id )
1647
	if ( !id )
1584
		return false;
1648
		return false;
1585
 
1649
 
1586
	bool ret = ReadFile ( id, readtype, progress );
1650
	bool ret = ReadFile ( id, readtype, progress );
1587
	if ( ret )
-
 
1588
		m_sFilename = filename;
1651
	if ( ret ) this->setFilename(filename.ToString());
1589
 
1652
 
1590
	fclose ( id );
1653
	fclose ( id );
1591
 
1654
 
1592
	return ret;
1655
	return ret;
1593
}
1656
}
Line 1777... Line 1840...
1777
}
1840
}
1778
 
1841
 
1779
Utils::String CBaseFile::CreateValuesLine () const
1842
Utils::String CBaseFile::CreateValuesLine () const
1780
{
1843
{
1781
	Utils::String values("Name: ");
1844
	Utils::String values("Name: ");
1782
	values += Utils::String(m_sName.ToString()) + "\n";
1845
	values += this->name() + "\n";
1783
	values += Utils::String("Author: ") + m_sAuthor.ToString() + "\n";
1846
	values += "Author: " + this->author() + "\n";
1784
	values += Utils::String("Version: ") + m_sVersion.ToString() + "\n";
1847
	values += "Version: " + this->version() + "\n";
1785
	if ( !m_sCreationDate.Empty() )
-
 
1786
		values += Utils::String("Date: ") + m_sCreationDate.ToString() + "\n";
1848
	if ( !this->creationDate().empty() )values += "Date: "			+ this->creationDate()	+ "\n";
1787
 
-
 
1788
	if ( !this->webAddress().empty() )	values += "WebAddress: "	+ this->webAddress()	+ "\n";
1849
	if ( !this->webAddress().empty() )	values += "WebAddress: "	+ this->webAddress()	+ "\n";
1789
	if ( !this->webSite().empty() )		values += "WebSite: "		+ this->webSite()		+ "\n";
1850
	if ( !this->webSite().empty() )		values += "WebSite: "		+ this->webSite()		+ "\n";
1790
	if ( !this->email().empty() )		values += "Email: "			+ this->email()			+ "\n";
1851
	if ( !this->email().empty() )		values += "Email: "			+ this->email()			+ "\n";
1791
	if ( !this->forumLink().empty() )	values += "ForumLink: "		+ this->forumLink()		+ "\n";
1852
	if ( !this->forumLink().empty() )	values += "ForumLink: "		+ this->forumLink()		+ "\n";
1792
 
1853
 
Line 2020... Line 2081...
2020
				progress->IncDone((int)written);
2081
				progress->IncDone((int)written);
2021
		}
2082
		}
2022
 
2083
 
2023
	}
2084
	}
2024
 
2085
 
2025
	m_bChanged = false;
2086
	_changed();
2026
 
2087
 
2027
	return true;
2088
	return true;
2028
}
2089
}
2029
 
2090
 
2030
 
2091
 
Line 2076... Line 2137...
2076
 
2137
 
2077
 
2138
 
2078
bool CBaseFile::ExtractAll ( CyString dir, int game, bool includedir, CProgressInfo *progress )
2139
bool CBaseFile::ExtractAll ( CyString dir, int game, bool includedir, CProgressInfo *progress )
2079
{
2140
{
2080
	// no file to read from
2141
	// no file to read from
2081
	if ( m_sFilename.Empty() )
2142
	if ( this->filename().empty() )
2082
		return false;
2143
		return false;
2083
 
2144
 
2084
	// now open the file
2145
	// now open the file
2085
	FILE *id = fopen ( m_sFilename.c_str(), "rb" );
2146
	FILE *id = fopen ( this->filename().c_str(), "rb" );
2086
	if ( !id )
2147
	if ( !id )
2087
		return false;
2148
		return false;
2088
 
2149
 
2089
	fseek ( id, 0, SEEK_SET );
2150
	fseek ( id, 0, SEEK_SET );
2090
	// read the header
2151
	// read the header
Line 2308... Line 2369...
2308
		list->PushBack("# $PATH variable is used to get the current path");
2369
		list->PushBack("# $PATH variable is used to get the current path");
2309
		list->PushBack("Variable: $GAMEDIR $PATH");
2370
		list->PushBack("Variable: $GAMEDIR $PATH");
2310
		list->PushBack("");
2371
		list->PushBack("");
2311
	}
2372
	}
2312
	list->PushBack("# The name of the script");
2373
	list->PushBack("# The name of the script");
2313
	list->PushBack(CyString("Name: ") + m_sName);
2374
	list->PushBack(CyString("Name: ") + this->name());
2314
	list->PushBack("");
2375
	list->PushBack("");
2315
	list->PushBack("# The author of the script, ie, you");
2376
	list->PushBack("# The author of the script, ie, you");
2316
	list->PushBack(CyString("Author: ") + m_sAuthor);
2377
	list->PushBack(CyString("Author: ") + this->author());
2317
	list->PushBack("");
2378
	list->PushBack("");
2318
	list->PushBack("# The creation data, when it was created");
2379
	list->PushBack("# The creation data, when it was created");
2319
	if ( datafile )
2380
	if ( datafile )
2320
		list->PushBack(CyString("Date: ") + m_sCreationDate);
2381
		list->PushBack(CyString("Date: ") + this->creationDate());
2321
	else
2382
	else {
2322
	{
-
 
2323
		list->PushBack("# $DATE variable is used to get the current date");
2383
		list->PushBack("# $DATE variable is used to get the current date");
2324
		list->PushBack("Date: $DATE");
2384
		list->PushBack("Date: $DATE");
2325
	}
2385
	}
2326
	list->PushBack("");
2386
	list->PushBack("");
2327
	list->PushBack("# The version of script");
2387
	list->PushBack("# The version of script");
2328
	if ( datafile )
2388
	if ( datafile )
2329
		list->PushBack(CyString("Version: ") + m_sVersion);
2389
		list->PushBack(CyString("Version: ") + this->version());
2330
	else
2390
	else
2331
	{
2391
	{
2332
		list->PushBack("# $ASK variable is used to get an input when creating");
2392
		list->PushBack("# $ASK variable is used to get an input when creating");
2333
		list->PushBack("Version: $ASK");
2393
		list->PushBack("Version: $ASK");
2334
	}
2394
	}
Line 2524... Line 2584...
2524
	}
2584
	}
2525
 
2585
 
2526
	return true;
2586
	return true;
2527
}
2587
}
2528
 
2588
 
2529
CyString CBaseFile::GetAutosaveName()
2589
Utils::String CBaseFile::GetAutosaveName()
2530
{
2590
{
2531
	CyString cdate = m_sCreationDate;
-
 
2532
	cdate = cdate.FindReplace("/", ".");
-
 
2533
	CyString name = m_sName + "-V" + m_sVersion + "-" + cdate;
2591
	return this->name() + "-V" + this->version() + "-" + this->creationDate().findReplace("/", ".");
2534
 
-
 
2535
	return name;
-
 
2536
}
2592
}
2537
 
2593
 
2538
bool CBaseFile::CheckGameCompatability(int game)
2594
bool CBaseFile::CheckGameCompatability(int game)
2539
{
2595
{
2540
	if ( m_lGames.empty() )
2596
	if ( m_lGames.empty() )
Line 2575... Line 2631...
2575
bool CBaseFile::RemoveGameCompatability(int game)
2631
bool CBaseFile::RemoveGameCompatability(int game)
2576
{
2632
{
2577
	for ( CListNode<SGameCompat> *node = m_lGames.Front(); node; node = node->next() ) {
2633
	for ( CListNode<SGameCompat> *node = m_lGames.Front(); node; node = node->next() ) {
2578
		if ( node->Data()->iGame == game ) {
2634
		if ( node->Data()->iGame == game ) {
2579
			m_lGames.remove(node);
2635
			m_lGames.remove(node);
2580
			m_bChanged = true;
2636
			_changed();
2581
			return true;
2637
			return true;
2582
		}
2638
		}
2583
	}
2639
	}
2584
 
2640
 
2585
	return false;
2641
	return false;
Line 2611... Line 2667...
2611
 
2667
 
2612
	if ( version.isin(".") || !version.isNumber() )
2668
	if ( version.isin(".") || !version.isNumber() )
2613
		Found->sVersion = version;
2669
		Found->sVersion = version;
2614
	else
2670
	else
2615
		Found->iVersion = version;
2671
		Found->iVersion = version;
2616
	m_bChanged = true;
2672
	_changed();
2617
}
2673
}
2618
 
2674
 
2619
bool CBaseFile::LoadPackageData(const Utils::String &sFirst, const Utils::String &sRest)
2675
bool CBaseFile::LoadPackageData(const Utils::String &sFirst, const Utils::String &sRest)
2620
{
2676
{
2621
	if ( sFirst.Compare("Name") )
2677
	if ( sFirst.Compare("Name") )					this->setName(sRest);
2622
		m_sName = sRest;
-
 
2623
	else if ( sFirst.Compare("Author") )
2678
	else if ( sFirst.Compare("Author") )			this->setAuthor(sRest);
2624
		m_sAuthor = sRest;
-
 
2625
	else if ( sFirst.Compare("ScriptName") )
2679
	else if ( sFirst.Compare("ScriptName") )
2626
		AddLanguageName(ParseLanguage(sRest.token(" ", 1)), sRest.tokens(" ", 2));
2680
		AddLanguageName(ParseLanguage(sRest.token(" ", 1)), sRest.tokens(" ", 2));
2627
	else if ( sFirst.Compare("UninstallBefore") )	this->addUninstallText(ParseLanguage(sRest.token(" ", 1)), true, sRest.tokens(" ", 2));
2681
	else if ( sFirst.Compare("UninstallBefore") )	this->addUninstallText(ParseLanguage(sRest.token(" ", 1)), true, sRest.tokens(" ", 2));
2628
	else if ( sFirst.Compare("UninstallAfter") )	this->addUninstallText(ParseLanguage(sRest.token(" ", 1)), false, sRest.tokens(" ", 2));
2682
	else if ( sFirst.Compare("UninstallAfter") )	this->addUninstallText(ParseLanguage(sRest.token(" ", 1)), false, sRest.tokens(" ", 2));
2629
	else if ( sFirst.Compare("InstallBefore") )		this->addInstallText(ParseLanguage(sRest.token(" ", 1)), true, sRest.tokens(" ", 2));
2683
	else if ( sFirst.Compare("InstallBefore") )		this->addInstallText(ParseLanguage(sRest.token(" ", 1)), true, sRest.tokens(" ", 2));
2630
	else if ( sFirst.Compare("InstallAfter") )		this->addInstallText(ParseLanguage(sRest.token(" ", 1)), false, sRest.tokens(" ", 2));
2684
	else if ( sFirst.Compare("InstallAfter") )		this->addInstallText(ParseLanguage(sRest.token(" ", 1)), false, sRest.tokens(" ", 2));
2631
	else if ( sFirst.Compare("Date") )
2685
	else if ( sFirst.Compare("Date") )				this->setCreationDate(sRest);
2632
		m_sCreationDate = sRest;
-
 
2633
	else if ( sFirst.Compare("Version") )
2686
	else if ( sFirst.Compare("Version") )			this->setVersion(sRest);
2634
		m_sVersion = sRest;
-
 
2635
	// old version
-
 
2636
	else if ( sFirst.Compare("GameVersion") )
2687
	else if ( sFirst.Compare("GameVersion") )
2637
		this->AddGameCompatability(-1, sRest);
2688
		this->AddGameCompatability(-1, sRest);
2638
	else if ( sFirst.Compare("PluginType") )
2689
	else if ( sFirst.Compare("PluginType") ) {
2639
	{
-
 
2640
		if ( sRest.isNumber() )						this->setPluginType(sRest);
2690
		if ( sRest.isNumber() )						this->setPluginType(sRest);
2641
		else if ( sRest.Compare("Normal") )			this->setPluginType(PLUGIN_NORMAL);
2691
		else if ( sRest.Compare("Normal") )			this->setPluginType(PLUGIN_NORMAL);
2642
		else if ( sRest.Compare("Stable") )			this->setPluginType(PLUGIN_STABLE);
2692
		else if ( sRest.Compare("Stable") )			this->setPluginType(PLUGIN_STABLE);
2643
		else if ( sRest.Compare("Experimental") )	this->setPluginType(PLUGIN_EXPERIMENTAL);
2693
		else if ( sRest.Compare("Experimental") )	this->setPluginType(PLUGIN_EXPERIMENTAL);
2644
		else if ( sRest.Compare("Cheat") )			this->setPluginType(PLUGIN_CHEAT);
2694
		else if ( sRest.Compare("Cheat") )			this->setPluginType(PLUGIN_CHEAT);
Line 2653... Line 2703...
2653
		this->AddGameCompatability(CBaseFile::GetGameFromString(sGame), sRest.token(" ", 2));
2703
		this->AddGameCompatability(CBaseFile::GetGameFromString(sGame), sRest.token(" ", 2));
2654
	}
2704
	}
2655
	else if ( sFirst.Compare("Description") )		this->setDescription(sRest);
2705
	else if ( sFirst.Compare("Description") )		this->setDescription(sRest);
2656
	else if ( sFirst.Compare("AutoSave") || sFirst.Compare("AutoExport") || sFirst.Compare("AutoRarExport") || sFirst.Compare("AutoZipExport") )
2706
	else if ( sFirst.Compare("AutoSave") || sFirst.Compare("AutoExport") || sFirst.Compare("AutoRarExport") || sFirst.Compare("AutoZipExport") )
2657
	{
2707
	{
2658
		CyString filename = sRest;
2708
		Utils::String filename = sRest;
2659
		CyString name = m_sName;
-
 
2660
		CyString author = m_sAuthor;
-
 
2661
		CyString cdate = m_sCreationDate;
-
 
2662
		cdate = cdate.FindReplace("/", ".").Remove(" ");
2709
		Utils::String cdate = this->creationDate().findReplace("/", ".").remove(' ');
2663
		if ( filename.IsIn("$AUTOSAVE") )
2710
		if ( filename.isin("$AUTOSAVE") )
2664
		{
2711
		{
2665
			if ( this->GetType() )
2712
			if ( this->GetType() )
2666
				filename.FindReplace("$AUTOSAVE", "$NAME-V$VERSION-$CDATE.xsp");
2713
				filename = filename.findReplace("$AUTOSAVE", "$NAME-V$VERSION-$CDATE.xsp");
2667
			else
2714
			else
2668
				filename.FindReplace("$AUTOSAVE", "$NAME-V$VERSION-$CDATE.spk");
2715
				filename = filename.findReplace("$AUTOSAVE", "$NAME-V$VERSION-$CDATE.spk");
2669
		}
2716
		}
2670
		if ( filename.IsIn("$NAME") )
-
 
2671
			filename.FindReplace("$NAME", name.Remove(" "));
2717
		filename = filename.findReplace("$NAME", this->name().remove(' '));
2672
		if ( filename.IsIn("$AUTHOR") )
-
 
2673
			filename.FindReplace("$AUTHOR", author.Remove(" "));
2718
		filename = filename.findReplace("$AUTHOR", this->author().remove(' '));
2674
		if ( filename.IsIn("$DATE") )
-
 
2675
			filename.FindReplace("$DATE", cdate);
2719
		filename = filename.findReplace("$DATE", cdate);
2676
		if ( filename.IsIn("$CDATE") )
-
 
2677
			filename.FindReplace("$CDATE", cdate);
2720
		filename = filename.findReplace("$CDATE", cdate);
2678
		if ( filename.IsIn("$VERSION") )
-
 
2679
			filename.FindReplace("$VERSION", m_sVersion);
2721
		filename = filename.findReplace("$VERSION", this->version());
2680
 
2722
 
2681
		if ( sFirst.Compare("AutoZipExport") || sFirst.Compare("AutoExport") )
2723
		if ( sFirst.Compare("AutoZipExport") || sFirst.Compare("AutoExport") )
2682
			m_sExportFilename = CFileIO(filename).ChangeFileExtension("zip");
2724
			this->setExportFilename(CFileIO(filename).ChangeFileExtension("zip").ToString());
2683
		else if ( sFirst.Compare("AutoRarExport") )
2725
		else if ( sFirst.Compare("AutoRarExport") )
2684
			m_sExportFilename = CFileIO(filename).ChangeFileExtension("rar");
2726
			this->setExportFilename(CFileIO(filename).ChangeFileExtension("rar").ToString());
2685
		else
2727
		else
2686
			m_sFilename = filename;
2728
			this->setFilename(filename);
2687
	}
2729
	}
2688
	else if ( sFirst.Compare("WebSite") )		this->setWebSite(sRest);
2730
	else if ( sFirst.Compare("WebSite") )		this->setWebSite(sRest);
2689
	else if ( sFirst.Compare("ForumLink") || sFirst.Compare("Forum") ) this->setForumLink(sRest);
2731
	else if ( sFirst.Compare("ForumLink") || sFirst.Compare("Forum") ) this->setForumLink(sRest);
2690
	else if ( sFirst.Compare("Email") )			this->setEmail(sRest);
2732
	else if ( sFirst.Compare("Email") )			this->setEmail(sRest);
2691
	else if ( sFirst.Compare("WebAddress") )	this->setWebAddress(sRest);
2733
	else if ( sFirst.Compare("WebAddress") )	this->setWebAddress(sRest);
Line 2713... Line 2755...
2713
	{
2755
	{
2714
		CPackages p;
2756
		CPackages p;
2715
		CBaseFile *spk =  p.OpenPackage(sRest, 0, 0, SPKREAD_VALUES);
2757
		CBaseFile *spk =  p.OpenPackage(sRest, 0, 0, SPKREAD_VALUES);
2716
		if ( spk )
2758
		if ( spk )
2717
		{
2759
		{
2718
			this->AddNeededLibrary(spk->GetName().ToString(), spk->GetAuthor().ToString(), spk->GetVersion().ToString());
2760
			this->AddNeededLibrary(spk->name(), spk->author(), spk->version());
2719
			delete spk;
2761
			delete spk;
2720
		}
2762
		}
2721
	}
2763
	}
2722
	else if ( sFirst.Compare("Icon") )
2764
	else if ( sFirst.Compare("Icon") )
2723
	{
2765
	{
Line 2929... Line 2971...
2929
	f->ChangeBaseName(baseName);
2971
	f->ChangeBaseName(baseName);
2930
}
2972
}
2931
 
2973
 
2932
CyString CBaseFile::CreateUpdateFile(CyString dir)
2974
CyString CBaseFile::CreateUpdateFile(CyString dir)
2933
{
2975
{
2934
	CyString file = this->GetNameValidFile() + "_" + m_sAuthor + ".dat";
2976
	CyString file = this->GetNameValidFile() + "_" + this->author() + ".dat";
2935
	file.RemoveChar(' ');
2977
	file.RemoveChar(' ');
2936
 
2978
 
2937
	CyStringList write;
2979
	CyStringList write;
2938
	write.PushBack(CyString("Package: ") + m_sName);
2980
	write.PushBack(CyString("Package: ") + this->name());
2939
	write.PushBack(CyString("Author: ") + m_sAuthor);
2981
	write.PushBack(CyString("Author: ") + this->author());
2940
	write.PushBack(CyString("Version: ") + m_sVersion);
2982
	write.PushBack(CyString("Version: ") + this->version());
2941
	write.PushBack(CyString("File: ") + CFileIO(m_sFilename).GetFilename());
2983
	write.PushBack(CyString("File: ") + CFileIO(this->filename()).GetFilename());
2942
 
2984
 
2943
	CFileIO File(dir + "/" + file);
2985
	CFileIO File(dir + "/" + file);
2944
	if ( File.WriteFile(&write) )
2986
	if ( File.WriteFile(&write) )
2945
		return File.GetFullFilename();
2987
		return File.GetFullFilename();
2946
	return NullString;
2988
	return NullString;