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 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 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 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 633... Line 633...
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
 
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 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 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 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() + "/PluginManager/PluginManager.dat") || CFileIO::Remove(m_sCurrentDir.ToString() + "/PluginManager/PluginManager.dat") ) {
2874
		if ( !CFileIO::Exists(m_sCurrentDir + "/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 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 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 3235... Line 3235...
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 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 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();
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 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 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("\\", "/");
7410
	Utils::String filename = sFilename.FindReplace("\\", "/").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
			}