Subversion Repositories spk

Rev

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

Rev 121 Rev 124
Line 743... Line 743...
743
	{
743
	{
744
		// lets check whats in the file first
744
		// lets check whats in the file first
745
		CCatFile openCat;
745
		CCatFile openCat;
746
		if ( openCat.Open(m_sCurrentDir + "/" + useFile + ".cat", addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE )
746
		if ( openCat.Open(m_sCurrentDir + "/" + useFile + ".cat", addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE )
747
		{
747
		{
748
			CLinkList<SInCatFile> *files = openCat.GetFiles();
748
			std::vector<SInCatFile *> *files = openCat.GetFiles();
749
			bool found = false;
749
			bool found = false;
750
			if ( files )
750
			if ( files )
751
			{
751
			{
752
				CyString useAddonDir = addonDir;
752
				Utils::String useAddonDir = addonDir.ToString();
753
				if ( !useAddonDir.Empty() ) useAddonDir += "\\";
753
				if ( !useAddonDir.empty() ) useAddonDir += "\\";
754
				for ( SInCatFile *inCat = files->First(); inCat; inCat = files->Next() )
754
				for (auto itr = files->cbegin(); itr != files->cend(); itr++)
755
				{
755
				{
756
					if ( inCat->sFile.Compare("PlugMan\\TFake.pck") )
756
					if ((*itr)->sFile.Compare("PlugMan\\TFake.pck") )
757
						continue;
757
						continue;
758
					if ( inCat->sFile.Compare(useAddonDir + "t\\44" + CyString::Number(PMTEXTFILE).PadNumber(4) + ".pck") )
758
					if ((*itr)->sFile.Compare(useAddonDir + "t\\44" + Utils::String::PadNumber(PMTEXTFILE, 4) + ".pck") )
759
						continue;
759
						continue;
760
					if ( inCat->sFile.Compare(useAddonDir + "t\\" + CyString::Number(PMTEXTFILE).PadNumber(4) + "-L044.pck") )
760
					if ((*itr)->sFile.Compare(useAddonDir + "t\\" + Utils::String::PadNumber(PMTEXTFILE, 4) + "-L044.pck") )
761
						continue;
761
						continue;
762
 
762
 
763
					found = true;
763
					found = true;
764
					break;
764
					break;
765
				}
765
				}
Line 1501... Line 1501...
1501
					CCatFile catTo, catFrom;
1501
					CCatFile catTo, catFrom;
1502
					if ( catFrom.Open(f->Data()->GetFilePointer(), this->GetAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
1502
					if ( catFrom.Open(f->Data()->GetFilePointer(), this->GetAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
1503
					{
1503
					{
1504
						if ( catTo.Open(findMatching->GetFilePointer(), this->GetAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
1504
						if ( catTo.Open(findMatching->GetFilePointer(), this->GetAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
1505
						{
1505
						{
1506
							for ( int i = 0; i < catFrom.GetNumFiles(); i++ )
1506
							for (unsigned int i = 0; i < catFrom.GetNumFiles(); i++ )
1507
							{
1507
							{
1508
								SInCatFile *c = catFrom.GetFile(i);								 
1508
								SInCatFile *c = catFrom.GetFile(i);								 
1509
								catTo.AppendFile((f->Data()->GetFilePointer() + "::" + c->sFile).ToString(), c->sFile.ToString());
1509
								catTo.AppendFile(f->Data()->GetFilePointer().ToString() + "::" + c->sFile, c->sFile);
1510
							}
1510
							}
1511
						}
1511
						}
1512
					}
1512
					}
1513
 
1513
 
1514
					// now remove the files
1514
					// now remove the files
Line 4611... Line 4611...
4611
		if ( CatFile.exists() ) {
4611
		if ( CatFile.exists() ) {
4612
			CCatFile cat;
4612
			CCatFile cat;
4613
			if ( cat.Open(CatFile.fullFilename(), this->GetAddonDir(), CATREAD_DAT, false) == CATERR_NONE ) {
4613
			if ( cat.Open(CatFile.fullFilename(), this->GetAddonDir(), CATREAD_DAT, false) == CATERR_NONE ) {
4614
				CyString fileName = file->GetFilePointer().GetToken("::", 2, 2);
4614
				CyString fileName = file->GetFilePointer().GetToken("::", 2, 2);
4615
				if ( cat.FindData(fileName) ) {
4615
				if ( cat.FindData(fileName) ) {
4616
					if ( cat.RemoveFile(fileName) ) {
4616
					if ( cat.removeFile(fileName.ToString()) ) {
4617
						this->AddLogEntry(SPKINSTALL_DELETEFILE, remFileStr, errors);
4617
						this->AddLogEntry(SPKINSTALL_DELETEFILE, remFileStr, errors);
4618
					}
4618
					}
4619
					else {
4619
					else {
4620
						this->AddLogEntry(SPKINSTALL_DELETEFILE_FAIL, remFileStr, errors);
4620
						this->AddLogEntry(SPKINSTALL_DELETEFILE_FAIL, remFileStr, errors);
4621
						return false;
4621
						return false;
Line 4959... Line 4959...
4959
			CCatFile catFile;
4959
			CCatFile catFile;
4960
			if ( catFile.Open(file->GetFilePointer(), addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE )
4960
			if ( catFile.Open(file->GetFilePointer(), addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE )
4961
			{
4961
			{
4962
				if ( catFile.ExtractFile(aFilename, aTo) )
4962
				if ( catFile.ExtractFile(aFilename, aTo) )
4963
					return 1;
4963
					return 1;
4964
				if ( catFile.Error() == CATERR_INVALIDDEST || catFile.Error() == CATERR_CANTCREATEDIR )
4964
				if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR )
4965
				{
4965
				{
4966
					if ( catFile.ExtractFile(aFilename) )
4966
					if ( catFile.ExtractFile(aFilename) )
4967
						return -1;
4967
						return -1;
4968
				}
4968
				}
4969
 
4969
 
Line 4977... Line 4977...
4977
			CCatFile catFile;
4977
			CCatFile catFile;
4978
			if ( catFile.Open(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat", addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE )
4978
			if ( catFile.Open(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat", addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE )
4979
			{
4979
			{
4980
				if ( catFile.ExtractFile(aFilename, aTo) )
4980
				if ( catFile.ExtractFile(aFilename, aTo) )
4981
					return 1;
4981
					return 1;
4982
				if ( catFile.Error() == CATERR_INVALIDDEST || catFile.Error() == CATERR_CANTCREATEDIR )
4982
				if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR )
4983
				{
4983
				{
4984
					if ( catFile.ExtractFile(aFilename) )
4984
					if ( catFile.ExtractFile(aFilename) )
4985
						return -1;
4985
						return -1;
4986
				}
4986
				}
4987
			}
4987
			}
Line 5003... Line 5003...
5003
		if ( catFile.Open(dir + "/" + CyString::Number(catNumber).PadNumber(2) + ".cat", addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE )
5003
		if ( catFile.Open(dir + "/" + CyString::Number(catNumber).PadNumber(2) + ".cat", addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE )
5004
		{
5004
		{
5005
			// check for the file
5005
			// check for the file
5006
			if ( catFile.ExtractFile(aFilename, aTo) )
5006
			if ( catFile.ExtractFile(aFilename, aTo) )
5007
				return 1;
5007
				return 1;
5008
			if ( catFile.Error() == CATERR_INVALIDDEST || catFile.Error() == CATERR_CANTCREATEDIR )
5008
			if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR )
5009
			{
5009
			{
5010
				if ( catFile.ExtractFile(aFilename) )
5010
				if ( catFile.ExtractFile(aFilename) )
5011
					return -1;
5011
					return -1;
5012
			}
5012
			}
5013
		}
5013
		}
Line 7805... Line 7805...
7805
		CCatFile cat;
7805
		CCatFile cat;
7806
		if ( cat.Open(file, this->GetAddonDir(), CATREAD_CATDECRYPT, false) != CATERR_NONE )
7806
		if ( cat.Open(file, this->GetAddonDir(), CATREAD_CATDECRYPT, false) != CATERR_NONE )
7807
			return false;
7807
			return false;
7808
 
7808
 
7809
		// extract 1 at a time
7809
		// extract 1 at a time
7810
		for ( int i = 0; i < cat.GetNumFiles(); i++ )
7810
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
7811
		{
7811
		{
7812
			SInCatFile *f = cat.GetFile(i);
7812
			SInCatFile *f = cat.GetFile(i);
7813
			CyString sF = f->sFile;
7813
			CyString sF = f->sFile;
7814
			// is a text file
7814
			// is a text file
7815
			sF = sF.FindReplace("\\", "/");
7815
			sF = sF.FindReplace("\\", "/");
Line 7998... Line 7998...
7998
	delete pVfs;
7998
	delete pVfs;
7999
 
7999
 
8000
	return newShip;
8000
	return newShip;
8001
}
8001
}
8002
 
8002
 
8003
CyStringList *CPackages::GetMergedFiles(CCatFile *cat1, CCatFile *cat2)
8003
void CPackages::getMergedFiles(Utils::CStringList &list, CCatFile *cat1, CCatFile *cat2)
8004
{
8004
{
8005
	CyStringList *list = new CyStringList;
-
 
8006
 
-
 
8007
	// first add all files from the "primary" mod
8005
	// first add all files from the "primary" mod
8008
	for ( SInCatFile *f = cat1->GetFiles()->First(); f; f = cat1->GetFiles()->Next() )
8006
	for (auto itr = cat1->GetFiles()->cbegin(); itr != cat1->GetFiles()->cend(); itr++)
8009
		list->PushBack(f->sFile.findreplace("\\", "/"), "1");
8007
		list.pushBack((*itr)->sFile.findReplace("\\", "/"), "1");
8010
 
8008
 
8011
	// now add the ones from the secondary
8009
	// now add the ones from the secondary
8012
	for ( SInCatFile *f = cat2->GetFiles()->First(); f; f = cat2->GetFiles()->Next() )
8010
	for (auto itr = cat2->GetFiles()->cbegin(); itr != cat2->GetFiles()->cend(); itr++)
8013
	{
8011
	{
8014
		CyString sFile = f->sFile.findreplace("\\", "/");
8012
		Utils::String sFile = (*itr)->sFile.findReplace("\\", "/");
8015
		// if its found on the 2nd list, dont add, just adjust the type
8013
		// if its found on the 2nd list, dont add, just adjust the type
8016
		SStringList *found = list->FindString(sFile);
8014
		if(!list.changeData(sFile, "-1"))
8017
		if ( found )
-
 
8018
			found->data = "-1"; // found in both
-
 
8019
		else
-
 
8020
			list->PushBack(sFile, "2");
8015
			list.pushBack(sFile, "2");
8021
	}
8016
	}
8022
 
-
 
8023
	return list;
-
 
8024
}
8017
}
8025
 
8018
 
8026
bool CPackages::CanWeMerge(const Utils::String &file) const
8019
bool CPackages::CanWeMerge(const Utils::String &file) const
8027
{
8020
{
8028
	return CModDiff::CanBeDiffed(file);
8021
	return CModDiff::CanBeDiffed(file);
Line 8041... Line 8034...
8041
	return false;
8034
	return false;
8042
}
8035
}
8043
 
8036
 
8044
bool CPackages::MergeMods(CCatFile *mod1, CCatFile *mod2, CyString outFile, CyStringList *cantMerge)
8037
bool CPackages::MergeMods(CCatFile *mod1, CCatFile *mod2, CyString outFile, CyStringList *cantMerge)
8045
{
8038
{
8046
	CyStringList *list = this->GetMergedFiles(mod1, mod2);
-
 
8047
	if ( !list )
-
 
8048
		return false;
-
 
8049
 
-
 
8050
	CCatFile newCat;
8039
	CCatFile newCat;
8051
	if ( newCat.Open(outFile, this->GetAddonDir()) != CATERR_CREATED )
8040
	if ( newCat.Open(outFile, this->GetAddonDir()) != CATERR_CREATED )
8052
		return false;
8041
		return false;
8053
 
8042
 
-
 
8043
	Utils::CStringList list;
-
 
8044
	this->getMergedFiles(list, mod1, mod2);
-
 
8045
	if (list.empty())
-
 
8046
		return false;
-
 
8047
 
8054
	// add all the files to the new mod first
8048
	// add all the files to the new mod first
8055
	CyStringList conflicts;
8049
	Utils::CStringList conflicts;
8056
	for ( SStringList *str = list->Head(); str; str = str->next )
8050
	for(auto itr = list.begin(); itr != list.end(); itr++)
8057
	{
8051
	{		
8058
		int status = str->data.ToInt();
8052
		int status = (*itr)->data.toInt();
8059
		if ( status == 1 )
8053
		if ( status == 1 )
8060
		{
8054
		{
8061
			if ( !newCat.WriteFromCat(mod1, str->str) )
8055
			if ( !newCat.WriteFromCat(mod1, (*itr)->str) )
8062
			{
8056
			{
8063
				if ( cantMerge )
8057
				if ( cantMerge )
8064
					cantMerge->PushBack(str->str, "1");
8058
					cantMerge->PushBack(CyString((*itr)->str), "1");
8065
			}
8059
			}
8066
		}
8060
		}
8067
		else if ( status == 2 )
8061
		else if ( status == 2 )
8068
		{
8062
		{
8069
			if ( !newCat.WriteFromCat(mod2, str->str) )
8063
			if ( !newCat.WriteFromCat(mod2, (*itr)->str) )
8070
			{
8064
			{
8071
				if ( cantMerge )
8065
				if ( cantMerge )
8072
					cantMerge->PushBack(str->str, "2");
8066
					cantMerge->PushBack(CyString((*itr)->str), "2");
8073
			}
8067
			}
8074
		}
8068
		}
8075
		else if ( status == -1 )
8069
		else if ( status == -1 )
8076
		{
8070
		{
8077
			if ( this->NeedToMerge(str->str) )
8071
			if ( this->NeedToMerge((*itr)->str) )
8078
			{
8072
			{
8079
				if ( this->CanWeMerge(str->str.ToString()) )
8073
				if ( this->CanWeMerge((*itr)->str) )
8080
					conflicts.PushBack(str->str);
8074
					conflicts.pushBack((*itr)->str);
8081
				else if ( cantMerge )
8075
				else if ( cantMerge )
8082
					cantMerge->PushBack(str->str, "-1");
8076
					cantMerge->PushBack(CyString((*itr)->str), "-1");
8083
			}
8077
			}
8084
			else
8078
			else
8085
			{
8079
			{
8086
				if ( !newCat.WriteFromCat(mod1, str->str) )
8080
				if ( !newCat.WriteFromCat(mod1, (*itr)->str) )
8087
				{
8081
				{
8088
					if ( cantMerge )
8082
					if ( cantMerge )
8089
						cantMerge->PushBack(str->str, "1");
8083
						cantMerge->PushBack(CyString((*itr)->str), "1");
8090
				}
8084
				}
8091
			}
8085
			}
8092
		}
8086
		}
8093
	}
8087
	}
8094
 
8088
 
8095
	delete list;
-
 
8096
 
-
 
8097
	/* 
8089
	/* 
8098
		Merging Files
8090
		Merging Files
8099
 
8091
 
8100
		* Text Files: Join all text entries into a single file (excluding page 17)
8092
		* Text Files: Join all text entries into a single file (excluding page 17)
8101
		* Weapons: TBullets and TLaser (grab matching entrys from text files and adjust ids)
8093
		* Weapons: TBullets and TLaser (grab matching entrys from text files and adjust ids)
Line 8128... Line 8120...
8128
 
8120
 
8129
	// we need to read the file list for the mod
8121
	// we need to read the file list for the mod
8130
	CCatFile cat;
8122
	CCatFile cat;
8131
	if ( cat.Open(file->GetFilePointer(), this->GetAddonDir(), CATREAD_JUSTCONTENTS, false) == CATERR_NONE )
8123
	if ( cat.Open(file->GetFilePointer(), this->GetAddonDir(), CATREAD_JUSTCONTENTS, false) == CATERR_NONE )
8132
	{
8124
	{
8133
		for ( int i = 0; i < cat.GetNumFiles(); i++ )
8125
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8134
		{
8126
		{
8135
			SInCatFile *f = cat.GetFile(i);
8127
			SInCatFile *f = cat.GetFile(i);
8136
			CyString filename = f->sFile;
8128
			CyString filename = f->sFile;
8137
			filename = filename.FindReplace("\\", "/");
8129
			filename = filename.FindReplace("\\", "/");
8138
			bool found = false;
8130
			bool found = false;