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 28... Line 28...
28
	CyString		sSection;
28
	CyString		sSection;
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
 
-
 
34
//////////////////////////////////////////////////////////////////////////////////////
-
 
35
 
-
 
36
//////////////////////////////////////////////////////////////////////////////////////
33
 
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
{
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 2916... Line 2920...
2916
int CPackages::GetAllPackageFiles(CLinkList<CBaseFile> *list, CLinkList<C_File> *fileList, bool includeChild)
2920
int CPackages::GetAllPackageFiles(CLinkList<CBaseFile> *list, CLinkList<C_File> *fileList, bool includeChild)
2917
{
2921
{
2918
	for ( CListNode<CBaseFile> *node = list->Front(); node; node = node->next() )
2922
	for ( CListNode<CBaseFile> *node = list->Front(); node; node = node->next() )
2919
		this->GetAllPackageFiles(node->Data(), fileList, includeChild);
2923
		this->GetAllPackageFiles(node->Data(), fileList, includeChild);
2920
	return fileList->size();
2924
	return fileList->size();
2921
}
2925
}
2922
 
2926
 
2923
/**
2927
/**
2924
 * Add Log
2928
 * Add Log
2925
 *
2929
 *
2926
 * Adds a log entry to displayed at end
2930
 * Adds a log entry to displayed at end
2927
 */
2931
 */
Line 3158... Line 3162...
3158
			CBaseFile *p = node->Data();
3162
			CBaseFile *p = node->Data();
3159
			if ( p->IsFileAdded(f) )
3163
			if ( p->IsFileAdded(f) )
3160
			{
3164
			{
3161
				checkPackage = p;
3165
				checkPackage = p;
3162
				break;
3166
				break;
3163
			}
3167
			}
3164
		}
3168
		}
3165
 
3169
 
3166
		// update the progress count for the current file
3170
		// update the progress count for the current file
3167
		if ( progress )
3171
		if ( progress )
3168
		{
3172
		{
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()) &amp;& file->author().Compare(author.ToString()) )
3484
		if ( file->name().Compare(name) &amp;& 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;
3482
}
3490
}
3483
 
3491
 
3484
CBaseFile *CPackages::FindPackage(CyString name, CyString author)
3492
CBaseFile *CPackages::FindPackage(CyString name, CyString author)
3485
{
3493
{
3486
	// interate through all packages
3494
	// interate through all packages
3487
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3495
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3488
	{
3496
	{
3489
		CBaseFile *file = node->Data();
3497
		CBaseFile *file = node->Data();
3490
 
3498
 
3491
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3499
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3492
		if ( file->name().Compare(name.ToString()) && file->author().Compare(author.ToString()) )
3500
		if ( file->name().Compare(name.ToString()) && file->author().Compare(author.ToString()) )
3493
			return file;
3501
			return file;
3494
	}
3502
	}
3495
 
3503
 
3496
	// nothing found
3504
	// nothing found
3497
	return 0;
3505
	return 0;
3498
}
3506
}
Line 3510... Line 3518...
3510
		CBaseFile *file = node->Data();
3518
		CBaseFile *file = node->Data();
3511
 
3519
 
3512
		// only look for spk packages
3520
		// only look for spk packages
3513
		if ( file->GetType() != TYPE_XSP )
3521
		if ( file->GetType() != TYPE_XSP )
3514
			continue;
3522
			continue;
3515
 
3523
 
3516
		// now compare the id, "Compare" is a non case senseative check, opposed to ==.
3524
		// now compare the id, "Compare" is a non case senseative check, opposed to ==.
3517
		if ( ((CXspFile *)file)->GetShipID().Compare(id.ToString()) )
3525
		if ( ((CXspFile *)file)->GetShipID().Compare(id.ToString()) )
3518
			return file;
3526
			return file;
3519
	}
3527
	}
3520
 
3528
 
3521
	// nothing found
3529
	// nothing found
3522
	return 0;
3530
	return 0;
3523
}
3531
}
3524
 
3532
 
3525
/**
3533
/**
3526
 * Update the used files count
3534
 * Update the used files count
3527
 *
3535
 *
3528
 * counts how many packages are currently using the file
3536
 * counts how many packages are currently using the file
3529
 */
3537
 */
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
 
3719
		return true;
3733
		return true;
3720
	}
3734
	}
3721
 
3735
 
3722
	// now check the prepared list
3736
	// now check the prepared list
3723
	if ( includePrepared )
3737
	if ( includePrepared )
3724
	{
3738
	{
3725
		for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
3739
		for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
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()) &amp;& p->author().Compare(author.ToString()) )
3745
			if ( p->name().Compare(name) &amp;& 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;
-
 
3754
			}
-
 
3755
		}
-
 
3756
	}
-
 
3757
 
-
 
3758
	return false;
-
 
3759
}
-
 
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;
3740
			}
3856
			}
3741
		}
3857
		}
3742
 
-
 
3743
		m_lInstallList.RemoveEmpty();
-
 
3744
	}
3858
	}
3745
 
3859
 
3746
	return false;
3860
	return true;
3747
}
-
 
3748
 
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
 
3767
	if ( p->GetType() == TYPE_SPK )
3881
	if ( p->GetType() == TYPE_SPK )
3768
	{
3882
	{
3769
		CSpkFile *spk = (CSpkFile *)p;
3883
		CSpkFile *spk = (CSpkFile *)p;
3770
		if ( spk->IsAnotherMod() )
3884
		if ( spk->IsAnotherMod() )
3771
		{
3885
		{
3772
			bool found = true;
3886
			bool found = true;
3773
			if ( !this->FindSpkPackage(spk->GetOtherName(), spk->GetOtherAuthor()) )
3887
			if ( !this->FindSpkPackage(spk->GetOtherName(), spk->GetOtherAuthor()) )
3774
			{
3888
			{
3775
				if ( includePrepared )
3889
				if ( includePrepared )
3776
				{
3890
				{
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
 
3801
	return count;
3915
	return count;
3802
}
3916
}
3803
 
3917
 
3804
int CPackages::CheckPreparedInstallRequired(CLinkList<CBaseFile> *list)
3918
int CPackages::CheckPreparedInstallRequired(CLinkList<CBaseFile> *list)
3805
{
3919
{
3806
	// loop through all packages
3920
	// loop through all packages
Line 3824... Line 3938...
3824
				list->push_back(p);
3938
				list->push_back(p);
3825
			}
3939
			}
3826
			else
3940
			else
3827
				node->DeleteData();
3941
				node->DeleteData();
3828
			++count;
3942
			++count;
3829
		}
3943
		}
3830
	}
3944
	}
3831
 
3945
 
3832
	m_lInstallList.RemoveEmpty();
3946
	m_lInstallList.RemoveEmpty();
3833
 
3947
 
3834
	return count;
3948
	return count;
3835
}
3949
}
Line 3885... Line 3999...
3885
			C_File *checkFile = fNode->Data();
3999
			C_File *checkFile = fNode->Data();
3886
			if ( checkFile->GetFileType() != FILETYPE_SCRIPT )
4000
			if ( checkFile->GetFileType() != FILETYPE_SCRIPT )
3887
				continue;
4001
				continue;
3888
 
4002
 
3889
			if ( checkFile->GetFilename().Compare(file->GetFilename()) )
4003
			if ( checkFile->GetFilename().Compare(file->GetFilename()) )
3890
			{
4004
			{
3891
				found = true;
4005
				found = true;
3892
				break;
4006
				break;
3893
			}
4007
			}
3894
		}
4008
		}
3895
 
4009
 
3896
		// not found a matching file, we can safetly remove it
4010
		// not found a matching file, we can safetly remove it
3897
		if ( !found )
4011
		if ( !found )
Line 6772... Line 6886...
6772
					for ( CListNode<SComponantEntry2> *cNode = found->lEntries.Front(); cNode; cNode = cNode->next() )
6886
					for ( CListNode<SComponantEntry2> *cNode = found->lEntries.Front(); cNode; cNode = cNode->next() )
6773
					{
6887
					{
6774
						if ( cNode->Data()->sSection.Compare(CyString(dummy->sSection2)) )
6888
						if ( cNode->Data()->sSection.Compare(CyString(dummy->sSection2)) )
6775
						{
6889
						{
6776
							found2 = cNode->Data();
6890
							found2 = cNode->Data();
6777
							break;
6891
							break;
6778
						}
6892
						}
6779
					}
6893
					}
6780
 
6894
 
6781
					if ( !found2 )
6895
					if ( !found2 )
6782
					{
6896
					{
6783
						found2 = new SComponantEntry2;
6897
						found2 = new SComponantEntry2;
Line 6833... Line 6947...
6833
		CFileIO WriteFile(m_sTempDir + "/Components.txt");
6947
		CFileIO WriteFile(m_sTempDir + "/Components.txt");
6834
		if ( WriteFile.WriteFile(&lines) )
6948
		if ( WriteFile.WriteFile(&lines) )
6835
		{
6949
		{
6836
			this->PackFile(&WriteFile, "types\\Components.pck");
6950
			this->PackFile(&WriteFile, "types\\Components.pck");
6837
			WriteFile.remove();
6951
			WriteFile.remove();
6838
		}
6952
		}
6839
	}
6953
	}
6840
}
6954
}
6841
 
6955
 
6842
bool CPackages::readWares(int iLang, CLinkList<SWareEntry> &list)
6956
bool CPackages::readWares(int iLang, CLinkList<SWareEntry> &list)
6843
{
6957
{
6844
	if ( iLang == 0 ) iLang = m_iLanguage;
6958
	if ( iLang == 0 ) iLang = m_iLanguage;
6845
 
6959
 
6846
	Utils::String empWares = this->empWaresForGame();
6960
	Utils::String empWares = this->empWaresForGame();
6847
 
6961
 
6848
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
6962
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
6849
		if ( !node->Data()->IsEnabled() ) continue;
6963
		if ( !node->Data()->IsEnabled() ) continue;
6850
		node->Data()->readWares(iLang, list, empWares);
6964
		node->Data()->readWares(iLang, list, empWares);
6851
	}
6965
	}
6852
 
6966
 
6853
	return true;
6967
	return true;
6854
}
6968
}
6855
 
6969
 
6856
bool CPackages::readCommands(int iLang, CLinkList<SCommandSlot> &list)
6970
bool CPackages::readCommands(int iLang, CLinkList<SCommandSlot> &list)
6857
{
6971
{
6858
	if ( iLang == 0 ) iLang = m_iLanguage;
6972
	if ( iLang == 0 ) iLang = m_iLanguage;
6859
 
6973
 
6860
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
6974
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
6861
		if ( !node->Data()->IsEnabled() ) continue;
6975
		if ( !node->Data()->IsEnabled() ) continue;
6862
		node->Data()->readCommands(iLang, list);
6976
		node->Data()->readCommands(iLang, list);
6863
	}
6977
	}
6864
 
6978
 
6865
	return true;
6979
	return true;
6866
}
6980
}
6867
 
6981
 
6868
bool CPackages::readWingCommands(int iLang, CLinkList<SCommandSlot> &list)
6982
bool CPackages::readWingCommands(int iLang, CLinkList<SCommandSlot> &list)
6869
{
6983
{
6870
	if ( iLang == 0 ) iLang = m_iLanguage;
6984
	if ( iLang == 0 ) iLang = m_iLanguage;
6871
 
6985
 
6872
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
6986
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
6873
		if ( !node->Data()->IsEnabled() ) continue;
6987
		if ( !node->Data()->IsEnabled() ) continue;
6874
		node->Data()->readWingCommands(iLang, list);
6988
		node->Data()->readWingCommands(iLang, list);
Line 6894... Line 7008...
6894
		if ( node->Data()->type == type && node->Data()->bNotority ) {
7008
		if ( node->Data()->type == type && node->Data()->bNotority ) {
6895
			if ( node->Data()->type == Ware_Custom && !id.Compare(node->Data()->id) ) continue;
7009
			if ( node->Data()->type == Ware_Custom && !id.Compare(node->Data()->id) ) continue;
6896
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos != pos ) continue;
7010
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos != pos ) continue;
6897
		
7011
		
6898
			(*noto) = node->Data()->notority;
7012
			(*noto) = node->Data()->notority;
6899
			return true;
7013
			return true;
6900
		}
7014
		}
6901
	}
7015
	}
6902
	return false;
7016
	return false;
6903
}
7017
}
6904
 
7018
 
Line 7134... Line 7248...
7134
						if ( !added )
7248
						if ( !added )
7135
							tshipsList.PushBack(line);
7249
							tshipsList.PushBack(line);
7136
						--count;
7250
						--count;
7137
						if ( count < 0 )
7251
						if ( count < 0 )
7138
							break;
7252
							break;
7139
					}
7253
					}
7140
				}
7254
				}
7141
 
7255
 
7142
				delete lines;
7256
				delete lines;
7143
 
7257
 
7144
			}
7258
			}
7145
 
7259
 
7146
			File.remove();
7260
			File.remove();
7147
 
7261
 
7148
			// assign the ship buffer
7262
			// assign the ship buffer
7149
			if ( !m_iShipBuffer )
7263
			if ( !m_iShipBuffer )
7150
				m_iShipBuffer = tshipsList.Count() + 15;
7264
				m_iShipBuffer = tshipsList.Count() + 15;
7151
			// there seems to be too many additional entries, we have no choise but to change the buffer
7265
			// there seems to be too many additional entries, we have no choise but to change the buffer
7152
			else if ( m_iShipBuffer <= tshipsList.Count() )
7266
			else if ( m_iShipBuffer <= tshipsList.Count() )
7153
				m_iShipBuffer = tshipsList.Count() + 15;
7267
				m_iShipBuffer = tshipsList.Count() + 15;
7154
 
7268
 
7155
			CyString bufferStart;
7269
			CyString bufferStart;
7156
			if ( m_iGame == GAME_X3 )
7270
			if ( m_iGame == GAME_X3 )
7157
				bufferStart = "0;0;0;0;0;2;499999;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0.049988;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;4;1;0;0;0;0;0;0;2092;1;1;-1;0;0;1;1;0;1;1;1;0;0;0;;-1;0;0;0;0;0;0;0;0;0;";
7271
				bufferStart = "0;0;0;0;0;2;499999;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0.049988;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;4;1;0;0;0;0;0;0;2092;1;1;-1;0;0;1;1;0;1;1;1;0;0;0;;-1;0;0;0;0;0;0;0;0;0;";
7158
			else
7272
			else
7159
				bufferStart = "0;0;0;0;0;SG_SH_M5;499999;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0.049988;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;4;1;0;0;0;0;0;0;OBJ_BEACON;1;1;-1;0;0;1;1;0;1;1;1;0;0;0;;-1;0;0;0;0;0;0;0;0;0;";
7273
				bufferStart = "0;0;0;0;0;SG_SH_M5;499999;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0.049988;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;4;1;0;0;0;0;0;0;OBJ_BEACON;1;1;-1;0;0;1;1;0;1;1;1;0;0;0;;-1;0;0;0;0;0;0;0;0;0;";
Line 7192... Line 7306...
7192
			if ( WriteFile.WriteFile(&tshipsList) )
7306
			if ( WriteFile.WriteFile(&tshipsList) )
7193
			{
7307
			{
7194
				this->PackFile(&WriteFile, "types/TShips.pck");
7308
				this->PackFile(&WriteFile, "types/TShips.pck");
7195
				WriteFile.remove();
7309
				WriteFile.remove();
7196
			}
7310
			}
7197
		}
7311
		}
7198
	}
7312
	}
7199
 
7313
 
7200
}
7314
}
7201
 
7315
 
7202
bool CPackages::PackFile(CyString filename)
7316
bool CPackages::PackFile(CyString filename)
7203
{
7317
{
7204
	// compress the file
7318
	// compress the file
7205
	CFileIO File(filename);
7319
	CFileIO File(filename);
Line 7208... Line 7322...
7208
 
7322
 
7209
	if ( fileData && fileSize)
7323
	if ( fileData && fileSize)
7210
	{
7324
	{
7211
		size_t newFileSize;
7325
		size_t newFileSize;
7212
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
7326
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
7213
		if ( pckData )
7327
		if ( pckData )
7214
		{
7328
		{
7215
			CyString ext = "pck";
7329
			CyString ext = "pck";
7216
			if ( File.CheckFileExtension("bob") )
7330
			if ( File.CheckFileExtension("bob") )
7217
				ext = "pbb";
7331
				ext = "pbb";
7218
			else if ( File.CheckFileExtension("bod") )
7332
			else if ( File.CheckFileExtension("bod") )
7219
				ext = "pbd";
7333
				ext = "pbd";
Line 7224... Line 7338...
7224
			return true;
7338
			return true;
7225
		}
7339
		}
7226
	}
7340
	}
7227
 
7341
 
7228
	return false;
7342
	return false;
7229
}
7343
}
7230
 
7344
 
7231
bool CPackages::UnPackFile(CyString filename, bool checkxml)
7345
bool CPackages::UnPackFile(CyString filename, bool checkxml)
7232
{
7346
{
7233
	// compress the file
7347
	// compress the file
7234
	CFileIO File(filename);
7348
	CFileIO File(filename);
Line 7239... Line 7353...
7239
	{
7353
	{
7240
		size_t newFileSize;
7354
		size_t newFileSize;
7241
		unsigned char *pckData = UnPCKData((unsigned char *)fileData, fileSize, &newFileSize, false);
7355
		unsigned char *pckData = UnPCKData((unsigned char *)fileData, fileSize, &newFileSize, false);
7242
		if ( !pckData )
7356
		if ( !pckData )
7243
			pckData = UnPCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
7357
			pckData = UnPCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
7244
 
7358
 
7245
		if ( pckData )
7359
		if ( pckData )
7246
		{
7360
		{
7247
			CyString ext = "txt";
7361
			CyString ext = "txt";
7248
			if ( File.CheckFileExtension("pbb") )
7362
			if ( File.CheckFileExtension("pbb") )
7249
				ext = "bob";
7363
				ext = "bob";
Line 7254... Line 7368...
7254
				CDirIO(pckFile.dir()).Create();
7368
				CDirIO(pckFile.dir()).Create();
7255
			pckFile.WriteData((char *)pckData, newFileSize);
7369
			pckFile.WriteData((char *)pckData, newFileSize);
7256
 
7370
 
7257
			// check for xml and rename
7371
			// check for xml and rename
7258
			if ( checkxml )
7372
			if ( checkxml )
7259
			{
7373
			{
7260
				int readmaxlines = 20;
7374
				int readmaxlines = 20;
7261
				bool isxml = false;
7375
				bool isxml = false;
7262
				do {
7376
				do {
7263
					CyString line = pckFile.readEndOfLine();
7377
					CyString line = pckFile.readEndOfLine();
7264
					if ( line.IsIn("<language id=") )
7378
					if ( line.IsIn("<language id=") )
Line 7495... Line 7609...
7495
 
7609
 
7496
bool CPackages::generatePackagerScript(CBaseFile *baseFile, bool wildcard, Utils::CStringList *list, int game, bool datafile) const
7610
bool CPackages::generatePackagerScript(CBaseFile *baseFile, bool wildcard, Utils::CStringList *list, int game, bool datafile) const
7497
{	
7611
{	
7498
	if (!baseFile)
7612
	if (!baseFile)
7499
		return false;
7613
		return false;
7500
 
7614
 
7501
	Utils::CStringList gameAddons;
7615
	Utils::CStringList gameAddons;
7502
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
7616
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
7503
	{
7617
	{
7504
		SGameExe *exe = m_gameExe.GetGame(i);
7618
		SGameExe *exe = m_gameExe.GetGame(i);
7505
		if (!exe->sAddon.empty())
7619
		if (!exe->sAddon.empty())
Line 7615... Line 7729...
7615
					if ( rest.contains(strVar->str) )
7729
					if ( rest.contains(strVar->str) )
7616
						rest = rest.findReplace(strVar->str, strVar->data);
7730
						rest = rest.findReplace(strVar->str, strVar->data);
7617
				}
7731
				}
7618
 
7732
 
7619
				if ( variables )
7733
				if ( variables )
7620
				{
7734
				{
7621
					for (Utils::SStringList *strVar = variables->first(); strVar; strVar = variables->next())
7735
					for (Utils::SStringList *strVar = variables->first(); strVar; strVar = variables->next())
7622
					{
7736
					{
7623
						if ( rest.contains(strVar->str) )
7737
						if ( rest.contains(strVar->str) )
7624
							rest = rest.findReplace(strVar->str, strVar->data);
7738
							rest = rest.findReplace(strVar->str, strVar->data);
7625
					}
7739
					}
Line 7659... Line 7773...
7659
			// mydocuments
7773
			// mydocuments
7660
			if ( rest.isin("$MYDOCUMENTS") )
7774
			if ( rest.isin("$MYDOCUMENTS") )
7661
			{
7775
			{
7662
				if ( !m_sMyDoc.empty() )
7776
				if ( !m_sMyDoc.empty() )
7663
					rest = rest.findReplace("$MYDOCUMENTS", m_sMyDoc);
7777
					rest = rest.findReplace("$MYDOCUMENTS", m_sMyDoc);
7664
			}
7778
			}
7665
 
7779
 
7666
			// current path
7780
			// current path
7667
			if ( rest.isin("$PATH") )
7781
			if ( rest.isin("$PATH") )
7668
			{
7782
			{
7669
				Utils::String currentDir = CFileIO(filename).dir();
7783
				Utils::String currentDir = CFileIO(filename).dir();
7670
				if ( !currentDir.empty() )
7784
				if ( !currentDir.empty() )
Line 7704... Line 7818...
7704
			{
7818
			{
7705
				C_File *f = node->Data();
7819
				C_File *f = node->Data();
7706
				if (f->game() && f->game() != GAME_ALLNEW && !(f->game() & (1 << game)))
7820
				if (f->game() && f->game() != GAME_ALLNEW && !(f->game() & (1 << game)))
7707
					continue;
7821
					continue;
7708
				package->extractFile(f, itr->second, game, gameAddons);
7822
				package->extractFile(f, itr->second, game, gameAddons);
7709
			}
7823
			}
7710
		}
7824
		}
7711
	}
7825
	}
7712
 
7826
 
7713
	if (package->autoExporter())
7827
	if (package->autoExporter())
7714
	{
7828
	{
7715
		for (auto itr = package->autoExporter()->begin(); itr != package->autoExporter()->end(); itr++)
7829
		for (auto itr = package->autoExporter()->begin(); itr != package->autoExporter()->end(); itr++)
Line 7736... Line 7850...
7736
}
7850
}
7737
 
7851
 
7738
CyString CPackages::GetLanguageName() const
7852
CyString CPackages::GetLanguageName() const
7739
{
7853
{
7740
	return CPackages::ConvertLanguage(m_iLanguage);
7854
	return CPackages::ConvertLanguage(m_iLanguage);
-
 
7855
}
-
 
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;
7741
}
7988
}
7742
 
7989
 
7743
Utils::String CPackages::ConvertLanguage(int lang)
7990
Utils::String CPackages::ConvertLanguage(int lang)
7744
{
7991
{
7745
	switch ( lang )
7992
	switch ( lang )