Subversion Repositories spk

Rev

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

Rev 131 Rev 133
Line 29... Line 29...
29
	CLinkList<SComponantEntry2>	lEntries;
29
	CLinkList<SComponantEntry2>	lEntries;
30
} SComponantEntry;
30
} SComponantEntry;
31
 
31
 
32
Utils::String CPackages::m_sTempDir;
32
Utils::String CPackages::m_sTempDir;
33
 
33
 
-
 
34
//////////////////////////////////////////////////////////////////////////////////////
-
 
35
 
-
 
36
//////////////////////////////////////////////////////////////////////////////////////
-
 
37
 
34
CPackages::CPackages() : m_pCurrentGameExe(NULL),
38
CPackages::CPackages() : m_pCurrentGameExe(NULL),
35
	_pOriginalFiles(NULL),
39
	_pOriginalFiles(NULL),
36
	_pCurrentDir(NULL)	
40
	_pCurrentDir(NULL)	
37
{
41
{
38
	m_bRenameText = false;
42
	m_bRenameText = false;
Line 2206... Line 2210...
2206
				if ( spk->IsAnotherMod() )
2210
				if ( spk->IsAnotherMod() )
2207
				{
2211
				{
2208
					for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
2212
					for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
2209
					{
2213
					{
2210
						CBaseFile *p = node->Data();
2214
						CBaseFile *p = node->Data();
2211
						if ( spk->GetOtherName().Compare(p->name()) && spk->GetOtherAuthor().Compare(p->author()) )
2215
						if ( spk->otherName().Compare(p->name()) && spk->otherAuthor().Compare(p->author()) )
2212
						{
2216
						{
2213
							m_lInstallList.insert(m_lInstallList.FindPos(p) + 2, package);
2217
							m_lInstallList.insert(m_lInstallList.FindPos(p) + 2, package);
2214
							added = true;
2218
							added = true;
2215
							break;
2219
							break;
2216
						}
2220
						}
Line 2225... Line 2229...
2225
				{
2229
				{
2226
					if ( node->Data()->GetType() != TYPE_SPK )
2230
					if ( node->Data()->GetType() != TYPE_SPK )
2227
						continue;
2231
						continue;
2228
 
2232
 
2229
					CSpkFile *spk = (CSpkFile *)node->Data();
2233
					CSpkFile *spk = (CSpkFile *)node->Data();
2230
					if ( !spk->IsAnotherMod() )
2234
					if ( !spk->isAnotherMod() )
2231
						continue;
2235
						continue;
2232
 
2236
 
2233
					if ( spk->GetOtherName().Compare(package->name()) && spk->GetOtherAuthor().Compare(package->author()) )
2237
					if ( spk->otherName().Compare(package->name()) && spk->otherAuthor().Compare(package->author()) )
2234
					{
2238
					{
2235
						added = true;
2239
						added = true;
2236
						m_lInstallList.insert(node->Data(), package);
2240
						m_lInstallList.insert(node->Data(), package);
2237
						break;
2241
						break;
2238
					}
2242
					}
Line 3461... Line 3465...
3461
 *
3465
 *
3462
 * This searching all installed packages for a SPK Package matching the name and author
3466
 * This searching all installed packages for a SPK Package matching the name and author
3463
 */
3467
 */
3464
CBaseFile *CPackages::FindSpkPackage(CyString name, CyString author)
3468
CBaseFile *CPackages::FindSpkPackage(CyString name, CyString author)
3465
{
3469
{
-
 
3470
	return findSpkPackage(name.ToString(), author.ToString());
-
 
3471
}
-
 
3472
CBaseFile *CPackages::findSpkPackage(const Utils::String &name, const Utils::String &author) const
-
 
3473
{
3466
	// interate through all packages
3474
	// interate through all packages
3467
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3475
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3468
	{
3476
	{
3469
		CBaseFile *file = node->Data();
3477
		CBaseFile *file = node->Data();
3470
 
3478
 
3471
		// only look for spk packages
3479
		// only look for spk packages
3472
		if ( file->GetType() != TYPE_SPK )
3480
		if ( file->GetType() != TYPE_SPK )
3473
			continue;
3481
			continue;
3474
 
3482
 
3475
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3483
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3476
		if ( file->name().Compare(name.ToString()) && file->author().Compare(author.ToString()) )
3484
		if ( file->name().Compare(name) && file->author().Compare(author) )
3477
			return file;
3485
			return file;
3478
	}
3486
	}
3479
 
3487
 
3480
	// nothing found
3488
	// nothing found
3481
	return 0;
3489
	return 0;
Line 3704... Line 3712...
3704
	return true;
3712
	return true;
3705
}
3713
}
3706
 
3714
 
3707
bool CPackages::CheckInstalledDependacy(CyString name, CyString author, CyString version, bool onlyEnabled, bool includePrepared)
3715
bool CPackages::CheckInstalledDependacy(CyString name, CyString author, CyString version, bool onlyEnabled, bool includePrepared)
3708
{
3716
{
-
 
3717
	bool ret = checkInstalledDependacy(name.ToString(), author.ToString(), version.ToString(), onlyEnabled, includePrepared);
-
 
3718
	m_lInstallList.RemoveEmpty();
-
 
3719
	return ret;
-
 
3720
}
-
 
3721
bool CPackages::checkInstalledDependacy(const Utils::String &name, const Utils::String &author, const Utils::String &version, bool onlyEnabled, bool includePrepared) const
-
 
3722
{
3709
	CBaseFile *p = this->FindSpkPackage(name, author);
3723
	CBaseFile *p = this->findSpkPackage(name, author);
3710
	if ( p )
3724
	if ( p )
3711
	{
3725
	{
3712
		// now check version
3726
		// now check version
3713
		if ( version.CompareVersion(p->version()) == COMPARE_OLDER )
3727
		if (version.compareVersion(p->version()) == COMPARE_OLDER)
3714
			return false;
3728
			return false;
3715
 
3729
 
3716
		if ( onlyEnabled && !p->IsEnabled() )
3730
		if ( onlyEnabled && !p->IsEnabled() )
3717
			return false;
3731
			return false;
3718
 
3732
 
Line 3726... Line 3740...
3726
		{
3740
		{
3727
			p = node->Data();
3741
			p = node->Data();
3728
			if ( !p )
3742
			if ( !p )
3729
				continue;
3743
				continue;
3730
 
3744
 
3731
			if ( p->name().Compare(name.ToString()) && p->author().Compare(author.ToString()) )
3745
			if ( p->name().Compare(name) && p->author().Compare(author) )
3732
			{
3746
			{
3733
				if ( version.CompareVersion(p->version()) == COMPARE_OLDER )
3747
				if (version.compareVersion(p->version()) == COMPARE_OLDER)
3734
					continue;
3748
					continue;
3735
 
3749
 
3736
				if ( onlyEnabled && !p->IsEnabled() )
3750
				if ( onlyEnabled && !p->IsEnabled() )
3737
					continue;
3751
					continue;
3738
 
3752
 
3739
				return true;
3753
				return true;
3740
			}
3754
			}
3741
		}
3755
		}
3742
 
-
 
3743
		m_lInstallList.RemoveEmpty();
-
 
3744
	}
3756
	}
3745
 
3757
 
3746
	return false;
3758
	return false;
3747
}
3759
}
3748
 
3760
 
-
 
3761
bool CPackages::findAllNeededDependacies(CBaseFile *p, const CLinkList<CBaseFile> &packages, CLinkList<CBaseFile> *foundPackages, bool onlyEnabled, bool includePrepared) const
-
 
3762
{
-
 
3763
	CLinkList<SNeededLibrary> *neededList = p->GetNeededLibraries();
-
 
3764
	if (neededList)
-
 
3765
	{
-
 
3766
		for (CListNode<SNeededLibrary> *node = neededList->Front(); node; node = node->next())
-
 
3767
		{
-
 
3768
			SNeededLibrary *nl = node->Data();
-
 
3769
			if (!checkInstalledDependacy((nl->sName.Compare("<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor, nl->sMinVersion, (nl->sName.Compare("<package>")) ? false : onlyEnabled, (nl->sName.Compare("<package>")) ? false : includePrepared))
-
 
3770
			{
-
 
3771
				bool found = true;
-
 
3772
				for (auto itr = packages.Front(); itr; itr = itr->next())
-
 
3773
				{
-
 
3774
					if (itr->Data()->name().Compare(nl->sName) && itr->Data()->author().Compare(nl->sAuthor))
-
 
3775
					{
-
 
3776
						if (!findAllNeededDependacies(itr->Data(), packages, foundPackages, onlyEnabled, includePrepared))
-
 
3777
							return false;
-
 
3778
						if (foundPackages)
-
 
3779
						{
-
 
3780
							bool added = false;
-
 
3781
							for (auto itr2 = foundPackages->Front(); itr2; itr2 = itr2->next())
-
 
3782
							{
-
 
3783
								if (itr->Data() == itr2->Data() || (itr->Data()->name().Compare(itr2->Data()->name()) && itr->Data()->author().Compare(itr2->Data()->author())))
-
 
3784
								{
-
 
3785
									added = true;
-
 
3786
									break;
-
 
3787
								}
-
 
3788
							}
-
 
3789
							if(!added)
-
 
3790
								foundPackages->push_front(itr->Data());
-
 
3791
						}
-
 
3792
						found = true;
-
 
3793
						break;
-
 
3794
					}
-
 
3795
				}
-
 
3796
				if (!found)
-
 
3797
					return false;
-
 
3798
			}
-
 
3799
		}
-
 
3800
	}
-
 
3801
 
-
 
3802
	if (p->GetType() == TYPE_SPK)
-
 
3803
	{
-
 
3804
		CSpkFile *spk = (CSpkFile *)p;
-
 
3805
		if (spk->isAnotherMod())
-
 
3806
		{
-
 
3807
			bool found = true;
-
 
3808
			if (!this->findSpkPackage(spk->otherName(), spk->otherAuthor()))
-
 
3809
			{
-
 
3810
				if (includePrepared)
-
 
3811
				{
-
 
3812
					found = false;
-
 
3813
					for (CListNode<CBaseFile> *pNode = m_lInstallList.Front(); pNode; pNode = pNode->next())
-
 
3814
					{
-
 
3815
						CBaseFile *checkP = pNode->Data();
-
 
3816
						if (p->author().Compare(checkP->author()) && p->name().Compare(checkP->name()))
-
 
3817
						{
-
 
3818
							found = true;
-
 
3819
							break;
-
 
3820
						}
-
 
3821
					}
-
 
3822
				}
-
 
3823
				else
-
 
3824
					found = false;
-
 
3825
			}
-
 
3826
 
-
 
3827
			if (!found)
-
 
3828
			{
-
 
3829
				for (auto itr = packages.Front(); itr; itr = itr->next())
-
 
3830
				{
-
 
3831
					if (itr->Data()->name().Compare(spk->otherName()) && itr->Data()->author().Compare(spk->otherAuthor()))
-
 
3832
					{
-
 
3833
						if (!findAllNeededDependacies(itr->Data(), packages, foundPackages, onlyEnabled, includePrepared))
-
 
3834
							return false;
-
 
3835
						if(foundPackages)
-
 
3836
						{
-
 
3837
							bool added = false;
-
 
3838
							for (auto itr2 = foundPackages->Front(); itr2; itr2 = itr2->next())
-
 
3839
							{
-
 
3840
								if (itr->Data() == itr2->Data() || (itr->Data()->name().Compare(itr2->Data()->name()) && itr->Data()->author().Compare(itr2->Data()->author())))
-
 
3841
								{
-
 
3842
									added = true;
-
 
3843
									break;
-
 
3844
								}
-
 
3845
							}
-
 
3846
							if (!added)
-
 
3847
								foundPackages->push_front(itr->Data());
-
 
3848
						}
-
 
3849
						found = true;
-
 
3850
						break;
-
 
3851
					}
-
 
3852
				}
-
 
3853
 
-
 
3854
				if(!found)
-
 
3855
					return false;
-
 
3856
			}
-
 
3857
		}
-
 
3858
	}
-
 
3859
 
-
 
3860
	return true;
-
 
3861
 
-
 
3862
}
3749
int CPackages::GetMissingDependacies(CBaseFile *p, CyStringList *list, bool onlyEnabled, bool includePrepared)
3863
int CPackages::GetMissingDependacies(CBaseFile *p, Utils::CStringList *list, bool onlyEnabled, bool includePrepared)
3750
{
3864
{
3751
	int count = 0;
3865
	int count = 0;
3752
	CLinkList<SNeededLibrary> *neededList = p->GetNeededLibraries();
3866
	CLinkList<SNeededLibrary> *neededList = p->GetNeededLibraries();
3753
	if ( neededList )
3867
	if ( neededList )
3754
	{
3868
	{
Line 3756... Line 3870...
3756
		{
3870
		{
3757
			SNeededLibrary *nl = node->Data();
3871
			SNeededLibrary *nl = node->Data();
3758
			if ( !CheckInstalledDependacy((nl->sName.Compare("<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor, nl->sMinVersion, (nl->sName.Compare("<package>")) ? false : onlyEnabled, (nl->sName.Compare("<package>")) ? false : includePrepared) )
3872
			if ( !CheckInstalledDependacy((nl->sName.Compare("<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor, nl->sMinVersion, (nl->sName.Compare("<package>")) ? false : onlyEnabled, (nl->sName.Compare("<package>")) ? false : includePrepared) )
3759
			{
3873
			{
3760
				if ( list )
3874
				if ( list )
3761
					list->PushBack(((nl->sName.Compare("<package>")) ? CyString(p->name()) : nl->sName) + "|" + nl->sMinVersion, (nl->sAuthor.Compare("<author>")) ? CyString(p->author()) : nl->sAuthor);
3875
					list->pushBack(((nl->sName.Compare("<package>")) ? p->name() : nl->sName) + "|" + nl->sMinVersion, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor);
3762
				++count;
3876
				++count;
3763
			}
3877
			}
3764
		}
3878
		}
3765
	}
3879
	}
3766
 
3880
 
Line 3790... Line 3904...
3790
			}
3904
			}
3791
 
3905
 
3792
			if ( !found )
3906
			if ( !found )
3793
			{
3907
			{
3794
				if ( list )
3908
				if ( list )
3795
					list->PushBack(CyString(spk->GetOtherName()), CyString(spk->GetOtherAuthor()));
3909
					list->pushBack(spk->GetOtherName(), spk->GetOtherAuthor());
3796
				++count;
3910
				++count;
3797
			}
3911
			}
3798
		}
3912
		}
3799
	}
3913
	}
3800
 
3914
 
Line 7738... Line 7852...
7738
CyString CPackages::GetLanguageName() const
7852
CyString CPackages::GetLanguageName() const
7739
{
7853
{
7740
	return CPackages::ConvertLanguage(m_iLanguage);
7854
	return CPackages::ConvertLanguage(m_iLanguage);
7741
}
7855
}
7742
 
7856
 
-
 
7857
int CPackages::findAllPackages(CLinkList<CBaseFile> &packages, const Utils::String &dir)
-
 
7858
{
-
 
7859
	int count = 0;
-
 
7860
	if (!dir.empty())
-
 
7861
	{
-
 
7862
		count += findPackageDirectories(packages, dir + "/Addons");
-
 
7863
		count += findPackageDirectories(packages, dir + "/Downloads");
-
 
7864
	}
-
 
7865
 
-
 
7866
	count += findPackageDirectories(packages, "./Addons");
-
 
7867
	count += findPackageDirectories(packages, "./Downloads");
-
 
7868
	
-
 
7869
	if (_pCurrentDir)
-
 
7870
	{
-
 
7871
		count += findPackageDirectories(packages, _pCurrentDir->dir + "/Addons");
-
 
7872
		count += findPackageDirectories(packages, _pCurrentDir->dir + "/Downloads");
-
 
7873
		count += findPackageDirectories(packages, _pCurrentDir->dir + "/ExtraContent");
-
 
7874
	}
-
 
7875
 
-
 
7876
	return count;
-
 
7877
}
-
 
7878
int CPackages::findPackageDirectories(CLinkList<CBaseFile> &packages, const Utils::String &dir)
-
 
7879
{
-
 
7880
	CDirIO Dir(dir);
-
 
7881
	int count = 0;
-
 
7882
	Utils::CStringList files;
-
 
7883
	if (Dir.dirList(files))
-
 
7884
	{
-
 
7885
		for (auto itr = files.begin(); itr != files.end(); itr++)
-
 
7886
		{
-
 
7887
			Utils::String d = Dir.file((*itr)->str);
-
 
7888
			if (CDirIO(d).isDir())
-
 
7889
				count += findPackageDirectories(packages, d);
-
 
7890
		}
-
 
7891
	}
-
 
7892
 
-
 
7893
	count += findPackageFiles(packages, dir);
-
 
7894
	return count;
-
 
7895
}
-
 
7896
int CPackages::findPackageFiles(CLinkList<CBaseFile> &packages, const Utils::String &dir)
-
 
7897
{
-
 
7898
	CDirIO Dir(dir);
-
 
7899
	int count = 0;
-
 
7900
	for (int type = 0; type < 2; type++)
-
 
7901
	{
-
 
7902
		Utils::CStringList files;
-
 
7903
		if (type == 0)
-
 
7904
			Dir.dirList(files, Utils::String::Null(), "*.spk");
-
 
7905
		else if(type == 1)
-
 
7906
			Dir.dirList(files, Utils::String::Null(), "*.xsp");
-
 
7907
		else
-
 
7908
			break;
-
 
7909
			
-
 
7910
		for(auto itr = files.begin(); itr != files.end(); itr++)
-
 
7911
		{
-
 
7912
			Utils::String f = Dir.file((*itr)->str);
-
 
7913
			int error = 0;
-
 
7914
			CBaseFile *p = this->OpenPackage(f, &error, 0, SPKREAD_NODATA, READFLAG_NOUNCOMPRESS);
-
 
7915
			if (!p)
-
 
7916
				continue;
-
 
7917
			if (p->IsMod() || this->FindSpkPackage(p->name(), p->author()))
-
 
7918
			{
-
 
7919
				delete p;
-
 
7920
				continue;
-
 
7921
			}
-
 
7922
 
-
 
7923
			// check its for the correct game
-
 
7924
			if (!p->CheckGameCompatability(this->GetGame()))
-
 
7925
			{
-
 
7926
				delete p;
-
 
7927
				continue;
-
 
7928
			}
-
 
7929
 
-
 
7930
			// check if its already on the list
-
 
7931
			bool found = false;
-
 
7932
			for (CBaseFile *checkp = packages.First(); checkp; checkp = packages.Next())
-
 
7933
			{
-
 
7934
				if (p->name().Compare(checkp->name()) && p->author().Compare(checkp->author()))
-
 
7935
				{
-
 
7936
					found = true;
-
 
7937
					break;
-
 
7938
				}
-
 
7939
			}
-
 
7940
 
-
 
7941
			if (found)
-
 
7942
			{
-
 
7943
				delete p;
-
 
7944
				continue;
-
 
7945
			}
-
 
7946
			
-
 
7947
			if (p->GetIcon())
-
 
7948
			{
-
 
7949
				bool addedIcon = false;
-
 
7950
				p->ReadIconFileToMemory();
-
 
7951
				p->GetIcon()->SetFilename(this->tempDirectory().findReplace("\\", "/") + "/" + p->author() + "_" + p->name() + "." + p->GetIconExt().ToString());
-
 
7952
				p->GetIcon()->SetFullDir(this->tempDirectory());
-
 
7953
				if (p->GetIcon()->UncompressData())
-
 
7954
				{
-
 
7955
					if (p->GetIcon()->writeFilePointer())
-
 
7956
						addedIcon = true;
-
 
7957
				}
-
 
7958
 
-
 
7959
				if (!addedIcon)
-
 
7960
					p->SetIcon(NULL, "");
-
 
7961
			}
-
 
7962
 
-
 
7963
			// get an advert to display
-
 
7964
			if (p->GetFirstFile(FILETYPE_ADVERT))
-
 
7965
			{
-
 
7966
				bool done = false;
-
 
7967
				C_File *f = p->GetFirstFile(FILETYPE_ADVERT);
-
 
7968
				if (p->ReadFileToMemory(f))
-
 
7969
				{
-
 
7970
					f->SetFullDir(this->tempDirectory());
-
 
7971
					if (f->UncompressData())
-
 
7972
					{
-
 
7973
						if (f->writeFilePointer())
-
 
7974
							done = true;
-
 
7975
					}
-
 
7976
				}
-
 
7977
 
-
 
7978
				if (!done)
-
 
7979
					f->DeleteData();
-
 
7980
			}
-
 
7981
 
-
 
7982
			packages.push_back(p);
-
 
7983
			++count;
-
 
7984
		}
-
 
7985
	}
-
 
7986
 
-
 
7987
	return count;
-
 
7988
}
-
 
7989
 
7743
Utils::String CPackages::ConvertLanguage(int lang)
7990
Utils::String CPackages::ConvertLanguage(int lang)
7744
{
7991
{
7745
	switch ( lang )
7992
	switch ( lang )
7746
	{
7993
	{
7747
		case 44:
7994
		case 44: