Subversion Repositories spk

Rev

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

Rev 202 Rev 203
Line 1682... Line 1682...
1682
			{
1682
			{
1683
				if ( !icon->UncompressData() )
1683
				if ( !icon->UncompressData() )
1684
					package->setIcon(NULL, "");
1684
					package->setIcon(NULL, "");
1685
				else
1685
				else
1686
				{
1686
				{
1687
					CFileIO iconFile(m_sCurrentDir + L"/PluginManager/Icons/" + package->author().toWString() + L"_" + package->name().toWString() + L"." + package->iconExt());
1687
					CFileIO iconFile(m_sCurrentDir + L"/PluginManager/Icons/" + package->author() + L"_" + package->name() + L"." + package->iconExt());
1688
					if ( iconFile.WriteData((const char *)icon->GetData(), icon->GetDataSize()) )
1688
					if ( iconFile.WriteData((const char *)icon->GetData(), icon->GetDataSize()) )
1689
					{
1689
					{
1690
						icon->setFilename(package->author().toWString() + L"_" + package->name().toWString() + L"." + package->iconExt());
1690
						icon->setFilename(package->author() + L"_" + package->name() + L"." + package->iconExt());
1691
						icon->setFullDir(m_sCurrentDir + L"/PluginManager/Icons");
1691
						icon->setFullDir(m_sCurrentDir + L"/PluginManager/Icons");
1692
					}
1692
					}
1693
					else
1693
					else
1694
						package->setIcon(NULL, "");
1694
						package->setIcon(NULL, "");
1695
				}
1695
				}
Line 2070... Line 2070...
2070
	}
2070
	}
2071
 
2071
 
2072
	// check if it needs depancies
2072
	// check if it needs depancies
2073
	if ( package->AnyDependacies() )
2073
	if ( package->AnyDependacies() )
2074
	{
2074
	{
2075
		if ( this->GetMissingDependacies(package, NULL, true) )
2075
		if ( this->getMissingDependacies(package, NULL, true) )
2076
		{
2076
		{
2077
			m_iError = PKERR_MISSINGDEP;
2077
			m_iError = PKERR_MISSINGDEP;
2078
			return false;
2078
			return false;
2079
		}
2079
		}
2080
	}
2080
	}
Line 2150... Line 2150...
2150
int CPackages::GetDependacyList(CBaseFile *package, CLinkList<CBaseFile> *list)
2150
int CPackages::GetDependacyList(CBaseFile *package, CLinkList<CBaseFile> *list)
2151
{
2151
{
2152
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
2152
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
2153
	{
2153
	{
2154
		CBaseFile *p = node->Data();
2154
		CBaseFile *p = node->Data();
2155
		if ( p->IsPackageNeeded(package->name(), package->author()) )
2155
		if ( p->isPackageNeeded(package->name(), package->author()))
2156
			list->push_back(p);
2156
			list->push_back(p);
2157
	}
2157
	}
2158
 
2158
 
2159
	return list->size();
2159
	return list->size();
2160
}
2160
}
Line 2215... Line 2215...
2215
				if ( spk->IsAnotherMod() )
2215
				if ( spk->IsAnotherMod() )
2216
				{
2216
				{
2217
					for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
2217
					for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
2218
					{
2218
					{
2219
						CBaseFile *p = node->Data();
2219
						CBaseFile *p = node->Data();
2220
						if ( spk->otherName().Compare(p->name()) &&amp; spk->;otherAuthor().Compare(p->author()) )
2220
						if ( spk->otherName().Compare(p->name().toString()) &&amp; spk->;otherAuthor().Compare(p->author().toString()) )
2221
						{
2221
						{
2222
							m_lInstallList.insert(m_lInstallList.FindPos(p) + 2, package);
2222
							m_lInstallList.insert(m_lInstallList.FindPos(p) + 2, package);
2223
							added = true;
2223
							added = true;
2224
							break;
2224
							break;
2225
						}
2225
						}
Line 2237... Line 2237...
2237
 
2237
 
2238
					CSpkFile *spk = (CSpkFile *)node->Data();
2238
					CSpkFile *spk = (CSpkFile *)node->Data();
2239
					if ( !spk->isAnotherMod() )
2239
					if ( !spk->isAnotherMod() )
2240
						continue;
2240
						continue;
2241
 
2241
 
2242
					if ( spk->otherName().Compare(package->name()) &&amp; spk->;otherAuthor().Compare(package->author()) )
2242
					if ( spk->otherName().Compare(package->name().toString()) &&amp; spk->;otherAuthor().Compare(package->author().toString()) )
2243
					{
2243
					{
2244
						added = true;
2244
						added = true;
2245
						m_lInstallList.insert(node->Data(), package);
2245
						m_lInstallList.insert(node->Data(), package);
2246
						break;
2246
						break;
2247
					}
2247
					}
Line 3236... Line 3236...
3236
		if ( f->IsFakePatch() )
3236
		if ( f->IsFakePatch() )
3237
		{
3237
		{
3238
			// find package the fake patch belongs to
3238
			// find package the fake patch belongs to
3239
			if ( checkPackage )
3239
			if ( checkPackage )
3240
			{
3240
			{
3241
				newFilename = m_sCurrentDir + L"/PluginManager/Disabled/FakePatches/FakePatch_" + checkPackage->getNameValidFile() + L"_" + checkPackage->author().toWString() + L"_" + f->name();
3241
				newFilename = m_sCurrentDir + L"/PluginManager/Disabled/FakePatches/FakePatch_" + checkPackage->getNameValidFile() + L"_" + checkPackage->author() + L"_" + f->name();
3242
				shuffle = true;
3242
				shuffle = true;
3243
			}
3243
			}
3244
		}
3244
		}
3245
		else if ( f->isAutoTextFile() )
3245
		else if ( f->isAutoTextFile() )
3246
		{
3246
		{
3247
			if ( checkPackage )
3247
			if ( checkPackage )
3248
			{
3248
			{
3249
				newFilename = m_sCurrentDir + L"/PluginManager/Disabled/TextFiles/Text_" + checkPackage->getNameValidFile() + L"_" + checkPackage->author().toWString() + L"_" + f->name();
3249
				newFilename = m_sCurrentDir + L"/PluginManager/Disabled/TextFiles/Text_" + checkPackage->getNameValidFile() + L"_" + checkPackage->author() + L"_" + f->name();
3250
				shuffle = true;
3250
				shuffle = true;
3251
			}
3251
			}
3252
		}
3252
		}
3253
		// otherwise we can just use the standard filename
3253
		// otherwise we can just use the standard filename
3254
		else
3254
		else
Line 3381... Line 3381...
3381
	if ( package->GetType() == TYPE_SPK )
3381
	if ( package->GetType() == TYPE_SPK )
3382
		return findSpkPackage(package->name(), package->author());
3382
		return findSpkPackage(package->name(), package->author());
3383
	else if ( package->GetType() == TYPE_XSP )
3383
	else if ( package->GetType() == TYPE_XSP )
3384
		return findXspPackage(((CXspFile *)package)->GetShipID());
3384
		return findXspPackage(((CXspFile *)package)->GetShipID());
3385
	else if ( package->GetType() == TYPE_ARCHIVE )
3385
	else if ( package->GetType() == TYPE_ARCHIVE )
3386
		return findArchivePackage(package->name());
3386
		return findArchivePackage(package->name().toString());
3387
 
3387
 
3388
	// nothing found obviously
3388
	// nothing found obviously
3389
	return 0;
3389
	return 0;
3390
}
3390
}
3391
 
3391
 
Line 3461... Line 3461...
3461
/**
3461
/**
3462
 * Find a SPK Package
3462
 * Find a SPK Package
3463
 *
3463
 *
3464
 * This searching all installed packages for a SPK Package matching the name and author
3464
 * This searching all installed packages for a SPK Package matching the name and author
3465
 */
3465
 */
3466
CBaseFile *CPackages::findSpkPackage(const Utils::String &name, const Utils::String &author) const
3466
CBaseFile *CPackages::findSpkPackage(const Utils::WString &name, const Utils::WString &author) const
3467
{
3467
{
3468
	// interate through all packages
3468
	// interate through all packages
3469
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3469
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3470
	{
3470
	{
3471
		CBaseFile *file = node->Data();
3471
		CBaseFile *file = node->Data();
Line 3489... Line 3489...
3489
	for (CListNode<CBaseFile>* node = m_lPackages.Front(); node; node = node->next())
3489
	for (CListNode<CBaseFile>* node = m_lPackages.Front(); node; node = node->next())
3490
	{
3490
	{
3491
		CBaseFile* file = node->Data();
3491
		CBaseFile* file = node->Data();
3492
 
3492
 
3493
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3493
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3494
		if (file->name().toWString().Compare(name) &;& file->author().toWString().Compare(author))
3494
		if (file->name().Compare(name) &;& file->author().Compare(author))
3495
			return file;
3495
			return file;
3496
	}
3496
	}
3497
 
3497
 
3498
	// nothing found
3498
	// nothing found
3499
	return 0;
3499
	return 0;
Line 3655... Line 3655...
3655
					return false;
3655
					return false;
3656
 
3656
 
3657
				bool found = false;
3657
				bool found = false;
3658
				for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
3658
				for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
3659
				{
3659
				{
3660
					if ( spk->GetOtherName().Compare(node->Data()->name()) && spk->;GetOtherAuthor().Compare(node->Data()->author()) )
3660
					if ( spk->GetOtherName().Compare(node->Data()->name().toString()) && spk->;GetOtherAuthor().Compare(node->Data()->author().toString()) )
3661
					{
3661
					{
3662
						found = true;
3662
						found = true;
3663
						break;
3663
						break;
3664
					}
3664
					}
3665
				}
3665
				}
Line 3694... Line 3694...
3694
	// check any dependacies
3694
	// check any dependacies
3695
	if ( p->AnyDependacies() )
3695
	if ( p->AnyDependacies() )
3696
	{
3696
	{
3697
		for ( CListNode<SNeededLibrary> *dNode = p->GetNeededLibraries()->Front(); dNode; dNode = dNode->next() )
3697
		for ( CListNode<SNeededLibrary> *dNode = p->GetNeededLibraries()->Front(); dNode; dNode = dNode->next() )
3698
		{
3698
		{
3699
			if ( dNode->Data()->sName.Compare("<package>") )
3699
			if ( dNode->Data()->sName.Compare(L"<package>") )
3700
				continue;
3700
				continue;
3701
			if ( !this->checkInstalledDependacy(dNode->Data()->sName, dNode->Data()->sAuthor, dNode->Data()->sMinVersion, true, true) )
3701
			if ( !this->checkInstalledDependacy(dNode->Data()->sName.toString(), dNode->Data()->sAuthor.toString(), dNode->Data()->sMinVersion, true, true))
3702
				return false;
3702
				return false;
3703
		}
3703
		}
3704
	}
3704
	}
3705
 
3705
 
3706
	return true;
3706
	return true;
3707
}
3707
}
3708
 
3708
 
3709
bool CPackages::checkInstalledDependacy(const Utils::String &name, const Utils::String &author, const Utils::String &version, bool onlyEnabled, bool includePrepared) const
3709
bool CPackages::checkInstalledDependacy(const Utils::WString &name, const Utils::WString &author, const Utils::String &version, bool onlyEnabled, bool includePrepared) const
3710
{
3710
{
3711
	CBaseFile *p = this->findSpkPackage(name, author);
3711
	CBaseFile *p = this->findSpkPackage(name, author);
3712
	if ( p )
3712
	if ( p )
3713
	{
3713
	{
3714
		// now check version
3714
		// now check version
Line 3752... Line 3752...
3752
	if (neededList)
3752
	if (neededList)
3753
	{
3753
	{
3754
		for (CListNode<SNeededLibrary> *node = neededList->Front(); node; node = node->next())
3754
		for (CListNode<SNeededLibrary> *node = neededList->Front(); node; node = node->next())
3755
		{
3755
		{
3756
			SNeededLibrary *nl = node->Data();
3756
			SNeededLibrary *nl = node->Data();
3757
			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))
3757
			if (!checkInstalledDependacy((nl->sName.Compare(L"<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare(L"<author>")) ? p->author() : nl->sAuthor, nl->sMinVersion, (nl->sName.Compare(L"<package>")) ? false : onlyEnabled, (nl->sName.Compare(L"<package>")) ? false : includePrepared))
3758
			{
3758
			{
3759
				bool found = false;
3759
				bool found = false;
3760
				for (auto itr = packages.Front(); itr; itr = itr->next())
3760
				for (auto itr = packages.Front(); itr; itr = itr->next())
3761
				{
3761
				{
3762
					if (itr->Data()->name().Compare(nl->sName) && itr->Data()->author().Compare(nl->sAuthor) && nl->sMinVersion.compareVersion(itr->Data()->version()) >= 0)
3762
					if (itr->Data()->name().Compare(nl->sName) && itr->Data()->author().Compare(nl->sAuthor) && nl->sMinVersion.compareVersion(itr->Data()->version()) >= 0)
3763
					{
3763
					{
3764
						if (!findAllNeededDependacies(itr->Data(), packages, foundPackages, onlyEnabled, includePrepared))
3764
						if (!findAllNeededDependacies(itr->Data(), packages, foundPackages, onlyEnabled, includePrepared))
3765
							return false;
3765
							return false;
3766
						if (foundPackages)
3766
						if (foundPackages)
3767
						{
3767
						{
3768
							bool added = false;
3768
							bool added = false;
3769
							for (auto itr2 = foundPackages->Front(); itr2; itr2 = itr2->next())
3769
							for (auto itr2 = foundPackages->Front(); itr2; itr2 = itr2->next())
3770
							{
3770
							{
3771
								if (itr->Data() == itr2->Data() || (itr->Data()->name().Compare(itr2->Data()->name()) && itr->Data()->author().Compare(itr2->Data()->author())))
3771
								if (itr->Data() == itr2->Data() || (itr->Data()->name().Compare(itr2->Data()->name()) && itr->Data()->author().Compare(itr2->Data()->author())))
3772
								{
3772
								{
3773
									added = true;
3773
									added = true;
3774
									break;
3774
									break;
3775
								}
3775
								}
3776
							}
3776
							}
3777
							if(!added)
3777
							if(!added)
3778
								foundPackages->push_front(itr->Data());
3778
								foundPackages->push_front(itr->Data());
3779
						}
3779
						}
3780
						found = true;
3780
						found = true;
3781
						break;
3781
						break;
3782
					}
3782
					}
3783
				}
3783
				}
3784
				if (!found)
3784
				if (!found)
3785
					return false;
3785
					return false;
3786
			}
3786
			}
3787
		}
3787
		}
3788
	}
3788
	}
3789
 
3789
 
3790
	if (p->GetType() == TYPE_SPK)
3790
	if (p->GetType() == TYPE_SPK)
3791
	{
3791
	{
Line 3800... Line 3800...
3800
					found = false;
3800
					found = false;
3801
					for (CListNode<CBaseFile> *pNode = m_lInstallList.Front(); pNode; pNode = pNode->next())
3801
					for (CListNode<CBaseFile> *pNode = m_lInstallList.Front(); pNode; pNode = pNode->next())
3802
					{
3802
					{
3803
						CBaseFile *checkP = pNode->Data();
3803
						CBaseFile *checkP = pNode->Data();
3804
						if (p->author().Compare(checkP->author()) && p->name().Compare(checkP->name()))
3804
						if (p->author().Compare(checkP->author()) && p->name().Compare(checkP->name()))
3805
						{
3805
						{
3806
							found = true;
3806
							found = true;
3807
							break;
3807
							break;
3808
						}
3808
						}
3809
					}
3809
					}
3810
				}
3810
				}
Line 3830... Line 3830...
3830
									added = true;
3830
									added = true;
3831
									break;
3831
									break;
3832
								}
3832
								}
3833
							}
3833
							}
3834
							if (!added)
3834
							if (!added)
3835
								foundPackages->push_front(itr->Data());
3835
								foundPackages->push_front(itr->Data());
3836
						}
3836
						}
3837
						found = true;
3837
						found = true;
3838
						break;
3838
						break;
3839
					}
3839
					}
3840
				}
3840
				}
3841
 
3841
 
3842
				if(!found)
3842
				if(!found)
3843
					return false;
3843
					return false;
3844
			}
3844
			}
3845
		}
3845
		}
3846
	}
3846
	}
3847
 
3847
 
3848
	return true;
3848
	return true;
3849
 
3849
 
Line 3859... Line 3859...
3859
		{
3859
		{
3860
			SNeededLibrary* nl = node->Data();
3860
			SNeededLibrary* nl = node->Data();
3861
			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))
3861
			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))
3862
			{
3862
			{
3863
				const SAvailablePackage *available = findAvailablePackage((nl->sName.Compare("<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor);
3863
				const SAvailablePackage *available = findAvailablePackage((nl->sName.Compare("<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor);
3864
				if (available)
3864
				if (available)
3865
					list.push_back(available);
3865
					list.push_back(available);
3866
				++count;
3866
				++count;
3867
			}
3867
			}
3868
		}
3868
		}
3869
	}
3869
	}
Line 3904... Line 3904...
3904
	}
3904
	}
3905
 
3905
 
3906
	return count;
3906
	return count;
3907
}
3907
}
3908
 
3908
 
3909
int CPackages::GetMissingDependacies(CBaseFile *p, Utils::CStringList *list, bool onlyEnabled, bool includePrepared)
3909
int CPackages::getMissingDependacies(CBaseFile *p, Utils::WStringList *list, bool onlyEnabled, bool includePrepared)
3910
{
3910
{
3911
	int count = 0;
3911
	int count = 0;
3912
	CLinkList<SNeededLibrary> *neededList = p->GetNeededLibraries();
3912
	CLinkList<SNeededLibrary> *neededList = p->GetNeededLibraries();
3913
	if ( neededList )
3913
	if ( neededList )
3914
	{
3914
	{
3915
		for ( CListNode<SNeededLibrary> *node = neededList->Front(); node; node = node->next() )
3915
		for ( CListNode<SNeededLibrary> *node = neededList->Front(); node; node = node->next() )
3916
		{
3916
		{
3917
			SNeededLibrary *nl = node->Data();
3917
			SNeededLibrary *nl = node->Data();
3918
			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) )
3918
			if ( !checkInstalledDependacy((nl->sName.Compare(L"<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare(L"<author>")) ? p->author() : nl->sAuthor, nl->sMinVersion, (nl->sName.Compare(L"<package>")) ? false : onlyEnabled, (nl->sName.Compare(L"<package>")) ? false : includePrepared) )
3919
			{
3919
			{
3920
				if ( list )
3920
				if ( list )
3921
					list->pushBack(((nl->sName.Compare("<package>")) ? p->name() : nl->sName) + "|" + nl->sMinVersion, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor);
3921
					list->pushBack(((nl->sName.Compare(L"<package>")) ? p->name() : nl->sName) + L"|" + nl->sMinVersion.toWString(), (nl->sAuthor.Compare(L"<author>")) ? p->author() : nl->sAuthor);
3922
				++count;
3922
				++count;
3923
			}
3923
			}
3924
		}
3924
		}
3925
	}
3925
	}
3926
 
3926
 
3927
	if ( p->GetType() == TYPE_SPK )
3927
	if ( p->GetType() == TYPE_SPK )
3928
	{
3928
	{
3929
		CSpkFile *spk = (CSpkFile *)p;
3929
		CSpkFile *spk = (CSpkFile *)p;
3930
		if ( spk->IsAnotherMod() )
3930
		if ( spk->IsAnotherMod() )
Line 3971... Line 3971...
3971
 
3971
 
3972
		// no requirements found, remove from list
3972
		// no requirements found, remove from list
3973
		bool missingDep = false;
3973
		bool missingDep = false;
3974
		if ( !this->CheckOtherPackage(p) )
3974
		if ( !this->CheckOtherPackage(p) )
3975
			missingDep = true;
3975
			missingDep = true;
3976
		else if ( this->GetMissingDependacies(p, NULL, false, true) )
3976
		else if ( this->getMissingDependacies(p, NULL, false, true) )
3977
			missingDep = true;
3977
			missingDep = true;
3978
 
3978
 
3979
		if ( missingDep )
3979
		if ( missingDep )
3980
		{
3980
		{
3981
			if ( list )
3981
			if ( list )
Line 3990... Line 3990...
3990
	}
3990
	}
3991
 
3991
 
3992
	m_lInstallList.RemoveEmpty();
3992
	m_lInstallList.RemoveEmpty();
3993
 
3993
 
3994
	return count;
3994
	return count;
3995
}
3995
}
3996
 
3996
 
3997
 
3997
 
3998
/**
3998
/**
3999
 * Remove uninstall file
3999
 * Remove uninstall file
4000
 *
4000
 *
4001
 * Removes a single uninstall file
4001
 * Removes a single uninstall file
4002
 */
4002
 */
4003
bool CPackages::removeUninstallFile(C_File *file, Utils::WStringList *errors)
4003
bool CPackages::removeUninstallFile(C_File *file, Utils::WStringList *errors)
4004
{
4004
{
4005
	CFileIO fio(file->filePointer());
4005
	CFileIO fio(file->filePointer());
4006
	if ( fio.exists() )
4006
	if ( fio.exists() )
4007
	{
4007
	{
4008
		if ( fio.remove() ) {
4008
		if ( fio.remove() ) {
4009
			this->addLogEntry(SPKINSTALL_UNINSTALL_REMOVE, file->getNameDirectory(NULL), errors);
4009
			this->addLogEntry(SPKINSTALL_UNINSTALL_REMOVE, file->getNameDirectory(NULL), errors);
4010
			return true;
4010
			return true;
4011
		}
4011
		}
4012
		else if ( errors )
4012
		else if ( errors )
4013
			this->addLogEntry(SPKINSTALL_UNINSTALL_REMOVE_FAIL, file->getNameDirectory(NULL), errors);
4013
			this->addLogEntry(SPKINSTALL_UNINSTALL_REMOVE_FAIL, file->getNameDirectory(NULL), errors);
4014
	}
4014
	}
4015
 
4015
 
4016
	return false;
4016
	return false;
4017
}
4017
}
4018
 
4018
 
4019
/**
4019
/**
Line 4067... Line 4067...
4067
}
4067
}
4068
 
4068
 
4069
 
4069
 
4070
/**
4070
/**
4071
 * Remove unused shared file
4071
 * Remove unused shared file
4072
 *
4072
 *
4073
 * Removes a single file
4073
 * Removes a single file
4074
 */
4074
 */
4075
bool CPackages::removeSharedFile(C_File *file, Utils::WStringList *errors)
4075
bool CPackages::removeSharedFile(C_File *file, Utils::WStringList *errors)
4076
{
4076
{
4077
	CFileIO fio(file->filePointer());
4077
	CFileIO fio(file->filePointer());
Line 4085... Line 4085...
4085
		else if ( errors )
4085
		else if ( errors )
4086
			this->addLogEntry(SPKINSTALL_SHARED_FAIL, file->getNameDirectory(NULL), errors);
4086
			this->addLogEntry(SPKINSTALL_SHARED_FAIL, file->getNameDirectory(NULL), errors);
4087
	}
4087
	}
4088
 
4088
 
4089
	return false;
4089
	return false;
4090
}
4090
}
4091
 
4091
 
4092
/**
4092
/**
4093
 * Remove Unused Shared Files
4093
 * Remove Unused Shared Files
4094
 *
4094
 *
4095
 * Files that have been marked as shared will not be removed or disabled when the last package is removed
4095
 * Files that have been marked as shared will not be removed or disabled when the last package is removed
4096
 * This function will remove any that are no longer connected with packages
4096
 * This function will remove any that are no longer connected with packages
Line 4114... Line 4114...
4114
		// only do marked shared files
4114
		// only do marked shared files
4115
		if ( !file->IsShared() )
4115
		if ( !file->IsShared() )
4116
			continue;
4116
			continue;
4117
 
4117
 
4118
		// only do ones that are no longer needed
4118
		// only do ones that are no longer needed
4119
		if ( file->getUsed() )
4119
		if ( file->getUsed() )
4120
			continue;
4120
			continue;
4121
 
4121
 
4122
		if (removeSharedFile(file, errors) )
4122
		if (removeSharedFile(file, errors) )
4123
			++done;
4123
			++done;
4124
		node->ChangeData(NULL);
4124
		node->ChangeData(NULL);
4125
	}
4125
	}
Line 4144... Line 4144...
4144
	{
4144
	{
4145
		C_File *file = node->Data();
4145
		C_File *file = node->Data();
4146
 
4146
 
4147
		// only do marked shared files
4147
		// only do marked shared files
4148
		if ( !file->IsShared() )
4148
		if ( !file->IsShared() )
4149
			continue;
4149
			continue;
4150
 
4150
 
4151
		// only do ones that are no longer needed
4151
		// only do ones that are no longer needed
4152
		if ( file->getUsed() )
4152
		if ( file->getUsed() )
4153
			continue;
4153
			continue;
4154
 
4154
 
4155
		return true;
4155
		return true;
4156
	}
4156
	}
4157
 
4157
 
4158
	return false;
4158
	return false;
4159
 
4159
 
4160
}
4160
}
4161
 
4161
 
4162
void CPackages::shuffleTextFiles(Utils::WStringList *errors)
4162
void CPackages::shuffleTextFiles(Utils::WStringList *errors)
4163
{
4163
{
4164
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4164
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4165
	{
4165
	{
4166
		C_File *f = node->Data();
4166
		C_File *f = node->Data();
4167
		// only do files that are enabled
4167
		// only do files that are enabled
4168
		if ( f->IsDisabled() )
4168
		if ( f->IsDisabled() )
4169
			continue;
4169
			continue;
4170
 
4170
 
4171
		if ( f->GetFileType() != FILETYPE_TEXT )
4171
		if ( f->GetFileType() != FILETYPE_TEXT )
4172
			continue;
4172
			continue;
4173
 
4173
 
4174
		// check if the file is an auto text file
4174
		// check if the file is an auto text file
4175
		if ( !f->isAutoTextFile() )
4175
		if ( !f->isAutoTextFile() )
Line 4223... Line 4223...
4223
		if (p->AnyDependacies())
4223
		if (p->AnyDependacies())
4224
		{
4224
		{
4225
			for (SNeededLibrary* nl = p->GetNeededLibraries()->First(); nl; nl = p->GetNeededLibraries()->Next())
4225
			for (SNeededLibrary* nl = p->GetNeededLibraries()->First(); nl; nl = p->GetNeededLibraries()->Next())
4226
			{
4226
			{
4227
				auto package = findPackage(nl->sName, nl->sAuthor);
4227
				auto package = findPackage(nl->sName, nl->sAuthor);
4228
				if (package)
4228
				if (package)
4229
				{
4229
				{
4230
					packagesBefore.insert(package);
4230
					packagesBefore.insert(package);
4231
					packagesAfter[p].insert(package);
4231
					packagesAfter[p].insert(package);
4232
				}
4232
				}
4233
			}
4233
			}
Line 4379... Line 4379...
4379
					if (!file->checkFileExt(L"cat")) continue; // only do the cat file, we can shuffle the dat file to match later
4379
					if (!file->checkFileExt(L"cat")) continue; // only do the cat file, we can shuffle the dat file to match later
4380
					if (doneList.FindData(file)) continue; // already done?
4380
					if (doneList.FindData(file)) continue; // already done?
4381
 
4381
 
4382
					if ( !lowestFile )
4382
					if ( !lowestFile )
4383
						lowestFile = file;
4383
						lowestFile = file;
4384
					else
4384
					else
4385
					{
4385
					{
4386
						if ( file->baseName().toInt() < lowestFile->baseName().toInt() )
4386
						if ( file->baseName().toInt() < lowestFile->baseName().toInt() )
4387
							lowestFile = file;
4387
							lowestFile = file;
4388
					}
4388
					}
4389
				}
4389
				}
Line 4437... Line 4437...
4437
		if ( !f->IsFakePatch() )
4437
		if ( !f->IsFakePatch() )
4438
			continue;
4438
			continue;
4439
 
4439
 
4440
		// we only want cat and dat files, all fake patchs should be, but incase theres an error in the package somewhere we can check
4440
		// we only want cat and dat files, all fake patchs should be, but incase theres an error in the package somewhere we can check
4441
		if (!f->checkFileExt("cat"))
4441
		if (!f->checkFileExt("cat"))
4442
			continue;
4442
			continue;
4443
 
4443
 
4444
		// now lets check if its greater than our gap
4444
		// now lets check if its greater than our gap
4445
		int check = findNextFakePatch();
4445
		int check = findNextFakePatch();
4446
		int patchNum = f->filename().token(L".", 1).toInt();
4446
		int patchNum = f->filename().token(L".", 1).toInt();
4447
		if ( patchNum <= check )
4447
		if ( patchNum <= check )
4448
			continue;
4448
			continue;
4449
 
4449
 
4450
		shufflePatchTo(f, check, errors);
4450
		shufflePatchTo(f, check, errors);
4451
	}
4451
	}
4452
}
4452
}
4453
 
4453
 
4454
void CPackages::shufflePatchTo(C_File *file, int to, Utils::WStringList *errors)
4454
void CPackages::shufflePatchTo(C_File *file, int to, Utils::WStringList *errors)
4455
{
4455
{
4456
	// it is, we need to shift this to fill the gap
4456
	// it is, we need to shift this to fill the gap
4457
	Utils::WString newName = Utils::WString::PadNumber(to, 2) + L"." + file->fileExt();
4457
	Utils::WString newName = Utils::WString::PadNumber(to, 2) + L"." + file->fileExt();
4458
 
4458
 
4459
	// now rename the file
4459
	// now rename the file
4460
	CFileIO moveFile(file->filePointer());
4460
	CFileIO moveFile(file->filePointer());
4461
	if ( moveFile.Rename(m_sCurrentDir + L"/" + newName) )
4461
	if ( moveFile.Rename(m_sCurrentDir + L"/" + newName) )
4462
	{
4462
	{
4463
		// display moveing
4463
		// display moveing
4464
		this->addLogEntry(SPKINSTALL_FAKEPATCH, file->name() + L"~" + newName, errors);
4464
		this->addLogEntry(SPKINSTALL_FAKEPATCH, file->name() + L"~" + newName, errors);
4465
 
4465
 
4466
		// now find the matching pairing if it exists
4466
		// now find the matching pairing if it exists
4467
		for ( CListNode<C_File> *node2 = m_lFiles.Front(); node2; node2 = node2->next() )
4467
		for ( CListNode<C_File> *node2 = m_lFiles.Front(); node2; node2 = node2->next() )
Line 4512... Line 4512...
4512
				lowest = check;
4512
				lowest = check;
4513
		}
4513
		}
4514
	}
4514
	}
4515
 
4515
 
4516
	return lowest;
4516
	return lowest;
4517
}
4517
}
4518
 
4518
 
4519
int CPackages::findLastFakePatch(int start, const Utils::WString &dir) const
4519
int CPackages::findLastFakePatch(int start, const Utils::WString &dir) const
4520
{
4520
{
4521
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4521
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4522
 
4522
 
Line 4531... Line 4531...
4531
			// it doen't, check if theres a dat file (incase of package error)
4531
			// it doen't, check if theres a dat file (incase of package error)
4532
			if ( !Dir.exists(checkStr + L".dat") )
4532
			if ( !Dir.exists(checkStr + L".dat") )
4533
				break;
4533
				break;
4534
		}
4534
		}
4535
		--check;
4535
		--check;
4536
	}
4536
	}
4537
 
4537
 
4538
	return check;
4538
	return check;
4539
}
4539
}
4540
 
4540
 
4541
/**
4541
/**
4542
 * Find next fake patch
4542
 * Find next fake patch
4543
 *
4543
 *
4544
 * Searching for the next gap in patches, starting with 01.cat to 99.cat
4544
 * Searching for the next gap in patches, starting with 01.cat to 99.cat
4545
 */
4545
 */
4546
int CPackages::findNextFakePatch(int start, const Utils::WString &dir) const
4546
int CPackages::findNextFakePatch(int start, const Utils::WString &dir) const
4547
{
4547
{
4548
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4548
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4549
 
4549
 
4550
	int check = start;
4550
	int check = start;
4551
	while ( check < 99 )
4551
	while ( check < 99 )
4552
	{
4552
	{
4553
		++check;
4553
		++check;
4554
		Utils::WString checkStr = Utils::WString::PadNumber(check, 2);
4554
		Utils::WString checkStr = Utils::WString::PadNumber(check, 2);
4555
 
4555
 
Line 4573... Line 4573...
4573
unsigned int CPackages::findNextTextFile(unsigned int start) const
4573
unsigned int CPackages::findNextTextFile(unsigned int start) const
4574
{
4574
{
4575
	return findNextTextFile(Utils::String::Null(), start);
4575
	return findNextTextFile(Utils::String::Null(), start);
4576
}
4576
}
4577
unsigned int CPackages::findNextTextFile(const Utils::WString &dir, unsigned int start) const
4577
unsigned int CPackages::findNextTextFile(const Utils::WString &dir, unsigned int start) const
4578
{
4578
{
4579
	int check = start;
4579
	int check = start;
4580
	if ( check < 2 ) check = 2;
4580
	if ( check < 2 ) check = 2;
4581
	while ( check < 9999 )
4581
	while ( check < 9999 )
4582
	{
4582
	{
4583
		++check;
4583
		++check;
4584
		Utils::WString newFilename = SPK::FormatTextName(check, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4584
		Utils::WString newFilename = SPK::FormatTextName(check, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4585
 
4585
 
4586
		// check the vfs
4586
		// check the vfs
4587
		if ( m_pGameVFS.isFileAvailable(L"t/" + newFilename + L".pck") ) continue;
4587
		if ( m_pGameVFS.isFileAvailable(L"t/" + newFilename + L".pck") ) continue;
4588
		if ( m_pGameVFS.isFileAvailable(L"t/" + newFilename + L".xml") ) continue;
4588
		if ( m_pGameVFS.isFileAvailable(L"t/" + newFilename + L".xml") ) continue;
4589
 
4589
 
4590
		break;
4590
		break;
4591
	}
4591
	}
4592
 
4592
 
4593
	return check;
4593
	return check;
4594
}
4594
}
Line 4612... Line 4612...
4612
				break;
4612
				break;
4613
		}
4613
		}
4614
	}
4614
	}
4615
 
4615
 
4616
	return check;
4616
	return check;
4617
}
4617
}
4618
 
4618
 
4619
/**
4619
/**
4620
 * Read game language
4620
 * Read game language
4621
 *
4621
 *
4622
 * Reads the lang.dat file from the game directory for the language id
4622
 * Reads the lang.dat file from the game directory for the language id
4623
 */
4623
 */
Line 4847... Line 4847...
4847
{
4847
{
4848
	// now we need to find all scripts that have a matching file and add this to the list
4848
	// now we need to find all scripts that have a matching file and add this to the list
4849
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
4849
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
4850
	{
4850
	{
4851
		CBaseFile *package = node->Data();
4851
		CBaseFile *package = node->Data();
4852
 
4852
 
4853
		// first make sure it doesn't already exist
4853
		// first make sure it doesn't already exist
4854
		if ( package->GetFileList()->FindData(file) )
4854
		if ( package->GetFileList()->FindData(file) )
4855
			continue;
4855
			continue;
4856
 
4856
 
4857
		bool found = false;
4857
		bool found = false;
Line 4864... Line 4864...
4864
			Utils::WString id = tFile->baseName().token(L"-", 1);
4864
			Utils::WString id = tFile->baseName().token(L"-", 1);
4865
			if ( id == textid )
4865
			if ( id == textid )
4866
			{
4866
			{
4867
				found = true;
4867
				found = true;
4868
				break;
4868
				break;
4869
			}
4869
			}
4870
		}
4870
		}
4871
 
4871
 
4872
		if ( found )
4872
		if ( found )
4873
			package->GetFileList()->push_back(file);
4873
			package->GetFileList()->push_back(file);
4874
	}
4874
	}
4875
}
4875
}
Line 4922... Line 4922...
4922
	int files = 0;
4922
	int files = 0;
4923
 
4923
 
4924
	// remove all files
4924
	// remove all files
4925
	int max = m_lFiles.size() + _pOriginalFiles->count() + m_lUninstallFiles.size();
4925
	int max = m_lFiles.size() + _pOriginalFiles->count() + m_lUninstallFiles.size();
4926
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4926
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4927
	{
4927
	{
4928
		// update the progress
4928
		// update the progress
4929
		if ( progress )
4929
		if ( progress )
4930
			progress->UpdateProgress(files, max);
4930
			progress->UpdateProgress(files, max);
4931
		++files;
4931
		++files;
4932
 
4932
 
4933
		removeFile(node->Data());
4933
		removeFile(node->Data());
4934
		delete node->Data();
4934
		delete node->Data();
4935
	}
4935
	}
Line 4983... Line 4983...
4983
	return package->uninstallText(m_iLanguage, true);
4983
	return package->uninstallText(m_iLanguage, true);
4984
}
4984
}
4985
Utils::String CPackages::getUninstallAfterText(CBaseFile *package) const
4985
Utils::String CPackages::getUninstallAfterText(CBaseFile *package) const
4986
{
4986
{
4987
	return package->uninstallText(m_iLanguage, false);
4987
	return package->uninstallText(m_iLanguage, false);
4988
}
4988
}
4989
 
4989
 
4990
int CPackages::GetChildPackages(CBaseFile *package, CLinkList<CBaseFile> *children, bool recursive)
4990
int CPackages::GetChildPackages(CBaseFile *package, CLinkList<CBaseFile> *children, bool recursive)
4991
{
4991
{
4992
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
4992
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
4993
	{
4993
	{
4994
		CBaseFile *p = node->Data();
4994
		CBaseFile *p = node->Data();
Line 5003... Line 5003...
5003
 
5003
 
5004
	return children->size();
5004
	return children->size();
5005
}
5005
}
5006
 
5006
 
5007
void CPackages::AssignPackageNumbers()
5007
void CPackages::AssignPackageNumbers()
5008
{
5008
{
5009
	int num = 0;
5009
	int num = 0;
5010
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5010
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5011
		node->Data()->SetNum(num++);
5011
		node->Data()->SetNum(num++);
5012
}
5012
}
5013
 
5013
 
5014
Utils::WString CPackages::findDataDir(const Utils::WString &dir, const Utils::WString &file)
5014
Utils::WString CPackages::findDataDir(const Utils::WString &dir, const Utils::WString &file)
5015
{
5015
{
5016
	CDirIO Dir(dir);
5016
	CDirIO Dir(dir);
5017
 
5017
 
5018
	// data files could be in 4 places depending on what program is used, check for all of these
5018
	// data files could be in 4 places depending on what program is used, check for all of these
5019
	if (Dir.exists(file))
5019
	if (Dir.exists(file))
5020
		return Dir.file(file);
5020
		return Dir.file(file);
5021
	else if (Dir.exists(L"Data/" + file))
5021
	else if (Dir.exists(L"Data/" + file))
5022
		return Dir.file(L"Data/" + file);
5022
		return Dir.file(L"Data/" + file);
5023
	else if (Dir.exists(L"../" + file))
5023
	else if (Dir.exists(L"../" + file))
5024
		return Dir.file(L"../" + file);
5024
		return Dir.file(L"../" + file);
5025
	else if (Dir.exists(L"../Data/" + file))
5025
	else if (Dir.exists(L"../Data/" + file))
5026
		return Dir.file(L"../Data/" + file);
5026
		return Dir.file(L"../Data/" + file);
5027
 
5027
 
5028
	return Utils::WString::Null();
5028
	return Utils::WString::Null();
5029
}
5029
}
5030
 
5030
 
5031
void CPackages::startup(const Utils::WString &dir, const Utils::WString &tempDir, const Utils::WString &myDoc)
5031
void CPackages::startup(const Utils::WString &dir, const Utils::WString &tempDir, const Utils::WString &myDoc)
5032
{
5032
{
Line 5080... Line 5080...
5080
 
5080
 
5081
		if ( data )
5081
		if ( data )
5082
		{
5082
		{
5083
			Utils::String str(data);
5083
			Utils::String str(data);
5084
			return str.token("\n", 1).token(" ", 1).toLong();
5084
			return str.token("\n", 1).token(" ", 1).toLong();
5085
		}
5085
		}
5086
	}
5086
	}
5087
 
5087
 
5088
	return 0;
5088
	return 0;
5089
}
5089
}
5090
Utils::WString CPackages::getGameRunExe(const Utils::WString &dir) const
5090
Utils::WString CPackages::getGameRunExe(const Utils::WString &dir) const
5091
{
5091
{
Line 5312... Line 5312...
5312
			else if ( e == -2 )
5312
			else if ( e == -2 )
5313
				openFile = wareFile + L".txt";
5313
				openFile = wareFile + L".txt";
5314
		}
5314
		}
5315
 
5315
 
5316
		if ( !openFile.empty() )
5316
		if ( !openFile.empty() )
5317
		{
5317
		{
5318
			// read the file into memory
5318
			// read the file into memory
5319
			Utils::WStringList wareLines;
5319
			Utils::WStringList wareLines;
5320
			size_t oldSize = -1;
5320
			size_t oldSize = -1;
5321
			int version = -1;
5321
			int version = -1;
5322
 
5322
 
5323
			// read first number
5323
			// read first number
5324
			CFileIO readFile(m_sTempDir + L"/" + wareFile + L".txt");
5324
			CFileIO readFile(m_sTempDir + L"/" + wareFile + L".txt");
5325
			std::vector<Utils::WString> lines;
5325
			std::vector<Utils::WString> lines;
Line 5335... Line 5335...
5335
						continue;
5335
						continue;
5336
					if ( line[0] == '/' )
5336
					if ( line[0] == '/' )
5337
						continue;
5337
						continue;
5338
 
5338
 
5339
					if ( oldSize == -1 )
5339
					if ( oldSize == -1 )
5340
					{
5340
					{
5341
						version = line.token(L";", 1).toInt();
5341
						version = line.token(L";", 1).toInt();
5342
						oldSize = line.token(L";", 2).toInt();
5342
						oldSize = line.token(L";", 2).toInt();
5343
					}
5343
					}
5344
					else
5344
					else
5345
					{
5345
					{
Line 5392... Line 5392...
5392
						int notority = w->pWare->iNotority;
5392
						int notority = w->pWare->iNotority;
5393
						if ( !this->customWareOverideNoto(w->pWare->sID, &notority) ) notority = w->pWare->iNotority;
5393
						if ( !this->customWareOverideNoto(w->pWare->sID, &notority) ) notority = w->pWare->iNotority;
5394
						if ( !price ) price = w->pWare->iPrice;
5394
						if ( !price ) price = w->pWare->iPrice;
5395
 
5395
 
5396
						wareLines.pushBack(Utils::WString("28;0;0;0;0;") + (long)wareLines.size() + L";" + (long)(w->iText + 3) + L";" + (long)w->pWare->iVolumn + L";" + price + L";1;1;" + (long)w->pWare->iSize + L";" + price + L";" + (long)notority + L";0;0;" + w->sWareName.upper() + L";");
5396
						wareLines.pushBack(Utils::WString("28;0;0;0;0;") + (long)wareLines.size() + L";" + (long)(w->iText + 3) + L";" + (long)w->pWare->iVolumn + L";" + price + L";1;1;" + (long)w->pWare->iSize + L";" + price + L";" + (long)notority + L";0;0;" + w->sWareName.upper() + L";");
5397
					}
5397
					}
5398
				}
5398
				}
5399
 
5399
 
5400
				if ( create )
5400
				if ( create )
5401
				{
5401
				{
5402
					wareLines.pushFront(Utils::String::Number(version) + ";" + Utils::String::Number(wareLines.size()) + ";", Utils::String::Null());
5402
					wareLines.pushFront(Utils::String::Number(version) + ";" + Utils::String::Number(wareLines.size()) + ";", Utils::String::Null());
5403
					Utils::WString strV = Utils::WString::FromFloat(GetLibraryVersion(), 2);
5403
					Utils::WString strV = Utils::WString::FromFloat(GetLibraryVersion(), 2);
Line 5547... Line 5547...
5547
								line = line.replaceToken(L";", 13, Utils::WString::Number(price));
5547
								line = line.replaceToken(L";", 13, Utils::WString::Number(price));
5548
							}
5548
							}
5549
 
5549
 
5550
							int noto = 0;
5550
							int noto = 0;
5551
							if ( this->builtInWareOverideNoto(pos, &noto) ) {
5551
							if ( this->builtInWareOverideNoto(pos, &noto) ) {
5552
								line = line.replaceToken(L";", 14, Utils::WString::Number(noto));
5552
								line = line.replaceToken(L";", 14, Utils::WString::Number(noto));
5553
							}
5553
							}
5554
						}
5554
						}
5555
 
5555
 
5556
						// check for any override values for EMP
5556
						// check for any override values for EMP
5557
						if ( i >= 116 ) {
5557
						if ( i >= 116 ) {
5558
							int price = this->empOveridePrice(i - 116);
5558
							int price = this->empOveridePrice(i - 116);
5559
							if ( price ) {
5559
							if ( price ) {
Line 5568... Line 5568...
5568
						}
5568
						}
5569
 
5569
 
5570
						wareLines.pushBack(line);
5570
						wareLines.pushBack(line);
5571
						if ( wareLines.size() >= oldSize )
5571
						if ( wareLines.size() >= oldSize )
5572
							break;
5572
							break;
5573
					}
5573
					}
5574
				}
5574
				}
5575
			}
5575
			}
5576
 
5576
 
5577
			// now we too add/remove entries to match
5577
			// now we too add/remove entries to match
5578
			// need filler entries
5578
			// need filler entries
5579
			while ( wareLines.size() < maxsize )
5579
			while ( wareLines.size() < maxsize )
Line 5587... Line 5587...
5587
				for(size_t i = 0; i < empEntries; i++) {
5587
				for(size_t i = 0; i < empEntries; i++) {
5588
					int price = this->empOveridePrice(i);
5588
					int price = this->empOveridePrice(i);
5589
					if ( price ) {
5589
					if ( price ) {
5590
						empStr[i] = empStr[i].replaceToken(L";", 9, Utils::WString::Number(price));
5590
						empStr[i] = empStr[i].replaceToken(L";", 9, Utils::WString::Number(price));
5591
						empStr[i] = empStr[i].replaceToken(L";", 13, Utils::WString::Number(price));
5591
						empStr[i] = empStr[i].replaceToken(L";", 13, Utils::WString::Number(price));
5592
					}
5592
					}
5593
 
5593
 
5594
					int noto = 0;
5594
					int noto = 0;
5595
					if ( this->empOverideNoto(i, &noto) ) {
5595
					if ( this->empOverideNoto(i, &noto) ) {
5596
						empStr[i] = empStr[i].replaceToken(L";", 14, Utils::WString::Number(noto));
5596
						empStr[i] = empStr[i].replaceToken(L";", 14, Utils::WString::Number(noto));
5597
					}
5597
					}
5598
				}
5598
				}
Line 5608... Line 5608...
5608
					{
5608
					{
5609
						// more after emp
5609
						// more after emp
5610
						if ( wareLines.size() > (maxsize + empEntries) )
5610
						if ( wareLines.size() > (maxsize + empEntries) )
5611
						{
5611
						{
5612
							for (size_t i = (maxsize + empEntries); i < wareLines.size(); i++)
5612
							for (size_t i = (maxsize + empEntries); i < wareLines.size(); i++)
5613
							{
5613
							{
5614
								auto node = wareLines.get(i);
5614
								auto node = wareLines.get(i);
5615
								addAfter.pushBack(node->str);
5615
								addAfter.pushBack(node->str);
5616
							}
5616
							}
5617
						}
5617
						}
5618
 
5618
 
Line 5627... Line 5627...
5627
							Utils::WString test = wareLines.get(128)->str;
5627
							Utils::WString test = wareLines.get(128)->str;
5628
							if ( test.tokens(L";", -2).Compare(L"SS_WARE_SW_CUSTOM16_1;") )
5628
							if ( test.tokens(L";", -2).Compare(L"SS_WARE_SW_CUSTOM16_1;") )
5629
							{
5629
							{
5630
								// if theres any at the end, remove the last emp entry
5630
								// if theres any at the end, remove the last emp entry
5631
								if ( wareLines.size() > (maxsize + empEntries - 1) )
5631
								if ( wareLines.size() > (maxsize + empEntries - 1) )
5632
								{
5632
								{
5633
									wareLines.removeAt(maxsize + empEntries - 2);
5633
									wareLines.removeAt(maxsize + empEntries - 2);
5634
								}
5634
								}
5635
								wareLines.insertAt(128, L"0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;128;");
5635
								wareLines.insertAt(128, L"0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;128;");
5636
							}
5636
							}
5637
						}
5637
						}
Line 5782... Line 5782...
5782
}
5782
}
5783
 
5783
 
5784
void CPackages::CreatePluginManagerText()
5784
void CPackages::CreatePluginManagerText()
5785
{
5785
{
5786
	int gameNumber = _gameTextNumber();
5786
	int gameNumber = _gameTextNumber();
5787
 
5787
 
5788
	int lang = m_iLanguage;
5788
	int lang = m_iLanguage;
5789
	if ( !lang || lang < 0 )
5789
	if ( !lang || lang < 0 )
5790
		lang = 44;
5790
		lang = 44;
5791
 
5791
 
5792
	CDirIO Dir(m_sCurrentDir);
5792
	CDirIO Dir(m_sCurrentDir);
Line 5801... Line 5801...
5801
	std::vector<Utils::WString> writeData;
5801
	std::vector<Utils::WString> writeData;
5802
 
5802
 
5803
	CLinkList<SGameWare> lWares;
5803
	CLinkList<SGameWare> lWares;
5804
	CLinkList<SGameShip> lShips;
5804
	CLinkList<SGameShip> lShips;
5805
	for ( int i = 0; i < WAREBUFFERS; i++ )
5805
	for ( int i = 0; i < WAREBUFFERS; i++ )
5806
	{
5806
	{
5807
		for ( CListNode<SGameWare> *node = m_lGameWares[i].Front(); node; node = node->next() )
5807
		for ( CListNode<SGameWare> *node = m_lGameWares[i].Front(); node; node = node->next() )
5808
		{
5808
		{
5809
			SGameWare *w = node->Data();
5809
			SGameWare *w = node->Data();
5810
			if ( w->iType == WARETYPE_NONE )
5810
			if ( w->iType == WARETYPE_NONE )
5811
				continue;
5811
				continue;
5812
			lWares.push_back(w);
5812
			lWares.push_back(w);
5813
		}
5813
		}
5814
	}
5814
	}
5815
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
5815
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
5816
	{
5816
	{
5817
		if ( node->Data()->iType == WARETYPE_NONE )
5817
		if ( node->Data()->iType == WARETYPE_NONE )
5818
			continue;
5818
			continue;
5819
		lShips.push_back(node->Data());
5819
		lShips.push_back(node->Data());
5820
	}
5820
	}
5821
 
5821
 
Line 5860... Line 5860...
5860
 
5860
 
5861
		if ( p->GetType() != TYPE_SPK )
5861
		if ( p->GetType() != TYPE_SPK )
5862
			continue;
5862
			continue;
5863
 
5863
 
5864
		CSpkFile *spk = (CSpkFile *)p;
5864
		CSpkFile *spk = (CSpkFile *)p;
5865
 
5865
 
5866
		// count text files
5866
		// count text files
5867
		Utils::WString textEntries;
5867
		Utils::WString textEntries;
5868
		int textCount = 0;
5868
		int textCount = 0;
5869
		C_File *f = p->GetFirstFile(FILETYPE_TEXT);
5869
		C_File *f = p->GetFirstFile(FILETYPE_TEXT);
5870
		while ( f )
5870
		while ( f )
Line 6017... Line 6017...
6017
			if ( !s->pPackage || s->iType != WARETYPE_ADDED )
6017
			if ( !s->pPackage || s->iType != WARETYPE_ADDED )
6018
				continue;
6018
				continue;
6019
			if ( s->pPackage->GetOriginalDescription() )
6019
			if ( s->pPackage->GetOriginalDescription() )
6020
				continue;
6020
				continue;
6021
 
6021
 
6022
			Utils::WString name = s->pPackage->GetTextName(m_iLanguage);
6022
			Utils::WString name = s->pPackage->getTextName(m_iLanguage);
6023
			Utils::WString desc = s->pPackage->GetTextDescription(m_iLanguage);
6023
			Utils::WString desc = s->pPackage->GetTextDescription(m_iLanguage);
6024
			if ( !name.empty() )
6024
			if ( !name.empty() )
6025
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)s->iText + L"\">" + this->convertTextString(name) + L"</t>");
6025
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)s->iText + L"\">" + this->convertTextString(name) + L"</t>");
6026
			if ( !desc.empty() )
6026
			if ( !desc.empty() )
6027
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(s->iText + 1) + L"\">" + this->convertTextString(desc) + L"</t>");
6027
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(s->iText + 1) + L"\">" + this->convertTextString(desc) + L"</t>");
Line 6094... Line 6094...
6094
				if (!File.isFileExtension(L"sav"))
6094
				if (!File.isFileExtension(L"sav"))
6095
					continue;
6095
					continue;
6096
				// remove the file if already exists
6096
				// remove the file if already exists
6097
				if (gameSaveDir.exists((*itr)->str))
6097
				if (gameSaveDir.exists((*itr)->str))
6098
					CFileIO::Remove(gameSaveDir.file((*itr)->str));
6098
					CFileIO::Remove(gameSaveDir.file((*itr)->str));
6099
 
6099
 
6100
				// copy the file into the games save dir for backup
6100
				// copy the file into the games save dir for backup
6101
				File.copy(gameSaveDir.file(File.filename()), true);
6101
				File.copy(gameSaveDir.file(File.filename()), true);
6102
			}
6102
			}
6103
		}
6103
		}
6104
	}
6104
	}
Line 6250... Line 6250...
6250
							if ( currentSection->sSection.Compare("SDTYPE_GUN") )
6250
							if ( currentSection->sSection.Compare("SDTYPE_GUN") )
6251
							{
6251
							{
6252
								int states = line.token(";", 3).toInt();
6252
								int states = line.token(";", 3).toInt();
6253
								int parts = line.token(";", 4 + (states * 2)).toInt();
6253
								int parts = line.token(";", 4 + (states * 2)).toInt();
6254
								Utils::String data = line.tokens(";", 1, 4 + (states * 2) + (parts * 2)) + ";";
6254
								Utils::String data = line.tokens(";", 1, 4 + (states * 2) + (parts * 2)) + ";";
6255
								currentSection->lEntries.pushBack(data);
6255
								currentSection->lEntries.pushBack(data);
6256
 
6256
 
6257
								// remove done
6257
								// remove done
6258
								line = line.remTokens(";", 1, 4 + (states * 2) + (parts * 2));
6258
								line = line.remTokens(";", 1, 4 + (states * 2) + (parts * 2));
6259
							}
6259
							}
6260
							else
6260
							else
6261
							{
6261
							{
6262
								int states = line.token(";", 3).toInt();
6262
								int states = line.token(";", 3).toInt();
Line 7500... Line 7500...
7500
				if ( !CDirIO(pckFile.dir()).exists() )
7500
				if ( !CDirIO(pckFile.dir()).exists() )
7501
					CDirIO(pckFile.dir()).create();
7501
					CDirIO(pckFile.dir()).create();
7502
				pckFile.WriteData((char *)pckData, newFileSize);
7502
				pckFile.WriteData((char *)pckData, newFileSize);
7503
				const_cast<CPackages *>(this)->addCreatedFile(pckFile.fullFilename());
7503
				const_cast<CPackages *>(this)->addCreatedFile(pckFile.fullFilename());
7504
				return true;
7504
				return true;
7505
			}
7505
			}
7506
		}
7506
		}
7507
	}
7507
	}
7508
 
7508
 
7509
	return false;
7509
	return false;
7510
}
7510
}
Line 8016... Line 8016...
8016
			
8016
			
8017
			if (p->icon())
8017
			if (p->icon())
8018
			{
8018
			{
8019
				bool addedIcon = false;
8019
				bool addedIcon = false;
8020
				p->ReadIconFileToMemory();
8020
				p->ReadIconFileToMemory();
8021
				p->icon()->setFilename(this->tempDirectory().findReplace(L"\\", L"/") + L"/" + p->author().toWString() + L"_" + p->name().toWString() + L"." + p->iconExt());
8021
				p->icon()->setFilename(this->tempDirectory().findReplace(L"\\", L"/") + L"/" + p->author() + L"_" + p->name() + L"." + p->iconExt());
8022
				p->icon()->setFullDir(this->tempDirectory());
8022
				p->icon()->setFullDir(this->tempDirectory());
8023
				if (p->icon()->UncompressData())
8023
				if (p->icon()->UncompressData())
8024
				{
8024
				{
8025
					if (p->icon()->writeFilePointer())
8025
					if (p->icon()->writeFilePointer())
8026
						addedIcon = true;
8026
						addedIcon = true;
Line 8649... Line 8649...
8649
	if ( !to->AnyFileType(FILETYPE_MOD) ) return false;
8649
	if ( !to->AnyFileType(FILETYPE_MOD) ) return false;
8650
 
8650
 
8651
	if ( from == to ) return false; // cant have incompatabilities to itself
8651
	if ( from == to ) return false; // cant have incompatabilities to itself
8652
 
8652
 
8653
	// check if one is a depencacy of the other
8653
	// check if one is a depencacy of the other
8654
	if (from->IsPackageNeeded(to->name(), to->author())) return false;
8654
	if (from->isPackageNeeded(to->name(), to->author())) return false;
8655
	if (to->IsPackageNeeded(from->name(), from->author())) return false;
8655
	if (to->isPackageNeeded(from->name(), from->author())) return false;
8656
	// check if one is directly connected
8656
	// check if one is directly connected
8657
	if (from->type() == BaseFileType::TYPE_SPK)
8657
	if (from->type() == BaseFileType::TYPE_SPK)
8658
	{
8658
	{
8659
		CSpkFile* fromSpk = dynamic_cast<CSpkFile*>(from);
8659
		CSpkFile* fromSpk = dynamic_cast<CSpkFile*>(from);
8660
		if (fromSpk->isAnotherMod())
8660
		if (fromSpk->isAnotherMod())
8661
		{
8661
		{
8662
			if (fromSpk->otherName().Compare(to->name()) &amp;& fromSpk->otherAuthor().Compare(to->author()))
8662
			if (fromSpk->otherName().toWString().Compare(to->name()) &amp;& fromSpk->otherAuthor().toWString().Compare(to->author()))
8663
				return false;
8663
				return false;
8664
		}
8664
		}
8665
	}
8665
	}
8666
	if (to->type() == BaseFileType::TYPE_SPK)
8666
	if (to->type() == BaseFileType::TYPE_SPK)
8667
	{
8667
	{
8668
		CSpkFile* toSpk = dynamic_cast<CSpkFile*>(to);
8668
		CSpkFile* toSpk = dynamic_cast<CSpkFile*>(to);
8669
		if (toSpk->isAnotherMod())
8669
		if (toSpk->isAnotherMod())
8670
		{
8670
		{
8671
			if (toSpk->otherName().Compare(from->name()) &amp;& toSpk->otherAuthor().Compare(from->author()))
8671
			if (toSpk->otherName().toWString().Compare(from->name()) &amp;& toSpk->otherAuthor().toWString().Compare(from->author()))
8672
				return false;
8672
				return false;
8673
		}
8673
		}
8674
	}
8674
	}
8675
 
8675
 
8676
	int count = 0;
8676
	int count = 0;
Line 8751... Line 8751...
8751
	if ( p1->name().Compare(p2->name()) && p1->author().Compare(p2->author()) )
8751
	if ( p1->name().Compare(p2->name()) && p1->author().Compare(p2->author()) )
8752
		return true;
8752
		return true;
8753
	return false;
8753
	return false;
8754
}
8754
}
8755
 
8755
 
8756
void CPackages::ApplyFakePatchOrder(Utils::CStringList *list)
8756
void CPackages::applyFakePatchOrder(const Utils::WStringList &list)
8757
{
8757
{
8758
	if ( !list ) return;
-
 
8759
	_lFakePatchOrder.clear();
8758
	_lFakePatchOrder.clear();
8760
	for(auto itr = list->begin(); itr != list->end(); itr++)
8759
	for(auto itr = list.begin(); itr != list.end(); itr++)
8761
		_lFakePatchOrder.pushBack((*itr)->str, (*itr)->data);
8760
		_lFakePatchOrder.pushBack((*itr)->str, (*itr)->data);
8762
}
8761
}
8763
 
8762
 
8764
SAvailablePackage *CPackages::CreateAvailablePackageData(CBaseFile *package)
8763
SAvailablePackage *CPackages::CreateAvailablePackageData(CBaseFile *package)
8765
{
8764
{
Line 8787... Line 8786...
8787
	else 
8786
	else 
8788
	{
8787
	{
8789
		p->iType = ((CSpkFile *)package)->GetPackageType();
8788
		p->iType = ((CSpkFile *)package)->GetPackageType();
8790
		p->iScriptType = ((CSpkFile *)package)->GetScriptType();
8789
		p->iScriptType = ((CSpkFile *)package)->GetScriptType();
8791
	}
8790
	}
8792
	p->sAuthor = package->author().toWString();
8791
	p->sAuthor = package->author();
8793
	p->sDesc = package->description().toWString().findReplace(L"\n", L"::newline::");
8792
	p->sDesc = package->description().toWString().findReplace(L"\n", L"::newline::");
8794
	p->sName = package->name().toWString();
8793
	p->sName = package->name();
8795
	p->sUpdated = package->creationDate().toWString();
8794
	p->sUpdated = package->creationDate().toWString();
8796
	p->sVersion = package->version().toWString();
8795
	p->sVersion = package->version().toWString();
8797
	p->sFilename = CFileIO(package->filename()).filename();
8796
	p->sFilename = CFileIO(package->filename()).filename();
8798
 
8797
 
8799
	return p;
8798
	return p;
Line 8929... Line 8928...
8929
 
8928
 
8930
CBaseFile* CPackages::findFoundPackage(const Utils::WString& name, const Utils::WString& author) const
8929
CBaseFile* CPackages::findFoundPackage(const Utils::WString& name, const Utils::WString& author) const
8931
{
8930
{
8932
	for (CListNode<CBaseFile>* node = m_lFoundPackages.Front(); node; node = node->next())
8931
	for (CListNode<CBaseFile>* node = m_lFoundPackages.Front(); node; node = node->next())
8933
	{
8932
	{
8934
		if (node->Data()->name().toWString().Compare(name) &&; node->;Data()->author().toWString().Compare(author))
8933
		if (node->Data()->name().Compare(name) &&; node->;Data()->author().Compare(author))
8935
			return node->Data();
8934
			return node->Data();
8936
	}
8935
	}
8937
	return NULL;
8936
	return NULL;
8938
}
8937
}
8939
 
8938
 
Line 9569... Line 9568...
9569
						CBaseFile *package = p->Data();
9568
						CBaseFile *package = p->Data();
9570
						if ( package->IsFileAdded(f) )
9569
						if ( package->IsFileAdded(f) )
9571
						{
9570
						{
9572
							if ( !packages.empty() )
9571
							if ( !packages.empty() )
9573
								packages += L"\n";
9572
								packages += L"\n";
9574
							packages += package->getFullPackageName(m_iLanguage).toWString();
9573
							packages += package->getFullPackageName(m_iLanguage);
9575
						}
9574
						}
9576
					}
9575
					}
9577
				}
9576
				}
9578
				Utils::WString filename = f->filePointer();
9577
				Utils::WString filename = f->filePointer();
9579
				filename = filename.findRemove(m_sCurrentDir);
9578
				filename = filename.findRemove(m_sCurrentDir);