Subversion Repositories spk

Rev

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

Rev 155 Rev 158
Line 73... Line 73...
73
	m_lDisableList.clear();
73
	m_lDisableList.clear();
74
	m_lEnableList.clear();
74
	m_lEnableList.clear();
75
	this->Reset();
75
	this->Reset();
76
}
76
}
77
 
77
 
78
void CPackages::SetCurrentDir(CyString dir)
78
void CPackages::setCurrentDir(const Utils::String &dir)
79
{ 
79
{ 
80
	m_sCurrentDir = dir; 
80
	m_sCurrentDir = dir;
81
	if (_pCurrentDir) delete _pCurrentDir;
81
	if (_pCurrentDir) delete _pCurrentDir;
82
	_pCurrentDir = new GameDirectory();
82
	_pCurrentDir = new GameDirectory();
83
	_pCurrentDir->dir = dir.ToString();
83
	_pCurrentDir->dir = dir;
84
	_pCurrentDir->id = -1;
84
	_pCurrentDir->id = -1;
85
 
85
 
86
	m_gameExe.GetDirectoryData(_pCurrentDir);
86
	m_gameExe.GetDirectoryData(_pCurrentDir);
87
	_pCurrentDir->langid = this->GetGameLanguage(_pCurrentDir->dir);
87
	_pCurrentDir->langid = this->GetGameLanguage(_pCurrentDir->dir);
88
	if (_pCurrentDir->langid > 0)
88
	if (_pCurrentDir->langid > 0)
Line 201... Line 201...
201
			if ( f->IsFakePatch() ) continue;
201
			if ( f->IsFakePatch() ) continue;
202
			if ( f->CheckFileExt("cat") ) break;
202
			if ( f->CheckFileExt("cat") ) break;
203
		}
203
		}
204
 
204
 
205
		if ( f )
205
		if ( f )
206
			m_pGameVFS.LoadFilesystem(m_sCurrentDir.ToString(), f->filePointer(), 0);
206
			m_pGameVFS.LoadFilesystem(m_sCurrentDir, f->filePointer(), 0);
207
		else
207
		else
208
			m_pGameVFS.LoadFilesystem(m_sCurrentDir.ToString(), 0);
208
			m_pGameVFS.LoadFilesystem(m_sCurrentDir, 0);
209
	}
209
	}
210
	else
210
	else
211
		m_pGameVFS.LoadFilesystem(m_sCurrentDir.ToString(), 0);
211
		m_pGameVFS.LoadFilesystem(m_sCurrentDir, 0);
212
}
212
}
213
 
213
 
214
bool CPackages::isOldDir(const Utils::String &dir)
214
bool CPackages::isOldDir(const Utils::String &dir)
215
{
215
{
216
	bool oldPlugin = false;
216
	bool oldPlugin = false;
Line 228... Line 228...
228
				if ( cmd.Compare("<script>") || cmd.Compare("</scripts>") )
228
				if ( cmd.Compare("<script>") || cmd.Compare("</scripts>") )
229
					break;
229
					break;
230
				else if ( cmd.Compare("spkinstaller") || cmd.Compare("globalfiles") )
230
				else if ( cmd.Compare("spkinstaller") || cmd.Compare("globalfiles") )
231
					break;
231
					break;
232
				else if ( cmd.Compare("pluginmanager") )
232
				else if ( cmd.Compare("pluginmanager") )
233
				{
233
				{
234
					oldPlugin = true;
234
					oldPlugin = true;
235
					break;
235
					break;
236
				}
236
				}
237
			}
237
			}
238
 
238
 
Line 241... Line 241...
241
	}
241
	}
242
 
242
 
243
	return oldPlugin;
243
	return oldPlugin;
244
}
244
}
245
 
245
 
246
bool CPackages::read(const Utils::String &dir, CProgressInfo *progress)
246
bool CPackages::Read(CyString dir, CProgressInfo* progress)
247
{
247
{
248
	return Read(CyString(dir), progress);
248
	return read(dir.ToString(), progress);
249
}
249
}
250
 
250
 
251
bool CPackages::Read(CyString dir, CProgressInfo *progress)
251
bool CPackages::read(const Utils::String& dir, CProgressInfo* progress)
252
{
252
{
253
	m_sCurrentDir = dir;
253
	m_sCurrentDir = dir;
254
	m_sCurrentDir = m_sCurrentDir.FindReplace("\\", "/");
254
	m_sCurrentDir = m_sCurrentDir.findReplace("\\", "/");
255
	this->SetCurrentDir(dir);
255
	this->setCurrentDir(dir);
256
	m_bOldPlugin = false;
256
	m_bOldPlugin = false;
257
	m_lCreatedFiles.Clear();
257
	m_lCreatedFiles.Clear();
258
	m_bRemoveDir = false;
258
	m_bRemoveDir = false;
259
	m_bSurpressProtectedWarning = false;
259
	m_bSurpressProtectedWarning = false;
260
	m_iSaveGame = -1;
260
	m_iSaveGame = -1;
Line 262... Line 262...
262
	m_lNonRemovedFiles.Clear();
262
	m_lNonRemovedFiles.Clear();
263
	m_lGlobals.Clear();
263
	m_lGlobals.Clear();
264
	m_lFakePatchOrder.Clear();
264
	m_lFakePatchOrder.Clear();
265
 
265
 
266
	if ( _pOriginalFiles ) delete _pOriginalFiles;
266
	if ( _pOriginalFiles ) delete _pOriginalFiles;
267
	_pOriginalFiles = new COriginalFiles(m_sCurrentDir.ToString());
267
	_pOriginalFiles = new COriginalFiles(m_sCurrentDir);
268
 
268
 
269
	m_bVanilla = true;
269
	m_bVanilla = true;
270
 
270
 
271
	// check the pluginmanager data file exists
271
	// check the pluginmanager data file exists
272
	CFileIO datFile(m_sCurrentDir + "/PluginManager/pluginmanager.dat");
272
	CFileIO datFile(m_sCurrentDir + "/PluginManager/pluginmanager.dat");
Line 292... Line 292...
292
 
292
 
293
				Utils::String cmd = line.token(":", 1).lower();
293
				Utils::String cmd = line.token(":", 1).lower();
294
				Utils::String rest = line.tokens(":", 2).removeFirstSpace();
294
				Utils::String rest = line.tokens(":", 2).removeFirstSpace();
295
 
295
 
296
				if ( iStatus == READ_GLOBAL )
296
				if ( iStatus == READ_GLOBAL )
297
				{
297
				{
298
					if ( cmd == "<script>" )
298
					if ( cmd == "<script>" )
299
					{
299
					{
300
						packageFile = new CSpkFile();
300
						packageFile = new CSpkFile();
301
						iStatus = READ_SCRIPT;
301
						iStatus = READ_SCRIPT;
302
					}
302
					}
303
					else if ( cmd == "<ship>" )
303
					else if ( cmd == "<ship>" )
304
					{
304
					{
305
						packageFile = new CXspFile();
305
						packageFile = new CXspFile();
306
						iStatus = READ_SCRIPT;
306
						iStatus = READ_SCRIPT;
307
					}
307
					}
308
					else if ( cmd == "<base>" )
308
					else if ( cmd == "<base>" )
309
					{
309
					{
310
						packageFile = new CBaseFile();
310
						packageFile = new CBaseFile();
311
						iStatus = READ_SCRIPT;
311
						iStatus = READ_SCRIPT;
312
					}
312
					}
313
					else if ( cmd == "<archive>" )
313
					else if ( cmd == "<archive>" )
314
					{
314
					{
315
						packageFile = new CArchiveFile();
315
						packageFile = new CArchiveFile();
316
						iStatus = READ_SCRIPT;
316
						iStatus = READ_SCRIPT;
317
					}
317
					}
318
					else if ( cmd != "</scripts>" )
318
					else if ( cmd != "</scripts>" )
Line 335... Line 335...
335
						{
335
						{
336
							origName = fileName.token("O#", 2);
336
							origName = fileName.token("O#", 2);
337
							fileName = fileName.token("O#", 1);
337
							fileName = fileName.token("O#", 1);
338
						}
338
						}
339
 
339
 
340
						C_File *newFile = new C_File(m_sCurrentDir.ToString() + fileName);
340
						C_File *newFile = new C_File(m_sCurrentDir + fileName);
341
						newFile->setGame(game);
341
						newFile->setGame(game);
342
						newFile->SetOriginalName(origName);
342
						newFile->SetOriginalName(origName);
343
						newFile->SetDisabled(disabled);
343
						newFile->SetDisabled(disabled);
344
						newFile->setFileType((FileType)line.token(":", 1).toLong());
344
						newFile->setFileType((FileType)line.token(":", 1).toLong());
345
						newFile->SetCreationTime((time_t)line.token(":", 2).toLong());
345
						newFile->SetCreationTime((time_t)line.token(":", 2).toLong());
Line 347... Line 347...
347
						if ( line.token(":", 4).toLong() )
347
						if ( line.token(":", 4).toLong() )
348
							newFile->SetShared(true);
348
							newFile->SetShared(true);
349
						newFile->UpdateSigned();
349
						newFile->UpdateSigned();
350
 
350
 
351
						m_lFiles.push_back(newFile);
351
						m_lFiles.push_back(newFile);
352
					}
352
					}
353
				}
353
				}
354
				else if ( iStatus == READ_SCRIPT )
354
				else if ( iStatus == READ_SCRIPT )
355
				{
355
				{
356
					if ( cmd == "installspk" )
356
					if ( cmd == "installspk" )
357
						packageFile->setFilename(rest);
357
						packageFile->setFilename(rest);
Line 384... Line 384...
384
					}
384
					}
385
					else
385
					else
386
						packageFile->ParseValueLine(line);
386
						packageFile->ParseValueLine(line);
387
				}
387
				}
388
				else if ( iStatus == READ_SCRIPTFILE )
388
				else if ( iStatus == READ_SCRIPTFILE )
389
				{
389
				{
390
					if ( cmd == "<script>" )
390
					if ( cmd == "<script>" )
391
					{
391
					{
392
						if ( packageFile->IsMod() && packageFile->IsEnabled() )
392
						if ( packageFile->IsMod() && packageFile->IsEnabled() )
393
							m_pEnabledMod = packageFile;
393
							m_pEnabledMod = packageFile;
394
 
394
 
Line 571... Line 571...
571
	}
571
	}
572
 
572
 
573
	if ( m_pEnabledMod && !m_pEnabledMod->IsEnabled() )
573
	if ( m_pEnabledMod && !m_pEnabledMod->IsEnabled() )
574
		m_pEnabledMod = NULL;
574
		m_pEnabledMod = NULL;
575
 
575
 
576
	m_iGame = m_gameExe.GetGameType(m_sCurrentDir.ToString()) + 1;
576
	m_iGame = m_gameExe.GetGameType(m_sCurrentDir) + 1;
577
	m_pCurrentGameExe = m_gameExe.GetGame(m_gameExe.GetGameType(m_sCurrentDir.ToString()));
577
	m_pCurrentGameExe = m_gameExe.GetGame(m_gameExe.GetGameType(m_sCurrentDir));
578
	Utils::String sGameVersion;
578
	Utils::String sGameVersion;
579
	m_iGameVersion = m_gameExe.GetGameVersion(m_sCurrentDir.ToString(), &sGameVersion) + 1;
579
	m_iGameVersion = m_gameExe.GetGameVersion(m_sCurrentDir, &sGameVersion) + 1;
580
	m_sGameVersion = sGameVersion;
580
	m_sGameVersion = sGameVersion;
581
	m_iGameFlags = m_gameExe.GetGameFlags(m_iGame - 1);
581
	m_iGameFlags = m_gameExe.GetGameFlags(m_iGame - 1);
582
	m_iMaxPatch = m_gameExe.GetMaxPatch(m_iGame - 1);
582
	m_iMaxPatch = m_gameExe.GetMaxPatch(m_iGame - 1);
583
 
583
 
584
	// find the fake patch
584
	// find the fake patch
Line 611... Line 611...
611
		{
611
		{
612
			CXspFile *p = (CXspFile *)node->Data();
612
			CXspFile *p = (CXspFile *)node->Data();
613
			for ( CListNode<SGameShip> *gNode = m_lGameShips.Front(); gNode; gNode = gNode->next() )
613
			for ( CListNode<SGameShip> *gNode = m_lGameShips.Front(); gNode; gNode = gNode->next() )
614
			{
614
			{
615
				if ( p->GetShipID().Compare(gNode->Data()->sShipID.ToString()) )
615
				if ( p->GetShipID().Compare(gNode->Data()->sShipID.ToString()) )
616
				{
616
				{
617
					gNode->Data()->pPackage = p;
617
					gNode->Data()->pPackage = p;
618
					break;
618
					break;
619
				}
619
				}
620
			}
620
			}
621
		}
621
		}
622
	}
622
	}
623
 
623
 
624
	// check the purged time
624
	// check the purged time
625
	this->PurgeGameObjects();
625
	this->PurgeGameObjects();
626
 
626
 
627
	m_bLoaded = true;
627
	m_bLoaded = true;
628
 
628
 
629
	return true;
629
	return true;
630
}
630
}
631
 
631
 
632
void CPackages::RemoveCreatedFiles()
632
void CPackages::RemoveCreatedFiles()
633
{
633
{
634
	for ( SStringList *node = m_lCreatedFiles.Head(); node; node = node->next )
634
	for ( SStringList *node = m_lCreatedFiles.Head(); node; node = node->next )
635
	{
635
	{
636
		if ( CFileIO(node->str).ExistsOld() )
636
		if ( CFileIO(node->str).ExistsOld() )
637
			CFileIO::Remove(node->str.ToString());
637
			CFileIO::Remove(node->str.ToString());
638
		else if ( CFileIO(m_sCurrentDir + "/" + node->str).ExistsOld() )
638
		else if ( CFileIO(m_sCurrentDir + "/" + node->str.ToString()).ExistsOld() )
639
			CFileIO::Remove((m_sCurrentDir + "/" + node->str).ToString());
639
			CFileIO::Remove(m_sCurrentDir + "/" + node->str.ToString());
640
	}
640
	}
641
 
641
 
642
	m_lCreatedFiles.Clear();
642
	m_lCreatedFiles.Clear();
643
}
643
}
644
 
644
 
645
void CPackages::PurgeGameObjects()
645
void CPackages::PurgeGameObjects()
646
{
646
{
647
	// check for the log file
647
	// check for the log file
648
	Utils::String logDir = logDirectory();
648
	Utils::String logDir = logDirectory();
649
	CFileIO LogFile(logDir + "/log0" + Utils::String::PadNumber(PMTEXTFILE, 4) + ".txt");
649
	CFileIO LogFile(logDir + "/log0" + Utils::String::PadNumber(PMTEXTFILE, 4) + ".txt");
650
	if ( LogFile.exists() )
650
	if ( LogFile.exists() )
651
	{
651
	{
652
		// read the log file to memory
652
		// read the log file to memory
653
		std::vector<CyString> *lines = LogFile.ReadLines();
653
		std::vector<CyString> *lines = LogFile.ReadLines();
654
		if ( lines )
654
		if ( lines )
655
		{
655
		{
656
			for ( int i = 0; i < (int)lines->size(); i++ )
656
			for ( int i = 0; i < (int)lines->size(); i++ )
657
			{
657
			{
658
				CyString line(lines->at(i));
658
				CyString line(lines->at(i));
659
				CyString start = line.GetToken(":", 1, 1).ToLower();
659
				CyString start = line.GetToken(":", 1, 1).ToLower();
660
				CyString rest = line.GetToken(":", 2, 2).RemoveFirstSpace();
660
				CyString rest = line.GetToken(":", 2, 2).RemoveFirstSpace();
Line 669... Line 669...
669
					}
669
					}
670
				}
670
				}
671
			}
671
			}
672
 
672
 
673
			delete lines;
673
			delete lines;
674
		}
674
		}
675
		// remove the log file
675
		// remove the log file
676
		LogFile.remove();
676
		LogFile.remove();
677
	}
677
	}
678
}
678
}
679
 
679
 
Line 688... Line 688...
688
			if ( !w ) continue;
688
			if ( !w ) continue;
689
			if ( w->iType == WARETYPE_DELETED )
689
			if ( w->iType == WARETYPE_DELETED )
690
				w->iType = WARETYPE_NONE;
690
				w->iType = WARETYPE_NONE;
691
		}
691
		}
692
		m_lGameWares[i].RemoveEmpty();
692
		m_lGameWares[i].RemoveEmpty();
693
	}
693
	}
694
}
694
}
695
 
695
 
696
void CPackages::PurgeShips()
696
void CPackages::PurgeShips()
697
{
697
{
698
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
698
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
699
	{
699
	{
Line 705... Line 705...
705
	m_lGameShips.RemoveEmpty();
705
	m_lGameShips.RemoveEmpty();
706
}
706
}
707
 
707
 
708
Utils::String CPackages::logDirectory()
708
Utils::String CPackages::logDirectory()
709
{
709
{
710
	Utils::String logDir = m_sCurrentDir.ToString();
710
	Utils::String logDir = m_sCurrentDir;
711
	if ( m_iGameFlags & EXEFLAG_MYDOCLOG ) {
711
	if ( m_iGameFlags & EXEFLAG_MYDOCLOG ) {
712
		SGameExe *exe = m_gameExe.GetGame(m_iGame - 1);
712
		SGameExe *exe = m_gameExe.GetGame(m_iGame - 1);
713
		if ( exe ) {
713
		if ( exe ) {
714
			if ( !exe->sMyDoc.empty() )
714
			if ( !exe->sMyDoc.empty() )
715
				logDir = m_sMyDoc + "/" + exe->sMyDoc;
715
				logDir = m_sMyDoc + "/" + exe->sMyDoc;
Line 719... Line 719...
719
	return logDir;
719
	return logDir;
720
}
720
}
721
 
721
 
722
Utils::String CPackages::logDirectory(const Utils::String &gameExe)
722
Utils::String CPackages::logDirectory(const Utils::String &gameExe)
723
{
723
{
724
	Utils::String logDir = m_sCurrentDir.ToString();
724
	Utils::String logDir = m_sCurrentDir;
725
	if ( m_iGameFlags & EXEFLAG_MYDOCLOG )
725
	if ( m_iGameFlags & EXEFLAG_MYDOCLOG )
726
	{
726
	{
727
		SGameExe *exe = m_gameExe.gameExe(CFileIO(gameExe).filename());
727
		SGameExe *exe = m_gameExe.gameExe(CFileIO(gameExe).filename());
728
		if ( exe )
728
		if ( exe )
729
		{
729
		{
Line 750... Line 750...
750
	if ( CFileIO(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat").ExistsOld() && CFileIO(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat").ExistsOld() )
750
	if ( CFileIO(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat").ExistsOld() && CFileIO(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat").ExistsOld() )
751
		return true;
751
		return true;
752
 
752
 
753
	// if only one of them exists, lets remove them
753
	// if only one of them exists, lets remove them
754
	if ( CFileIO(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat").ExistsOld() )
754
	if ( CFileIO(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat").ExistsOld() )
755
		CFileIO::Remove(m_sCurrentDir.ToString() + "/PluginManager/PlugMan_Fake.cat");
755
		CFileIO::Remove(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat");
756
	if ( CFileIO(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat").ExistsOld() )
756
	if ( CFileIO(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat").ExistsOld() )
757
		CFileIO::Remove(m_sCurrentDir.ToString() + "/PluginManager/PlugMan_Fake.dat");
757
		CFileIO::Remove(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat");
758
 
758
 
759
	// fake patch is not being used
759
	// fake patch is not being used
760
	if ( m_iFakePatch < 0 ) return true;
760
	if ( m_iFakePatch < 0 ) return true;
761
	// now lets find the fake patch
761
	// now lets find the fake patch
762
	CyString useFile;
762
	Utils::String useFile;
763
	if ( m_iFakePatch > 0 )
763
	if ( m_iFakePatch > 0 )
764
	{
764
	{
765
		CyString file = CyString::Number(m_iFakePatch).PadNumber(2);
765
		Utils::String file = Utils::String::PadNumber(m_iFakePatch, 2);
766
		if ( CheckValidPluginManagerFile(file) )
766
		if ( CheckValidPluginManagerFile(file) )
767
			useFile = file;
767
			useFile = file;
768
		else if ( CheckIfPluginManagerFile(file) )
768
		else if ( CheckIfPluginManagerFile(file) )
769
			useFile = file;
769
			useFile = file;
770
	}
770
	}
771
 
771
 
772
	if ( useFile.Empty() )
772
	if ( useFile.empty() )
773
	{
773
	{
774
		int nextfree = this->FindNextFakePatch();
774
		int nextfree = this->FindNextFakePatch();
775
		--nextfree; // gets the end fake patch
775
		--nextfree; // gets the end fake patch
776
 
776
 
777
		// work backwards till we find a valid one
777
		// work backwards till we find a valid one
778
		while ( nextfree > m_iMaxPatch )
778
		while ( nextfree > m_iMaxPatch )
779
		{
779
		{
780
			CyString file = CyString::Number(nextfree).PadNumber(2);
780
			Utils::String file = Utils::String::PadNumber(nextfree, 2);
781
			if ( CheckValidPluginManagerFile(file) )
781
			if ( CheckValidPluginManagerFile(file) )
782
			{
782
			{
783
				useFile = file;
783
				useFile = file;
784
				break;
784
				break;
785
			}
785
			}
Line 788... Line 788...
788
	}
788
	}
789
 
789
 
790
	CyString addonDir = this->GetAddonDir();
790
	CyString addonDir = this->GetAddonDir();
791
 
791
 
792
	// couldn't find the correct file, lets search for it
792
	// couldn't find the correct file, lets search for it
793
	if ( useFile.Empty() ) {
793
	if ( useFile.empty() ) {
794
		int nextfree = this->FindNextFakePatch();
794
		int nextfree = this->FindNextFakePatch();
795
		--nextfree; // gets the end fake patch
795
		--nextfree; // gets the end fake patch
796
 
796
 
797
		// work backwards till we find a valid one
797
		// work backwards till we find a valid one
798
		while ( nextfree > m_iMaxPatch )
798
		while ( nextfree > m_iMaxPatch )
799
		{
799
		{
800
			CyString file = CyString::Number(nextfree).PadNumber(2);
800
			Utils::String file = Utils::String::PadNumber(nextfree, 2);
801
			if ( CheckIfPluginManagerFile(file) )
801
			if ( CheckIfPluginManagerFile(file) )
802
			{
802
			{
803
				useFile = file;
803
				useFile = file;
804
				break;
804
				break;
805
			}
805
			}
806
			--nextfree;
806
			--nextfree;
807
		}		
807
		}		
808
	}
808
	}
809
 
809
 
810
	if ( !useFile.Empty() )
810
	if ( !useFile.empty() )
811
	{
811
	{
812
		// lets check whats in the file first
812
		// lets check whats in the file first
813
		CCatFile openCat;
813
		CCatFile openCat;
814
		if ( openCat.open((m_sCurrentDir + "/" + useFile + ".cat").ToString(), addonDir.ToString(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
814
		if ( openCat.open(m_sCurrentDir + "/" + useFile + ".cat", addonDir.ToString(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
815
		{
815
		{
816
			std::vector<SInCatFile *> *files = openCat.GetFiles();
816
			std::vector<SInCatFile *> *files = openCat.GetFiles();
817
			bool found = false;
817
			bool found = false;
818
			if ( files )
818
			if ( files )
819
			{
819
			{
Line 864... Line 864...
864
	// no files found, but we have a fake patch ? restore from backup
864
	// no files found, but we have a fake patch ? restore from backup
865
	else if ( m_iFakePatch > 0 ) {
865
	else if ( m_iFakePatch > 0 ) {
866
		CLog::log(CLog::Log_Directory, 1, "PlugMan FakePatch seems to be missing (" + Utils::String::Number(m_iFakePatch) + "), Restoring from backup");
866
		CLog::log(CLog::Log_Directory, 1, "PlugMan FakePatch seems to be missing (" + Utils::String::Number(m_iFakePatch) + "), Restoring from backup");
867
		CFileIO catFile(m_sCurrentDir + "/PluginManager/Backup/PlugMan_Fake.cat");
867
		CFileIO catFile(m_sCurrentDir + "/PluginManager/Backup/PlugMan_Fake.cat");
868
		if ( catFile.exists() ) {
868
		if ( catFile.exists() ) {
869
			catFile.copy(m_sCurrentDir.ToString() + "/PluginManager/PlugMan_Fake.cat");
869
			catFile.copy(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat");
870
			CFileIO datFile(m_sCurrentDir + "/PluginManager/Backup/PlugMan_Fake.dat");
870
			CFileIO datFile(m_sCurrentDir + "/PluginManager/Backup/PlugMan_Fake.dat");
871
			if ( datFile.exists() ) datFile.copy(m_sCurrentDir.ToString() + "/PluginManager/PlugMan_Fake.dat");
871
			if ( datFile.exists() ) datFile.copy(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat");
872
		}
872
		}
873
	}
873
	}
874
 
874
 
875
	// otherwise we didn't need to (hopefully)
875
	// otherwise we didn't need to (hopefully)
876
	return true;
876
	return true;
Line 879... Line 879...
879
 
879
 
880
bool CPackages::CheckIfPluginManagerFile(CyString filename)
880
bool CPackages::CheckIfPluginManagerFile(CyString filename)
881
{
881
{
882
	bool found = false;
882
	bool found = false;
883
 
883
 
884
	CFileIO catFile(m_sCurrentDir + "/" + filename + ".cat");
884
	CFileIO catFile(m_sCurrentDir + "/" + filename.ToString() + ".cat");
885
	if ( catFile.exists() && CFileIO(m_sCurrentDir + "/" + filename + ".dat").ExistsOld() )
885
	if ( catFile.exists() && CFileIO::Exists(m_sCurrentDir + "/" + filename.ToString() + ".dat"))
886
	{
886
	{
887
		CCatFile openFile;
887
		CCatFile openFile;
888
		if ( openFile.open(catFile.fullFilename(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
888
		if ( openFile.open(catFile.fullFilename(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
889
		{
889
		{
890
//			if ( openFile.internaldatFilename().Compare("PlugMan_Fake.dat") ) return true;
890
//			if ( openFile.internaldatFilename().Compare("PlugMan_Fake.dat") ) return true;
Line 914... Line 914...
914
}
914
}
915
 
915
 
916
bool CPackages::CheckValidPluginManagerFile(CyString filename)
916
bool CPackages::CheckValidPluginManagerFile(CyString filename)
917
{
917
{
918
	// both the cat file and dat file exists, lets open it
918
	// both the cat file and dat file exists, lets open it
919
	CFileIO catFile(m_sCurrentDir + "/" + filename + ".cat");
919
	CFileIO catFile(m_sCurrentDir + "/" + filename.ToString() + ".cat");
920
	if ( catFile.exists() && CFileIO(m_sCurrentDir + "/" + filename + ".dat").ExistsOld() )
920
	if ( catFile.exists() && CFileIO::Exists(m_sCurrentDir + "/" + filename.ToString() + ".dat"))
921
	{
921
	{
922
		CCatFile openFile;
922
		CCatFile openFile;
923
		if ( openFile.open(catFile.fullFilename(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
923
		if ( openFile.open(catFile.fullFilename(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
924
		{
924
		{
925
			if ( openFile.FindData("PlugMan\\TFake.pck") )
925
			if ( openFile.FindData("PlugMan\\TFake.pck") )
Line 1334... Line 1334...
1334
			if ( !checkFile ) continue;
1334
			if ( !checkFile ) continue;
1335
 
1335
 
1336
			if ( checkFile->GetFileType() != FILETYPE_UNINSTALL && checkFile->GetFileType() != FILETYPE_SCRIPT )
1336
			if ( checkFile->GetFileType() != FILETYPE_UNINSTALL && checkFile->GetFileType() != FILETYPE_SCRIPT )
1337
				continue;
1337
				continue;
1338
 
1338
 
1339
			if ( uf->GetFilename().Compare(checkFile->GetFilename()) )
1339
			if ( uf->filename().Compare(checkFile->filename()) )
1340
			{
1340
			{
1341
				if ( RemoveUninstallFile(uf, errors) )
1341
				if ( RemoveUninstallFile(uf, errors) )
1342
					fNode->DeleteData();
1342
					fNode->DeleteData();
1343
				break;
1343
				break;
1344
			}
1344
			}
Line 1379... Line 1379...
1379
}
1379
}
1380
 
1380
 
1381
void CPackages::_addToFakePatch(CBaseFile *pPackage)
1381
void CPackages::_addToFakePatch(CBaseFile *pPackage)
1382
{
1382
{
1383
	CCatFile cat;
1383
	CCatFile cat;
1384
	if ( CCatFile::Opened(cat.open((m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat").ToString(), this->getAddonDir(), CATREAD_DAT)) ) {
1384
	if ( CCatFile::Opened(cat.open(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat", this->getAddonDir(), CATREAD_DAT)) ) {
1385
		for ( CListNode<C_File> *f = pPackage->GetFileList()->Front(); f; f = f->next() ) {
1385
		for ( CListNode<C_File> *f = pPackage->GetFileList()->Front(); f; f = f->next() ) {
1386
			if ( f->Data()->GetFileType() != FILETYPE_SHIPSCENE && f->Data()->GetFileType() != FILETYPE_COCKPITSCENE && f->Data()->GetFileType() != FILETYPE_SHIPMODEL && f->Data()->GetFileType() != FILETYPE_SHIPOTHER ) {
1386
			if ( f->Data()->GetFileType() != FILETYPE_SHIPSCENE && f->Data()->GetFileType() != FILETYPE_COCKPITSCENE && f->Data()->GetFileType() != FILETYPE_SHIPMODEL && f->Data()->GetFileType() != FILETYPE_SHIPOTHER ) {
1387
				continue;
1387
				continue;
1388
			}
1388
			}
1389
			if ( CCatFile::IsAddonDir(f->Data()->GetNameDirectory(pPackage).ToString()) ) {
1389
			if ( CCatFile::IsAddonDir(f->Data()->GetNameDirectory(pPackage).ToString()) ) {
Line 1395... Line 1395...
1395
			}
1395
			}
1396
			Utils::String toFile;
1396
			Utils::String toFile;
1397
			if ( cat.AppendFile(f->Data()->filePointer(), f->Data()->GetNameDirectory(pPackage).ToString(), true, (m_iGameFlags & EXEFLAG_NOXOR) ? false : true, &toFile) ) {
1397
			if ( cat.AppendFile(f->Data()->filePointer(), f->Data()->GetNameDirectory(pPackage).ToString(), true, (m_iGameFlags & EXEFLAG_NOXOR) ? false : true, &toFile) ) {
1398
				CLog::logf(CLog::Log_Install, 2, "Adding file: %s into the fake patch", f->Data()->GetNameDirectory(pPackage).c_str());
1398
				CLog::logf(CLog::Log_Install, 2, "Adding file: %s into the fake patch", f->Data()->GetNameDirectory(pPackage).c_str());
1399
				CFileIO::Remove(f->Data()->filePointer());
1399
				CFileIO::Remove(f->Data()->filePointer());
1400
				f->Data()->SetFilename(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat::" + toFile);
1400
				f->Data()->setFilename(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat::" + toFile);
1401
			}
1401
			}
1402
		}
1402
		}
1403
	}
1403
	}
1404
}
1404
}
1405
 
1405
 
Line 1604... Line 1604...
1604
				{
1604
				{
1605
					if ( f->Data()->GetBaseName().Left(5).Compare("fake_") )
1605
					if ( f->Data()->GetBaseName().Left(5).Compare("fake_") )
1606
					{
1606
					{
1607
						shuffle = true;
1607
						shuffle = true;
1608
						C_File *match = package->FindMatchingMod(f->Data());
1608
						C_File *match = package->FindMatchingMod(f->Data());
1609
						CyString next = CyString::Number(this->FindNextFakePatch()).PadNumber(2);
1609
						Utils::String next = Utils::String::PadNumber(this->FindNextFakePatch(), 2);
1610
						
1610
						
1611
						CyString oldFilePointer = f->Data()->GetFilePointer();
1611
						CyString oldFilePointer = f->Data()->GetFilePointer();
1612
						f->Data()->SetDir("");
1612
						f->Data()->setDir("");
1613
						f->Data()->ChangeBaseName(next);
1613
						f->Data()->changeBaseName(next);
1614
						if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + "/" + f->Data()->GetNameDirectory(package)) )
1614
						if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package)) )
1615
							f->Data()->SetFilename(m_sCurrentDir + "/" + f->Data()->GetNameDirectory(package));
1615
							f->Data()->setFilename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package));
1616
 
1616
 
1617
						if ( match )
1617
						if ( match )
1618
						{
1618
						{
1619
							CyString oldFilePointer = match->GetFilePointer();
1619
							Utils::String oldFilePointer = match->filePointer();
1620
							match->SetDir("");
1620
							match->setDir("");
1621
							match->ChangeBaseName(next);
1621
							match->changeBaseName(next);
1622
							if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + "/" + match->GetNameDirectory(package)) )
1622
							if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + "/" + match->getNameDirectory(package)) )
1623
								match->SetFilename(m_sCurrentDir + "/" + match->GetNameDirectory(package));
1623
								match->setFilename(m_sCurrentDir + "/" + match->getNameDirectory(package));
1624
						}
1624
						}
1625
					}
1625
					}
1626
					else
1626
					else
1627
					{
1627
					{
1628
						C_File *match = package->FindMatchingMod(f->Data());
1628
						C_File *match = package->FindMatchingMod(f->Data());
1629
 
1629
 
1630
						f->Data()->SetDir("");
1630
						f->Data()->setDir("");
1631
						if ( CFileIO(f->Data()->GetFilePointer()).Rename(m_sCurrentDir + "/" + f->Data()->GetNameDirectory(package)) )
1631
						if ( CFileIO(f->Data()->GetFilePointer()).Rename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package)) )
1632
							f->Data()->SetFilename(m_sCurrentDir + "/" + f->Data()->GetNameDirectory(package));
1632
							f->Data()->setFilename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package));
1633
						if ( match )
1633
						if ( match )
1634
						{
1634
						{
1635
							match->SetDir("");
1635
							match->setDir("");
1636
							if ( CFileIO(match->GetFilePointer()).Rename(m_sCurrentDir + "/" + match->GetNameDirectory(package)) )
1636
							if ( CFileIO(match->filePointer()).Rename(m_sCurrentDir + "/" + match->getNameDirectory(package)) )
1637
								match->SetFilename(m_sCurrentDir + "/" + match->GetNameDirectory(package));
1637
								match->setFilename(m_sCurrentDir + "/" + match->getNameDirectory(package));
1638
						}
1638
						}
1639
					}
1639
					}
1640
				}
1640
				}
1641
			}
1641
			}
1642
 
1642
 
Line 1680... Line 1680...
1680
			{
1680
			{
1681
				if ( !icon->UncompressData() )
1681
				if ( !icon->UncompressData() )
1682
					package->SetIcon(NULL, "");
1682
					package->SetIcon(NULL, "");
1683
				else
1683
				else
1684
				{
1684
				{
1685
					CFileIO iconFile(m_sCurrentDir + "/PluginManager/Icons/" + package->author() + "_" + package->name() + "." + package->GetIconExt());
1685
					CFileIO iconFile(m_sCurrentDir + "/PluginManager/Icons/" + package->author() + "_" + package->name() + "." + package->iconExt());
1686
					if ( iconFile.WriteData((const char *)icon->GetData(), icon->GetDataSize()) )
1686
					if ( iconFile.WriteData((const char *)icon->GetData(), icon->GetDataSize()) )
1687
					{
1687
					{
1688
						icon->SetFilename(CyString(package->author()) + "_" + package->name() + "." + package->GetIconExt());
1688
						icon->SetFilename(CyString(package->author()) + "_" + package->name() + "." + package->iconExt());
1689
						icon->SetFullDir(m_sCurrentDir + "/PluginManager/Icons");
1689
						icon->SetFullDir(m_sCurrentDir + "/PluginManager/Icons");
1690
					}
1690
					}
1691
					else
1691
					else
1692
						package->SetIcon(NULL, "");
1692
						package->SetIcon(NULL, "");
1693
				}
1693
				}
Line 1745... Line 1745...
1745
				m_lFiles.remove(f, false);
1745
				m_lFiles.remove(f, false);
1746
 
1746
 
1747
				// if its a readme file, then check if its in the new package
1747
				// if its a readme file, then check if its in the new package
1748
				bool dontRemove = false;
1748
				bool dontRemove = false;
1749
				if ( f->GetFileType() == FILETYPE_README ) {
1749
				if ( f->GetFileType() == FILETYPE_README ) {
1750
					if ( package->FindFile(f->GetFilename(), FILETYPE_README) )
1750
					if ( package->FindFile(f->filename(), FILETYPE_README) )
1751
						dontRemove = true;
1751
						dontRemove = true;
1752
				}
1752
				}
1753
 
1753
 
1754
				// remove from hard drive
1754
				// remove from hard drive
1755
				if ( !dontRemove && RemoveFile(f, errors) )
1755
				if ( !dontRemove && RemoveFile(f, errors) )
Line 1938... Line 1938...
1938
 
1938
 
1939
		for ( C_File *uf = uninstallFiles.First(); uf; uf = uninstallFiles.Next() )
1939
		for ( C_File *uf = uninstallFiles.First(); uf; uf = uninstallFiles.Next() )
1940
		{
1940
		{
1941
			C_File *newFile = new C_File();
1941
			C_File *newFile = new C_File();
1942
			newFile->SetFileType(FILETYPE_SCRIPT);
1942
			newFile->SetFileType(FILETYPE_SCRIPT);
1943
			newFile->SetFilename(uf->GetFilename());
1943
			newFile->setFilename(uf->filename());
1944
			newFile->SetCreationTime(uf->GetCreationTime());
1944
			newFile->SetCreationTime(uf->GetCreationTime());
1945
 
1945
 
1946
			// other installed packages use this file as well, copy it
1946
			// other installed packages use this file as well, copy it
1947
			CyString newFilename = m_sCurrentDir + "/" + newFile->GetNameDirectory(NULL);
1947
			Utils::String newFilename = m_sCurrentDir + "/" + newFile->getNameDirectory(NULL);
1948
			CFileIO file(uf->GetFilePointer());
1948
			CFileIO file(uf->filePointer());
1949
 
1949
 
1950
			if ( uf->GetUsed() )
1950
			if ( uf->GetUsed() )
1951
			{
1951
			{
1952
				if ( file.copy(newFilename.ToString()) )
1952
				if ( file.copy(newFilename) )
1953
					this->AddLogEntry(SPKINSTALL_UNINSTALL_COPY, newFile->GetNameDirectory(NULL), errors);
1953
					this->AddLogEntry(SPKINSTALL_UNINSTALL_COPY, newFile->getNameDirectory(NULL), errors);
1954
				else
1954
				else
1955
				{
1955
				{
1956
					this->AddLogEntry(SPKINSTALL_UNINSTALL_COPY_FAIL, newFile->GetNameDirectory(NULL), errors);
1956
					this->AddLogEntry(SPKINSTALL_UNINSTALL_COPY_FAIL, newFile->getNameDirectory(NULL), errors);
1957
					delete newFile;
1957
					delete newFile;
1958
					newFile = NULL;
1958
					newFile = NULL;
1959
				}
1959
				}
1960
			}
1960
			}
1961
			// otherwise just move it
1961
			// otherwise just move it
1962
			else
1962
			else
1963
			{
1963
			{
1964
				if ( file.Rename(newFilename) )
1964
				if ( file.Rename(newFilename) )
1965
					this->AddLogEntry(SPKINSTALL_UNINSTALL_MOVE, newFile->GetNameDirectory(NULL), errors);
1965
					this->AddLogEntry(SPKINSTALL_UNINSTALL_MOVE, newFile->getNameDirectory(NULL), errors);
1966
				else
1966
				else
1967
				{
1967
				{
1968
					this->AddLogEntry(SPKINSTALL_UNINSTALL_MOVE_FAIL, newFile->GetNameDirectory(NULL), errors);
1968
					this->AddLogEntry(SPKINSTALL_UNINSTALL_MOVE_FAIL, newFile->getNameDirectory(NULL), errors);
1969
					delete newFile;
1969
					delete newFile;
1970
					newFile = NULL;
1970
					newFile = NULL;
1971
				}
1971
				}
1972
 
1972
 
1973
				m_lFiles.remove(uf, false);
1973
				m_lFiles.remove(uf, false);
Line 1980... Line 1980...
1980
				// first check if theres a matching one
1980
				// first check if theres a matching one
1981
				bool found = false;
1981
				bool found = false;
1982
				for ( CListNode<C_File> *node = m_lUninstallFiles.Front(); node; node = node->next() )
1982
				for ( CListNode<C_File> *node = m_lUninstallFiles.Front(); node; node = node->next() )
1983
				{
1983
				{
1984
					C_File *checkFile = node->Data();
1984
					C_File *checkFile = node->Data();
1985
					if ( checkFile->GetFilename().Compare(newFile->GetFilename()) )
1985
					if ( checkFile->filename().Compare(newFile->filename()) )
1986
					{
1986
					{
1987
						found = true;
1987
						found = true;
1988
						break;
1988
						break;
1989
					}
1989
					}
1990
				}
1990
				}
Line 2447... Line 2447...
2447
 *
2447
 *
2448
 * When existing, program needs to close the directory
2448
 * When existing, program needs to close the directory
2449
 */
2449
 */
2450
bool CPackages::CloseDir ( CyStringList *errors, CProgressInfo *progress, bool removedir )
2450
bool CPackages::CloseDir ( CyStringList *errors, CProgressInfo *progress, bool removedir )
2451
{
2451
{
2452
	if ( m_sCurrentDir.Empty() )
2452
	if ( m_sCurrentDir.empty() )
2453
		return true;
2453
		return true;
2454
	if ( !m_bLoaded )
2454
	if ( !m_bLoaded )
2455
		return true;
2455
		return true;
2456
 
2456
 
2457
	CLog::log(CLog::Log_Directory, 1, "closing directory: " + m_sCurrentDir.ToString());
2457
	CLog::log(CLog::Log_Directory, 1, "closing directory: " + m_sCurrentDir);
2458
 
2458
 
2459
	if ( m_bRenameText ) {
2459
	if ( m_bRenameText ) {
2460
		CLog::log(CLog::Log_Directory, 2, "Creating other language files for game");
2460
		CLog::log(CLog::Log_Directory, 2, "Creating other language files for game");
2461
		CreateLanguageTextFiles(errors);
2461
		CreateLanguageTextFiles(errors);
2462
	}
2462
	}
2463
 
2463
 
2464
	CLog::log(CLog::Log_Directory, 2, "Backing up save game files");
2464
	CLog::log(CLog::Log_Directory, 2, "Backing up save game files");
2465
 
2465
 
2466
	if ( CFileIO(m_sCurrentDir + "/mods/PluginManager.dat").ExistsOld() ) {
2466
	if ( CFileIO(m_sCurrentDir + "/mods/PluginManager.dat").ExistsOld() ) {
2467
		CLog::log(CLog::Log_IO, 3, "Removing old PluginManager.dat file");
2467
		CLog::log(CLog::Log_IO, 3, "Removing old PluginManager.dat file");
2468
		CFileIO::Remove(m_sCurrentDir.ToString() + "/mods/PluginManager.dat");
2468
		CFileIO::Remove(m_sCurrentDir + "/mods/PluginManager.dat");
2469
	}
2469
	}
2470
	if ( CFileIO(m_sCurrentDir + "/mods/PluginManager.cat").ExistsOld() ) {
2470
	if ( CFileIO(m_sCurrentDir + "/mods/PluginManager.cat").ExistsOld() ) {
2471
		CLog::log(CLog::Log_IO, 3, "Removing old PluginManager.cat file");
2471
		CLog::log(CLog::Log_IO, 3, "Removing old PluginManager.cat file");
2472
		CFileIO::Remove(m_sCurrentDir.ToString() + "/mods/PluginManager.cat");
2472
		CFileIO::Remove(m_sCurrentDir + "/mods/PluginManager.cat");
2473
	}
2473
	}
2474
 
2474
 
2475
	if ( !m_bVanilla )
2475
	if ( !m_bVanilla )
2476
	{
2476
	{
2477
		// base mode for Reunion
2477
		// base mode for Reunion
Line 2487... Line 2487...
2487
				while ( fCat && !fCat->IsFakePatch() && !fCat->CheckFileExt("cat") && !fCat->GetBaseName().Compare(fDat->GetBaseName()) )
2487
				while ( fCat && !fCat->IsFakePatch() && !fCat->CheckFileExt("cat") && !fCat->GetBaseName().Compare(fDat->GetBaseName()) )
2488
					fCat = m_pEnabledMod->GetNextFile(fCat);
2488
					fCat = m_pEnabledMod->GetNextFile(fCat);
2489
 
2489
 
2490
				if ( fCat )
2490
				if ( fCat )
2491
				{
2491
				{
2492
					CFileIO(fDat->GetFilePointer()).copy(m_sCurrentDir.ToString() + "/mods/PluginManager.dat");
2492
					CFileIO(fDat->GetFilePointer()).copy(m_sCurrentDir + "/mods/PluginManager.dat");
2493
					CFileIO(fCat->GetFilePointer()).copy(m_sCurrentDir.ToString() + "/mods/PluginManager.cat");
2493
					CFileIO(fCat->GetFilePointer()).copy(m_sCurrentDir + "/mods/PluginManager.cat");
2494
				}
2494
				}
2495
			}
2495
			}
2496
		}
2496
		}
2497
		else if ( m_iGame == GAME_X3 && !m_sSetMod.Empty() && CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat").ExistsOld() && CFileIO(m_sCurrentDir + "/mods/"; + m_sSetMod + ".dat").ExistsOld() )
2497
		else if ( m_iGame == GAME_X3 && !m_sSetMod.Empty() && CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod.ToString() + ".cat").ExistsOld() && CFileIO(m_sCurrentDir + "/mods/"; + m_sSetMod.ToString() + ".dat").ExistsOld())
2498
		{
2498
		{
2499
			CLog::log(CLog::Log_Directory, 2, "Copying mod file: " + m_sSetMod.ToString() + ", to PluginManager.cat");
2499
			CLog::log(CLog::Log_Directory, 2, "Copying mod file: " + m_sSetMod.ToString() + ", to PluginManager.cat");
2500
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ";.dat").copy(m_sCurrentDir.ToString() + "/mods/PluginManager.dat");
2500
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod.ToString() + ";.dat").copy(m_sCurrentDir + "/mods/PluginManager.dat");
2501
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ";.cat").copy(m_sCurrentDir.ToString() + "/mods/PluginManager.cat");
2501
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod.ToString() + ";.cat").copy(m_sCurrentDir + "/mods/PluginManager.cat");
2502
		}
2502
		}
2503
 
2503
 
2504
		if ( !CDirIO(m_sCurrentDir).exists("mods") )
2504
		if ( !CDirIO(m_sCurrentDir).exists("mods") )
2505
			CDirIO(m_sCurrentDir).Create("mods");
2505
			CDirIO(m_sCurrentDir).Create("mods");
2506
 
2506
 
Line 2529... Line 2529...
2529
		CyStringList removeDirs;
2529
		CyStringList removeDirs;
2530
		removeDirs.PushBack(".");
2530
		removeDirs.PushBack(".");
2531
		RemoveUnusedDirectories(removeDirs, errors);
2531
		RemoveUnusedDirectories(removeDirs, errors);
2532
	}
2532
	}
2533
 
2533
 
2534
	this->SetCurrentDir("");
2534
	this->setCurrentDir("");
2535
		 
2535
		 
2536
	m_bLoaded = false;
2536
	m_bLoaded = false;
2537
	return true;
2537
	return true;
2538
}
2538
}
2539
 
2539
 
Line 2542... Line 2542...
2542
	return m_gameExe.GetModKey(m_iGame - 1);
2542
	return m_gameExe.GetModKey(m_iGame - 1);
2543
}
2543
}
2544
CyString CPackages::GetSelectedModName()
2544
CyString CPackages::GetSelectedModName()
2545
{
2545
{
2546
	if ( !m_pEnabledMod )
2546
	if ( !m_pEnabledMod )
2547
	{
2547
	{
2548
		if ( m_sSetMod.Empty() && m_iGame == GAME_X3 )
2548
		if ( m_sSetMod.Empty() && m_iGame == GAME_X3 )
2549
			return "PluginManager";
2549
			return "PluginManager";
2550
		return m_sSetMod;
2550
		return m_sSetMod;
2551
	}
2551
	}
2552
 
2552
 
Line 2555... Line 2555...
2555
 
2555
 
2556
	C_File *f = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2556
	C_File *f = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2557
	if ( !f )
2557
	if ( !f )
2558
		return m_sSetMod;
2558
		return m_sSetMod;
2559
 
2559
 
2560
	CyString name = f->GetFilename();
2560
	CyString name = f->filename();
2561
	name = name.Left(-4);
2561
	name = name.Left(-4);
2562
	return name;
2562
	return name;
2563
 
2563
 
2564
}
2564
}
2565
 
2565
 
Line 2658... Line 2658...
2658
 *
2658
 *
2659
 * Writes the current package list data into pluginmanager.dat file
2659
 * Writes the current package list data into pluginmanager.dat file
2660
 */
2660
 */
2661
void CPackages::WriteData()
2661
void CPackages::WriteData()
2662
{
2662
{
2663
	if ( m_sCurrentDir.Empty() )
2663
	if ( m_sCurrentDir.empty() )
2664
		return;
2664
		return;
2665
 
2665
 
2666
	CLog::log(CLog::Log_Directory, 1, "Writing data file for current directory: " + m_sCurrentDir.ToString());
2666
	CLog::log(CLog::Log_Directory, 1, "Writing data file for current directory: " + m_sCurrentDir);
2667
 
2667
 
2668
	CyStringList lines;
2668
	CyStringList lines;
2669
	CyString version;
2669
	CyString version;
2670
	version.FromFloat(GetLibraryVersion(), 2);
2670
	version.FromFloat(GetLibraryVersion(), 2);
2671
	version.Prepend("SpkInstaller: ");
2671
	version.Prepend("SpkInstaller: ");
Line 2695... Line 2695...
2695
	for ( int i = 0; i < WAREBUFFERS; i++ )
2695
	for ( int i = 0; i < WAREBUFFERS; i++ )
2696
	{
2696
	{
2697
		if ( !m_lGameWares[i].size() )
2697
		if ( !m_lGameWares[i].size() )
2698
			continue;
2698
			continue;
2699
		lines.PushBack(CyString("Wares: ") + (long)i + " " + (long)m_lGameWares[i].size());
2699
		lines.PushBack(CyString("Wares: ") + (long)i + " " + (long)m_lGameWares[i].size());
2700
 
2700
 
2701
		for ( CListNode<SGameWare> *node = m_lGameWares[i].Front(); node; node = node->next() )
2701
		for ( CListNode<SGameWare> *node = m_lGameWares[i].Front(); node; node = node->next() )
2702
		{
2702
		{
2703
			SGameWare *gm = node->Data();
2703
			SGameWare *gm = node->Data();
2704
			lines.PushBack(CyString((long)gm->iPos) + " " + (long)gm->iType + " " + CyString((char)gm->cType) + " " + gm->sWareName);
2704
			lines.PushBack(CyString((long)gm->iPos) + " " + (long)gm->iType + " " + CyString((char)gm->cType) + " " + gm->sWareName);
2705
		}
2705
		}
2706
	}
2706
	}
2707
 
2707
 
2708
	for ( SStringList *str = m_lNonRemovedFiles.Head(); str; str = str->next )
2708
	for ( SStringList *str = m_lNonRemovedFiles.Head(); str; str = str->next )
2709
		lines.PushBack(CyString("NonRemovedFile: ") + str->str);
2709
		lines.PushBack(CyString("NonRemovedFile: ") + str->str);
2710
 
2710
 
2711
	if ( m_lGameShips.size() )
2711
	if ( m_lGameShips.size() )
2712
	{
2712
	{
2713
		lines.PushBack(CyString("Ships: ") + (long)m_lGameShips.size());
2713
		lines.PushBack(CyString("Ships: ") + (long)m_lGameShips.size());
2714
 
2714
 
2715
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
2715
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
2716
		{
2716
		{
2717
			SGameShip *gm = node->Data();
2717
			SGameShip *gm = node->Data();
2718
			lines.PushBack(CyString((long)gm->iType) + " $#C:" + gm->sShipClass + " " + gm->sShipID);
2718
			lines.PushBack(CyString((long)gm->iType) + " $#C:" + gm->sShipClass + " " + gm->sShipID);
2719
		}
2719
		}
2720
	}
2720
	}
2721
 
2721
 
2722
	// write created Files
2722
	// write created Files
2723
	if ( !m_lCreatedFiles.Empty() )
2723
	if ( !m_lCreatedFiles.Empty() )
2724
	{
2724
	{
Line 2732... Line 2732...
2732
		for ( CListNode<C_File> *node = m_lUninstallFiles.Front(); node; node = node->next() )
2732
		for ( CListNode<C_File> *node = m_lUninstallFiles.Front(); node; node = node->next() )
2733
		{
2733
		{
2734
			C_File *uf = node->Data();
2734
			C_File *uf = node->Data();
2735
			CyString uString = "Uninstall: ";
2735
			CyString uString = "Uninstall: ";
2736
			uString += CyString::Number((long)uf->GetCreationTime()) + " ";
2736
			uString += CyString::Number((long)uf->GetCreationTime()) + " ";
2737
			uString += uf->GetFilename();
2737
			uString += uf->filename();
2738
			lines.PushBack(uString);
2738
			lines.PushBack(uString);
2739
		}
2739
		}
2740
	}
2740
	}
2741
 
2741
 
2742
	// write the original file data
2742
	// write the original file data
Line 2771... Line 2771...
2771
				break;
2771
				break;
2772
			case Ware_BuiltIn:
2772
			case Ware_BuiltIn:
2773
				lines.PushBack(CyString(Utils::String("BuiltInWarePriceOverride:") + (long)ware->pos + " " + (long)ware->relval));
2773
				lines.PushBack(CyString(Utils::String("BuiltInWarePriceOverride:") + (long)ware->pos + " " + (long)ware->relval));
2774
				if ( ware->bNotority )
2774
				if ( ware->bNotority )
2775
					lines.PushBack(CyString(Utils::String("BuiltInWareNotoOverride:") + (long)ware->pos + " " + (long)ware->notority));
2775
					lines.PushBack(CyString(Utils::String("BuiltInWareNotoOverride:") + (long)ware->pos + " " + (long)ware->notority));
2776
				break;
2776
				break;
2777
		}
2777
		}
2778
	}
2778
	}
2779
 
2779
 
2780
	// write the global file list
2780
	// write the global file list
2781
	lines.PushBack("GlobalFiles:");
2781
	lines.PushBack("GlobalFiles:");
Line 2840... Line 2840...
2840
			lines.PushBack("Disabled");
2840
			lines.PushBack("Disabled");
2841
		if ( !package->IsModifiedEnabled() )
2841
		if ( !package->IsModifiedEnabled() )
2842
			lines.PushBack("ModifiedDisabled");
2842
			lines.PushBack("ModifiedDisabled");
2843
 
2843
 
2844
		if ( package->GetIcon() )
2844
		if ( package->GetIcon() )
2845
			lines.PushBack(CyString("Icon: ") + package->GetIconExt() + " " + package->GetIcon()->GetFilePointer() );
2845
			lines.PushBack(CyString("Icon: ") + package->iconExt() + " " + package->GetIcon()->filePointer() );
2846
 
2846
 
2847
		CyString fileline("Files:");
2847
		CyString fileline("Files:");
2848
		for ( CListNode<C_File> *fn = package->GetFileList()->Front(); fn; fn = fn->next() )
2848
		for ( CListNode<C_File> *fn = package->GetFileList()->Front(); fn; fn = fn->next() )
2849
		{
2849
		{
2850
			C_File *f = fn->Data();
2850
			C_File *f = fn->Data();
Line 2862... Line 2862...
2862
	if ( !Dir.exists("PluginManager") ) {
2862
	if ( !Dir.exists("PluginManager") ) {
2863
		CLog::log(CLog::Log_IO, 2, "Creating PluginManager directory");
2863
		CLog::log(CLog::Log_IO, 2, "Creating PluginManager directory");
2864
 		Dir.Create("PluginManager");
2864
 		Dir.Create("PluginManager");
2865
	}
2865
	}
2866
 
2866
 
2867
	CLog::log(CLog::Log_IO, 2, "Writing data file: " + m_sCurrentDir.ToString() + "/PluginManager/PluginManager.new");
2867
	CLog::log(CLog::Log_IO, 2, "Writing data file: " + m_sCurrentDir + "/PluginManager/PluginManager.new");
2868
	if ( !datFile.WriteFile(&lines) )
2868
	if ( !datFile.WriteFile(&lines) )
2869
	{
2869
	{
2870
		CLog::log(CLog::Log_IO, 1, "ERROR: Failed to write data file");
2870
		CLog::log(CLog::Log_IO, 1, "ERROR: Failed to write data file");
2871
	}
2871
	}
2872
	else {
2872
	else {
2873
		CLog::log(CLog::Log_IO, 2, "Removing old data file: " + m_sCurrentDir.ToString() + "/PluginManager/PluginManager.dat");
2873
		CLog::log(CLog::Log_IO, 2, "Removing old data file: " + m_sCurrentDir + "/PluginManager/PluginManager.dat");
2874
		if ( !CFileIO::Exists(m_sCurrentDir.ToString() + &quot;/PluginManager/PluginManager.dat") || CFileIO::Remove(m_sCurrentDir.ToString() + "/PluginManager/PluginManager.dat") ) {
2874
		if ( !CFileIO::Exists(m_sCurrentDir + &quot;/PluginManager/PluginManager.dat") || CFileIO::Remove(m_sCurrentDir + "/PluginManager/PluginManager.dat") ) {
2875
			CLog::log(CLog::Log_IO, 2, "Renaming data file: PluginManager.new => PluginManager.dat");
2875
			CLog::log(CLog::Log_IO, 2, "Renaming data file: PluginManager.new => PluginManager.dat");
2876
			datFile.Rename(m_sCurrentDir + "/PluginManager/PluginManager.dat");
2876
			datFile.Rename(m_sCurrentDir + "/PluginManager/PluginManager.dat");
2877
		}
2877
		}
2878
	}
2878
	}
2879
}
2879
}
Line 2924... Line 2924...
2924
	return fileList->size();
2924
	return fileList->size();
2925
}
2925
}
2926
 
2926
 
2927
/**
2927
/**
2928
 * Add Log
2928
 * Add Log
2929
 *
2929
 *
2930
 * Adds a log entry to displayed at end
2930
 * Adds a log entry to displayed at end
2931
 */
2931
 */
2932
void CPackages::AddLogEntry(int type, CyString args, CyStringList *errors)
2932
void CPackages::AddLogEntry(int type, CyString args, CyStringList *errors)
2933
{
2933
{
2934
	if ( !errors )
2934
	if ( !errors )
2935
		return;
2935
		return;
2936
 
2936
 
2937
	errors->PushBack(args, ERRORLOG_OLD(type));
2937
	errors->PushBack(args, ERRORLOG_OLD(type));
2938
}
2938
}
2939
 
2939
 
2940
/**
2940
/**
2941
 * Enable a package
2941
 * Enable a package
2942
 *
2942
 *
2943
 * Enables all files in the package, unless they are already enabled, ie, used by other packages
2943
 * Enables all files in the package, unless they are already enabled, ie, used by other packages
2944
 * Backs up any original files before attempting to enable the file
2944
 * Backs up any original files before attempting to enable the file
Line 2952... Line 2952...
2952
 * param: progress		- The progress class, updates a progress screen of the derived class
2952
 * param: progress		- The progress class, updates a progress screen of the derived class
2953
 *
2953
 *
2954
 * return: boolen - Returns true if the package enabling was successful
2954
 * return: boolen - Returns true if the package enabling was successful
2955
 */
2955
 */
2956
bool CPackages::EnablePackage ( CBaseFile *package, CyStringList *errors, CProgressInfo *progress )
2956
bool CPackages::EnablePackage ( CBaseFile *package, CyStringList *errors, CProgressInfo *progress )
2957
{
2957
{
2958
	ClearError();
2958
	ClearError();
2959
 
2959
 
2960
	// if already enabled, just skip
2960
	// if already enabled, just skip
2961
	if ( package->IsEnabled() )
2961
	if ( package->IsEnabled() )
2962
		return true;
2962
		return true;
2963
 
2963
 
Line 2981... Line 2981...
2981
	return false;
2981
	return false;
2982
}
2982
}
2983
bool CPackages::EnablePreparedPackages ( CyStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *enabledPackages )
2983
bool CPackages::EnablePreparedPackages ( CyStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *enabledPackages )
2984
{
2984
{
2985
	ClearError();
2985
	ClearError();
2986
 
2986
 
2987
	// get all files, including children
2987
	// get all files, including children
2988
	CLinkList<C_File> fileList;
2988
	CLinkList<C_File> fileList;
2989
	int maxFiles = this->GetAllPackageFiles(&m_lEnableList, &fileList, false);
2989
	int maxFiles = this->GetAllPackageFiles(&m_lEnableList, &fileList, false);
2990
 
2990
 
2991
	int fileCount = 0;
2991
	int fileCount = 0;
Line 2999... Line 2999...
2999
		CBaseFile *package = NULL;
2999
		CBaseFile *package = NULL;
3000
		for ( CListNode<CBaseFile> *node = m_lEnableList.Front(); node; node = node->next() )
3000
		for ( CListNode<CBaseFile> *node = m_lEnableList.Front(); node; node = node->next() )
3001
		{
3001
		{
3002
			CBaseFile *p = node->Data();
3002
			CBaseFile *p = node->Data();
3003
			if ( p->IsFileAdded(f) )
3003
			if ( p->IsFileAdded(f) )
3004
			{
3004
			{
3005
				package = p;
3005
				package = p;
3006
				break;
3006
				break;
3007
			}
3007
			}
3008
		}
3008
		}
3009
 
3009
 
Line 3035... Line 3035...
3035
		}
3035
		}
3036
 
3036
 
3037
		// check if theres an original file to backup
3037
		// check if theres an original file to backup
3038
		_pOriginalFiles->doBackup(f, errors);
3038
		_pOriginalFiles->doBackup(f, errors);
3039
 
3039
 
3040
		CyString newFilename = f->GetNameDirectory(package);
3040
		Utils::String newFilename = f->getNameDirectory(package);
3041
 
3041
 
3042
		// fake patches need to be renamed
3042
		// fake patches need to be renamed
3043
		if ( f->IsFakePatch() )
3043
		if ( f->IsFakePatch() )
3044
		{
3044
		{
3045
			// first check if the matching file has been done already
3045
			// first check if the matching file has been done already
Line 3083... Line 3083...
3083
		}
3083
		}
3084
 
3084
 
3085
		this->AddLogEntry(SPKINSTALL_ENABLEFILE, newFilename, errors);
3085
		this->AddLogEntry(SPKINSTALL_ENABLEFILE, newFilename, errors);
3086
 
3086
 
3087
		// adjust the internal name to match the new filename
3087
		// adjust the internal name to match the new filename
3088
		f->SetFilename(m_sCurrentDir + "/" + newFilename);
3088
		f->setFilename(m_sCurrentDir + "/" + newFilename);
3089
		// no longer disabled, we need to remove the flag
3089
		// no longer disabled, we need to remove the flag
3090
		f->SetDisabled(false);
3090
		f->SetDisabled(false);
3091
	}
3091
	}
3092
 
3092
 
3093
	// recursive, auto enable all children
3093
	// recursive, auto enable all children
Line 3150... Line 3150...
3150
	for ( CListNode<C_File> *node = fileList.Front(); node; node = node->next() )
3150
	for ( CListNode<C_File> *node = fileList.Front(); node; node = node->next() )
3151
	{
3151
	{
3152
		C_File *f = node->Data();
3152
		C_File *f = node->Data();
3153
		CBaseFile *checkPackage = NULL;
3153
		CBaseFile *checkPackage = NULL;
3154
		for ( CListNode<CBaseFile> *node = m_lDisableList.Front(); node; node = node->next() )
3154
		for ( CListNode<CBaseFile> *node = m_lDisableList.Front(); node; node = node->next() )
3155
		{
3155
		{
3156
			CBaseFile *p = node->Data();
3156
			CBaseFile *p = node->Data();
3157
			if ( p->IsFileAdded(f) )
3157
			if ( p->IsFileAdded(f) )
3158
			{
3158
			{
3159
				checkPackage = p;
3159
				checkPackage = p;
3160
				break;
3160
				break;
Line 3168... Line 3168...
3168
			progress->UpdateFile(f);
3168
			progress->UpdateFile(f);
3169
		}
3169
		}
3170
 
3170
 
3171
		// only delete files that are not used by any other enabled packages, counter from UpdateUsedFiles()
3171
		// only delete files that are not used by any other enabled packages, counter from UpdateUsedFiles()
3172
		if ( f->GetUsed() || (f->IsShared() && !m_bDisableVanilla) )
3172
		if ( f->GetUsed() || (f->IsShared() && !m_bDisableVanilla) )
3173
			continue;
3173
			continue;
3174
 
3174
 
3175
		// file is already disabled, no need to disable again
3175
		// file is already disabled, no need to disable again
3176
		if ( f->IsDisabled() )
3176
		if ( f->IsDisabled() )
3177
			continue;
3177
			continue;
3178
 
3178
 
Line 3186... Line 3186...
3186
		{
3186
		{
3187
			bool found = false;
3187
			bool found = false;
3188
			for ( CListNode<C_File> *uNode = m_lUninstallFiles.Front(); uNode; uNode = uNode->next() )
3188
			for ( CListNode<C_File> *uNode = m_lUninstallFiles.Front(); uNode; uNode = uNode->next() )
3189
			{
3189
			{
3190
				C_File *uFile = uNode->Data();
3190
				C_File *uFile = uNode->Data();
3191
				if ( uFile->GetFilename().Compare(f->GetFilename()) )
3191
				if ( uFile->filename().Compare(f->filename()) )
3192
				{
3192
				{
3193
					found = true;
3193
					found = true;
3194
					break;
3194
					break;
3195
				}
3195
				}
3196
			}
3196
			}
Line 3225... Line 3225...
3225
			{
3225
			{
3226
				this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY_FAIL, newFilename, errors);
3226
				this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY_FAIL, newFilename, errors);
3227
				continue;
3227
				continue;
3228
			}
3228
			}
3229
			this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY, newFilename, errors);
3229
			this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY, newFilename, errors);
3230
		}
3230
		}
3231
 
3231
 
3232
		// fake patches need a special directory and filename so they dont overright each other as thier filenames are always changes
3232
		// fake patches need a special directory and filename so they dont overright each other as thier filenames are always changes
3233
		// if a package with a fake patch is installed while another one is disabled, it will fill the gap left by the disabled one
3233
		// if a package with a fake patch is installed while another one is disabled, it will fill the gap left by the disabled one
3234
		// they will then end up with the same filename, if it gets disabled they would overright each other, so we change the filename to prevent that from happening
3234
		// they will then end up with the same filename, if it gets disabled they would overright each other, so we change the filename to prevent that from happening
3235
		if ( f->IsFakePatch() )
3235
		if ( f->IsFakePatch() )
3236
		{
3236
		{
3237
			// find package the fake patch belongs to
3237
			// find package the fake patch belongs to
3238
			if ( checkPackage )
3238
			if ( checkPackage )
3239
			{
3239
			{
3240
				newFilename = Utils::String(m_sCurrentDir.ToString()) + "/PluginManager/Disabled/FakePatches/FakePatch_" + checkPackage->getNameValidFile() + "_" + checkPackage->author() + "_" + f->name();
3240
				newFilename = Utils::String(m_sCurrentDir) + "/PluginManager/Disabled/FakePatches/FakePatch_" + checkPackage->getNameValidFile() + "_" + checkPackage->author() + "_" + f->name();
3241
				shuffle = true;
3241
				shuffle = true;
3242
			}
3242
			}
3243
		}
3243
		}
3244
		else if ( f->isAutoTextFile() )
3244
		else if ( f->isAutoTextFile() )
3245
		{
3245
		{
3246
			if ( checkPackage )
3246
			if ( checkPackage )
3247
			{
3247
			{
3248
				newFilename = Utils::String(m_sCurrentDir.ToString()) + "/PluginManager/Disabled/TextFiles/Text_" + checkPackage->getNameValidFile() + "_" + checkPackage->author() + "_" + f->name();
3248
				newFilename = Utils::String(m_sCurrentDir) + "/PluginManager/Disabled/TextFiles/Text_" + checkPackage->getNameValidFile() + "_" + checkPackage->author() + "_" + f->name();
3249
				shuffle = true;
3249
				shuffle = true;
3250
			}
3250
			}
3251
		}
3251
		}
3252
		// otherwise we can just use the standard filename
3252
		// otherwise we can just use the standard filename
3253
		else
3253
		else
3254
			newFilename = Utils::String(m_sCurrentDir.ToString()) + "/PluginManager/Disabled/" + f->GetNameDirectory(checkPackage).ToString();
3254
			newFilename = Utils::String(m_sCurrentDir) + "/PluginManager/Disabled/" + f->GetNameDirectory(checkPackage).ToString();
3255
 
3255
 
3256
		// now to move the file by renameing it to its new location
3256
		// now to move the file by renameing it to its new location
3257
		// !!error checking!!
3257
		// !!error checking!!
3258
		// check the file, if it doesn't exist, and exists as disabled, we should just adjust the setting instead of an error
3258
		// check the file, if it doesn't exist, and exists as disabled, we should just adjust the setting instead of an error
3259
		CFileIO currentFile(f->GetFilePointer());
3259
		CFileIO currentFile(f->GetFilePointer());
Line 3420... Line 3420...
3420
	{
3420
	{
3421
		C_File *f = node->Data();
3421
		C_File *f = node->Data();
3422
		if ( f->GetFileType() != filetype )
3422
		if ( f->GetFileType() != filetype )
3423
			continue;
3423
			continue;
3424
 
3424
 
3425
		if ( !f->GetFilename().Compare(filename) )
3425
		if ( !f->filename().Compare(filename.ToString()) )
3426
			continue;
3426
			continue;
3427
 
3427
 
3428
		if ( !dir.Empty() && f->GetDir().Compare(dir) )
3428
		if ( !dir.Empty() && f->dir().Compare(dir.ToString()) )
3429
			continue;
3429
			continue;
3430
 
3430
 
3431
		return f;
3431
		return f;
3432
	}
3432
	}
3433
 
3433
 
Line 3605... Line 3605...
3605
 */
3605
 */
3606
int CPackages::CheckInstallPackage(CBaseFile *package, int check)
3606
int CPackages::CheckInstallPackage(CBaseFile *package, int check)
3607
{
3607
{
3608
	if ( package->GetType() == TYPE_XSP && m_iGame == GAME_X2 )
3608
	if ( package->GetType() == TYPE_XSP && m_iGame == GAME_X2 )
3609
		return INSTALLCHECK_NOSHIP;
3609
		return INSTALLCHECK_NOSHIP;
3610
 
3610
 
3611
	// search for an old version
3611
	// search for an old version
3612
	CBaseFile *oldPackage = FindPackage(package);
3612
	CBaseFile *oldPackage = FindPackage(package);
3613
 
3613
 
3614
	// check versions are newer
3614
	// check versions are newer
3615
	if (oldPackage && (check & IC_OLDVERSION))
3615
	if (oldPackage && (check & IC_OLDVERSION))
3616
	{
3616
	{
3617
		if ( oldPackage->version().compareVersion(package->version()) == COMPARE_OLDER )
3617
		if ( oldPackage->version().compareVersion(package->version()) == COMPARE_OLDER )
3618
			return INSTALLCHECK_OLDVERSION;
3618
			return INSTALLCHECK_OLDVERSION;
3619
	}
3619
	}
3620
 
3620
 
3621
	// now check for game version
3621
	// now check for game version
3622
	if ((check & IC_WRONGGAME) || (check & IC_WRONGVERSION))
3622
	if ((check & IC_WRONGGAME) || (check & IC_WRONGVERSION))
3623
	{
3623
	{
3624
		if ( package->AnyGameCompatability() )
3624
		if ( package->AnyGameCompatability() )
3625
		{
3625
		{
Line 3633... Line 3633...
3633
	// check for modified
3633
	// check for modified
3634
	if (m_bVanilla && (check & IC_MODIFIED))
3634
	if (m_bVanilla && (check & IC_MODIFIED))
3635
	{
3635
	{
3636
		if ( !package->IsSigned() )
3636
		if ( !package->IsSigned() )
3637
			return INSTALLCHECK_MODIFIED;
3637
			return INSTALLCHECK_MODIFIED;
3638
	}
3638
	}
3639
 
3639
 
3640
	return INSTALLCHECK_OK;
3640
	return INSTALLCHECK_OK;
3641
}
3641
}
3642
 
3642
 
3643
bool CPackages::CheckOtherPackage(CBaseFile *package)
3643
bool CPackages::CheckOtherPackage(CBaseFile *package)
3644
{
3644
{
Line 3680... Line 3680...
3680
	{
3680
	{
3681
		if ( ((CSpkFile *)p)->IsAnotherMod() )
3681
		if ( ((CSpkFile *)p)->IsAnotherMod() )
3682
		{
3682
		{
3683
			CBaseFile *parent = this->FindSpkPackage(((CSpkFile *)p)->GetOtherName(), ((CSpkFile *)p)->GetOtherAuthor());
3683
			CBaseFile *parent = this->FindSpkPackage(((CSpkFile *)p)->GetOtherName(), ((CSpkFile *)p)->GetOtherAuthor());
3684
			if ( parent )
3684
			if ( parent )
3685
			{
3685
			{
3686
				if ( !parent->IsEnabled() )
3686
				if ( !parent->IsEnabled() )
3687
					return false;
3687
					return false;
3688
			}
3688
			}
3689
			else
3689
			else
3690
				return false;
3690
				return false;
Line 3698... Line 3698...
3698
		{
3698
		{
3699
			if ( dNode->Data()->sName.Compare("<package>") )
3699
			if ( dNode->Data()->sName.Compare("<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, dNode->Data()->sAuthor, 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(CyString name, CyString author, CyString version, bool onlyEnabled, bool includePrepared)
3709
bool CPackages::CheckInstalledDependacy(CyString name, CyString author, CyString version, bool onlyEnabled, bool includePrepared)
Line 3717... Line 3717...
3717
	CBaseFile *p = this->findSpkPackage(name, author);
3717
	CBaseFile *p = this->findSpkPackage(name, author);
3718
	if ( p )
3718
	if ( p )
3719
	{
3719
	{
3720
		// now check version
3720
		// now check version
3721
		if (version.compareVersion(p->version()) == COMPARE_OLDER)
3721
		if (version.compareVersion(p->version()) == COMPARE_OLDER)
3722
			return false;
3722
			return false;
3723
 
3723
 
3724
		if ( onlyEnabled && !p->IsEnabled() )
3724
		if ( onlyEnabled && !p->IsEnabled() )
3725
			return false;
3725
			return false;
3726
 
3726
 
3727
		return true;
3727
		return true;
Line 3754... Line 3754...
3754
 
3754
 
3755
bool CPackages::findAllNeededDependacies(CBaseFile *p, const CLinkList<CBaseFile> &packages, CLinkList<CBaseFile> *foundPackages, bool onlyEnabled, bool includePrepared) const
3755
bool CPackages::findAllNeededDependacies(CBaseFile *p, const CLinkList<CBaseFile> &packages, CLinkList<CBaseFile> *foundPackages, bool onlyEnabled, bool includePrepared) const
3756
{
3756
{
3757
	CLinkList<SNeededLibrary> *neededList = p->GetNeededLibraries();
3757
	CLinkList<SNeededLibrary> *neededList = p->GetNeededLibraries();
3758
	if (neededList)
3758
	if (neededList)
3759
	{
3759
	{
3760
		for (CListNode<SNeededLibrary> *node = neededList->Front(); node; node = node->next())
3760
		for (CListNode<SNeededLibrary> *node = neededList->Front(); node; node = node->next())
3761
		{
3761
		{
3762
			SNeededLibrary *nl = node->Data();
3762
			SNeededLibrary *nl = node->Data();
3763
			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))
3763
			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))
3764
			{
3764
			{
Line 3900... Line 3900...
3900
			if ( !found )
3900
			if ( !found )
3901
			{
3901
			{
3902
				if ( list )
3902
				if ( list )
3903
					list->pushBack(spk->GetOtherName(), spk->GetOtherAuthor());
3903
					list->pushBack(spk->GetOtherName(), spk->GetOtherAuthor());
3904
				++count;
3904
				++count;
3905
			}
3905
			}
3906
		}
3906
		}
3907
	}
3907
	}
3908
 
3908
 
3909
	return count;
3909
	return count;
3910
}
3910
}
3911
 
3911
 
3912
int CPackages::CheckPreparedInstallRequired(CLinkList<CBaseFile> *list)
3912
int CPackages::CheckPreparedInstallRequired(CLinkList<CBaseFile> *list)
3913
{
3913
{
3914
	// loop through all packages
3914
	// loop through all packages
Line 3992... Line 3992...
3992
		{
3992
		{
3993
			C_File *checkFile = fNode->Data();
3993
			C_File *checkFile = fNode->Data();
3994
			if ( checkFile->GetFileType() != FILETYPE_SCRIPT )
3994
			if ( checkFile->GetFileType() != FILETYPE_SCRIPT )
3995
				continue;
3995
				continue;
3996
 
3996
 
3997
			if ( checkFile->GetFilename().Compare(file->GetFilename()) )
3997
			if ( checkFile->filename().Compare(file->filename()) )
3998
			{
3998
			{
3999
				found = true;
3999
				found = true;
4000
				break;
4000
				break;
4001
			}
4001
			}
4002
		}
4002
		}
Line 4054... Line 4054...
4054
	for ( CListNode<C_File> *node = m_lFiles.Back(); node; node = node->prev() )
4054
	for ( CListNode<C_File> *node = m_lFiles.Back(); node; node = node->prev() )
4055
	{
4055
	{
4056
		if ( progress )
4056
		if ( progress )
4057
			progress->UpdateProgress(files, m_lFiles.size());
4057
			progress->UpdateProgress(files, m_lFiles.size());
4058
		files++;
4058
		files++;
4059
 
4059
 
4060
		C_File *file = node->Data();
4060
		C_File *file = node->Data();
4061
 
4061
 
4062
		// only do marked shared files
4062
		// only do marked shared files
4063
		if ( !file->IsShared() )
4063
		if ( !file->IsShared() )
4064
			continue;
4064
			continue;
4065
 
4065
 
4066
		// only do ones that are no longer needed
4066
		// only do ones that are no longer needed
4067
		if ( file->GetUsed() )
4067
		if ( file->GetUsed() )
4068
			continue;
4068
			continue;
4069
 
4069
 
4070
		if ( RemoveSharedFile(file, errors) )
4070
		if ( RemoveSharedFile(file, errors) )
4071
			++done;
4071
			++done;
4072
		node->ChangeData(NULL);
4072
		node->ChangeData(NULL);
4073
	}
4073
	}
4074
 
4074
 
4075
	m_lFiles.RemoveEmpty();
4075
	m_lFiles.RemoveEmpty();
4076
 
4076
 
4077
	return done;
4077
	return done;
4078
}
4078
}
4079
 
4079
 
4080
/**
4080
/**
4081
 * Any Unused Shared
4081
 * Any Unused Shared
4082
 *
4082
 *
4083
 * Checks if theres any unused shared files available
4083
 * Checks if theres any unused shared files available
4084
 *
4084
 *
4085
 * Any file thats marked as shared, and is no longer connected to any installed package
4085
 * Any file thats marked as shared, and is no longer connected to any installed package
4086
 */
4086
 */
4087
bool CPackages::AnyUnusedShared()
4087
bool CPackages::AnyUnusedShared()
4088
{
4088
{
4089
	UpdateUsedFiles();
4089
	UpdateUsedFiles();
4090
 
4090
 
4091
	for ( CListNode<C_File> *node = m_lFiles.Back(); node; node = node->prev() )
4091
	for ( CListNode<C_File> *node = m_lFiles.Back(); node; node = node->prev() )
4092
	{
4092
	{
4093
		C_File *file = node->Data();
4093
		C_File *file = node->Data();
4094
 
4094
 
4095
		// only do marked shared files
4095
		// only do marked shared files
4096
		if ( !file->IsShared() )
4096
		if ( !file->IsShared() )
4097
			continue;
4097
			continue;
4098
 
4098
 
4099
		// only do ones that are no longer needed
4099
		// only do ones that are no longer needed
4100
		if ( file->GetUsed() )
4100
		if ( file->GetUsed() )
4101
			continue;
4101
			continue;
4102
 
4102
 
Line 4129... Line 4129...
4129
		{
4129
		{
4130
			CFileIO moveFile(f->filePointer());
4130
			CFileIO moveFile(f->filePointer());
4131
	
4131
	
4132
			Utils::String newName = SPK::FormatTextName(current, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT)) + "." + moveFile.extension();
4132
			Utils::String newName = SPK::FormatTextName(current, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT)) + "." + moveFile.extension();
4133
			if ( moveFile.Rename(m_sCurrentDir + "/t/" + newName) )
4133
			if ( moveFile.Rename(m_sCurrentDir + "/t/" + newName) )
4134
			{
4134
			{
4135
				this->AddLogEntry(SPKINSTALL_AUTOTEXT, f->name() + "~" + newName, errors);
4135
				this->AddLogEntry(SPKINSTALL_AUTOTEXT, f->name() + "~" + newName, errors);
4136
				f->SetName(newName);
4136
				f->SetName(newName);
4137
			}
4137
			}
4138
			else
4138
			else
4139
				this->AddLogEntry(SPKINSTALL_AUTOTEXT_FAIL, f->name() + "~" + newName, errors);
4139
				this->AddLogEntry(SPKINSTALL_AUTOTEXT_FAIL, f->name() + "~" + newName, errors);
Line 4183... Line 4183...
4183
			if ( sCheck->str.Compare(CyString(p->name())) && sCheck->data.Compare(CyString(p->author())) )
4183
			if ( sCheck->str.Compare(CyString(p->name())) && sCheck->data.Compare(CyString(p->author())) )
4184
			{
4184
			{
4185
				added = true;
4185
				added = true;
4186
				break;
4186
				break;
4187
			}
4187
			}
4188
		}
4188
		}
4189
 
4189
 
4190
		if ( added ) continue;
4190
		if ( added ) continue;
4191
 
4191
 
4192
		bool anyFound = false;
4192
		bool anyFound = false;
4193
		for ( C_File *file = p->GetFirstFile(FILETYPE_MOD); file; file = p->GetNextFile(file) )
4193
		for ( C_File *file = p->GetFirstFile(FILETYPE_MOD); file; file = p->GetNextFile(file) )
4194
		{
4194
		{
4195
			if ( !file->IsFakePatch() ) continue;
4195
			if ( !file->IsFakePatch() ) continue;
4196
			if ( !file->CheckFileExt("cat") ) continue;
4196
			if ( !file->CheckFileExt("cat") ) continue;
Line 4204... Line 4204...
4204
			packages.push_back(p);
4204
			packages.push_back(p);
4205
	}
4205
	}
4206
 
4206
 
4207
	// lets adjust the order (only if theres more than 1
4207
	// lets adjust the order (only if theres more than 1
4208
	if ( packages.size() > 1 )
4208
	if ( packages.size() > 1 )
4209
	{
4209
	{
4210
		CLinkList<CBaseFile> sortedPackages;
4210
		CLinkList<CBaseFile> sortedPackages;
4211
 
4211
 
4212
		// first add all the packages that dont need to be installed after
4212
		// first add all the packages that dont need to be installed after
4213
		for ( CListNode<CBaseFile> *pNode = packages.Front(); pNode; pNode = pNode->next() )
4213
		for ( CListNode<CBaseFile> *pNode = packages.Front(); pNode; pNode = pNode->next() )
4214
		{
4214
		{
Line 4290... Line 4290...
4290
 
4290
 
4291
				if ( !lowestFile ) // no more files ?
4291
				if ( !lowestFile ) // no more files ?
4292
					break;
4292
					break;
4293
 
4293
 
4294
				// check its filename, it might already be in the correct place
4294
				// check its filename, it might already be in the correct place
4295
				if ( lowestFile->GetBaseName().ToInt() != lowest )
4295
				if ( lowestFile->baseName().toInt() != lowest )
4296
				{
4296
				{
4297
					// if the file already exists, we need to move it elsewhere
4297
					// if the file already exists, we need to move it elsewhere
4298
					CyString nextName = CyString::Number(lowest).PadNumber(2);
4298
					Utils::String nextName = Utils::String::PadNumber(lowest, 2);
4299
					if ( CFileIO(m_sCurrentDir + "/" + nextName + ".cat").ExistsOld() )
4299
					if ( CFileIO::Exists(m_sCurrentDir + "/" + nextName + ".cat") )
4300
					{
4300
					{
4301
						// find the file in our internal file list
4301
						// find the file in our internal file list
4302
						C_File *moveFile = FindFile(FILETYPE_MOD, nextName + ".cat");
4302
						C_File *moveFile = FindFile(FILETYPE_MOD, nextName + ".cat");
4303
						if ( !moveFile ) // must not have it in our list ? lets move to the next
4303
						if ( !moveFile ) // must not have it in our list ? lets move to the next
4304
						{
4304
						{
Line 4341... Line 4341...
4341
		if ( !f->CheckFileExt("cat") )
4341
		if ( !f->CheckFileExt("cat") )
4342
			continue;
4342
			continue;
4343
 
4343
 
4344
		// now lets check if its greater than our gap
4344
		// now lets check if its greater than our gap
4345
		int check = FindNextFakePatch();
4345
		int check = FindNextFakePatch();
4346
		int patchNum = f->GetFilename().GetToken(".", 1, 1).ToInt();
4346
		int patchNum = f->filename().token(".", 1).toInt();
4347
		if ( patchNum <= check )
4347
		if ( patchNum <= check )
4348
			continue;
4348
			continue;
4349
 
4349
 
4350
		ShufflePatchTo(f, check, errors);
4350
		ShufflePatchTo(f, check, errors);
4351
	}
4351
	}
4352
}
4352
}
4353
 
4353
 
4354
void CPackages::ShufflePatchTo(C_File *file, int to, CyStringList *errors)
4354
void CPackages::ShufflePatchTo(C_File *file, int to, CyStringList *errors)
4355
{
4355
{
4356
	// it is, we need to shift this to fill the gap
4356
	// it is, we need to shift this to fill the gap
4357
	CyString newName = CyString::Number(to).PadNumber(2) + "." + file->GetFileExt();
4357
	Utils::String newName = Utils::String::PadNumber(to, 2) + "." + file->fileExt();
4358
 
4358
 
4359
	// now rename the file
4359
	// now rename the file
4360
	CFileIO moveFile(file->GetFilePointer());
4360
	CFileIO moveFile(file->filePointer());
4361
	if ( moveFile.Rename(m_sCurrentDir + "/" + newName) )
4361
	if ( moveFile.Rename(m_sCurrentDir + "/" + newName) )
4362
	{
4362
	{
4363
		// display moveing
4363
		// display moveing
4364
		this->AddLogEntry(SPKINSTALL_FAKEPATCH, file->GetName() + "~" + newName, errors);
4364
		this->AddLogEntry(SPKINSTALL_FAKEPATCH, file->name() + "~" + newName, errors);
4365
 
4365
 
4366
		// now find the matching pairing if it exists
4366
		// now find the matching pairing if it exists
4367
		for ( CListNode<C_File> *node2 = m_lFiles.Front(); node2; node2 = node2->next() )
4367
		for ( CListNode<C_File> *node2 = m_lFiles.Front(); node2; node2 = node2->next() )
4368
		{
4368
		{
4369
			C_File *f2 = node2->Data();
4369
			C_File *f2 = node2->Data();
4370
 
4370
 
Line 4373... Line 4373...
4373
 
4373
 
4374
			// needs to be the same file
4374
			// needs to be the same file
4375
			if ( f2->GetBaseName() != file->GetBaseName() )
4375
			if ( f2->GetBaseName() != file->GetBaseName() )
4376
				continue;
4376
				continue;
4377
 
4377
 
4378
			CyString newName2 = CyString::Number(to).PadNumber(2) + "." + f2->GetFileExt();
4378
			Utils::String newName2 = Utils::String::PadNumber(to, 2) + "." + f2->fileExt();
4379
			CFileIO moveFile(f2->GetFilePointer());
4379
			CFileIO moveFile(f2->filePointer());
4380
			if ( moveFile.Rename(m_sCurrentDir + "/" + newName2) )
4380
			if ( moveFile.Rename(m_sCurrentDir + "/" + newName2) )
4381
			{
4381
			{
4382
				this->AddLogEntry(SPKINSTALL_FAKEPATCH, f2->GetName() + "~" + newName2, errors);
4382
				this->AddLogEntry(SPKINSTALL_FAKEPATCH, f2->name() + "~" + newName2, errors);
4383
				f2->SetName(newName2);
4383
				f2->setName(newName2);
4384
			}
4384
			}
4385
			else
4385
			else
4386
				this->AddLogEntry(SPKINSTALL_FAKEPATCH_FAIL, f2->GetName() + "~" + newName2, errors);
4386
				this->AddLogEntry(SPKINSTALL_FAKEPATCH_FAIL, f2->name() + "~" + newName2, errors);
4387
		}
4387
		}
4388
 
4388
 
4389
		// finally make sure the internal name matches the new one
4389
		// finally make sure the internal name matches the new one
4390
		file->SetName(newName);
4390
		file->setName(newName);
4391
	}
4391
	}
4392
	else
4392
	else
4393
		this->AddLogEntry(SPKINSTALL_FAKEPATCH_FAIL, file->GetName() + "~" + newName, errors);
4393
		this->AddLogEntry(SPKINSTALL_FAKEPATCH_FAIL, file->name() + "~" + newName, errors);
4394
}
4394
}
4395
 
4395
 
4396
int CPackages::FindLowestFakePatchInstalled()
4396
int CPackages::FindLowestFakePatchInstalled()
4397
{
4397
{
4398
	int lowest = 99;
4398
	int lowest = 99;
Line 4442... Line 4442...
4442
 * Find next fake patch
4442
 * Find next fake patch
4443
 *
4443
 *
4444
 * Searching for the next gap in patches, starting with 01.cat to 99.cat
4444
 * Searching for the next gap in patches, starting with 01.cat to 99.cat
4445
 */
4445
 */
4446
int CPackages::FindNextFakePatch(int start, CyString dir)
4446
int CPackages::FindNextFakePatch(int start, CyString dir)
4447
{
4447
{
4448
	CDirIO Dir((dir.Empty()) ? m_sCurrentDir : dir);
4448
	CDirIO Dir((dir.Empty()) ? m_sCurrentDir : dir);
4449
 
4449
 
4450
	int check = start;
4450
	int check = start;
4451
	while ( check < 99 )
4451
	while ( check < 99 )
4452
	{
4452
	{
Line 4664... Line 4664...
4664
	if ( !addFile )
4664
	if ( !addFile )
4665
		addFile = FindFile(FILETYPE_TEXT, newFilename + ".pck");
4665
		addFile = FindFile(FILETYPE_TEXT, newFilename + ".pck");
4666
 
4666
 
4667
	// we have found the file, lets just add it to our scripts
4667
	// we have found the file, lets just add it to our scripts
4668
	if ( addFile )
4668
	if ( addFile )
4669
	{
4669
	{
4670
		AddTextFileToScripts(addFile, textid);
4670
		AddTextFileToScripts(addFile, textid);
4671
		return true;
4671
		return true;
4672
	}
4672
	}
4673
 
4673
 
4674
	// first we need to find our text file
4674
	// first we need to find our text file
4675
	Utils::String filename;
4675
	Utils::String filename;
4676
	if ( languageid != -1 )
4676
	if ( languageid != -1 )
Line 4715... Line 4715...
4715
		lines->insert(lines->begin(), *it);
4715
		lines->insert(lines->begin(), *it);
4716
 
4716
 
4717
	addFile = new C_File(newFilename + ".xml");
4717
	addFile = new C_File(newFilename + ".xml");
4718
	addFile->SetFileType(FILETYPE_TEXT);
4718
	addFile->SetFileType(FILETYPE_TEXT);
4719
 
4719
 
4720
	CFileIO writeFile(m_sCurrentDir + "/" + addFile->GetNameDirectory(NULL));
4720
	CFileIO writeFile(m_sCurrentDir + "/" + addFile->getNameDirectory(NULL));
4721
	if ( writeFile.WriteFile(lines) )
4721
	if ( writeFile.WriteFile(lines) )
4722
	{
4722
	{
4723
		this->AddLogEntry(SPKINSTALL_WRITEFILE, addFile->GetNameDirectory(NULL), errors);
4723
		this->AddLogEntry(SPKINSTALL_WRITEFILE, addFile->getNameDirectory(NULL), errors);
4724
 
4724
 
4725
		addFile->SetFilename(m_sCurrentDir + "/" + addFile->GetNameDirectory(NULL));
4725
		addFile->SetFilename(m_sCurrentDir + "/" + addFile->getNameDirectory(NULL));
4726
		// now we have the file wrriten, we need to add it to all scripts that need it
4726
		// now we have the file wrriten, we need to add it to all scripts that need it
4727
		// first we add it to the global list
4727
		// first we add it to the global list
4728
		m_lFiles.push_back(addFile);
4728
		m_lFiles.push_back(addFile);
4729
 
4729
 
4730
		// now add it to the scripts
4730
		// now add it to the scripts
4731
		AddTextFileToScripts(addFile, textid);
4731
		AddTextFileToScripts(addFile, textid);
4732
	}
4732
	}
4733
	else
4733
	else
4734
	{
4734
	{
4735
		this->AddLogEntry(SPKINSTALL_WRITEFILE_FAIL, addFile->GetNameDirectory(NULL), errors);
4735
		this->AddLogEntry(SPKINSTALL_WRITEFILE_FAIL, addFile->getNameDirectory(NULL), errors);
4736
		if ( lines )
4736
		if ( lines )
4737
			delete lines;
4737
			delete lines;
4738
		return false;
4738
		return false;
4739
	}
4739
	}
4740
 
4740
 
Line 4745... Line 4745...
4745
	return true;
4745
	return true;
4746
}
4746
}
4747
 
4747
 
4748
/**
4748
/**
4749
 * Add file to scripts
4749
 * Add file to scripts
4750
 *
4750
 *
4751
 * Adds a file to all scripts that need it
4751
 * Adds a file to all scripts that need it
4752
 */
4752
 */
4753
void CPackages::AddTextFileToScripts(C_File *file, CyString textid)
4753
void CPackages::AddTextFileToScripts(C_File *file, CyString textid)
4754
{
4754
{
4755
	// now we need to find all scripts that have a matching file and add this to the list
4755
	// now we need to find all scripts that have a matching file and add this to the list
Line 4784... Line 4784...
4784
bool CPackages::RemoveFile(C_File *file, CyStringList *errors)
4784
bool CPackages::RemoveFile(C_File *file, CyStringList *errors)
4785
{
4785
{
4786
	if ( !file )
4786
	if ( !file )
4787
		return true;
4787
		return true;
4788
 
4788
 
4789
	CyString remFileStr = file->GetFilePointer();
4789
	Utils::String remFileStr = file->filePointer();
4790
	remFileStr.FindReplace(m_sCurrentDir, "");
4790
	remFileStr.findReplace(m_sCurrentDir, "");
4791
 
4791
 
4792
	if ( file->GetFilePointer().IsIn("::") ) {
4792
	if ( file->filePointer().contains("::")) {
4793
		CFileIO CatFile(file->GetFilePointer().GetToken("::", 1, 1));
4793
		CFileIO CatFile(file->GetFilePointer().GetToken("::", 1, 1));
4794
		if ( CatFile.exists() ) {
4794
		if ( CatFile.exists() ) {
4795
			CCatFile cat;
4795
			CCatFile cat;
4796
			if ( cat.open(CatFile.fullFilename(), this->getAddonDir(), CATREAD_DAT, false) == CATERR_NONE ) {
4796
			if ( cat.open(CatFile.fullFilename(), this->getAddonDir(), CATREAD_DAT, false) == CATERR_NONE ) {
4797
				CyString fileName = file->GetFilePointer().GetToken("::", 2, 2);
4797
				CyString fileName = file->GetFilePointer().GetToken("::", 2, 2);
Line 4806... Line 4806...
4806
				}
4806
				}
4807
			}
4807
			}
4808
		}
4808
		}
4809
	}
4809
	}
4810
	else {
4810
	else {
4811
		CFileIO f(file->GetFilePointer());
4811
		CFileIO f(file->filePointer());
4812
		if ( f.exists() )
4812
		if ( f.exists() )
4813
		{
4813
		{
4814
			if ( f.remove() ) this->AddLogEntry(SPKINSTALL_DELETEFILE, remFileStr, errors);
4814
			if ( f.remove() ) this->AddLogEntry(SPKINSTALL_DELETEFILE, remFileStr, errors);
4815
			else if ( errors )
4815
			else if ( errors )
4816
			{
4816
			{
Line 4961... Line 4961...
4961
void CPackages::startup(const Utils::String &dir, const Utils::String &tempDir, const Utils::String &myDoc, const Utils::String &mod)
4961
void CPackages::startup(const Utils::String &dir, const Utils::String &tempDir, const Utils::String &myDoc, const Utils::String &mod)
4962
{
4962
{
4963
	startup(dir, tempDir, myDoc);
4963
	startup(dir, tempDir, myDoc);
4964
	m_sSetMod = mod;
4964
	m_sSetMod = mod;
4965
}
4965
}
-
 
4966
/*
4966
void CPackages::Startup(CyString dir, CyString tempDir, CyString myDoc, CyString mod)
4967
void CPackages::Startup(CyString dir, CyString tempDir, CyString myDoc, CyString mod)
4967
{
4968
{
4968
	startup(dir.ToString(), tempDir.ToString(), myDoc.ToString(), mod.ToString());
4969
	startup(dir.ToString(), tempDir.ToString(), myDoc.ToString(), mod.ToString());
4969
}
4970
}*/
4970
 
4971
 
4971
int CPackages::GetGameLanguage() const
4972
int CPackages::GetGameLanguage() const
4972
{
4973
{
4973
	return this->GetGameLanguage(m_sCurrentDir.ToString());
4974
	return this->GetGameLanguage(m_sCurrentDir);
4974
}
4975
}
4975
int CPackages::GetGameLanguage(const Utils::String &sDir) const
4976
int CPackages::GetGameLanguage(const Utils::String &sDir) const
4976
{
4977
{
4977
	Utils::String dir = sDir;
4978
	Utils::String dir = sDir;
4978
	if (dir.empty())
4979
	if (dir.empty())
4979
		dir = m_sCurrentDir.ToString();
4980
		dir = m_sCurrentDir;
4980
	else
4981
	else
4981
		dir = this->getProperDir(dir);
4982
		dir = this->getProperDir(dir);
4982
 
4983
 
4983
	CDirIO Dir(dir);
4984
	CDirIO Dir(dir);
4984
 
4985
 
Line 5003... Line 5004...
5003
{
5004
{
5004
	return m_gameExe.GetGameRunExe(dir);
5005
	return m_gameExe.GetGameRunExe(dir);
5005
}
5006
}
5006
Utils::String CPackages::GetGameRunExe()
5007
Utils::String CPackages::GetGameRunExe()
5007
{
5008
{
5008
	return m_gameExe.GetGameRunExe(m_sCurrentDir.ToString());
5009
	return m_gameExe.GetGameRunExe(m_sCurrentDir);
5009
}
5010
}
5010
 
5011
 
5011
CyString CPackages::GetGameNameFromType(int game)
5012
CyString CPackages::GetGameNameFromType(int game)
5012
{
5013
{
5013
	return m_gameExe.GetGameNameFromType(game - 1);
5014
	return m_gameExe.GetGameNameFromType(game - 1);
5014
}
5015
}
5015
Utils::String CPackages::getGameName() const
5016
Utils::String CPackages::getGameName() const
5016
{
5017
{
5017
	return getGameName(m_sCurrentDir.ToString());
5018
	return getGameName(m_sCurrentDir);
5018
}
5019
}
5019
 
5020
 
5020
Utils::String CPackages::getGameName(const Utils::String &dir) const
5021
Utils::String CPackages::getGameName(const Utils::String &dir) const
5021
{
5022
{
5022
	return m_gameExe.GetGameName(dir.empty() ? m_sCurrentDir.ToString() : dir);
5023
	return m_gameExe.GetGameName(dir.empty() ? m_sCurrentDir : dir);
5023
}
5024
}
5024
 
5025
 
5025
CyString CPackages::GetGameName(CyString dir)
5026
CyString CPackages::GetGameName(CyString dir)
5026
{
5027
{
5027
	return m_gameExe.GetGameName((dir.Empty()) ? m_sCurrentDir.ToString() : dir.ToString());
5028
	return m_gameExe.GetGameName((dir.Empty()) ? m_sCurrentDir : dir.ToString());
5028
}
5029
}
5029
CyString CPackages::GetProperDir(CyString dir)
5030
CyString CPackages::GetProperDir(CyString dir)
5030
{
5031
{
5031
	return m_gameExe.GetProperDir((dir.Empty()) ? m_sCurrentDir.ToString() : dir.ToString());
5032
	return m_gameExe.GetProperDir((dir.Empty()) ? m_sCurrentDir : dir.ToString());
5032
}
5033
}
5033
CyString CPackages::GetAddonDir(CyString dir)
5034
CyString CPackages::GetAddonDir(CyString dir)
5034
{
5035
{
5035
	return m_gameExe.GetAddonDir((dir.Empty()) ? m_sCurrentDir.ToString() : dir.ToString());
5036
	return m_gameExe.GetAddonDir((dir.Empty()) ? m_sCurrentDir : dir.ToString());
5036
}
5037
}
5037
Utils::String CPackages::getProperDir() const
5038
Utils::String CPackages::getProperDir() const
5038
{
5039
{
5039
	return getProperDir(m_sCurrentDir.ToString());
5040
	return getProperDir(m_sCurrentDir);
5040
}
5041
}
5041
Utils::String CPackages::getProperDir(const Utils::String &dir) const
5042
Utils::String CPackages::getProperDir(const Utils::String &dir) const
5042
{
5043
{
5043
	return m_gameExe.GetProperDir((dir.empty()) ? m_sCurrentDir.ToString() : dir);
5044
	return m_gameExe.GetProperDir((dir.empty()) ? m_sCurrentDir : dir);
5044
}
5045
}
5045
Utils::String CPackages::getAddonDir() const
5046
Utils::String CPackages::getAddonDir() const
5046
{
5047
{
5047
	return getAddonDir(m_sCurrentDir.ToString());
5048
	return getAddonDir(m_sCurrentDir);
5048
}
5049
}
5049
Utils::String CPackages::getAddonDir(const Utils::String &dir) const
5050
Utils::String CPackages::getAddonDir(const Utils::String &dir) const
5050
{
5051
{
5051
	return m_gameExe.GetAddonDir((dir.empty()) ? m_sCurrentDir.ToString() : dir);
5052
	return m_gameExe.GetAddonDir((dir.empty()) ? m_sCurrentDir : dir);
5052
}
5053
}
5053
int CPackages::GetGameAddons(Utils::CStringList &exes, const Utils::String &dir)
5054
int CPackages::GetGameAddons(Utils::CStringList &exes, const Utils::String &dir)
5054
{
5055
{
5055
	return m_gameExe.GetGameAddons((dir.empty()) ? m_sCurrentDir.ToString() : dir, exes);
5056
	return m_gameExe.GetGameAddons((dir.empty()) ? m_sCurrentDir : dir, exes);
5056
}
5057
}
5057
int CPackages::GetGameAddons(Utils::CStringList &exes)
5058
int CPackages::GetGameAddons(Utils::CStringList &exes)
5058
{
5059
{
5059
	return m_gameExe.GetGameAddons(m_sCurrentDir.ToString(), exes);
5060
	return m_gameExe.GetGameAddons(m_sCurrentDir, exes);
5060
}
5061
}
5061
 
5062
 
5062
Utils::String CPackages::getGameTypesString(CBaseFile *package, bool includeVersion)
5063
Utils::String CPackages::getGameTypesString(CBaseFile *package, bool includeVersion)
5063
{
5064
{
5064
	if ( !package->AnyGameCompatability() )
5065
	if ( !package->AnyGameCompatability() )
Line 5162... Line 5163...
5162
			}
5163
			}
5163
		}
5164
		}
5164
	}
5165
	}
5165
	else if ( !m_sSetMod.Empty() )
5166
	else if ( !m_sSetMod.Empty() )
5166
	{
5167
	{
5167
		if ( CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat").ExistsOld() )
5168
		if ( CFileIO::Exists(m_sCurrentDir + "/mods/" + m_sSetMod.ToString() + ".cat"))
5168
		{
5169
		{
5169
			CCatFile catFile;
5170
			CCatFile catFile;
5170
			if (catFile.open((m_sCurrentDir + ";/mods/" + m_sSetMod + ".cat").ToString(), addonDir.ToString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
5171
			if (catFile.open(m_sCurrentDir + "/mods/"; + m_sSetMod.ToString() + ".cat", addonDir.ToString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
5171
			{
5172
			{
5172
				if ( catFile.ExtractFile(aFilename, aTo) )
5173
				if ( catFile.ExtractFile(aFilename, aTo) )
5173
					return 1;
5174
					return 1;
5174
				if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR )
5175
				if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR )
5175
				{
5176
				{
Line 5678... Line 5679...
5678
 
5679
 
5679
	CDirIO Dir(m_sCurrentDir);
5680
	CDirIO Dir(m_sCurrentDir);
5680
	if ( !Dir.exists("t") )
5681
	if ( !Dir.exists("t") )
5681
		Dir.Create("t");
5682
		Dir.Create("t");
5682
 
5683
 
5683
	CyString filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5684
	Utils::String filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5684
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
5685
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
5685
 
5686
 
5686
	std::vector<CyString> writeData;
5687
	std::vector<CyString> writeData;
5687
 
5688
 
5688
	writeData.push_back(CyString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"));
5689
	writeData.push_back(CyString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"));
Line 5730... Line 5731...
5730
	if ( !Dir.exists("t") )
5731
	if ( !Dir.exists("t") )
5731
		Dir.Create("t");
5732
		Dir.Create("t");
5732
 
5733
 
5733
	m_iLastUpdated = (int)time(NULL);
5734
	m_iLastUpdated = (int)time(NULL);
5734
 
5735
 
5735
	CyString filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5736
	Utils::String filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5736
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
5737
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
5737
 
5738
 
5738
	std::vector<CyString> writeData;
5739
	std::vector<CyString> writeData;
5739
 
5740
 
5740
	CLinkList<SGameWare> lWares;
5741
	CLinkList<SGameWare> lWares;
Line 5979... Line 5980...
5979
	textFile.remove();
5980
	textFile.remove();
5980
}
5981
}
5981
 
5982
 
5982
bool CPackages::isCurrentDir(const Utils::String &dir) const
5983
bool CPackages::isCurrentDir(const Utils::String &dir) const
5983
{
5984
{
5984
	Utils::String cur = m_sCurrentDir.ToString();
5985
	Utils::String cur = m_sCurrentDir;
5985
 
5986
 
5986
	if ( dir.Compare(cur) )
5987
	if ( dir.Compare(cur) )
5987
		return true;
5988
		return true;
5988
 
5989
 
5989
	Utils::String checkDir = cur;
5990
	Utils::String checkDir = cur;
Line 6723... Line 6724...
6723
				if ( e )
6724
				if ( e )
6724
				{
6725
				{
6725
					CFileIO File((e == -1) ? (str->data + ".pck") : (m_sTempDir + "/" + str->data.ToString() + ".pck"));
6726
					CFileIO File((e == -1) ? (str->data + ".pck") : (m_sTempDir + "/" + str->data.ToString() + ".pck"));
6726
					if ( File.exists() )
6727
					if ( File.exists() )
6727
					{
6728
					{
6728
						File.Rename(m_sCurrentDir + "/" + dir + "/" + str->str + ".pck");
6729
						File.Rename(m_sCurrentDir + "/" + dir + "/" + str->str.ToString() + ".pck");
6729
						this->AddCreatedFile(dir + "/" + str->str.ToString() + ".pck");
6730
						this->AddCreatedFile(dir + "/" + str->str.ToString() + ".pck");
6730
					}
6731
					}
6731
				}
6732
				}
6732
			}
6733
			}
6733
		}
6734
		}
Line 7335... Line 7336...
7335
	}
7336
	}
7336
 
7337
 
7337
	return false;
7338
	return false;
7338
}
7339
}
7339
 
7340
 
7340
bool CPackages::UnPackFile(CyString filename, bool checkxml)
7341
bool CPackages::UnPackFile(const Utils::String &filename, bool checkxml)
7341
{
7342
{
7342
	// compress the file
7343
	// compress the file
7343
	CFileIO File(filename);
7344
	CFileIO File(filename);
7344
	size_t fileSize;
7345
	size_t fileSize;
7345
	char *fileData = File.ReadToData(&fileSize);
7346
	char *fileData = File.ReadToData(&fileSize);
Line 7392... Line 7393...
7392
 
7393
 
7393
				if ( pckFile.isOpened() )
7394
				if ( pckFile.isOpened() )
7394
					pckFile.close();
7395
					pckFile.close();
7395
 
7396
 
7396
				if ( isxml )
7397
				if ( isxml )
7397
					pckFile.Rename(pckFile.ChangeFileExtension("xml"));
7398
					pckFile.Rename(pckFile.changeFileExtension("xml"));
7398
			}
7399
			}
7399
 
7400
 
7400
			return true;
7401
			return true;
7401
		}
7402
		}
7402
	}
7403
	}
7403
 
7404
 
7404
	return false;
7405
	return false;
7405
}
7406
}
7406
 
7407
 
7407
bool CPackages::PackFile(CFileIO *File, CyString filename)
7408
bool CPackages::PackFile(CFileIO *File, CyString sFilename)
7408
{
7409
{
7409
	filename = filename.FindReplace(&quot;\\", &quot;/");
7410
	Utils::String filename = sFilename.FindReplace(&quot;\\", &quot;/").ToString();
7410
	if ( m_iGame == GAME_X3 )
7411
	if ( m_iGame == GAME_X3 )
7411
	{
7412
	{
7412
		CCatFile catFile;
7413
		CCatFile catFile;
7413
		int error = catFile.open((m_sCurrentDir + "/mods/PluginManager.cat").ToString(), this->getAddonDir(), CATREAD_CATDECRYPT, true);
7414
		int error = catFile.open(m_sCurrentDir + "/mods/PluginManager.cat", this->getAddonDir(), CATREAD_CATDECRYPT, true);
7414
		if ( error == CATERR_NONE || error == CATERR_CREATED )
7415
		if ( error == CATERR_NONE || error == CATERR_CREATED )
7415
		{
7416
		{
7416
			// it it wrote ok, remove the old ones
7417
			// it it wrote ok, remove the old ones
7417
			if ( !catFile.AppendFile(File->fullFilename(), filename.ToString(), true, true) )
7418
			if ( !catFile.AppendFile(File->fullFilename(), filename, true, true) )
7418
				return false;
7419
				return false;
7419
			return true;
7420
			return true;
7420
		}
7421
		}
7421
	}
7422
	}
7422
	else
7423
	else
Line 7941... Line 7942...
7941
			
7942
			
7942
			if (p->GetIcon())
7943
			if (p->GetIcon())
7943
			{
7944
			{
7944
				bool addedIcon = false;
7945
				bool addedIcon = false;
7945
				p->ReadIconFileToMemory();
7946
				p->ReadIconFileToMemory();
7946
				p->GetIcon()->SetFilename(this->tempDirectory().findReplace("\\", "/") + "/" + p->author() + "_" + p->name() + "." + p->GetIconExt().ToString());
7947
				p->GetIcon()->setFilename(this->tempDirectory().findReplace("\\", "/") + "/" + p->author() + "_" + p->name() + "." + p->iconExt());
7947
				p->GetIcon()->SetFullDir(this->tempDirectory());
7948
				p->GetIcon()->setFullDir(this->tempDirectory());
7948
				if (p->GetIcon()->UncompressData())
7949
				if (p->GetIcon()->UncompressData())
7949
				{
7950
				{
7950
					if (p->GetIcon()->writeFilePointer())
7951
					if (p->GetIcon()->writeFilePointer())
7951
						addedIcon = true;
7952
						addedIcon = true;
7952
				}
7953
				}
Line 8573... Line 8574...
8573
					toFile = toFile.FindReplace("\\", "/");
8574
					toFile = toFile.FindReplace("\\", "/");
8574
					toFile = toFile.FindReplace("//", "/");
8575
					toFile = toFile.FindReplace("//", "/");
8575
					if ( fromFile.Compare(toFile) )
8576
					if ( fromFile.Compare(toFile) )
8576
					{
8577
					{
8577
						if ( list )
8578
						if ( list )
8578
							list->PushBack(from->GetFilename() + "::" + str->str, to->GetFilename() + "::" + toStr->str);
8579
							list->PushBack(CyString((from->filename() + "::" + str->str.ToString(), to->filename() + "::" + toStr->str.ToString())).c_str());
8579
						else
8580
						else
8580
							return true;
8581
							return true;
8581
					}
8582
					}
8582
				}
8583
				}
8583
			}
8584
			}