Subversion Repositories spk

Rev

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

Rev 177 Rev 178
Line 207... Line 207...
207
	if ( m_pEnabledMod )
207
	if ( m_pEnabledMod )
208
	{
208
	{
209
		C_File *f;
209
		C_File *f;
210
		for ( f = m_pEnabledMod->GetFirstFile(FILETYPE_MOD); f; f = m_pEnabledMod->GetNextFile(f) )
210
		for ( f = m_pEnabledMod->GetFirstFile(FILETYPE_MOD); f; f = m_pEnabledMod->GetNextFile(f) )
211
		{
211
		{
212
			if ( f->IsFakePatch() ) continue;
212
			if (f->IsFakePatch()) continue;
213
			if ( f->CheckFileExt("cat") ) break;
213
			if (f->checkFileExt("cat")) break;
214
		}
214
		}
215
 
215
 
216
		if ( f )
216
		if ( f )
217
			m_pGameVFS.LoadFilesystem(m_sCurrentDir, f->filePointer(), 0);
217
			m_pGameVFS.LoadFilesystem(m_sCurrentDir, f->filePointer(), 0);
218
		else
218
		else
Line 352... Line 352...
352
						newFile->setGame(game);
352
						newFile->setGame(game);
353
						newFile->SetOriginalName(origName);
353
						newFile->SetOriginalName(origName);
354
						newFile->SetDisabled(disabled);
354
						newFile->SetDisabled(disabled);
355
						newFile->setFileType((FileType)line.token(":", 1).toLong());
355
						newFile->setFileType((FileType)line.token(":", 1).toLong());
356
						newFile->SetCreationTime((time_t)line.token(":", 2).toLong());
356
						newFile->SetCreationTime((time_t)line.token(":", 2).toLong());
357
						newFile->SetDir(line.token(":", 3));
357
						newFile->setDir(line.token(":", 3));
358
						if ( line.token(":", 4).toLong() )
358
						if ( line.token(":", 4).toLong() )
359
							newFile->SetShared(true);
359
							newFile->SetShared(true);
360
						newFile->UpdateSigned();
360
						newFile->UpdateSigned();
361
 
361
 
362
						m_lFiles.push_back(newFile);
362
						m_lFiles.push_back(newFile);
Line 536... Line 536...
536
				else if ( cmd == "uninstall" )
536
				else if ( cmd == "uninstall" )
537
				{
537
				{
538
					C_File *uf = new C_File();
538
					C_File *uf = new C_File();
539
					uf->setFileType(FILETYPE_SCRIPT);
539
					uf->setFileType(FILETYPE_SCRIPT);
540
					uf->SetCreationTime(rest.token(" ", 1).toLong());
540
					uf->SetCreationTime(rest.token(" ", 1).toLong());
541
					uf->SetFilename(m_sCurrentDir + "/Scripts/" + rest.tokens(" ", 2));
541
					uf->setFilename(m_sCurrentDir + "/Scripts/" + rest.tokens(" ", 2));
542
					m_lUninstallFiles.push_back(uf);
542
					m_lUninstallFiles.push_back(uf);
543
				}
543
				}
544
				else if ( cmd == "nonremovedfile" )
544
				else if ( cmd == "nonremovedfile" )
545
				{
545
				{
546
					if ( !CFileIO::Remove(rest) )
546
					if ( !CFileIO::Remove(rest) )
Line 904... Line 904...
904
			int count = 0;
904
			int count = 0;
905
			int noncount = 0;
905
			int noncount = 0;
906
 
906
 
907
			// check for some of the files
907
			// check for some of the files
908
			for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
908
			for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
909
				if ( node->Data()->GetFullDir().IsIn("::") ) {
909
				if ( node->Data()->fullDir().contains("::") ) {
910
					if (CFileIO(node->Data()->GetFullDir().GetToken("::", 1, 1)).filename().Compare("PlugMan_Fake.cat") ) {
910
					if (CFileIO(node->Data()->fullDir().token("::", 1)).filename().Compare("PlugMan_Fake.cat") ) {
911
						Utils::String filename = node->Data()->GetFilePointer().GetToken("::", 2, 2).ToString();
911
						Utils::String filename = node->Data()->filePointer().token("::", 2);
912
						filename = filename.findReplace("/", "\\");
912
						filename = filename.findReplace("/", "\\");
913
						if ( openFile.FindData(filename) )
913
						if ( openFile.FindData(filename) )
914
							++count;
914
							++count;
915
						else
915
						else
916
							++noncount;
916
							++noncount;
Line 1042... Line 1042...
1042
	// any extra files that are in director folder
1042
	// any extra files that are in director folder
1043
	if ( package->AnyFileType(FILETYPE_EXTRA) )
1043
	if ( package->AnyFileType(FILETYPE_EXTRA) )
1044
	{
1044
	{
1045
		for ( C_File *f = package->GetFirstFile(FILETYPE_EXTRA); f; f = package->GetNextFile(f) )
1045
		for ( C_File *f = package->GetFirstFile(FILETYPE_EXTRA); f; f = package->GetNextFile(f) )
1046
		{
1046
		{
1047
			if ( !f->GetDir().Compare("director") )
1047
			if ( !f->dir().Compare("director") )
1048
				continue;
1048
				continue;
1049
			if ( f->CheckFileExt("xml") || f->CheckFileExt("pck") )
1049
			if (f->checkFileExt("xml") || f->checkFileExt("pck"))
1050
			{
1050
			{
1051
				f->setDir("");
1051
				f->setDir("");
1052
				f->setFileType(FILETYPE_MISSION);
1052
				f->setFileType(FILETYPE_MISSION);
1053
			}
1053
			}
1054
		}
1054
		}
Line 1397... Line 1397...
1397
	if ( CCatFile::Opened(cat.open(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat", this->getAddonDir(), CATREAD_DAT)) ) {
1397
	if ( CCatFile::Opened(cat.open(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat", this->getAddonDir(), CATREAD_DAT)) ) {
1398
		for ( CListNode<C_File> *f = pPackage->GetFileList()->Front(); f; f = f->next() ) {
1398
		for ( CListNode<C_File> *f = pPackage->GetFileList()->Front(); f; f = f->next() ) {
1399
			if ( f->Data()->GetFileType() != FILETYPE_SHIPSCENE && f->Data()->GetFileType() != FILETYPE_COCKPITSCENE && f->Data()->GetFileType() != FILETYPE_SHIPMODEL && f->Data()->GetFileType() != FILETYPE_SHIPOTHER ) {
1399
			if ( f->Data()->GetFileType() != FILETYPE_SHIPSCENE && f->Data()->GetFileType() != FILETYPE_COCKPITSCENE && f->Data()->GetFileType() != FILETYPE_SHIPMODEL && f->Data()->GetFileType() != FILETYPE_SHIPOTHER ) {
1400
				continue;
1400
				continue;
1401
			}
1401
			}
1402
			if ( CCatFile::IsAddonDir(f->Data()->GetNameDirectory(pPackage).ToString()) ) {
1402
			if ( CCatFile::IsAddonDir(f->Data()->getNameDirectory(pPackage)) ) {
1403
				continue;
1403
				continue;
1404
			}
1404
			}
1405
			// check if its already in the fake patch
1405
			// check if its already in the fake patch
1406
			if ( f->Data()->GetFullDir().IsIn("::") ) {
1406
			if ( f->Data()->fullDir().contains("::") ) {
1407
				continue;
1407
				continue;
1408
			}
1408
			}
1409
			Utils::String toFile;
1409
			Utils::String toFile;
1410
			if ( cat.AppendFile(f->Data()->filePointer(), f->Data()->GetNameDirectory(pPackage).ToString(), true, (m_iGameFlags & EXEFLAG_NOXOR) ? false : true, &toFile) ) {
1410
			if ( cat.AppendFile(f->Data()->filePointer(), f->Data()->getNameDirectory(pPackage), true, (m_iGameFlags & EXEFLAG_NOXOR) ? false : true, &toFile) ) {
1411
				CLog::logf(CLog::Log_Install, 2, "Adding file: %s into the fake patch", f->Data()->GetNameDirectory(pPackage).c_str());
1411
				CLog::logf(CLog::Log_Install, 2, "Adding file: %s into the fake patch", f->Data()->getNameDirectory(pPackage).c_str());
1412
				CFileIO::Remove(f->Data()->filePointer());
1412
				CFileIO::Remove(f->Data()->filePointer());
1413
				f->Data()->setFilename(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat::" + toFile);
1413
				f->Data()->setFilename(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat::" + toFile);
1414
			}
1414
			}
1415
		}
1415
		}
1416
	}
1416
	}
Line 1473... Line 1473...
1473
			for ( CListNode<C_File> *f = package->GetFileList()->Front(); f; f = f->next() )
1473
			for ( CListNode<C_File> *f = package->GetFileList()->Front(); f; f = f->next() )
1474
			{
1474
			{
1475
				if ( f->Data()->GetFileType() != FILETYPE_MOD )
1475
				if ( f->Data()->GetFileType() != FILETYPE_MOD )
1476
					continue;
1476
					continue;
1477
 
1477
 
1478
				f->Data()->SetDir("temp");
1478
				f->Data()->setDir("temp");
1479
				if ( f->Data()->IsFakePatch() ) {
1479
				if ( f->Data()->IsFakePatch() ) {
1480
					CLog::logf(CLog::Log_Install, 2, "Moving fake package to temporary location to preper for update, %s", f->Data()->GetFilePointer().c_str());
1480
					CLog::logf(CLog::Log_Install, 2, "Moving fake package to temporary location to preper for update, %s", f->Data()->filePointer().c_str());
1481
					f->Data()->SetName(CyString("Fake_") + f->Data()->GetName());
1481
					f->Data()->setName("Fake_" + f->Data()->name());
1482
				}
1482
				}
1483
			}
1483
			}
1484
		}
1484
		}
1485
	}
1485
	}
1486
 
1486
 
Line 1538... Line 1538...
1538
				if ( !f->Data() )
1538
				if ( !f->Data() )
1539
					continue;
1539
					continue;
1540
				if ( f->Data()->GetFileType() != FILETYPE_MOD )
1540
				if ( f->Data()->GetFileType() != FILETYPE_MOD )
1541
					continue;
1541
					continue;
1542
				// we only need the cat file
1542
				// we only need the cat file
1543
				if ( !f->Data()->CheckFileExt("cat") )
1543
				if (!f->Data()->checkFileExt("cat"))
1544
					continue;
1544
					continue;
1545
 
1545
 
1546
				// if fake patch, find first fake patch in package
1546
				// if fake patch, find first fake patch in package
1547
				C_File *findMatching = NULL;
1547
				C_File *findMatching = NULL;
1548
				if ( f->Data()->GetBaseName().Left(5).Compare("fake_") )
1548
				if ( f->Data()->baseName().left(5).Compare("fake_") )
1549
				{
1549
				{
1550
					for ( CListNode<C_File> *node = oldPackage->GetFileList()->Front(); node; node = node->next() )
1550
					for ( CListNode<C_File> *node = oldPackage->GetFileList()->Front(); node; node = node->next() )
1551
					{
1551
					{
1552
						if ( !node->Data() )
1552
						if ( !node->Data() )
1553
							continue;
1553
							continue;
1554
						if ( node->Data()->GetFileType() != FILETYPE_MOD )
1554
						if ( node->Data()->GetFileType() != FILETYPE_MOD )
1555
							continue;
1555
							continue;
1556
						// we only need the cat file
1556
						// we only need the cat file
1557
						if ( !node->Data()->CheckFileExt("cat") )
1557
						if ( !node->Data()->checkFileExt("cat") )
1558
							continue;
1558
							continue;
1559
						if ( !node->Data()->IsFakePatch() )
1559
						if ( !node->Data()->IsFakePatch() )
1560
							continue;
1560
							continue;
1561
 
1561
 
1562
						findMatching = node->Data();
1562
						findMatching = node->Data();
Line 1571... Line 1571...
1571
						if ( !node->Data() )
1571
						if ( !node->Data() )
1572
							continue;
1572
							continue;
1573
						if ( node->Data()->GetFileType() != FILETYPE_MOD )
1573
						if ( node->Data()->GetFileType() != FILETYPE_MOD )
1574
							continue;
1574
							continue;
1575
						// we only need the cat file
1575
						// we only need the cat file
1576
						if ( !node->Data()->CheckFileExt("cat") )
1576
						if (!node->Data()->checkFileExt("cat"))
1577
							continue;
1577
							continue;
1578
 
1578
 
1579
						if ( node->Data()->GetName().Compare(f->Data()->GetName()) )
1579
						if ( node->Data()->name().Compare(f->Data()->name()) )
1580
						{
1580
						{
1581
							findMatching = node->Data();
1581
							findMatching = node->Data();
1582
							break;
1582
							break;
1583
						}
1583
						}
1584
					}
1584
					}
Line 1615... Line 1615...
1615
					}
1615
					}
1616
				}
1616
				}
1617
				// no matching file, then we shall just renaming back
1617
				// no matching file, then we shall just renaming back
1618
				else
1618
				else
1619
				{
1619
				{
1620
					if ( f->Data()->GetBaseName().Left(5).Compare("fake_") )
1620
					if ( f->Data()->baseName().left(5).Compare("fake_") )
1621
					{
1621
					{
1622
						shuffle = true;
1622
						shuffle = true;
1623
						C_File *match = package->findMatchingMod(f->Data());
1623
						C_File *match = package->findMatchingMod(f->Data());
1624
						Utils::String next = Utils::String::PadNumber(this->FindNextFakePatch(), 2);
1624
						Utils::String next = Utils::String::PadNumber(this->FindNextFakePatch(), 2);
1625
						
1625
						
1626
						CyString oldFilePointer = f->Data()->GetFilePointer();
1626
						Utils::String oldFilePointer = f->Data()->filePointer();
1627
						f->Data()->setDir("");
1627
						f->Data()->setDir("");
1628
						f->Data()->changeBaseName(next);
1628
						f->Data()->changeBaseName(next);
1629
						if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package)) )
1629
						if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package)) )
1630
							f->Data()->setFilename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package));
1630
							f->Data()->setFilename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package));
1631
 
1631
 
Line 1641... Line 1641...
1641
					else
1641
					else
1642
					{
1642
					{
1643
						C_File *match = package->findMatchingMod(f->Data());
1643
						C_File *match = package->findMatchingMod(f->Data());
1644
 
1644
 
1645
						f->Data()->setDir("");
1645
						f->Data()->setDir("");
1646
						if ( CFileIO(f->Data()->GetFilePointer()).Rename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package)) )
1646
						if ( CFileIO(f->Data()->filePointer()).Rename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package)) )
1647
							f->Data()->setFilename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package));
1647
							f->Data()->setFilename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package));
1648
						if ( match )
1648
						if ( match )
1649
						{
1649
						{
1650
							match->setDir("");
1650
							match->setDir("");
1651
							if ( CFileIO(match->filePointer()).Rename(m_sCurrentDir + "/" + match->getNameDirectory(package)) )
1651
							if ( CFileIO(match->filePointer()).Rename(m_sCurrentDir + "/" + match->getNameDirectory(package)) )
Line 1767... Line 1767...
1767
				}
1767
				}
1768
 
1768
 
1769
				// remove from hard drive
1769
				// remove from hard drive
1770
				if ( !dontRemove && RemoveFile(f, errors) )
1770
				if ( !dontRemove && RemoveFile(f, errors) )
1771
				{
1771
				{
1772
					CLog::logf(CLog::Log_Install, 1, "Removed unused file: %s", f->GetFilePointer().c_str());
1772
					CLog::logf(CLog::Log_Install, 1, "Removed unused file: %s", f->filePointer().c_str());
1773
					// if a fake patch, we need to shufle
1773
					// if a fake patch, we need to shufle
1774
					if ( f->IsFakePatch() )
1774
					if ( f->IsFakePatch() )
1775
						shuffle = true;
1775
						shuffle = true;
1776
					else if ( f->isAutoTextFile() )
1776
					else if ( f->isAutoTextFile() )
1777
						shuffle = true;
1777
						shuffle = true;
Line 1818... Line 1818...
1818
	return true;
1818
	return true;
1819
}
1819
}
1820
 
1820
 
1821
bool CPackages::UninstallPreparedPackages(CyStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *uninstalledPackages, CLinkList<CBaseFile> *disabledPackages)
1821
bool CPackages::UninstallPreparedPackages(CyStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *uninstalledPackages, CLinkList<CBaseFile> *disabledPackages)
1822
{
1822
{
-
 
1823
	Utils::CStringList lErrors;
-
 
1824
 
1823
	if ( m_lInstallList.empty() ) return false;
1825
	if ( m_lInstallList.empty() ) return false;
1824
 
1826
 
1825
	// update the used status, excluding all packages we are about to remove
1827
	// update the used status, excluding all packages we are about to remove
1826
	UpdateUsedFiles(&m_lInstallList);
1828
	UpdateUsedFiles(&m_lInstallList);
1827
 
1829
 
1828
	CyStringList removeDirs;
1830
	Utils::CStringList removeDirs;
1829
	CLinkList<C_File> uninstallFiles;
1831
	CLinkList<C_File> uninstallFiles;
1830
	CLinkList<C_File> fileList;
1832
	CLinkList<C_File> fileList;
1831
	bool readme = false, original = false, shuffle = false;
1833
	bool readme = false, original = false, shuffle = false;
1832
 
1834
 
1833
	// find all files that need to be removed
1835
	// find all files that need to be removed
Line 1840... Line 1842...
1840
		// disable any dependants
1842
		// disable any dependants
1841
		if ( p->GetType() == TYPE_SPK && ((CSpkFile *)p)->IsLibrary() )
1843
		if ( p->GetType() == TYPE_SPK && ((CSpkFile *)p)->IsLibrary() )
1842
		{
1844
		{
1843
			CLinkList<CBaseFile> depList;
1845
			CLinkList<CBaseFile> depList;
1844
			if ( this->GetDependacyList(p, &depList) )
1846
			if ( this->GetDependacyList(p, &depList) )
1845
			{
1847
			{
1846
				for ( CBaseFile *depP = depList.First(); depP; depP = depList.Next() )
1848
				for ( CBaseFile *depP = depList.First(); depP; depP = depList.Next() )
1847
				{
1849
				{
1848
					if ( depP->IsEnabled() )
1850
					if ( depP->IsEnabled() )
1849
						this->PrepareDisablePackage(depP);
1851
						this->PrepareDisablePackage(depP);
1850
				}
1852
				}
Line 1864... Line 1866...
1864
		// display progress if needed
1866
		// display progress if needed
1865
		if ( progress )
1867
		if ( progress )
1866
		{
1868
		{
1867
			progress->UpdateProgress(fileCount++, maxFiles);
1869
			progress->UpdateProgress(fileCount++, maxFiles);
1868
			progress->UpdateFile(f);
1870
			progress->UpdateFile(f);
1869
		}
1871
		}
1870
 
1872
 
1871
		// skip uninstall files
1873
		// skip uninstall files
1872
		if ( f->GetFileType() == FILETYPE_UNINSTALL )
1874
		if ( f->GetFileType() == FILETYPE_UNINSTALL )
1873
		{
1875
		{
1874
			uninstallFiles.push_back(f);
1876
			uninstallFiles.push_back(f);
1875
			continue;
1877
			continue;
1876
		}
1878
		}
1877
 
1879
 
1878
		// only delete files that are not used
1880
		// only delete files that are not used
1879
		// if its a shared file, we skip it
1881
		// if its a shared file, we skip it
1880
		if ( f->getUsed() || f->IsShared() )
1882
		if ( f->getUsed() || f->IsShared() )
1881
			continue;
1883
			continue;
1882
 
1884
 
1883
		if ( f->GetFileType() == FILETYPE_README )
1885
		if ( f->GetFileType() == FILETYPE_README )
1884
			readme = true;
1886
			readme = true;
1885
		else if ( f->GetFileType() == FILETYPE_UNINSTALL || f->GetFileType() == FILETYPE_MAP || f->GetFileType() == FILETYPE_SOUND || f->GetFileType() == FILETYPE_EXTRA || f->GetFileType() == FILETYPE_SHIPSCENE || f->GetFileType() == FILETYPE_COCKPITSCENE || f->GetFileType() == FILETYPE_SHIPOTHER || f->GetFileType() == FILETYPE_SHIPMODEL || f->GetFileType() == FILETYPE_ADVERT )
1887
		else if ( f->GetFileType() == FILETYPE_UNINSTALL || f->GetFileType() == FILETYPE_MAP || f->GetFileType() == FILETYPE_SOUND || f->GetFileType() == FILETYPE_EXTRA || f->GetFileType() == FILETYPE_SHIPSCENE || f->GetFileType() == FILETYPE_COCKPITSCENE || f->GetFileType() == FILETYPE_SHIPOTHER || f->GetFileType() == FILETYPE_SHIPMODEL || f->GetFileType() == FILETYPE_ADVERT )
1886
		{
1888
		{
1887
			CyString dir = f->GetDirectory(NULL);
1889
			Utils::String dir = f->getDirectory(NULL);
-
 
1890
			if(!removeDirs.contains(dir))
1888
			removeDirs.PushBack(dir, true);
1891
				removeDirs.pushBack(dir);
1889
			dir = dir.FindReplace("\\", "/");
1892
			dir = dir.findReplace("\\", "/");
1890
			if ( dir.IsIn("/") )
1893
			if ( dir.contains("/") )
1891
			{
1894
			{
1892
				for ( int i = dir.NumToken("/"); i; i-- )
1895
				for ( int i = dir.countToken("/"); i; i-- )
1893
				{
1896
				{
1894
					CyString remDir = dir.GetToken("/", 1, i);
1897
					Utils::String remDir = dir.tokens("/", 1, i);
-
 
1898
					if(!removeDirs.contains(remDir))
1895
					removeDirs.PushBack(remDir, true);
1899
						removeDirs.pushBack(remDir);
1896
				}
1900
				}
1897
			}
1901
			}
1898
		}
1902
		}
1899
 
1903
 
1900
		if ( f->GetFileType() == FILETYPE_EXTRA &&amp; f-&gt;GetDir().Left(6).lower() == "extras" )
1904
		if (f->GetFileType() == FILETYPE_EXTRA &&amp; f-&gt;dir().left(6).lower() == "extras")
-
 
1905
		{
-
 
1906
			if (!removeDirs.contains("Extras"))
1901
			removeDirs.PushBack("Extras", true);
1907
				removeDirs.pushBack("Extras");
-
 
1908
		}
1902
 
1909
 
1903
		if ( RemoveFile(f, errors) )
1910
		if ( RemoveFile(f, errors) )
1904
		{
-
 
1905
			original = _pOriginalFiles->restoreFile(f, errors);
1911
			original = _pOriginalFiles->restoreFile(f, errors);
1906
		}
-
 
1907
		else // problem removeing (try when the program closes)
1912
		else // problem removeing (try when the program closes)
1908
			m_lNonRemovedFiles.pushBack(f->filePointer());
1913
			m_lNonRemovedFiles.pushBack(f->filePointer());
1909
 
1914
 
1910
		// check for fake patchs
1915
		// check for fake patchs
1911
		if ( f->IsFakePatch() )
1916
		if ( f->IsFakePatch() )
Line 1937... Line 1942...
1937
	m_lInstallList.clear();
1942
	m_lInstallList.clear();
1938
 
1943
 
1939
	// check unistall files
1944
	// check unistall files
1940
	if ( !uninstallFiles.empty() )
1945
	if ( !uninstallFiles.empty() )
1941
	{
1946
	{
1942
		removeDirs.PushBack(CyString("PluginManager/Uninstall"));
1947
		removeDirs.pushBack("PluginManager/Uninstall");
1943
 
1948
 
1944
		// make sure the scripts directory is created, even thou it should always be there anyways
1949
		// make sure the scripts directory is created, even thou it should always be there anyways
1945
		CDirIO scriptDir(m_sCurrentDir);
1950
		CDirIO scriptDir(m_sCurrentDir);
1946
		if ( !scriptDir.exists("scripts") )
1951
		if ( !scriptDir.exists("scripts") )
1947
		{
1952
		{
Line 1967... Line 1972...
1967
				if ( file.copy(newFilename) )
1972
				if ( file.copy(newFilename) )
1968
					this->AddLogEntry(SPKINSTALL_UNINSTALL_COPY, newFile->getNameDirectory(NULL), errors);
1973
					this->AddLogEntry(SPKINSTALL_UNINSTALL_COPY, newFile->getNameDirectory(NULL), errors);
1969
				else
1974
				else
1970
				{
1975
				{
1971
					this->AddLogEntry(SPKINSTALL_UNINSTALL_COPY_FAIL, newFile->getNameDirectory(NULL), errors);
1976
					this->AddLogEntry(SPKINSTALL_UNINSTALL_COPY_FAIL, newFile->getNameDirectory(NULL), errors);
1972
					delete newFile;
1977
					delete newFile;
1973
					newFile = NULL;
1978
					newFile = NULL;
1974
				}
1979
				}
1975
			}
1980
			}
1976
			// otherwise just move it
1981
			// otherwise just move it
1977
			else
1982
			else
1978
			{
1983
			{
1979
				if ( file.Rename(newFilename) )
1984
				if ( file.Rename(newFilename) )
1980
					this->AddLogEntry(SPKINSTALL_UNINSTALL_MOVE, newFile->getNameDirectory(NULL), errors);
1985
					this->AddLogEntry(SPKINSTALL_UNINSTALL_MOVE, newFile->getNameDirectory(NULL), errors);
Line 2016... Line 2021...
2016
	uninstallFiles.clear();
2021
	uninstallFiles.clear();
2017
 
2022
 
2018
	// remove all directies that we're not using
2023
	// remove all directies that we're not using
2019
	if ( readme )
2024
	if ( readme )
2020
	{
2025
	{
2021
		removeDirs.PushBack(CyString("PluginManager/Readme"));
2026
		removeDirs.pushBack("PluginManager/Readme");
2022
		removeDirs.PushBack(CyString("Readme"));
2027
		removeDirs.pushBack("Readme");
2023
	}
2028
	}
2024
	if ( original ) {
2029
	if ( original ) {
2025
		removeDirs.PushBack(CyString("PluginManager/Original/Replacements"));
2030
		removeDirs.pushBack("PluginManager/Original/Replacements");
2026
		removeDirs.PushBack(CyString("PluginManager/Original"));
2031
		removeDirs.pushBack("PluginManager/Original");
2027
	}
2032
	}
2028
	removeDirs.PushBack(CyString("PluginManager/Disabled"));
2033
	removeDirs.pushBack("PluginManager/Disabled");
2029
	RemoveUnusedDirectories(removeDirs, errors);
2034
	removeUnusedDirectories(removeDirs, &lErrors);
2030
 
2035
 
2031
	// finally lets shuffle any fake patchs to fill in gaps
2036
	// finally lets shuffle any fake patchs to fill in gaps
2032
	if ( shuffle )
2037
	if ( shuffle )
2033
	{
2038
	{
2034
		ShuffleFakePatches(errors);
2039
		ShuffleFakePatches(errors);
Line 2493... Line 2498...
2493
	{
2498
	{
2494
		// base mode for Reunion
2499
		// base mode for Reunion
2495
		if ( m_iGame == GAME_X3 && m_pEnabledMod )
2500
		if ( m_iGame == GAME_X3 && m_pEnabledMod )
2496
		{
2501
		{
2497
			C_File *fDat = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2502
			C_File *fDat = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2498
			while ( fDat && !fDat->IsFakePatch() && !fDat->;CheckFileExt(&quot;dat") )
2503
			while (fDat && !fDat->;IsFakePatch() &&amp; !fDat->checkFileExt(";dat"))
2499
				fDat = m_pEnabledMod->GetNextFile(fDat);
2504
				fDat = m_pEnabledMod->GetNextFile(fDat);
2500
 
2505
 
2501
			if ( fDat )
2506
			if ( fDat )
2502
			{
2507
			{
2503
				C_File *fCat = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2508
				C_File *fCat = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2504
				while ( fCat && !fCat->IsFakePatch() && !fCat->CheckFileExt("cat") && !fCat->GetBaseName().Compare(fDat->GetBaseName()) )
2509
				while ( fCat && !fCat->IsFakePatch() && !fCat->checkFileExt("cat") && !fCat->baseName().Compare(fDat->baseName()) )
2505
					fCat = m_pEnabledMod->GetNextFile(fCat);
2510
					fCat = m_pEnabledMod->GetNextFile(fCat);
2506
 
2511
 
2507
				if ( fCat )
2512
				if ( fCat )
2508
				{
2513
				{
2509
					CFileIO(fDat->filePointer()).copy(m_sCurrentDir + "/mods/PluginManager.dat");
2514
					CFileIO(fDat->filePointer()).copy(m_sCurrentDir + "/mods/PluginManager.dat");
2510
					CFileIO(fCat->filePointer()).copy(m_sCurrentDir + "/mods/PluginManager.cat");
2515
					CFileIO(fCat->filePointer()).copy(m_sCurrentDir + "/mods/PluginManager.cat");
2511
				}
2516
				}
2512
			}
2517
			}
2513
		}
2518
		}
2514
		else if ( m_iGame == GAME_X3 && !m_sSetMod.empty() && CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat").ExistsOld() &&amp; CFileIO(m_sCurrentDir + &quot;/mods/" + m_sSetMod + ".dat").ExistsOld())
2519
		else if ( m_iGame == GAME_X3 && !m_sSetMod.empty() && CFileIO::Exists(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat") &&amp; CFileIO::Exists(m_sCurrentDir + &quot;/mods/" + m_sSetMod + ".dat"))
2515
		{
2520
		{
2516
			CLog::log(CLog::Log_Directory, 2, "Copying mod file: " + m_sSetMod + ", to PluginManager.cat");
2521
			CLog::log(CLog::Log_Directory, 2, "Copying mod file: " + m_sSetMod + ", to PluginManager.cat");
2517
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ".dat").copy(m_sCurrentDir + "/mods/PluginManager.dat");
2522
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ".dat").copy(m_sCurrentDir + "/mods/PluginManager.dat");
2518
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat").copy(m_sCurrentDir + "/mods/PluginManager.cat");
2523
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat").copy(m_sCurrentDir + "/mods/PluginManager.cat");
2519
		}
2524
		}
Line 3053... Line 3058...
3053
		{
3058
		{
3054
			if ( !Dir.exists(f->getDirectory(package)) )
3059
			if ( !Dir.exists(f->getDirectory(package)) )
3055
			{
3060
			{
3056
				if ( !Dir.create(f->getDirectory(package)) )
3061
				if ( !Dir.create(f->getDirectory(package)) )
3057
				{
3062
				{
3058
					this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY_FAIL, f->GetDirectory(package), errors);
3063
					this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY_FAIL, f->getDirectory(package), errors);
3059
					continue;
3064
					continue;
3060
				}
3065
				}
3061
				this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY, f->GetDirectory(package), errors);
3066
				this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY, f->getDirectory(package), errors);
3062
			}
3067
			}
3063
		}
3068
		}
3064
 
3069
 
3065
		// check if theres an original file to backup
3070
		// check if theres an original file to backup
3066
		_pOriginalFiles->doBackup(f, errors);
3071
		_pOriginalFiles->doBackup(f, errors);
Line 3204... Line 3209...
3204
		if ( f->IsDisabled() )
3209
		if ( f->IsDisabled() )
3205
			continue;
3210
			continue;
3206
 
3211
 
3207
		// readmes, uninstall and extra files dont need to be disabled
3212
		// readmes, uninstall and extra files dont need to be disabled
3208
		// Extra files not in the "Extras" directory could be anywhere, so these should be disabled incase they are game changing files, ie in "types"
3213
		// Extra files not in the "Extras" directory could be anywhere, so these should be disabled incase they are game changing files, ie in "types"
3209
		if ( f->GetFileType() == FILETYPE_README || f->GetFileType() == FILETYPE_UNINSTALL || (f->GetFileType() == FILETYPE_EXTRA && f->GetDir().Left(5).lower() == "Extra") )
3214
		if ( f->GetFileType() == FILETYPE_README || f->GetFileType() == FILETYPE_UNINSTALL || (f->GetFileType() == FILETYPE_EXTRA && f->dir().left(5).lower() == "Extra") )
3210
			continue;
3215
			continue;
3211
 
3216
 
3212
		// check if there is a matching uninstall file, ie there the script file is also an uninstall script file for a previously uninstalled package that has yet to be removed
3217
		// check if there is a matching uninstall file, ie there the script file is also an uninstall script file for a previously uninstalled package that has yet to be removed
3213
		if ( f->GetFileType() == FILETYPE_SCRIPT )
3218
		if ( f->GetFileType() == FILETYPE_SCRIPT )
3214
		{
3219
		{
Line 3225... Line 3230...
3225
 
3230
 
3226
			if ( found )
3231
			if ( found )
3227
				continue;
3232
				continue;
3228
		}
3233
		}
3229
 
3234
 
3230
		if ( f->GetFileType() == FILETYPE_MOD && !f->IsFakePatch() && f->CheckFileExt("cat") )
3235
		if ( f->GetFileType() == FILETYPE_MOD && !f->IsFakePatch() && f->checkFileExt("cat") )
3231
		{
3236
		{
3232
			if ( f->baseName().Compare(m_sSetMod) )
3237
			if ( f->baseName().Compare(m_sSetMod) )
3233
				m_sSetMod = Utils::String::Null();
3238
				m_sSetMod = Utils::String::Null();
3234
		}
3239
		}
3235
 
3240
 
Line 3277... Line 3282...
3277
				shuffle = true;
3282
				shuffle = true;
3278
			}
3283
			}
3279
		}
3284
		}
3280
		// otherwise we can just use the standard filename
3285
		// otherwise we can just use the standard filename
3281
		else
3286
		else
3282
			newFilename = Utils::String(m_sCurrentDir) + "/PluginManager/Disabled/" + f->GetNameDirectory(checkPackage).ToString();
3287
			newFilename = Utils::String(m_sCurrentDir) + "/PluginManager/Disabled/" + f->getNameDirectory(checkPackage);
3283
 
3288
 
3284
		// now to move the file by renameing it to its new location
3289
		// now to move the file by renameing it to its new location
3285
		// !!error checking!!
3290
		// !!error checking!!
3286
		// check the file, if it doesn't exist, and exists as disabled, we should just adjust the setting instead of an error
3291
		// check the file, if it doesn't exist, and exists as disabled, we should just adjust the setting instead of an error
3287
		CFileIO currentFile(f->GetFilePointer());
3292
		CFileIO currentFile(f->filePointer());
3288
		if ( !currentFile.exists() )
3293
		if ( !currentFile.exists() )
3289
		{
3294
		{
3290
			if ( !CFileIO(newFilename).exists() )
3295
			if ( !CFileIO(newFilename).exists() )
3291
			{
3296
			{
3292
				this->AddLogEntry(SPKINSTALL_MISSINGFILE, f->GetNameDirectory(checkPackage), errors);
3297
				this->AddLogEntry(SPKINSTALL_MISSINGFILE, f->getNameDirectory(checkPackage), errors);
3293
				continue;
3298
				continue;
3294
			}
3299
			}
3295
		}
3300
		}
3296
		// otherwise the file must exists, so lets move it
3301
		// otherwise the file must exists, so lets move it
3297
		else if ( !currentFile.Rename(newFilename) )
3302
		else if ( !currentFile.Rename(newFilename) )
3298
		{
3303
		{
3299
			this->AddLogEntry(SPKINSTALL_DISABLEFILE_FAIL, f->GetNameDirectory(checkPackage), errors);
3304
			this->AddLogEntry(SPKINSTALL_DISABLEFILE_FAIL, f->getNameDirectory(checkPackage), errors);
3300
			continue;
3305
			continue;
3301
		}
3306
		}
3302
 
3307
 
3303
		// must have been fine
3308
		// must have been fine
3304
		this->AddLogEntry(SPKINSTALL_DISABLEFILE, f->GetNameDirectory(checkPackage), errors);
3309
		this->AddLogEntry(SPKINSTALL_DISABLEFILE, f->getNameDirectory(checkPackage), errors);
3305
 
3310
 
3306
		original = _pOriginalFiles->restoreFile(f, errors);
3311
		original = _pOriginalFiles->restoreFile(f, errors);
3307
 
3312
 
3308
		// extra file thats not in the extras directory
3313
		// extra file thats not in the extras directory
3309
		if ( f->GetFileType() == FILETYPE_EXTRA || f->GetFileType() == FILETYPE_MAP || f->GetFileType() == FILETYPE_SOUND )
3314
		if ( f->GetFileType() == FILETYPE_EXTRA || f->GetFileType() == FILETYPE_MAP || f->GetFileType() == FILETYPE_SOUND )
3310
			removeDirs.PushBack(f->GetDirectory(checkPackage), NullString, true);
3315
			removeDirs.PushBack(CyString(f->getDirectory(checkPackage)), NullString, true);
3311
 
3316
 
3312
		// change the filename
3317
		// change the filename
3313
		f->SetFilename(newFilename);
3318
		f->setFilename(newFilename);
3314
 
3319
 
3315
		// finally mark the file as disabled so we know not to try to move it again
3320
		// finally mark the file as disabled so we know not to try to move it again
3316
		f->SetDisabled(true);
3321
		f->SetDisabled(true);
3317
	}
3322
	}
3318
 
3323
 
Line 3361... Line 3366...
3361
 * Any files that are being used by other enabled packages are skipped and left enabled
3366
 * Any files that are being used by other enabled packages are skipped and left enabled
3362
 *
3367
 *
3363
 * Original Files are restored when file is disabled
3368
 * Original Files are restored when file is disabled
3364
 *
3369
 *
3365
 * Fake patches are shuffled to fill in any gaps caused by disabling fake patches
3370
 * Fake patches are shuffled to fill in any gaps caused by disabling fake patches
3366
 *
3371
 *
3367
 * All files go into the Plugin/Disabled directory into thier respective directories.
3372
 * All files go into the Plugin/Disabled directory into thier respective directories.
3368
 *
3373
 *
3369
 * Any directories left empty when disabling files are then removed
3374
 * Any directories left empty when disabling files are then removed
3370
 *
3375
 *
3371
 * param: package	- Package file to be disabled
3376
 * param: package	- Package file to be disabled
3372
 * param: errors	- A string list used to add the status as it progresses, used in debugging output
3377
 * param: errors	- A string list used to add the status as it progresses, used in debugging output
3373
 * param: progress	- The progress class, updates the progress of the current disabling.  Needs a divered class to report the progress somewhere
3378
 * param: progress	- The progress class, updates the progress of the current disabling.  Needs a divered class to report the progress somewhere
3374
 *
3379
 *
3375
 * return: boolean, true if there was no errors, otherwise false
3380
 * return: boolean, true if there was no errors, otherwise false
3376
 */
3381
 */
3377
bool CPackages::DisablePackage ( CBaseFile *package, CyStringList *errors, CProgressInfo *progress )
3382
bool CPackages::DisablePackage ( CBaseFile *package, CyStringList *errors, CProgressInfo *progress )
3378
{
3383
{
3379
	// if already disabled, just skip
3384
	// if already disabled, just skip
3380
	if ( !package->IsEnabled() )
3385
	if ( !package->IsEnabled() )
3381
		return true;
3386
		return true;
Line 3385... Line 3390...
3385
		return this->DisablePreparedPackages(errors, progress);
3390
		return this->DisablePreparedPackages(errors, progress);
3386
 
3391
 
3387
	return false;
3392
	return false;
3388
}
3393
}
3389
 
3394
 
3390
 
3395
 
3391
/**
3396
/**
3392
 * Find a Package
3397
 * Find a Package
3393
 *
3398
 *
3394
 * Finds a matching package so we can find if one is already installed
3399
 * Finds a matching package so we can find if one is already installed
3395
 *
3400
 *
Line 3398... Line 3403...
3398
CBaseFile* CPackages::FindPackage(CBaseFile* package)
3403
CBaseFile* CPackages::FindPackage(CBaseFile* package)
3399
{
3404
{
3400
	// no point checking if we've been sent a null pointer
3405
	// no point checking if we've been sent a null pointer
3401
	if ( !package )
3406
	if ( !package )
3402
		return 0;
3407
		return 0;
3403
 
3408
 
3404
	// we are checking against a SPK package, so we match the name and author
3409
	// we are checking against a SPK package, so we match the name and author
3405
	if ( package->GetType() == TYPE_SPK )
3410
	if ( package->GetType() == TYPE_SPK )
3406
		return FindSpkPackage(package->name(), package->author());
3411
		return FindSpkPackage(package->name(), package->author());
3407
	else if ( package->GetType() == TYPE_XSP )
3412
	else if ( package->GetType() == TYPE_XSP )
3408
		return FindXspPackage(((CXspFile *)package)->GetShipID());
3413
		return FindXspPackage(((CXspFile *)package)->GetShipID());
Line 3583... Line 3588...
3583
		CListNode<C_File> *fnode = file->GetFileList()->Front();
3588
		CListNode<C_File> *fnode = file->GetFileList()->Front();
3584
		while ( fnode )
3589
		while ( fnode )
3585
		{
3590
		{
3586
			fnode->Data()->incUsed();
3591
			fnode->Data()->incUsed();
3587
			fnode = fnode->next();
3592
			fnode = fnode->next();
3588
		}
3593
		}
3589
	}
3594
	}
3590
}
3595
}
3591
 
3596
 
3592
/**
3597
/**
3593
 * Removes all empty directories that might have been created
3598
 * Removes all empty directories that might have been created
Line 3794... Line 3799...
3794
 
3799
 
3795
				if ( onlyEnabled && !p->IsEnabled() )
3800
				if ( onlyEnabled && !p->IsEnabled() )
3796
					continue;
3801
					continue;
3797
 
3802
 
3798
				return true;
3803
				return true;
3799
			}
3804
			}
3800
		}
3805
		}
3801
	}
3806
	}
3802
 
3807
 
3803
	return false;
3808
	return false;
3804
}
3809
}
3805
 
3810
 
3806
bool CPackages::findAllNeededDependacies(CBaseFile *p, const CLinkList<CBaseFile> &packages, CLinkList<CBaseFile> *foundPackages, bool onlyEnabled, bool includePrepared) const
3811
bool CPackages::findAllNeededDependacies(CBaseFile *p, const CLinkList<CBaseFile> &packages, CLinkList<CBaseFile> *foundPackages, bool onlyEnabled, bool includePrepared) const
3807
{
3812
{
3808
	CLinkList<SNeededLibrary> *neededList = p->GetNeededLibraries();
3813
	CLinkList<SNeededLibrary> *neededList = p->GetNeededLibraries();
3809
	if (neededList)
3814
	if (neededList)
3810
	{
3815
	{
Line 4017... Line 4022...
4017
 
4022
 
4018
	return count;
4023
	return count;
4019
}
4024
}
4020
 
4025
 
4021
int CPackages::CheckPreparedInstallRequired(CLinkList<CBaseFile> *list)
4026
int CPackages::CheckPreparedInstallRequired(CLinkList<CBaseFile> *list)
4022
{
4027
{
4023
	// loop through all packages
4028
	// loop through all packages
4024
	int count = 0;
4029
	int count = 0;
4025
	for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
4030
	for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
4026
	{
4031
	{
4027
		CBaseFile *p = node->Data();
4032
		CBaseFile *p = node->Data();
Line 4057... Line 4062...
4057
 *
4062
 *
4058
 * Removes a single uninstall file
4063
 * Removes a single uninstall file
4059
 */
4064
 */
4060
bool CPackages::RemoveUninstallFile(C_File *file, CyStringList *errors)
4065
bool CPackages::RemoveUninstallFile(C_File *file, CyStringList *errors)
4061
{
4066
{
4062
	CFileIO fio(file->GetFilePointer());
4067
	CFileIO fio(file->filePointer());
4063
	if ( fio.exists() )
4068
	if ( fio.exists() )
4064
	{
4069
	{
4065
		if ( fio.remove() ) {
4070
		if ( fio.remove() ) {
4066
			this->AddLogEntry(SPKINSTALL_UNINSTALL_REMOVE, file->GetNameDirectory(NULL), errors);
4071
			this->AddLogEntry(SPKINSTALL_UNINSTALL_REMOVE, file->getNameDirectory(NULL), errors);
4067
			return true;
4072
			return true;
4068
		}
4073
		}
4069
		else if ( errors )
4074
		else if ( errors )
4070
			this->AddLogEntry(SPKINSTALL_UNINSTALL_REMOVE_FAIL, file->GetNameDirectory(NULL), errors);
4075
			this->AddLogEntry(SPKINSTALL_UNINSTALL_REMOVE_FAIL, file->getNameDirectory(NULL), errors);
4071
	}
4076
	}
4072
 
4077
 
4073
	return false;
4078
	return false;
4074
}
4079
}
4075
 
4080
 
Line 4129... Line 4134...
4129
 *
4134
 *
4130
 * Removes a single file
4135
 * Removes a single file
4131
 */
4136
 */
4132
bool CPackages::RemoveSharedFile(C_File *file, CyStringList *errors)
4137
bool CPackages::RemoveSharedFile(C_File *file, CyStringList *errors)
4133
{
4138
{
4134
	CFileIO fio(file->GetFilePointer());
4139
	CFileIO fio(file->filePointer());
4135
	if ( fio.exists() )
4140
	if ( fio.exists() )
4136
	{
4141
	{
4137
		if ( fio.remove() ) {
4142
		if ( fio.remove() ) {
4138
			this->AddLogEntry(SPKINSTALL_SHARED, file->GetNameDirectory(NULL), errors);
4143
			this->AddLogEntry(SPKINSTALL_SHARED, file->getNameDirectory(NULL), errors);
4139
			delete file;
4144
			delete file;
4140
			return true;
4145
			return true;
4141
		}
4146
		}
4142
		else if ( errors )
4147
		else if ( errors )
4143
			this->AddLogEntry(SPKINSTALL_SHARED_FAIL, file->GetNameDirectory(NULL), errors);
4148
			this->AddLogEntry(SPKINSTALL_SHARED_FAIL, file->getNameDirectory(NULL), errors);
4144
	}
4149
	}
4145
 
4150
 
4146
	return false;
4151
	return false;
4147
}
4152
}
4148
 
4153
 
Line 4232... Line 4237...
4232
		if ( !f->isAutoTextFile() )
4237
		if ( !f->isAutoTextFile() )
4233
			continue;
4238
			continue;
4234
 
4239
 
4235
		// we need to rename it
4240
		// we need to rename it
4236
		int current = findNextTextFile();
4241
		int current = findNextTextFile();
4237
		if ( current < f->GetTextFileID() )
4242
		if ( current < f->textFileID() )
4238
		{
4243
		{
4239
			CFileIO moveFile(f->filePointer());
4244
			CFileIO moveFile(f->filePointer());
4240
	
4245
	
4241
			Utils::String newName = SPK::FormatTextName(current, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT)) + "." + moveFile.extension();
4246
			Utils::String newName = SPK::FormatTextName(current, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT)) + "." + moveFile.extension();
4242
			if ( moveFile.Rename(m_sCurrentDir + "/t/" + newName) )
4247
			if ( moveFile.Rename(m_sCurrentDir + "/t/" + newName) )
4243
			{
4248
			{
4244
				this->AddLogEntry(SPKINSTALL_AUTOTEXT, f->name() + "~" + newName, errors);
4249
				this->AddLogEntry(SPKINSTALL_AUTOTEXT, f->name() + "~" + newName, errors);
4245
				f->SetName(newName);
4250
				f->setName(newName);
4246
			}
4251
			}
4247
			else
4252
			else
4248
				this->AddLogEntry(SPKINSTALL_AUTOTEXT_FAIL, f->name() + "~" + newName, errors);
4253
				this->AddLogEntry(SPKINSTALL_AUTOTEXT_FAIL, f->name() + "~" + newName, errors);
4249
		}
4254
		}
4250
	}
4255
	}
4251
}
4256
}
4252
 
4257
 
Line 4280... Line 4285...
4280
		if (p->AnyDependacies())
4285
		if (p->AnyDependacies())
4281
		{
4286
		{
4282
			for (SNeededLibrary* nl = p->GetNeededLibraries()->First(); nl; nl = p->GetNeededLibraries()->Next())
4287
			for (SNeededLibrary* nl = p->GetNeededLibraries()->First(); nl; nl = p->GetNeededLibraries()->Next())
4283
			{
4288
			{
4284
				auto package = FindPackage(nl->sName, nl->sAuthor);
4289
				auto package = FindPackage(nl->sName, nl->sAuthor);
4285
				if (package)
4290
				if (package)
4286
				{
4291
				{
4287
					packagesBefore.insert(package);
4292
					packagesBefore.insert(package);
4288
					packagesAfter[p].insert(package);
4293
					packagesAfter[p].insert(package);
4289
				}
4294
				}
4290
			}
4295
			}
4291
		}
4296
		}
4292
		CSpkFile* spk = dynamic_cast<CSpkFile*>(p);
4297
		CSpkFile* spk = dynamic_cast<CSpkFile*>(p);
4293
		if (spk)
4298
		if (spk)
4294
		{
4299
		{
4295
			if (spk->IsAnotherMod())
4300
			if (spk->IsAnotherMod())
4296
			{
4301
			{
4297
				auto package = FindPackage(spk->otherName(), spk->otherAuthor());
4302
				auto package = FindPackage(spk->otherName(), spk->otherAuthor());
4298
				if (package)
4303
				if (package)
4299
				{
4304
				{
4300
					packagesBefore.insert(package);
4305
					packagesBefore.insert(package);
4301
					packagesAfter[p].insert(package);
4306
					packagesAfter[p].insert(package);
4302
				}
4307
				}
4303
			}
4308
			}
4304
		}
4309
		}
4305
 
4310
 
4306
		if (!p->getFakePatchBeforeOrder().empty())
4311
		if (!p->getFakePatchBeforeOrder().empty())
4307
		{
4312
		{
Line 4310... Line 4315...
4310
			for (auto itr = list.begin(); itr != list.end(); itr++)
4315
			for (auto itr = list.begin(); itr != list.end(); itr++)
4311
			{
4316
			{
4312
				auto package = FindPackage((*itr)->str, (*itr)->data);
4317
				auto package = FindPackage((*itr)->str, (*itr)->data);
4313
				if (package)				
4318
				if (package)				
4314
					packagesAfter[package].insert(p);
4319
					packagesAfter[package].insert(p);
4315
			}
4320
			}
4316
		}
4321
		}
4317
		if (!p->getFakePatchAfterOrder().empty())
4322
		if (!p->getFakePatchAfterOrder().empty())
4318
		{
4323
		{
4319
			auto& list = p->getFakePatchAfterOrder();
4324
			auto& list = p->getFakePatchAfterOrder();
4320
			for (auto itr = list.begin(); itr != list.end(); itr++)
4325
			for (auto itr = list.begin(); itr != list.end(); itr++)
4321
			{
4326
			{
4322
				auto package = FindPackage((*itr)->str, (*itr)->data);
4327
				auto package = FindPackage((*itr)->str, (*itr)->data);
4323
				if (package)
4328
				if (package)
4324
				{
4329
				{
4325
					packagesBefore.insert(package);
4330
					packagesBefore.insert(package);
4326
					packagesAfter[p].insert(package);
4331
					packagesAfter[p].insert(package);
4327
				}
4332
				}
4328
			}
4333
			}
4329
		}
4334
		}
4330
	}
4335
	}
4331
 
4336
 
4332
	auto addOrderedList = [](const std::vector<CBaseFile*>& addList, const Utils::CStringList& orderList, std::vector<CBaseFile*>& addTo, const CPackages *packages)
4337
	auto addOrderedList = [](const std::vector<CBaseFile*>& addList, const Utils::CStringList& orderList, std::vector<CBaseFile*>& addTo, const CPackages *packages)
4333
	{
4338
	{
4334
		// add all the items in the ordered list first
4339
		// add all the items in the ordered list first
Line 4351... Line 4356...
4351
		for (auto itr = addList.begin(); itr != addList.end(); itr++)
4356
		for (auto itr = addList.begin(); itr != addList.end(); itr++)
4352
		{
4357
		{
4353
			auto checkItr = std::find(addTo.begin(), addTo.end(), *itr);
4358
			auto checkItr = std::find(addTo.begin(), addTo.end(), *itr);
4354
			if (checkItr == addTo.end())
4359
			if (checkItr == addTo.end())
4355
				addTo.push_back(*itr);
4360
				addTo.push_back(*itr);
4356
		}
4361
		}
4357
	};
4362
	};
4358
 
4363
 
4359
	auto removeList = [](const std::vector<CBaseFile*>& removeList, std::set<CBaseFile*>& list)
4364
	auto removeList = [](const std::vector<CBaseFile*>& removeList, std::set<CBaseFile*>& list)
4360
	{
4365
	{
4361
		for (auto itr = removeList.begin(); itr != removeList.end(); itr++)
4366
		for (auto itr = removeList.begin(); itr != removeList.end(); itr++)
Line 4392... Line 4397...
4392
					}
4397
					}
4393
				}
4398
				}
4394
 
4399
 
4395
				if (!notAdded)
4400
				if (!notAdded)
4396
					packagesOrder.push_back(p);
4401
					packagesOrder.push_back(p);
4397
			}
4402
			}
4398
		}
4403
		}
4399
 
4404
 
4400
 
4405
 
4401
		// no valid packages left ? lets just add the rest
4406
		// no valid packages left ? lets just add the rest
4402
		if (packagesOrder.empty())
4407
		if (packagesOrder.empty())
4403
		{
4408
		{
4404
			for (auto itr = packagesBefore.begin(); itr != packagesBefore.end(); itr++)
4409
			for (auto itr = packagesBefore.begin(); itr != packagesBefore.end(); itr++)
4405
				packagesOrder.push_back(*itr);
4410
				packagesOrder.push_back(*itr);
4406
		}
4411
		}
4407
 
4412
 
4408
		addOrderedList(packagesOrder, m_lFakePatchOrder, order, this);
4413
		addOrderedList(packagesOrder, m_lFakePatchOrder, order, this);
4409
		removeList(packagesOrder, packagesBefore);
4414
		removeList(packagesOrder, packagesBefore);
4410
	}
4415
	}
4411
 
4416
 
4412
	// now add the remaining list ordered list
4417
	// now add the remaining list ordered list
4413
	for (auto itr = m_lFakePatchOrder.begin(); itr != m_lFakePatchOrder.end(); itr++)
4418
	for (auto itr = m_lFakePatchOrder.begin(); itr != m_lFakePatchOrder.end(); itr++)
4414
	{
4419
	{
4415
		auto p = findPackage((*itr)->str, (*itr)->data);
4420
		auto p = findPackage((*itr)->str, (*itr)->data);
Line 4460... Line 4465...
4460
			{
4465
			{
4461
				int findPos = fakePatchOrder.findStringAndData(spk->otherName(), spk->otherAuthor());
4466
				int findPos = fakePatchOrder.findStringAndData(spk->otherName(), spk->otherAuthor());
4462
				if (existingPos == -1)
4467
				if (existingPos == -1)
4463
					fakePatchOrder.pushBack(spk->otherName(), spk->otherAuthor());
4468
					fakePatchOrder.pushBack(spk->otherName(), spk->otherAuthor());
4464
				else if (findPos == -1)
4469
				else if (findPos == -1)
4465
					fakePatchOrder.insertAt(existingPos, spk->otherName(), spk->otherAuthor());
4470
					fakePatchOrder.insertAt(existingPos, spk->otherName(), spk->otherAuthor());
4466
				else if (findPos > existingPos)
4471
				else if (findPos > existingPos)
4467
				{
4472
				{
4468
					fakePatchOrder.removeAt(findPos);
4473
					fakePatchOrder.removeAt(findPos);
4469
					fakePatchOrder.insertAt(existingPos, spk->otherName(), spk->otherAuthor());
4474
					fakePatchOrder.insertAt(existingPos, spk->otherName(), spk->otherAuthor());
4470
				}				
4475
				}				
4471
			}
4476
			}
4472
		}
4477
		}
4473
 
4478
 
4474
		// must have an order define
4479
		// must have an order define
4475
		if (!p->anyFakePatchOrder())
4480
		if (!p->anyFakePatchOrder())
4476
			continue;
4481
			continue;
4477
 
4482
 
Line 4489... Line 4494...
4489
		}
4494
		}
4490
 
4495
 
4491
		// we have some fake patches that need to be shuffled
4496
		// we have some fake patches that need to be shuffled
4492
		if ( anyFound )
4497
		if ( anyFound )
4493
			packages.push_back(p);
4498
			packages.push_back(p);
4494
	}
4499
	}
4495
 
4500
 
4496
	// lets adjust the order (only if theres more than 1
4501
	// lets adjust the order (only if theres more than 1
4497
	if ( packages.size() > 1 )
4502
	if ( packages.size() > 1 )
4498
	{
4503
	{
4499
		CLinkList<CBaseFile> sortedPackages;
4504
		CLinkList<CBaseFile> sortedPackages;
Line 4517... Line 4522...
4517
						if ((*itr)->str.Compare(sNode->Data()->name()) && (*itr)->data.Compare(sNode->Data()->author()) )
4522
						if ((*itr)->str.Compare(sNode->Data()->name()) && (*itr)->data.Compare(sNode->Data()->author()) )
4518
						{
4523
						{
4519
							if ( earliestPos == -1 || pos < earliestPos )
4524
							if ( earliestPos == -1 || pos < earliestPos )
4520
								earliestPos = pos;
4525
								earliestPos = pos;
4521
							break;
4526
							break;
4522
						}
4527
						}
4523
						++pos;
4528
						++pos;
4524
					}					
4529
					}					
4525
				}
4530
				}
4526
 
4531
 
4527
				if ( earliestPos > -1 )
4532
				if ( earliestPos > -1 )
Line 4563... Line 4568...
4563
			while ( true )
4568
			while ( true )
4564
			{
4569
			{
4565
				C_File *lowestFile = NULL;
4570
				C_File *lowestFile = NULL;
4566
				for ( C_File *file = package->GetFirstFile(FILETYPE_MOD); file; file = package->GetNextFile(file) )
4571
				for ( C_File *file = package->GetFirstFile(FILETYPE_MOD); file; file = package->GetNextFile(file) )
4567
				{
4572
				{
4568
					if ( !file->IsFakePatch() ) continue;
4573
					if (!file->IsFakePatch()) continue;
4569
					if ( !file->CheckFileExt("cat") ) continue; // only do the cat file, we can shuffle the dat file to match later
4574
					if (!file->checkFileExt("cat")) continue; // only do the cat file, we can shuffle the dat file to match later
4570
					if ( doneList.FindData(file) ) continue; // already done?
4575
					if (doneList.FindData(file)) continue; // already done?
4571
 
4576
 
4572
					if ( !lowestFile )
4577
					if ( !lowestFile )
4573
						lowestFile = file;
4578
						lowestFile = file;
4574
					else
4579
					else
4575
					{
4580
					{
4576
						if ( file->GetBaseName().ToInt() < lowestFile->GetBaseName().ToInt() )
4581
						if ( file->baseName().toInt() < lowestFile->baseName().toInt() )
4577
							lowestFile = file;
4582
							lowestFile = file;
4578
					}
4583
					}
4579
				}
4584
				}
4580
 
4585
 
4581
				if ( !lowestFile ) // no more files ?
4586
				if ( !lowestFile ) // no more files ?
4582
					break;
4587
					break;
4583
 
4588
 
4584
				// check its filename, it might already be in the correct place
4589
				// check its filename, it might already be in the correct place
4585
				if ( lowestFile->baseName().toInt() != lowest )
4590
				if ( lowestFile->baseName().toInt() != lowest )
4586
				{
4591
				{
4587
					// if the file already exists, we need to move it elsewhere
4592
					// if the file already exists, we need to move it elsewhere
Line 4593... Line 4598...
4593
						if ( !moveFile ) // must not have it in our list ? lets move to the next
4598
						if ( !moveFile ) // must not have it in our list ? lets move to the next
4594
						{
4599
						{
4595
							lowest++;
4600
							lowest++;
4596
							continue;
4601
							continue;
4597
						}
4602
						}
4598
 
4603
 
4599
						// now we can move the the cat/dat file elsewhere, lets shuffle it to the highest free number
4604
						// now we can move the the cat/dat file elsewhere, lets shuffle it to the highest free number
4600
						ShufflePatchTo(moveFile, FindLastFakePatch(), errors);
4605
						ShufflePatchTo(moveFile, FindLastFakePatch(), errors);
4601
					}
4606
					}
4602
 
4607
 
4603
					// space should be free, now lets shuffle it
4608
					// space should be free, now lets shuffle it
4604
					ShufflePatchTo(lowestFile, lowest, errors);
4609
					ShufflePatchTo(lowestFile, lowest, errors);
4605
				}
4610
				}
4606
 
4611
 
4607
				doneList.push_back(lowestFile); // we've done this file now
4612
				doneList.push_back(lowestFile); // we've done this file now
4608
				lowest++; // move up the lowest ready for the next patch
4613
				lowest++; // move up the lowest ready for the next patch
4609
			}
4614
			}
4610
		}
4615
		}
4611
	}
4616
	}
4612
 
4617
 
4613
	// now lets shuffle the rest
4618
	// now lets shuffle the rest
4614
	// now find any packages with greater fake patchs and fill the gaps
4619
	// now find any packages with greater fake patchs and fill the gaps
4615
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4620
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4616
	{
4621
	{
4617
		C_File *f = node->Data();
4622
		C_File *f = node->Data();
4618
		// already done?
4623
		// already done?
4619
		if ( doneList.FindData(f) ) 
4624
		if ( doneList.FindData(f) ) 
4620
			continue;
4625
			continue;
4621
 
4626
 
4622
		// only do files that are enabled
4627
		// only do files that are enabled
4623
		if ( f->IsDisabled() )
4628
		if ( f->IsDisabled() )
4624
			continue;
4629
			continue;
4625
 
4630
 
4626
		// check if the file is a fake patch
4631
		// check if the file is a fake patch
4627
		if ( !f->IsFakePatch() )
4632
		if ( !f->IsFakePatch() )
4628
			continue;
4633
			continue;
4629
 
4634
 
4630
		// we only want cat and dat files, all fake patchs should be, but incase theres an error in the package somewhere we can check
4635
		// we only want cat and dat files, all fake patchs should be, but incase theres an error in the package somewhere we can check
4631
		if ( !f->CheckFileExt("cat") )
4636
		if (!f->checkFileExt("cat"))
4632
			continue;
4637
			continue;
4633
 
4638
 
4634
		// now lets check if its greater than our gap
4639
		// now lets check if its greater than our gap
4635
		int check = FindNextFakePatch();
4640
		int check = FindNextFakePatch();
4636
		int patchNum = f->filename().token(".", 1).toInt();
4641
		int patchNum = f->filename().token(".", 1).toInt();
4637
		if ( patchNum <= check )
4642
		if ( patchNum <= check )
4638
			continue;
4643
			continue;
4639
 
4644
 
4640
		ShufflePatchTo(f, check, errors);
4645
		ShufflePatchTo(f, check, errors);
4641
	}
4646
	}
4642
}
4647
}
4643
 
4648
 
4644
void CPackages::ShufflePatchTo(C_File *file, int to, CyStringList *errors)
4649
void CPackages::ShufflePatchTo(C_File *file, int to, CyStringList *errors)
Line 4656... Line 4661...
4656
		// now find the matching pairing if it exists
4661
		// now find the matching pairing if it exists
4657
		for ( CListNode<C_File> *node2 = m_lFiles.Front(); node2; node2 = node2->next() )
4662
		for ( CListNode<C_File> *node2 = m_lFiles.Front(); node2; node2 = node2->next() )
4658
		{
4663
		{
4659
			C_File *f2 = node2->Data();
4664
			C_File *f2 = node2->Data();
4660
 
4665
 
4661
			if ( f2->IsDisabled() || !f2->IsFakePatch() || f2->CheckFileExt(file->GetFileExt()) )
4666
			if ( f2->IsDisabled() || !f2->IsFakePatch() || f2->checkFileExt(file->fileExt()))
4662
				continue;
4667
				continue;
4663
 
4668
 
4664
			// needs to be the same file
4669
			// needs to be the same file
4665
			if ( f2->GetBaseName() != file->GetBaseName() )
4670
			if ( f2->baseName() != file->baseName() )
4666
				continue;
4671
				continue;
4667
 
4672
 
4668
			Utils::String newName2 = Utils::String::PadNumber(to, 2) + "." + f2->fileExt();
4673
			Utils::String newName2 = Utils::String::PadNumber(to, 2) + "." + f2->fileExt();
4669
			CFileIO moveFile(f2->filePointer());
4674
			CFileIO moveFile(f2->filePointer());
4670
			if ( moveFile.Rename(m_sCurrentDir + "/" + newName2) )
4675
			if ( moveFile.Rename(m_sCurrentDir + "/" + newName2) )
Line 4693... Line 4698...
4693
		if ( !p->AnyFileType(FILETYPE_MOD) ) continue;
4698
		if ( !p->AnyFileType(FILETYPE_MOD) ) continue;
4694
 
4699
 
4695
		// now get all fake patches
4700
		// now get all fake patches
4696
		for ( C_File *file = p->GetFirstFile(FILETYPE_MOD); file; file = p->GetNextFile(file) )
4701
		for ( C_File *file = p->GetFirstFile(FILETYPE_MOD); file; file = p->GetNextFile(file) )
4697
		{
4702
		{
4698
			if ( !file->IsFakePatch() ) continue;
4703
			if (!file->IsFakePatch()) continue;
4699
			if ( file->CheckFileExt("dat") ) continue;
4704
			if (file->checkFileExt("dat")) continue;
4700
			int check = file->GetBaseName().ToInt();
4705
			int check = file->baseName().toInt();
4701
			if ( check < lowest )
4706
			if ( check < lowest )
4702
				lowest = check;
4707
				lowest = check;
4703
		}
4708
		}
4704
	}
4709
	}
4705
 
4710
 
Line 5013... Line 5018...
5013
	CFileIO writeFile(m_sCurrentDir + "/" + addFile->getNameDirectory(NULL));
5018
	CFileIO writeFile(m_sCurrentDir + "/" + addFile->getNameDirectory(NULL));
5014
	if ( writeFile.writeFile(lines) )
5019
	if ( writeFile.writeFile(lines) )
5015
	{
5020
	{
5016
		this->addLogEntry(SPKINSTALL_WRITEFILE, addFile->getNameDirectory(NULL), errors);
5021
		this->addLogEntry(SPKINSTALL_WRITEFILE, addFile->getNameDirectory(NULL), errors);
5017
 
5022
 
5018
		addFile->SetFilename(m_sCurrentDir + "/" + addFile->getNameDirectory(NULL));
5023
		addFile->setFilename(m_sCurrentDir + "/" + addFile->getNameDirectory(NULL));
5019
		// now we have the file wrriten, we need to add it to all scripts that need it
5024
		// now we have the file wrriten, we need to add it to all scripts that need it
5020
		// first we add it to the global list
5025
		// first we add it to the global list
5021
		m_lFiles.push_back(addFile);
5026
		m_lFiles.push_back(addFile);
5022
 
5027
 
5023
		// now add it to the scripts
5028
		// now add it to the scripts
Line 5059... Line 5064...
5059
		{
5064
		{
5060
			C_File *tFile = fNode->Data();
5065
			C_File *tFile = fNode->Data();
5061
			if ( tFile->GetFileType() != FILETYPE_TEXT )
5066
			if ( tFile->GetFileType() != FILETYPE_TEXT )
5062
				continue;
5067
				continue;
5063
 
5068
 
5064
			CyString id = tFile->GetBaseName().GetToken("-", 1, 1);
5069
			Utils::String id = tFile->baseName().token("-", 1);
5065
			if ( id == textid )
5070
			if ( id == textid.ToString() )
5066
			{
5071
			{
5067
				found = true;
5072
				found = true;
5068
				break;
5073
				break;
5069
			}
5074
			}
5070
		}
5075
		}
Line 5081... Line 5086...
5081
 
5086
 
5082
	Utils::String remFileStr = file->filePointer();
5087
	Utils::String remFileStr = file->filePointer();
5083
	remFileStr.findReplace(m_sCurrentDir, "");
5088
	remFileStr.findReplace(m_sCurrentDir, "");
5084
 
5089
 
5085
	if ( file->filePointer().contains("::")) {
5090
	if ( file->filePointer().contains("::")) {
5086
		CFileIO CatFile(file->GetFilePointer().GetToken("::", 1, 1));
5091
		CFileIO CatFile(file->filePointer().token("::", 1));
5087
		if ( CatFile.exists() ) {
5092
		if ( CatFile.exists() ) {
5088
			CCatFile cat;
5093
			CCatFile cat;
5089
			if ( cat.open(CatFile.fullFilename(), this->getAddonDir(), CATREAD_DAT, false) == CATERR_NONE ) {
5094
			if ( cat.open(CatFile.fullFilename(), this->getAddonDir(), CATREAD_DAT, false) == CATERR_NONE ) {
5090
				CyString fileName = file->GetFilePointer().GetToken("::", 2, 2);
5095
				Utils::String fileName = file->filePointer().token("::", 2);
5091
				if ( cat.FindData(fileName) ) {
5096
				if ( cat.FindData(fileName) ) {
5092
					if ( cat.removeFile(fileName.ToString()) ) {
5097
					if ( cat.removeFile(fileName) ) {
5093
						this->AddLogEntry(SPKINSTALL_DELETEFILE, remFileStr, errors);
5098
						this->AddLogEntry(SPKINSTALL_DELETEFILE, remFileStr, errors);
5094
					}
5099
					}
5095
					else {
5100
					else {
5096
						this->AddLogEntry(SPKINSTALL_DELETEFILE_FAIL, remFileStr, errors);
5101
						this->AddLogEntry(SPKINSTALL_DELETEFILE_FAIL, remFileStr, errors);
5097
						return false;
5102
						return false;
Line 5438... Line 5443...
5438
 
5443
 
5439
	if (m_pEnabledMod && m_pEnabledMod->AnyFileType(FILETYPE_MOD))
5444
	if (m_pEnabledMod && m_pEnabledMod->AnyFileType(FILETYPE_MOD))
5440
	{
5445
	{
5441
		for (C_File* file = m_pEnabledMod->GetFirstFile(FILETYPE_MOD); file; file = m_pEnabledMod->GetNextFile(file))
5446
		for (C_File* file = m_pEnabledMod->GetFirstFile(FILETYPE_MOD); file; file = m_pEnabledMod->GetNextFile(file))
5442
		{
5447
		{
5443
			if (!file->CheckFileExt("cat"))
5448
			if (!file->checkFileExt("cat"))
5444
				continue;
5449
				continue;
5445
 
5450
 
5446
			CCatFile catFile;
5451
			CCatFile catFile;
5447
			if (catFile.open(file->filePointer(), addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE)
5452
			if (catFile.open(file->filePointer(), addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE)
5448
			{
5453
			{
Line 7083... Line 7088...
7083
					// read the section, first entry is section, second is size
7088
					// read the section, first entry is section, second is size
7084
					while ( !line.empty() )
7089
					while ( !line.empty() )
7085
					{
7090
					{
7086
						line = line.removeFirstSpace();
7091
						line = line.removeFirstSpace();
7087
						if ( line.empty() )
7092
						if ( line.empty() )
7088
							break;
7093
							break;
7089
 
7094
 
7090
						if ( !insection && !insubsection )
7095
						if ( !insection && !insubsection )
7091
						{
7096
						{
7092
							Utils::String section = line.token(";", 1);
7097
							Utils::String section = line.token(";", 1);
7093
							insection = line.token(";", 2).toInt();
7098
							insection = line.token(";", 2).toInt();
Line 8266... Line 8271...
8266
			{
8271
			{
8267
				bool done = false;
8272
				bool done = false;
8268
				C_File *f = p->GetFirstFile(FILETYPE_ADVERT);
8273
				C_File *f = p->GetFirstFile(FILETYPE_ADVERT);
8269
				if (p->ReadFileToMemory(f))
8274
				if (p->ReadFileToMemory(f))
8270
				{
8275
				{
8271
					f->SetFullDir(this->tempDirectory());
8276
					f->setFullDir(this->tempDirectory());
8272
					if (f->UncompressData())
8277
					if (f->UncompressData())
8273
					{
8278
					{
8274
						if (f->writeFilePointer())
8279
						if (f->writeFilePointer())
8275
							done = true;
8280
							done = true;
8276
					}
8281
					}
Line 8400... Line 8405...
8400
		C_File f(file.ToString());
8405
		C_File f(file.ToString());
8401
		if ( !f.ReadFromFile() )
8406
		if ( !f.ReadFromFile() )
8402
			return false;
8407
			return false;
8403
		f.UnPCKFile();
8408
		f.UnPCKFile();
8404
 
8409
 
8405
		f.SetFilename(m_sTempDir + "/tships.txt");
8410
		f.setFilename(m_sTempDir + "/tships.txt");
8406
		if ( !f.writeFilePointer() )
8411
		if ( !f.writeFilePointer() )
8407
			return false;
8412
			return false;
8408
 
8413
 
8409
		File.open(m_sTempDir + "/tships.txt");
8414
		File.open(m_sTempDir + "/tships.txt");
8410
		deleteFile = true;
8415
		deleteFile = true;
Line 8535... Line 8540...
8535
		C_File f(file.ToString());
8540
		C_File f(file.ToString());
8536
		if ( !f.ReadFromFile() )
8541
		if ( !f.ReadFromFile() )
8537
			return false;
8542
			return false;
8538
		f.UnPCKFile();
8543
		f.UnPCKFile();
8539
 
8544
 
8540
		f.SetFilename(m_sTempDir + "/textfile.xml");
8545
		f.setFilename(m_sTempDir + "/textfile.xml");
8541
		if ( !f.writeFilePointer() )
8546
		if ( !f.writeFilePointer() )
8542
			return false;
8547
			return false;
8543
 
8548
 
8544
		File.open(m_sTempDir + "/textfile.xml");
8549
		File.open(m_sTempDir + "/textfile.xml");
8545
		deleteFile = true;
8550
		deleteFile = true;
Line 8799... Line 8804...
8799
 *
8804
 *
8800
 * This includes all types and text files
8805
 * This includes all types and text files
8801
 *
8806
 *
8802
 * Returns true if it finds any files
8807
 * Returns true if it finds any files
8803
 */
8808
 */
8804
bool CPackages::GetModCompatabilityList(C_File *file, CyStringList *list)
8809
bool CPackages::getModCompatabilityList(C_File *file, Utils::CStringList *list)
8805
{
8810
{
8806
	// not a valid file
8811
	// not a valid file
8807
	if ( !file ) return false;
8812
	if ( !file ) return false;
8808
	if ( file->GetFileType() != FILETYPE_MOD ) return false;
8813
	if ( file->GetFileType() != FILETYPE_MOD ) return false;
8809
	if ( !file->GetFileExt().Compare("cat") ) return false;
8814
	if ( !file->fileExt().Compare("cat") ) return false;
8810
 
8815
 
8811
	// we need to read the file list for the mod
8816
	// we need to read the file list for the mod
8812
	CCatFile cat;
8817
	CCatFile cat;
8813
	if ( cat.open(file->filePointer(), this->getAddonDir(), CATREAD_JUSTCONTENTS, false) == CATERR_NONE )
8818
	if ( cat.open(file->filePointer(), this->getAddonDir(), CATREAD_JUSTCONTENTS, false) == CATERR_NONE )
8814
	{
8819
	{
8815
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8820
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8816
		{
8821
		{
8817
			SInCatFile *f = cat.GetFile(i);
8822
			SInCatFile *f = cat.GetFile(i);
8818
			CyString filename = f->sFile;
8823
			Utils::String filename = f->sFile;
8819
			filename = filename.FindReplace("\\", "/");
8824
			filename = filename.findReplace("\\", "/");
8820
			bool found = false;
8825
			bool found = false;
-
 
8826
			//TODO: rework this
8821
			if ( filename.Left(2).Compare("t/") || filename.Left(6).Compare("types/") )
8827
			if ( filename.left(2).Compare("t/") || filename.left(6).Compare("types/") )
8822
				found = true;
8828
				found = true;
8823
			else if ( filename.Left(8).Compare("addon/t/") || filename.Left(12).Compare(&quot;addon/types/") )
8829
			else if (filename.left(8).Compare("addon/t/") || filename.left(12).Compare(&quot;addon/types/"))
-
 
8830
				found = true;
-
 
8831
			else if (filename.left(9).Compare("addon2/t/") || filename.left(13).Compare("addon2/types/"))
8824
				found = true;
8832
				found = true;
8825
 
8833
 
8826
			if ( found ) {
8834
			if ( found ) {
8827
				if ( list )
8835
				if ( list )
8828
					list->PushBack(filename, CyString(f->lSize));
8836
					list->pushBack(filename, Utils::String::Number(f->lSize));
8829
				else
8837
				else
8830
					return true;
8838
					return true;
8831
			}
8839
			}
8832
		}
8840
		}
8833
	}
8841
	}
8834
 
8842
 
8835
	if ( list && !list->Empty() )
8843
	if ( list && !list->empty() )
8836
		return true;
8844
		return true;
8837
 
8845
 
8838
	return false;
8846
	return false;
8839
}
8847
}
8840
 
8848
 
Line 8849... Line 8857...
8849
{
8857
{
8850
	// not a valid file
8858
	// not a valid file
8851
	if ( !from || !to ) return false;
8859
	if ( !from || !to ) return false;
8852
	if ( from->GetFileType() != FILETYPE_MOD ) return false;
8860
	if ( from->GetFileType() != FILETYPE_MOD ) return false;
8853
	if ( to->GetFileType() != FILETYPE_MOD ) return false;
8861
	if ( to->GetFileType() != FILETYPE_MOD ) return false;
8854
	if ( !from->GetFileExt().Compare("cat") ) return false;
8862
	if (!from->fileExt().Compare("cat")) return false;
8855
	if ( !to->GetFileExt().Compare("cat") ) return false;
8863
	if (!to->fileExt().Compare("cat")) return false;
8856
 
8864
 
8857
	// get file lists from each file
8865
	// get file lists from each file
8858
	CyStringList fromList;
8866
	Utils::CStringList fromList;
8859
	if ( GetModCompatabilityList(from, &fromList) )
8867
	if (getModCompatabilityList(from, &fromList))
8860
	{
8868
	{
8861
		CyStringList toList;
8869
		Utils::CStringList toList;
8862
		if ( GetModCompatabilityList(to, &toList) )
8870
		if (getModCompatabilityList(to, &toList))
8863
		{
8871
		{
8864
			// both have files we need to check, compare them
8872
			// both have files we need to check, compare them
8865
			for ( SStringList *str = fromList.Head(); str; str = str->;next )
8873
			for(auto itr = fromList.begin(); itr != fromList.end(); itr++)
8866
			{
8874
			{
8867
				CyString fromFile = str->str;
8875
				Utils::String fromFile = (*itr)->str;
8868
				fromFile = fromFile.FindReplace("\\", "/");
8876
				fromFile = fromFile.findReplace("\\", "/");
8869
				fromFile = fromFile.FindReplace("//", "/");
8877
				fromFile = fromFile.findReplace("//", "/");
8870
				for ( SStringList *toStr = toList.Head(); toStr; toStr = toStr->next )
8878
				for (auto toItr = toList.begin(); itr != toList.end(); itr++)
8871
				{
8879
				{
8872
					CyString toFile = toStr->str;
8880
					Utils::String toFile = (*toItr)->str;
8873
					toFile = toFile.FindReplace("\\", "/");
8881
					toFile = toFile.findReplace("\\", "/");
8874
					toFile = toFile.FindReplace("//", "/");
8882
					toFile = toFile.findReplace("//", "/");
8875
					if ( fromFile.Compare(toFile) )
8883
					if ( fromFile.Compare(toFile) )
8876
					{
8884
					{
8877
						if ( list )
8885
						if ( list )
8878
							list->PushBack(CyString((from->filename() + "::" + str->;str.ToString(), to->filename() + "::" + toStr->str.ToString())).c_str());
8886
							list->PushBack(CyString((from->filename() + "::" + (*itr)->;str, to->filename() + "::" + (*itr)->str)).c_str());
8879
						else
8887
						else
8880
							return true;
8888
							return true;
8881
					}
8889
					}
8882
				}
8890
				}
8883
			}
8891
			}
Line 8901... Line 8909...
8901
 
8909
 
8902
	int count = 0;
8910
	int count = 0;
8903
	for ( C_File *f = from->GetFirstFile(FILETYPE_MOD); f; f = from->GetNextFile(f) )
8911
	for ( C_File *f = from->GetFirstFile(FILETYPE_MOD); f; f = from->GetNextFile(f) )
8904
	{
8912
	{
8905
		if ( !f->IsFakePatch() ) continue;
8913
		if ( !f->IsFakePatch() ) continue;
8906
		if ( f->GetFileExt().Compare("dat") ) continue;
8914
		if ( f->fileExt().Compare("dat") ) continue;
8907
 
8915
 
8908
		for ( C_File *compareFile = to->GetFirstFile(FILETYPE_MOD); compareFile; compareFile = to->GetNextFile(compareFile) )
8916
		for ( C_File *compareFile = to->GetFirstFile(FILETYPE_MOD); compareFile; compareFile = to->GetNextFile(compareFile) )
8909
		{
8917
		{
8910
			if ( compareFile == f ) continue; // same file we're checking against
8918
			if ( compareFile == f ) continue; // same file we're checking against
8911
			if ( !compareFile->IsFakePatch() ) continue;
8919
			if ( !compareFile->IsFakePatch() ) continue;
8912
			if ( compareFile->GetFileExt().Compare("dat") ) continue;
8920
			if ( compareFile->fileExt().Compare("dat") ) continue;
8913
 
8921
 
8914
			// now we have to files to compare
8922
			// now we have to files to compare
8915
			if ( CheckCompatabilityBetweenModFiles(f, compareFile, list) )
8923
			if ( CheckCompatabilityBetweenModFiles(f, compareFile, list) )
8916
				++count;
8924
				++count;
8917
		}
8925
		}
Line 8932... Line 8940...
8932
	for ( CListNode<C_File> *fNode = newFile->GetFileList()->Front(); fNode; fNode = fNode->next() )
8940
	for ( CListNode<C_File> *fNode = newFile->GetFileList()->Front(); fNode; fNode = fNode->next() )
8933
	{
8941
	{
8934
		C_File *f = fNode->Data();
8942
		C_File *f = fNode->Data();
8935
		if ( f->GetFileType() != FILETYPE_MOD ) continue;
8943
		if ( f->GetFileType() != FILETYPE_MOD ) continue;
8936
		if ( !f->IsFakePatch() ) continue;
8944
		if ( !f->IsFakePatch() ) continue;
8937
		if ( !f->CheckFileExt("cat") ) continue;
8945
		if (!f->checkFileExt("cat")) continue;
8938
 
8946
 
8939
		if (newFile->extractFile(f, m_sTempDir) )
8947
		if (newFile->extractFile(f, m_sTempDir) )
8940
			f->setFullDir(m_sTempDir);
8948
			f->setFullDir(m_sTempDir);
8941
	}
8949
	}
8942
 
8950
 
Line 8961... Line 8969...
8961
	
8969
	
8962
	for ( CListNode<C_File> *fNode = newFile->GetFileList()->Front(); fNode; fNode = fNode->next() )
8970
	for ( CListNode<C_File> *fNode = newFile->GetFileList()->Front(); fNode; fNode = fNode->next() )
8963
	{
8971
	{
8964
		C_File *f = fNode->Data();
8972
		C_File *f = fNode->Data();
8965
		CFileIO::Remove(f->filePointer());
8973
		CFileIO::Remove(f->filePointer());
8966
		f->SetFullDir("");
8974
		f->setFullDir("");
8967
	}
8975
	}
8968
 
8976
 
8969
	return count;
8977
	return count;
8970
}
8978
}
8971
 
8979
 
Line 9538... Line 9546...
9538
				C_File *f = NULL;
9546
				C_File *f = NULL;
9539
 
9547
 
9540
				if ( type == FILETYPE_SCRIPT_UNINSTALL ) {
9548
				if ( type == FILETYPE_SCRIPT_UNINSTALL ) {
9541
					f = archive->addFile(CFileIO(fileName).filename(), "", FILETYPE_SCRIPT);
9549
					f = archive->addFile(CFileIO(fileName).filename(), "", FILETYPE_SCRIPT);
9542
					if ( f ) {
9550
					if ( f ) {
9543
						f->ReadFromFile(File.fullFilename());
9551
						f->readFromFile(File.fullFilename());
9544
					}
9552
					}
9545
					type = FILETYPE_UNINSTALL;
9553
					type = FILETYPE_UNINSTALL;
9546
				}
9554
				}
9547
 
9555
 
9548
				if ( type == -1 )
9556
				if ( type == -1 )
9549
					f = archive->addFile(CFileIO(fileName).filename(), CFileIO(fileName).dir(), FILETYPE_EXTRA);
9557
					f = archive->addFile(CFileIO(fileName).filename(), CFileIO(fileName).dir(), FILETYPE_EXTRA);
9550
				else
9558
				else
9551
					f = archive->addFile(CFileIO(fileName).filename(), extradir, static_cast<FileType>(type));
9559
					f = archive->addFile(CFileIO(fileName).filename(), extradir, static_cast<FileType>(type));
9552
				f->ReadFromFile(File.fullFilename());
9560
				f->readFromFile(File.fullFilename());
9553
			}
9561
			}
9554
 
9562
 
9555
			File.remove();
9563
			File.remove();
9556
		}
9564
		}
9557
	}
9565
	}