Subversion Repositories spk

Rev

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

Rev 196 Rev 197
Line 193... Line 193...
193
	}
193
	}
194
 
194
 
195
	return NULL;
195
	return NULL;
196
}
196
}
197
 
197
 
198
int CBaseFile::CheckFile(const Utils::String &filename, float *version )
198
int CBaseFile::CheckFile(const Utils::WString &filename, float *version )
199
{
199
{
200
	CFileIO File(filename);
200
	CFileIO File(filename);
201
	if ( !File.startRead() ) return 0;
201
	if ( !File.startRead() ) return 0;
202
	Utils::String line = File.readEndOfLine();
202
	Utils::String line = File.readEndOfLineStr();
203
	Utils::String type = line.token(";", 1);
203
	Utils::String type = line.token(";", 1);
204
	File.close();
204
	File.close();
205
 
205
 
206
	// check for old version
206
	// check for old version
207
	if ( line.left(3) == "HiP" ) return SPKFILE_OLD;
207
	if ( line.left(3) == "HiP" ) return SPKFILE_OLD;
Line 222... Line 222...
222
	{
222
	{
223
		f->Data()->DeleteData();
223
		f->Data()->DeleteData();
224
	}
224
	}
225
}
225
}
226
 
226
 
227
Utils::String CBaseFile::getNameValidFile() const
227
Utils::WString CBaseFile::getNameValidFile() const
228
{
228
{
229
	Utils::String name = this->name();
229
	Utils::WString name = this->name();
230
	name.removeChar(':');
230
	name.removeChar(':');
231
	name.removeChar('/');
231
	name.removeChar('/');
232
	name.removeChar('\\');
232
	name.removeChar('\\');
233
	name.removeChar('*');
233
	name.removeChar('*');
234
	name.removeChar('?');
234
	name.removeChar('?');
Line 283... Line 283...
283
	}
283
	}
284
 
284
 
285
	_addFile(file);
285
	_addFile(file);
286
}
286
}
287
 
287
 
288
C_File *CBaseFile::addFile(const Utils::String &file, const Utils::String &dir, FileType type, int game, bool packed)
288
C_File *CBaseFile::addFile(const Utils::WString &file, const Utils::WString &dir, FileType type, int game, bool packed)
289
{
289
{
290
	C_File *newfile = new C_File(file);
290
	C_File *newfile = new C_File(file);
291
	newfile->setDir(dir);
291
	newfile->setDir(dir);
292
	newfile->setFileType(type);
292
	newfile->setFileType(type);
293
	newfile->setGame(game);
293
	newfile->setGame(game);
294
 
294
 
295
	if (packed)
295
	if (packed)
296
	{
296
	{
297
		if (newfile->PCKFile())
297
		if (newfile->PCKFile())
298
		{
-
 
299
			newfile->setFilename(CFileIO(newfile->filePointer()).changeFileExtension(L"pck").toString());
298
			newfile->setFilename(CFileIO(newfile->filePointer()).changeFileExtension(L"pck"));
300
		}
-
 
301
	}
299
	}
302
 
300
 
303
	// first check if the file already exists
301
	// first check if the file already exists
304
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
302
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
305
	{
303
	{
306
		C_File *f = node->Data();
304
		C_File *f = node->Data();
307
		if ( f->fileType() != newfile->fileType() )
305
		if ( f->fileType() != newfile->fileType() )
308
			continue;
306
			continue;
309
		if ( f->name() != newfile->name () )
307
		if ( f->name() != newfile->name () )
310
			continue;
308
			continue;
311
		if ( f->dir() != newfile->dir() )
309
		if ( f->dir() != newfile->dir() )
312
			continue;
310
			continue;
313
		if (f->game() != newfile->game())
311
		if (f->game() != newfile->game())
314
		{
312
		{
315
			//same file, for different game, check if they are the same and combine them
313
			//same file, for different game, check if they are the same and combine them
Line 339... Line 337...
339
						if (data[i] != newData[i])
337
						if (data[i] != newData[i])
340
						{
338
						{
341
							matched = false;
339
							matched = false;
342
							break;
340
							break;
343
						}
341
						}
344
					}
342
					}
345
				}
343
				}
346
 
344
 
347
				if (data)
345
				if (data)
348
					delete data;
346
					delete data;
349
				if (newData)
347
				if (newData)
350
					delete newData;
348
					delete newData;
351
 
349
 
Line 359... Line 357...
359
					break;
357
					break;
360
				}
358
				}
361
			}
359
			}
362
			continue;
360
			continue;
363
		}
361
		}
364
 
362
 
365
		// must already exist, delete this one
363
		// must already exist, delete this one
366
		m_lFiles.remove(node, true);
364
		m_lFiles.remove(node, true);
367
		break;
365
		break;
368
	}
366
	}
369
 
367
 
370
	_addFile(newfile);
368
	_addFile(newfile);
371
 
369
 
372
	return newfile;
370
	return newfile;
373
}
371
}
374
 
372
 
Line 380... Line 378...
380
 
378
 
381
	// compress the file
379
	// compress the file
382
	return f->CompressData(m_SHeader2.iDataCompression, progress);
380
	return f->CompressData(m_SHeader2.iDataCompression, progress);
383
}
381
}
384
 
382
 
385
C_File *CBaseFile::appendFile(const Utils::String &file, int type, int game, bool packed, const Utils::String &dir, CProgressInfo *progress )
383
C_File *CBaseFile::appendFile(const Utils::WString &file, int type, int game, bool packed, const Utils::WString &dir, CProgressInfo *progress )
386
{
384
{
387
	C_File *newfile = addFile(file, dir, static_cast<FileType>(type), game, packed);
385
	C_File *newfile = addFile(file, dir, static_cast<FileType>(type), game, packed);
388
	if ( !newfile )
386
	if ( !newfile )
389
		return NULL;
387
		return NULL;
390
 
388
 
391
	// read the file into memory
389
	// read the file into memory
392
	if (newfile->GetData() && newfile->GetDataSize())
390
	if (newfile->GetData() && newfile->GetDataSize())
393
	{
391
	{
394
		// now compress the file
392
		// now compress the file
395
		if (newfile->CompressData(m_SHeader2.iDataCompression, progress))
393
		if (newfile->CompressData(m_SHeader2.iDataCompression, progress))
396
			return newfile;
394
			return newfile;
397
	}
395
	}
398
	if ( newfile->ReadFromFile () )
396
	if ( newfile->ReadFromFile () )
Line 429... Line 427...
429
	}
427
	}
430
 
428
 
431
	return NULL;
429
	return NULL;
432
}
430
}
433
 
431
 
434
C_File* CBaseFile::findFile(const Utils::String &filename, FileType type, const Utils::String &dir, int game) const
432
C_File* CBaseFile::findFile(const Utils::WString &filename, FileType type, const Utils::WString &dir, int game) const
435
{	
433
{	
436
	Utils::String lfile = CFileIO(filename.lower()).filename().toString();
434
	Utils::WString lfile = CFileIO(filename.lower()).filename();
437
 
435
 
438
	CListNode<C_File>* node = m_lFiles.Front();
436
	CListNode<C_File>* node = m_lFiles.Front();
439
	while (node)
437
	while (node)
440
	{
438
	{
441
		C_File* f = node->Data();
439
		C_File* f = node->Data();
Line 482... Line 480...
482
	C_File *file = m_lFiles.Get ( pos );
480
	C_File *file = m_lFiles.Get ( pos );
483
	m_lFiles.erase ( pos + 1 );
481
	m_lFiles.erase ( pos + 1 );
484
 
482
 
485
	if ( file )
483
	if ( file )
486
		delete file;
484
		delete file;
487
 
485
 
488
	_changed();
486
	_changed();
489
 
487
 
490
	return true;
488
	return true;
491
}
489
}
492
 
490
 
493
 
491
 
494
void CBaseFile::removeAllFiles(FileType type, int game)
492
void CBaseFile::removeAllFiles(FileType type, int game)
495
{
493
{
496
	if ( m_lFiles.empty() )
494
	if ( m_lFiles.empty() )
497
		return;
495
		return;
498
 
496
 
499
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
497
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
500
	{
498
	{
501
		if (game == 0 && node->Data()->game() && node->Data()->game() != GAME_ALLNEW)
499
		if (game == 0 && node->Data()->game() && node->Data()->game() != GAME_ALLNEW)
502
			continue;
500
			continue;
503
		if ( game > -1 )
501
		if ( game > -1 )
Line 527... Line 525...
527
		C_File *file = node->Data();
525
		C_File *file = node->Data();
528
		if ( progress )
526
		if ( progress )
529
			progress->UpdateFile(file);
527
			progress->UpdateFile(file);
530
 
528
 
531
		if ( file->GetCompressionType() == type )
529
		if ( file->GetCompressionType() == type )
532
			continue;
530
			continue;
533
 
531
 
534
		if ( !file->GetData() )
532
		if ( !file->GetData() )
535
			file->ReadFromFile();
533
			file->ReadFromFile();
536
 
534
 
537
		file->ChangeCompression ( type, progress );
535
		file->ChangeCompression ( type, progress );
538
	}
536
	}
Line 664... Line 662...
664
	Return: String - returns the full string for files list
662
	Return: String - returns the full string for files list
665
	Desc:   Creates a signle line list of all the files
663
	Desc:   Creates a signle line list of all the files
666
*/
664
*/
667
Utils::String CBaseFile::createFilesLine(SSPKHeader2 *header, CProgressInfo* progress) const
665
Utils::String CBaseFile::createFilesLine(SSPKHeader2 *header, CProgressInfo* progress) const
668
{
666
{
669
	Utils::String line;
667
	Utils::WString line;
670
 
668
 
671
	if (progress)
669
	if (progress)
672
	{
670
	{
673
		progress->SetDone(0);
671
		progress->SetDone(0);
674
		progress->UpdateStatus(STATUS_COMPRESS);
672
		progress->UpdateStatus(STATUS_COMPRESS);
675
	}
673
	}
676
 
674
 
677
	if (header)
675
	if (header)
Line 691... Line 689...
691
 
689
 
692
		// compress the file
690
		// compress the file
693
		if (!m_pIconFile->CompressData(m_SHeader2.iDataCompression, progress))
691
		if (!m_pIconFile->CompressData(m_SHeader2.iDataCompression, progress))
694
			m_pIconFile->SetDataCompression(SPKCOMPRESS_NONE);
692
			m_pIconFile->SetDataCompression(SPKCOMPRESS_NONE);
695
 
693
 
696
		line += "Icon:" + Utils::String::Number(m_pIconFile->GetDataSize() + (long)4) + ":" + m_pIconFile->uncompressedDataSize() + ":" + (long)m_pIconFile->GetCompressionType() + ":" + _sIconExt + "\n";
694
		line += L"Icon:" + Utils::WString::Number(m_pIconFile->GetDataSize() + (long)4) + L":" + m_pIconFile->uncompressedDataSize() + L":" + (long)m_pIconFile->GetCompressionType() + L":" + _sIconExt + L"\n";
697
		if (header)
695
		if (header)
698
		{
696
		{
699
			++header->iNumFiles;
697
			++header->iNumFiles;
700
			header->lFullSize += (m_pIconFile->GetDataSize() + 4);
698
			header->lFullSize += (m_pIconFile->GetDataSize() + 4);
701
		}
699
		}
Line 728... Line 726...
728
		{
726
		{
729
			file->SetDataCompression(SPKCOMPRESS_NONE);
727
			file->SetDataCompression(SPKCOMPRESS_NONE);
730
			file->SetUncompressedDataSize(file->GetDataSize());
728
			file->SetUncompressedDataSize(file->GetDataSize());
731
		}
729
		}
732
 
730
 
733
		Utils::String command = GetFileTypeString(file->GetFileType());
731
		Utils::WString command = GetFileTypeString(file->GetFileType());
734
		if (command.empty())
732
		if (command.empty())
735
			continue;
733
			continue;
736
 
734
 
737
		if (file->IsShared())
735
		if (file->IsShared())
738
			command = "$" + command;
736
			command = L"$" + command;
739
 
737
 
740
		if (file->dir().empty())
738
		if (file->dir().empty())
741
			line += command + ":" + (file->GetDataSize() + (long)4) + ":" + file->uncompressedDataSize() + ":" + (long)file->GetCompressionType() + ":" + (long)file->GetCreationTime() + ":" + ((file->IsCompressedToFile()) ? "1" : "0") + ":" + file->filename() + ":NULL:" + (long)file->game() + "\n";
739
			line += command + L":" + (file->GetDataSize() + (long)4) + L":" + file->uncompressedDataSize() + L":" + (long)file->GetCompressionType() + L":" + (long)file->GetCreationTime() + L":" + ((file->IsCompressedToFile()) ? L"1" : L"0") + L":" + file->filename() + L":NULL:" + (long)file->game() + L"\n";
742
		else
740
		else
743
			line += command + ":" + (file->GetDataSize() + (long)4) + ":" + file->uncompressedDataSize() + ":" + (long)file->GetCompressionType() + ":" + (long)file->GetCreationTime() + ":" + ((file->IsCompressedToFile()) ? "1" : "0") + ":" + file->filename() + ":" + file->dir() + ":" + (long)file->game() + "\n";
741
			line += command + L":" + (file->GetDataSize() + (long)4) + L":" + file->uncompressedDataSize() + L":" + (long)file->GetCompressionType() + L":" + (long)file->GetCreationTime() + L":" + ((file->IsCompressedToFile()) ? L"1" : L"0") + L":" + file->filename() + L":" + file->dir() + L":" + (long)file->game() + L"\n";
744
 
742
 
745
		if (header)
743
		if (header)
746
		{
744
		{
747
			++header->iNumFiles;
745
			++header->iNumFiles;
748
			header->lFullSize += (file->GetDataSize() + 4);
746
			header->lFullSize += (file->GetDataSize() + 4);
749
		}
747
		}
750
	}
748
	}
751
 
749
 
752
	return line;
750
	return line.toString();
753
}
751
}
754
 
752
 
755
/*
753
/*
756
######################################################################################
754
######################################################################################
757
##########							Reading Functions			    		##########
755
##########							Reading Functions			    		##########
Line 766... Line 764...
766
	// now open the file
764
	// now open the file
767
	CFileIO File(this->filename());
765
	CFileIO File(this->filename());
768
	if ( !File.startRead() ) return;
766
	if ( !File.startRead() ) return;
769
 
767
 
770
	// read the header
768
	// read the header
771
	File.readEndOfLine();
769
	File.readEndOfLineStr();
772
	// skip past values
770
	// skip past values
773
	File.seek(4 + m_SHeader.lValueCompressSize);
771
	File.seek(4 + m_SHeader.lValueCompressSize);
774
 
772
 
775
	// read the next header
773
	// read the next header
776
	File.readEndOfLine();
774
	File.readEndOfLineStr();
777
	// skip past files
775
	// skip past files
778
	File.seek(4 + m_SHeader2.lSize);
776
	File.seek(4 + m_SHeader2.lSize);
779
 
777
 
780
	if ( m_pIconFile )
778
	if ( m_pIconFile )
781
	{
779
	{
Line 829... Line 827...
829
	// now open the file
827
	// now open the file
830
	CFileIO *File = new CFileIO(this->filename());
828
	CFileIO *File = new CFileIO(this->filename());
831
	if ( !File->startRead() ) return NULL;
829
	if ( !File->startRead() ) return NULL;
832
 
830
 
833
	// read the header
831
	// read the header
834
	File->readEndOfLine();
832
	File->readEndOfLineStr();
835
	// skip past values
833
	// skip past values
836
	File->seek(4 + m_SHeader.lValueCompressSize);
834
	File->seek(4 + m_SHeader.lValueCompressSize);
837
 
835
 
838
	// read the next header
836
	// read the next header
839
	File->readEndOfLine();
837
	File->readEndOfLineStr();
840
	// skip past files
838
	// skip past files
841
	File->seek(4 + m_SHeader2.lSize);
839
	File->seek(4 + m_SHeader2.lSize);
842
 
840
 
843
	return File;
841
	return File;
844
}
842
}
Line 855... Line 853...
855
}
853
}
856
 
854
 
857
void CBaseFile::_updateTextDB(C_File *file)
855
void CBaseFile::_updateTextDB(C_File *file)
858
{
856
{
859
	if ( !_pTextDB ) _pTextDB = new CTextDB();
857
	if ( !_pTextDB ) _pTextDB = new CTextDB();
860
 
858
 
861
	if ( file->GetFileType() == FILETYPE_TEXT ) {
859
	if ( file->GetFileType() == FILETYPE_TEXT ) {
862
		Utils::WString baseFile = CFileIO(file->filePointer()).baseName();
860
		Utils::WString baseFile = CFileIO(file->filePointer()).baseName();
863
		int lang = (baseFile.contains(L"-L")) ? baseFile.right(3) : baseFile.truncate(-4);
861
		int lang = (baseFile.contains(L"-L")) ? baseFile.right(3) : baseFile.truncate(-4);
864
 
862
 
865
		// read in the text file to the database
863
		// read in the text file to the database
Line 876... Line 874...
876
		_updateTextDB(node->Data());
874
		_updateTextDB(node->Data());
877
	}
875
	}
878
}
876
}
879
 
877
 
880
void CBaseFile::ReadIconFileToMemory ()
878
void CBaseFile::ReadIconFileToMemory ()
881
{
879
{
882
	if ( !m_pIconFile )	return;
880
	if ( !m_pIconFile )	return;
883
	CFileIO *File = _startRead();
881
	CFileIO *File = _startRead();
884
	if ( !File ) return;
882
	if ( !File ) return;
885
 
883
 
886
	if ( (!m_pIconFile->GetData()) && (!m_pIconFile->Skip()) )
884
	if ( (!m_pIconFile->GetData()) && (!m_pIconFile->Skip()) )
Line 891... Line 889...
891
	delete File;
889
	delete File;
892
}
890
}
893
 
891
 
894
void CBaseFile::_install_adjustFakePatches(CPackages *pPackages)
892
void CBaseFile::_install_adjustFakePatches(CPackages *pPackages)
895
{
893
{
896
	Utils::CStringList lPatches;
894
	Utils::WStringList lPatches;
897
	int startfake = pPackages->findNextFakePatch();
895
	int startfake = pPackages->findNextFakePatch();
898
 
896
 
899
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
897
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
900
	{
898
	{
901
		C_File *fit = node->Data();
899
		C_File *fit = node->Data();
902
		// only do fake patchs
900
		// only do fake patchs
903
		if ( !fit->IsFakePatch() )
901
		if ( !fit->IsFakePatch() )
904
			continue;
902
			continue;
905
 
903
 
906
		// we should only have cat and dat files, but lets check just incase they have been added incorrectly
904
		// we should only have cat and dat files, but lets check just incase they have been added incorrectly
907
		if ( !fit->checkFileExt ("cat") && !fit->checkFileExt("dat") )
905
		if ( !fit->checkFileExt ("cat") && !fit->checkFileExt("dat") )
908
			continue;
906
			continue;
909
 
907
 
910
		// search for the name on the list
908
		// search for the name on the list
911
		Utils::String newname;
909
		Utils::WString newname;
912
		bool isOpposite = false;
910
		bool isOpposite = false;
913
		if (lPatches.contains(fit->baseName()))
911
		if (lPatches.contains(fit->baseName()))
914
		{
912
		{
915
			newname = lPatches.findString(fit->baseName());
913
			newname = lPatches.findString(fit->baseName());
916
			isOpposite = true;
914
			isOpposite = true;
917
		}
915
		}
918
		else
916
		else
919
		{
917
		{
920
			newname = Utils::String::PadNumber((long)startfake, 2);
918
			newname = Utils::WString::PadNumber((long)startfake, 2);
921
			lPatches.pushBack(fit->baseName(), newname);
919
			lPatches.pushBack(fit->baseName(), newname);
922
		}
920
		}
923
 
921
 
924
		// rename the file
922
		// rename the file
925
		fit->FixOriginalName();
923
		fit->FixOriginalName();
Line 939... Line 937...
939
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
937
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
940
		C_File *fit = node->Data();
938
		C_File *fit = node->Data();
941
		if ( !fit->isAutoTextFile() )
939
		if ( !fit->isAutoTextFile() )
942
			continue;
940
			continue;
943
 
941
 
944
		Utils::String newname = SPK::FormatTextName(starttext, pPackages->GetLanguage(), (pPackages->GetCurrentGameFlags() & EXEFLAG_TCTEXT));
942
		Utils::WString newname = SPK::FormatTextName(starttext, pPackages->GetLanguage(), (pPackages->GetCurrentGameFlags() & EXEFLAG_TCTEXT));
945
		fit->FixOriginalName();
943
		fit->FixOriginalName();
946
		CLog::logf(CLog::Log_Install, 2, "Adjusting text file, %s => %s", fit->getNameDirectory(this).c_str(), (newname + "." + fit->fileExt()).c_str());
944
		CLog::logf(CLog::Log_Install, 2, "Adjusting text file, %s => %s", fit->getNameDirectory(this).c_str(), (newname + "." + fit->fileExt()).c_str());
947
		fit->setName(newname + "." + fit->fileExt());
945
		fit->setName(newname + "." + fit->fileExt());
948
 
946
 
949
		++starttext;
947
		++starttext;
Line 965... Line 963...
965
	}
963
	}
966
 
964
 
967
	return bEnable;
965
	return bEnable;
968
}
966
}
969
 
967
 
970
bool CBaseFile::_install_uncompress(C_File *fit, CProgressInfo *progress, Utils::CStringList *errorStr, bool *uncomprToFile)
968
bool CBaseFile::_install_uncompress(C_File *fit, CProgressInfo *progress, Utils::WStringList *errorStr, bool *uncomprToFile)
971
{
969
{
972
	*uncomprToFile = false;
970
	*uncomprToFile = false;
973
	_sLastError = fit->getNameDirectory(this);
971
	_sLastError = fit->getNameDirectory(this);
974
	_iLastError = SPKERR_UNCOMPRESS;
972
	_iLastError = SPKERR_UNCOMPRESS;
975
 
973
 
976
	if ( !fit->UncompressData ( progress ) )
974
	if ( !fit->UncompressData ( progress ) )
977
	{
975
	{
978
		CLog::log(CLog::Log_Install, 2, "Failed to uncompress data, attempting file decompression");
976
		CLog::log(CLog::Log_Install, 2, "Failed to uncompress data, attempting file decompression");
979
		if ( fit->GetCompressionType() == SPKCOMPRESS_7ZIP )
977
		if ( fit->GetCompressionType() == SPKCOMPRESS_7ZIP )
980
		{
978
		{
981
			if ( fit->uncompressToFile(Utils::String::Null(), this, false, progress ) )
979
			if ( fit->uncompressToFile(Utils::WString::Null(), this, false, progress ) )
982
				*uncomprToFile = true;
980
				*uncomprToFile = true;
983
		}
981
		}
984
 
982
 
985
		if ( !uncomprToFile )
983
		if ( !uncomprToFile )
986
		{
984
		{
Line 993... Line 991...
993
	ClearError ();
991
	ClearError ();
994
 
992
 
995
	return true;
993
	return true;
996
}
994
}
997
 
995
 
998
bool CBaseFile::_install_checkVersion(C_File *pFile, const Utils::String &sDestination)
996
bool CBaseFile::_install_checkVersion(C_File *pFile, const Utils::WString &sDestination)
999
{
997
{
1000
	// new check if we should install the file
998
	// new check if we should install the file
1001
	// first get the version
999
	// first get the version
1002
	if ( !m_bOverrideFiles && pFile->ReadScriptVersion() )
1000
	if ( !m_bOverrideFiles && pFile->ReadScriptVersion() )
1003
	{
1001
	{
1004
		CLog::log(CLog::Log_Install, 2, "Checking for existing file version");
1002
		CLog::log(CLog::Log_Install, 2, "Checking for existing file version");
1005
		C_File checkfile;
1003
		C_File checkfile;
1006
		Utils::String checkfilename = sDestination;
1004
		Utils::WString checkfilename = sDestination;
1007
		if ( !checkfilename.empty() ) checkfilename += "/";
1005
		if ( !checkfilename.empty() ) checkfilename += L"/";
1008
		checkfilename += pFile->getNameDirectory(this);
1006
		checkfilename += pFile->getNameDirectory(this);
1009
		checkfile.setFilename(checkfilename);
1007
		checkfile.setFilename(checkfilename);
1010
		checkfile.setFileType(pFile->fileType());
1008
		checkfile.setFileType(pFile->fileType());
1011
		if ( checkfile.CheckValidFilePointer() ) {
1009
		if ( checkfile.CheckValidFilePointer() ) {
1012
			if ( checkfile.ReadScriptVersion() > pFile->GetVersion() ) {
1010
			if ( checkfile.ReadScriptVersion() > pFile->GetVersion() ) {
Line 1017... Line 1015...
1017
	}
1015
	}
1018
 
1016
 
1019
	return true;
1017
	return true;
1020
}
1018
}
1021
 
1019
 
1022
Utils::String CBaseFile::_install_adjustFilepointer(C_File *pFile, bool bEnabled, const Utils::String &sDestination)
1020
Utils::String CBaseFile::_install_adjustFilepointer(C_File *pFile, bool bEnabled, const Utils::WString &sDestination)
1023
{
1021
{
1024
	Utils::String filename = sDestination;
1022
	Utils::WString filename = sDestination;
1025
	if ( !filename.empty() ) filename += "/";
1023
	if ( !filename.empty() ) filename += L"/";
1026
 
1024
 
1027
	if ( (IsPatch()) && (pFile->fileType() == FILETYPE_MOD) )
1025
	if ( (IsPatch()) && (pFile->fileType() == FILETYPE_MOD) )
1028
		pFile->setDir("Patch");
1026
		pFile->setDir(L"Patch");
1029
 
1027
 
1030
	if ( pFile->isInMod() )
1028
	if ( pFile->isInMod() )
1031
	{
1029
	{
1032
		if ( bEnabled )
1030
		if ( bEnabled )
1033
			pFile->setFilename(filename + pFile->getInMod() + "::" + pFile->getNameDirectory(this));
1031
			pFile->setFilename(filename + pFile->getInMod() + L"::" + pFile->getNameDirectory(this));
1034
		else
1032
		else
1035
			pFile->setFilename(filename + "PluginManager/DisabledFiles.cat::" + pFile->getNameDirectory(this));
1033
			pFile->setFilename(filename + L"PluginManager/DisabledFiles.cat::" + pFile->getNameDirectory(this));
1036
	}
1034
	}
1037
	else
1035
	else
1038
		pFile->setFilename ( filename + pFile->getNameDirectory(this) );
1036
		pFile->setFilename ( filename + pFile->getNameDirectory(this) );
1039
 
1037
 
1040
	if ( !bEnabled )
1038
	if ( !bEnabled )
1041
	{
1039
	{
1042
		if ( !pFile->isInMod() )
1040
		if ( !pFile->isInMod() )
1043
		{
1041
		{
1044
			if ( pFile->IsFakePatch() )
1042
			if ( pFile->IsFakePatch() )
1045
				pFile->setFilename ( filename + "PluginManager/Disabled/FakePatches/FakePatch_" + this->getNameValidFile() + "_" + this->author() + "_&quot; + pFile->name() );
1043
				pFile->setFilename ( filename + L"PluginManager/Disabled/FakePatches/FakePatch_" + this->getNameValidFile() + L"_" + this->author().toWString() + L"_&quot; + pFile->name());
1046
			else if ( pFile->isAutoTextFile() )
1044
			else if ( pFile->isAutoTextFile() )
1047
				pFile->setFilename ( filename + "PluginManager/Disabled/TextFiles/Text_" + this->getNameValidFile() + "_" + this->author() + "_&quot; + pFile->name() );
1045
				pFile->setFilename ( filename + L"PluginManager/Disabled/TextFiles/Text_" + this->getNameValidFile() + L"_" + this->author().toWString() + L"_&quot; + pFile->name());
1048
			else
1046
			else
1049
				pFile->setFullDir ( filename + "PluginManager/Disabled/" + pFile->getDirectory(this) );
1047
				pFile->setFullDir ( filename + L"PluginManager/Disabled/" + pFile->getDirectory(this) );
1050
		}
1048
		}
1051
		pFile->SetDisabled(true);
1049
		pFile->SetDisabled(true);
1052
	}
1050
	}
1053
 
1051
 
1054
	CLog::logf(CLog::Log_Install, 2, "Adjusting the file pointer to correct install destintation, %s", pFile->filePointer().c_str());
1052
	CLog::logf(CLog::Log_Install, 2, "Adjusting the file pointer to correct install destintation, %s", pFile->filePointer().c_str());
1055
 
1053
 
1056
	return filename;
1054
	return filename.toString();
1057
}
1055
}
1058
 
1056
 
1059
C_File *CBaseFile::_install_checkFile(C_File *pFile, Utils::CStringList *errorStr, bool *bDoFile, CLinkList<C_File> *pFileList)
1057
C_File *CBaseFile::_install_checkFile(C_File *pFile, Utils::WStringList *errorStr, bool *bDoFile, CLinkList<C_File> *pFileList)
1060
{
1058
{
1061
	if ( !pFile->IsFakePatch() && pFile->GetFileType() != FILETYPE_README )
1059
	if ( !pFile->IsFakePatch() && pFile->GetFileType() != FILETYPE_README )
1062
	{
1060
	{
1063
		C_File *cFile;
1061
		C_File *cFile;
1064
		for ( cFile = pFileList->First(); cFile; cFile = pFileList->Next() )
1062
		for ( cFile = pFileList->First(); cFile; cFile = pFileList->Next() )
Line 1076... Line 1074...
1076
	}
1074
	}
1077
 
1075
 
1078
	return NULL;
1076
	return NULL;
1079
}
1077
}
1080
 
1078
 
1081
bool CBaseFile::_install_checkFileEnable(C_File *pCheckFile, C_File *fit, const Utils::String &sDestination, bool bEnabled, Utils::CStringList *errorStr)
1079
bool CBaseFile::_install_checkFileEnable(C_File *pCheckFile, C_File *fit, const Utils::WString &sDestination, bool bEnabled, Utils::WStringList *errorStr)
1082
{
1080
{
1083
	// found a file, check if its in the disabled directory
1081
	// found a file, check if its in the disabled directory
1084
	Utils::WString dir = CFileIO(pCheckFile->filePointer()).dir();
1082
	Utils::WString dir = CFileIO(pCheckFile->filePointer()).dir();
1085
	Utils::WString lastDir = CDirIO(dir).topDir().lower();
1083
	Utils::WString lastDir = CDirIO(dir).topDir().lower();
1086
 
1084
 
Line 1088... Line 1086...
1088
	if ( ((pCheckFile->IsDisabled()) || (lastDir == L"disabled") || (dir.lower().contains(L"/disabled/"))) && (bEnabled) )
1086
	if ( ((pCheckFile->IsDisabled()) || (lastDir == L"disabled") || (dir.lower().contains(L"/disabled/"))) && (bEnabled) )
1089
	{
1087
	{
1090
		CLog::logf(CLog::Log_Install, 2, "Existing file, %s, is disabled, re-enabling it", pCheckFile->filePointer().c_str());
1088
		CLog::logf(CLog::Log_Install, 2, "Existing file, %s, is disabled, re-enabling it", pCheckFile->filePointer().c_str());
1091
		// first check if the directory exists
1089
		// first check if the directory exists
1092
		if ( pCheckFile->isInMod() ) {
1090
		if ( pCheckFile->isInMod() ) {
1093
			Utils::String tofile = pCheckFile->filePointer().token("::", 2);
1091
			Utils::WString tofile = pCheckFile->filePointer().token(L"::", 2);
1094
 
1092
 
1095
			CCatFile tocat;
1093
			CCatFile tocat;
1096
			int err = tocat.open(fit->filePointer().token("::", 1), "", CATREAD_CATDECRYPT, true);
1094
			int err = tocat.open(fit->filePointer().token(L"::", 1), L"", CATREAD_CATDECRYPT, true);
1097
			if ( (err == CATERR_NONE) || (err == CATERR_CREATED) ) {
1095
			if ( (err == CATERR_NONE) || (err == CATERR_CREATED) ) {
1098
				tocat.appendFile(pCheckFile->filePointer(), tofile);
1096
				tocat.appendFile(pCheckFile->filePointer(), tofile);
1099
				CLog::logf(CLog::Log_Install, 2, "Adding existing file into new mod File, %s => %s", fit->filePointer().token("::", 1).c_str(), tofile.c_str());
1097
				CLog::logf(CLog::Log_Install, 2, "Adding existing file into new mod File, %s => %s", fit->filePointer().token(L"::", 1).c_str(), tofile.c_str());
1100
			}
1098
			}
1101
 
1099
 
1102
			CCatFile fromcat;
1100
			CCatFile fromcat;
1103
			err = fromcat.open(pCheckFile->filePointer().token("::", 1), "", CATREAD_CATDECRYPT, false);
1101
			err = fromcat.open(pCheckFile->filePointer().token(L"::", 1), L"", CATREAD_CATDECRYPT, false);
1104
			if ( err == CATERR_NONE ) {
1102
			if ( err == CATERR_NONE ) {
1105
				fromcat.removeFile(tofile);
1103
				fromcat.removeFile(tofile);
1106
				CLog::logf(CLog::Log_Install, 2, "Removing file from existing mod, %s::%s", pCheckFile->filePointer().token("::", 1).c_str(), tofile.c_str());
1104
				CLog::logf(CLog::Log_Install, 2, "Removing file from existing mod, %s::%s", pCheckFile->filePointer().token(L"::", 1).c_str(), tofile.c_str());
1107
			}
1105
			}
1108
 
1106
 
1109
			CLog::logf(CLog::Log_Install, 1, "Adjusting existing file name %s => %s", pCheckFile->filePointer().c_str(), fit->filePointer().c_str());
1107
			CLog::logf(CLog::Log_Install, 1, "Adjusting existing file name %s => %s", pCheckFile->filePointer().c_str(), fit->filePointer().c_str());
1110
			pCheckFile->setFilename(fit->filePointer());
1108
			pCheckFile->setFilename(fit->filePointer());
1111
			CLog::logf(CLog::Log_Install, 2, "Adjusting In Mod setting, %s => %s", pCheckFile->getInMod().c_str(), fit->getInMod().c_str());
1109
			CLog::logf(CLog::Log_Install, 2, "Adjusting In Mod setting, %s => %s", pCheckFile->getInMod().c_str(), fit->getInMod().c_str());
1112
			pCheckFile->setInMod(fit->getInMod());
1110
			pCheckFile->setInMod(fit->getInMod());
1113
		}
1111
		}
1114
		else {
1112
		else {
1115
			Utils::String to = pCheckFile->getDirectory(this);
1113
			Utils::WString to = pCheckFile->getDirectory(this);
1116
			CDirIO Dir(sDestination);
1114
			CDirIO Dir(sDestination);
1117
			if ( !Dir.exists(to) ) {
1115
			if ( !Dir.exists(to) ) {
1118
				if ( !Dir.create ( to ) ) {
1116
				if ( !Dir.create ( to ) ) {
1119
					if ( errorStr )	errorStr->pushBack(to, ERRORLOG(SPKINSTALL_CREATEDIRECTORY_FAIL));
1117
					if ( errorStr )	errorStr->pushBack(to.toString(), ERRORLOG(SPKINSTALL_CREATEDIRECTORY_FAIL));
1120
					return false;
1118
					return false;
1121
				}
1119
				}
1122
				if ( errorStr )	errorStr->pushBack(to, ERRORLOG(SPKINSTALL_CREATEDIRECTORY));
1120
				if ( errorStr )	errorStr->pushBack(to.toString(), ERRORLOG(SPKINSTALL_CREATEDIRECTORY));
1123
			}
1121
			}
1124
 
1122
 
1125
			Utils::String destfile = sDestination + "/" + pCheckFile->getNameDirectory(this);
1123
			Utils::WString destfile = sDestination + L"/" + pCheckFile->getNameDirectory(this);
1126
			if ( CFileIO(destfile).ExistsOld() ) CFileIO::Remove(destfile);
1124
			if ( CFileIO::Exists(destfile) ) CFileIO::Remove(destfile);
1127
			CLog::logf(CLog::Log_Install, 1, "Adjusting existing filename, %s => %s", pCheckFile->filePointer().c_str(), destfile.c_str());
1125
			CLog::logf(CLog::Log_Install, 1, "Adjusting existing filename, %s => %s", pCheckFile->filePointer().c_str(), destfile.c_str());
1128
			rename ( pCheckFile->filePointer().c_str(), destfile.c_str() );
1126
			CFileIO::Rename(pCheckFile->filePointer(), destfile);
1129
			pCheckFile->setFilename (sDestination + "/" + pCheckFile->getNameDirectory(this) );
1127
			pCheckFile->setFilename (sDestination + L"/" + pCheckFile->getNameDirectory(this) );
1130
		}
1128
		}
1131
		pCheckFile->SetDisabled(false);
1129
		pCheckFile->SetDisabled(false);
1132
 
1130
 
1133
		if ( errorStr ) errorStr->pushBack(pCheckFile->getNameDirectory(this), ERRORLOG(SPKINSTALL_ENABLEFILE));
1131
		if ( errorStr ) errorStr->pushBack(pCheckFile->getNameDirectory(this), ERRORLOG(SPKINSTALL_ENABLEFILE));
1134
	}
1132
	}
1135
 
1133
 
1136
	return true;
1134
	return true;
1137
}
1135
}
1138
 
1136
 
1139
bool CBaseFile::_install_createDirectory(CDirIO &Dir, const Utils::String &sTo, C_File *pFile, Utils::CStringList *errorStr)
1137
bool CBaseFile::_install_createDirectory(CDirIO &Dir, const Utils::WString &sTo, C_File *pFile, Utils::WStringList *errorStr)
1140
{
1138
{
1141
	_sLastError = sTo;
1139
	_sLastError = sTo;
1142
	if ( !sTo.contains( "::" ) )
1140
	if ( !sTo.contains(L"::"))
1143
	{
1141
	{
1144
		if ( !Dir.exists(sTo) )
1142
		if ( !Dir.exists(sTo) )
1145
		{
1143
		{
1146
			CLog::logf(CLog::Log_Install, 2, "Creating directory to install file into, %s", sTo.c_str());
1144
			CLog::logf(CLog::Log_Install, 2, "Creating directory to install file into, %s", sTo.c_str());
1147
			if ( !Dir.create(sTo) )
1145
			if ( !Dir.create(sTo) )
Line 1160... Line 1158...
1160
	}
1158
	}
1161
 
1159
 
1162
	return true;
1160
	return true;
1163
}
1161
}
1164
 
1162
 
1165
void CBaseFile::_install_writeFile(C_File *pFile, const Utils::String &sDestination, Utils::CStringList *errorStr)
1163
void CBaseFile::_install_writeFile(C_File *pFile, const Utils::WString &sDestination, Utils::WStringList *errorStr)
1166
{
1164
{
1167
	_iLastError = SPKERR_WRITEFILE;
1165
	_iLastError = SPKERR_WRITEFILE;
1168
	_sLastError = pFile->filePointer();
1166
	_sLastError = pFile->filePointer();
1169
	Utils::String sInstalledFile = pFile->getNameDirectory(this);
1167
	Utils::WString sInstalledFile = pFile->getNameDirectory(this);
1170
	if ( pFile->IsDisabled() )
1168
	if ( pFile->IsDisabled() )
1171
	{
1169
	{
1172
		sInstalledFile = pFile->filePointer().findRemove(sDestination);
1170
		sInstalledFile = pFile->filePointer().findRemove(sDestination);
1173
		if ( sInstalledFile[0] == '/' || sInstalledFile[0] == '\\' )
1171
		if ( sInstalledFile[0] == '/' || sInstalledFile[0] == '\\' )
1174
			sInstalledFile.erase(0, 1);
1172
			sInstalledFile.erase(0, 1);
Line 1197... Line 1195...
1197
				break;
1195
				break;
1198
		}
1196
		}
1199
	}
1197
	}
1200
}
1198
}
1201
 
1199
 
1202
bool CBaseFile::installFiles(const Utils::String &destdir, CProgressInfo *progress, CLinkList<C_File> *filelist, Utils::CStringList *errorStr, bool enabled, CPackages *packages )
1200
bool CBaseFile::installFiles(const Utils::WString &destdir, CProgressInfo *progress, CLinkList<C_File> *filelist, Utils::WStringList *errorStr, bool enabled, CPackages *packages )
1203
{
1201
{
1204
	//TODO: add errorStr and progress as member variables
1202
	//TODO: add errorStr and progress as member variables
1205
	if ( enabled ) {
1203
	if ( enabled ) {
1206
		this->_install_adjustFakePatches(packages);
1204
		this->_install_adjustFakePatches(packages);
1207
		if ( packages ) this->_install_renameText(packages);
1205
		if ( packages ) this->_install_renameText(packages);
Line 1243... Line 1241...
1243
		}
1241
		}
1244
 
1242
 
1245
		bool dofile = _install_checkVersion(fit, destdir);
1243
		bool dofile = _install_checkVersion(fit, destdir);
1246
 
1244
 
1247
		// change file pointer
1245
		// change file pointer
1248
		Utils::String sInstallDir = _install_adjustFilepointer(fit, fileEnabled, destdir);
1246
		Utils::WString sInstallDir = _install_adjustFilepointer(fit, fileEnabled, destdir);
1249
 
1247
 
1250
		C_File *adjustPointer = NULL;
1248
		C_File *adjustPointer = NULL;
1251
 
1249
 
1252
		if ( filelist ) {
1250
		if ( filelist ) {
1253
			C_File *cFile = _install_checkFile(fit, errorStr, &dofile, filelist);
1251
			C_File *cFile = _install_checkFile(fit, errorStr, &dofile, filelist);
Line 1299... Line 1297...
1299
		{
1297
		{
1300
			// uncompressed to file, rename and move
1298
			// uncompressed to file, rename and move
1301
			if ( uncomprToFile )
1299
			if ( uncomprToFile )
1302
			{
1300
			{
1303
				_iLastError = SPKERR_WRITEFILE;
1301
				_iLastError = SPKERR_WRITEFILE;
1304
				Utils::String to = fit->getDirectory(this);
1302
				Utils::WString to = fit->getDirectory(this);
1305
				if ( !fileEnabled )	to = "PluginManager/Disabled/" + to;
1303
				if ( !fileEnabled )	to = L"PluginManager/Disabled/" + to;
1306
 
1304
 
1307
				if ( !_install_createDirectory(Dir, to, fit, errorStr) ) {
1305
				if ( !_install_createDirectory(Dir, to, fit, errorStr) ) {
1308
					bFailed = true;
1306
					bFailed = true;
1309
					continue;
1307
					continue;
1310
				}
1308
				}
1311
 
1309
 
1312
				int err = 1;
1310
				bool err = true;
1313
				_sLastError = to;
1311
				_sLastError = to;
-
 
1312
				if ( !fit->getTempFile().empty())
1314
				if ( !fit->getTempFile().empty())	err = rename ( fit->getTempFile().c_str(), to.c_str() );
1313
					err = CFileIO::Rename(fit->getTempFile(), to);
1315
				if ( err ) {
1314
				if ( err ) {
1316
					bFailed = true;
1315
					bFailed = true;
1317
					continue;
1316
					continue;
1318
				}
1317
				}
1319
			}
1318
			}
Line 1324... Line 1323...
1324
				if ( (filelist) && (adjustPointer) ) {
1323
				if ( (filelist) && (adjustPointer) ) {
1325
					adjustPointer->CopyData(fit, false);
1324
					adjustPointer->CopyData(fit, false);
1326
					CLog::log(CLog::Log_Install, 2, "Copying data into existing file");
1325
					CLog::log(CLog::Log_Install, 2, "Copying data into existing file");
1327
				}
1326
				}
1328
 
1327
 
1329
				Utils::String fpointer = fit->filePointer();
1328
				Utils::WString fpointer = fit->filePointer();
1330
				_iLastError = SPKERR_CREATEDIRECTORY;
1329
				_iLastError = SPKERR_CREATEDIRECTORY;
1331
				Utils::String dir = CFileIO(fit->filePointer()).dir().toString();
1330
				Utils::WString dir = CFileIO(fit->filePointer()).dir().toString();
1332
 
1331
 
1333
				dir = dir.findRemove(destdir);
1332
				dir = dir.findRemove(destdir);
1334
				if (!dir.empty() && (dir[0] == '/' || dir[0] == '\\')) 
1333
				if (!dir.empty() && (dir[0] == '/' || dir[0] == '\\')) 
1335
					dir.erase(0, 1);
1334
					dir.erase(0, 1);
1336
 
1335
 
Line 1427... Line 1426...
1427
	if ( first.Compare("Name:") )					this->setName(rest);
1426
	if ( first.Compare("Name:") )					this->setName(rest);
1428
	else if ( first.Compare("Author:") )			this->setAuthor(rest);
1427
	else if ( first.Compare("Author:") )			this->setAuthor(rest);
1429
	else if ( first.Compare("Version:") )			this->setVersion(rest);
1428
	else if ( first.Compare("Version:") )			this->setVersion(rest);
1430
	else if ( first.Compare("fGameVersion:") ) {
1429
	else if ( first.Compare("fGameVersion:") ) {
1431
		if ( m_lGames.Back() ) {
1430
		if ( m_lGames.Back() ) {
1432
			m_lGames.Back()->Data()->sVersion = rest;
1431
			m_lGames.Back()->Data()->sVersion = rest.toWString();
1433
		}
1432
		}
1434
	}
1433
	}
1435
	else if ( first.Compare("GameVersion:") ) {
1434
	else if ( first.Compare("GameVersion:") ) {
1436
		if ( m_lGames.Back() ) {
1435
		if ( m_lGames.Back() ) {
1437
			m_lGames.Back()->Data()->iVersion = rest;
1436
			m_lGames.Back()->Data()->iVersion = rest.toInt();
1438
		}
1437
		}
1439
	}
1438
	}
1440
	else if ( first.Compare("Game:") )
1439
	else if ( first.Compare("Game:") )
1441
		this->AddGameCompatability(rest, "");
1440
		this->AddGameCompatability(rest, "");
1442
	else if ( first.Compare("GameCompat:") )
1441
	else if ( first.Compare("GameCompat:") )
Line 1522... Line 1521...
1522
	long usize = line.token(":", 3).toInt ();
1521
	long usize = line.token(":", 3).toInt ();
1523
	long compression = line.token(":", 4).toInt ();
1522
	long compression = line.token(":", 4).toInt ();
1524
 
1523
 
1525
	if ( command == "Icon" )
1524
	if ( command == "Icon" )
1526
	{
1525
	{
1527
		_sIconExt = line.token (":", 5);
1526
		_sIconExt = line.token(":", 5).toWString();
1528
		m_pIconFile = new C_File ();
1527
		m_pIconFile = new C_File ();
1529
		m_pIconFile->SetDataSize ( size - 4 );
1528
		m_pIconFile->SetDataSize ( size - 4 );
1530
		m_pIconFile->SetDataCompression ( compression );
1529
		m_pIconFile->SetDataCompression ( compression );
1531
		m_pIconFile->SetUncompressedDataSize ( usize );
1530
		m_pIconFile->SetUncompressedDataSize ( usize );
1532
 
1531
 
Line 1784... Line 1783...
1784
bool CBaseFile::readFile(CFileIO &File, int readtype, CProgressInfo *progress)
1783
bool CBaseFile::readFile(CFileIO &File, int readtype, CProgressInfo *progress)
1785
{
1784
{
1786
	ClearError ();
1785
	ClearError ();
1787
 
1786
 
1788
	// first read the header
1787
	// first read the header
1789
	if ( !_parseHeader(File.readEndOfLine()) ) return false;
1788
	if ( !_parseHeader(File.readEndOfLineStr()) ) return false;
1790
	if ( readtype == SPKREAD_HEADER ) return true;
1789
	if ( readtype == SPKREAD_HEADER ) return true;
1791
 
1790
 
1792
	// update the progress for each section
1791
	// update the progress for each section
1793
	int maxProgress = (readtype == SPKREAD_VALUES) ? 3 : 6;
1792
	int maxProgress = (readtype == SPKREAD_VALUES) ? 3 : 6;
1794
	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(1, maxProgress);
1793
	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(1, maxProgress);
Line 1800... Line 1799...
1800
	// update the progress for each section
1799
	// update the progress for each section
1801
	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(3, maxProgress);
1800
	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(3, maxProgress);
1802
	if ( readtype == SPKREAD_VALUES ) return true;
1801
	if ( readtype == SPKREAD_VALUES ) return true;
1803
 
1802
 
1804
	// next should be the next header
1803
	// next should be the next header
1805
	if ( !_parseFileHeader(File.readEndOfLine()) ) return false;
1804
	if ( !_parseFileHeader(File.readEndOfLineStr()) ) return false;
1806
 
1805
 
1807
	// clear the current file list
1806
	// clear the current file list
1808
	m_lFiles.clear(true);
1807
	m_lFiles.clear(true);
1809
	if ( _pTextDB ) {
1808
	if ( _pTextDB ) {
1810
		delete _pTextDB;
1809
		delete _pTextDB;
Line 1828... Line 1827...
1828
	if ( readtype != SPKREAD_ALL && progress )	progress->UpdateProgress(6, maxProgress);
1827
	if ( readtype != SPKREAD_ALL && progress )	progress->UpdateProgress(6, maxProgress);
1829
 
1828
 
1830
	if ( readtype == SPKREAD_ALL ) {
1829
	if ( readtype == SPKREAD_ALL ) {
1831
		int fileCount = 2;
1830
		int fileCount = 2;
1832
		if ( m_pIconFile ) m_pIconFile->readFromFile(File, m_pIconFile->GetDataSize());
1831
		if ( m_pIconFile ) m_pIconFile->readFromFile(File, m_pIconFile->GetDataSize());
1833
 
1832
 
1834
		// ok finally we need to read all the file
1833
		// ok finally we need to read all the file
1835
		for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
1834
		for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
1836
			node->Data()->readFromFile(File, node->Data()->GetDataSize());
1835
			node->Data()->readFromFile(File, node->Data()->GetDataSize());
1837
			if ( progress )	progress->UpdateProgress(fileCount++, m_lFiles.size() + 2);
1836
			if ( progress )	progress->UpdateProgress(fileCount++, m_lFiles.size() + 2);
1838
		}
1837
		}
1839
 
1838
 
1840
		m_bFullyLoaded = true;
1839
		m_bFullyLoaded = true;
1841
	}
1840
	}
1842
 
1841
 
1843
	return true;
1842
	return true;
1844
}
1843
}
1845
 
1844
 
1846
bool CBaseFile::IsMod()
1845
bool CBaseFile::IsMod()
1847
{
1846
{
1848
	// check for any mod files that are not fake patchs
1847
	// check for any mod files that are not fake patchs
1849
	for ( CListNode<C_File> *fNode = m_lFiles.Front(); fNode; fNode = fNode->next() )
1848
	for ( CListNode<C_File> *fNode = m_lFiles.Front(); fNode; fNode = fNode->next() )
1850
	{
1849
	{
1851
		C_File *f = fNode->Data();
1850
		C_File *f = fNode->Data();
1852
		if ( f->GetFileType() != FILETYPE_MOD )
1851
		if ( f->GetFileType() != FILETYPE_MOD )
1853
			continue;
1852
			continue;
1854
 
1853
 
1855
		if ( !f->IsFakePatch() )
1854
		if ( !f->IsFakePatch() )
1856
			return true;
1855
			return true;
1857
	}
1856
	}
1858
 
1857
 
1859
	return false;
1858
	return false;
1860
}
1859
}
1861
 
1860
 
1862
bool CBaseFile::IsFakePatch() const
1861
bool CBaseFile::IsFakePatch() const
1863
{
1862
{
1864
	// check for any mod files that are not fake patchs
1863
	// check for any mod files that are not fake patchs
1865
	for ( CListNode<C_File> *fNode = m_lFiles.Front(); fNode; fNode = fNode->next() )
1864
	for ( CListNode<C_File> *fNode = m_lFiles.Front(); fNode; fNode = fNode->next() )
1866
	{
1865
	{
Line 1874... Line 1873...
1874
 
1873
 
1875
	return false;
1874
	return false;
1876
}
1875
}
1877
 
1876
 
1878
Utils::String CBaseFile::createValuesLine () const
1877
Utils::String CBaseFile::createValuesLine () const
1879
{
1878
{
1880
	Utils::String values("Name: ");
1879
	Utils::String values("Name: ");
1881
	values += this->name() + "\n";
1880
	values += this->name() + "\n";
1882
	values += "Author: " + this->author() + "\n";
1881
	values += "Author: " + this->author() + "\n";
1883
	values += "Version: " + this->version() + "\n";
1882
	values += "Version: " + this->version() + "\n";
1884
	if ( !this->creationDate().empty() )values += "Date: "			+ this->creationDate()	+ "\n";
1883
	if ( !this->creationDate().empty() )values += "Date: "			+ this->creationDate()	+ "\n";
Line 1897... Line 1896...
1897
		values += "Desc: " + desc + "\n";
1896
		values += "Desc: " + desc + "\n";
1898
	}
1897
	}
1899
 
1898
 
1900
	for ( CListNode<SGameCompat> *gc = m_lGames.Front(); gc; gc = gc->next() ) {
1899
	for ( CListNode<SGameCompat> *gc = m_lGames.Front(); gc; gc = gc->next() ) {
1901
		if ( !gc->Data()->sVersion.empty() )
1900
		if ( !gc->Data()->sVersion.empty() )
1902
			values += Utils::String("GameCompatExact: ") + (long)gc->Data()->iGame + " " + gc->Data()->sVersion + "\n";
1901
			values += Utils::String("GameCompatExact: ") + (long)gc->Data()->iGame + " " + gc->Data()->sVersion.toString() + "\n";
1903
		else
1902
		else
1904
			values += Utils::String("GameCompat: ") + (long)gc->Data()->iGame + " " + (long)gc->Data()->iVersion + "\n";
1903
			values += Utils::String("GameCompat: ") + (long)gc->Data()->iGame + " " + (long)gc->Data()->iVersion + "\n";
1905
	}
1904
	}
1906
 
1905
 
1907
	if (computeSigned(true))
1906
	if (computeSigned(true))
Line 2097... Line 2096...
2097
 
2096
 
2098
	return true;
2097
	return true;
2099
}
2098
}
2100
 
2099
 
2101
bool CBaseFile::extractFile(C_File *file, const Utils::String &dir, bool includedir, CProgressInfo *progress)
2100
bool CBaseFile::extractFile(C_File *file, const Utils::String &dir, bool includedir, CProgressInfo *progress)
2102
{
2101
{
2103
	if (ReadFileToMemory(file))
2102
	if (ReadFileToMemory(file))
2104
	{
2103
	{
2105
		// now finally, uncompress the file
2104
		// now finally, uncompress the file
2106
		long len = 0;
2105
		long len = 0;
2107
		unsigned char *data = file->UncompressData(&len, progress);
2106
		unsigned char *data = file->UncompressData(&len, progress);
2108
		if (!data)
2107
		if (!data)
2109
		{
2108
		{
2110
			// attempt a file decompress
2109
			// attempt a file decompress
2111
			if (file->GetCompressionType() == SPKCOMPRESS_7ZIP)
2110
			if (file->GetCompressionType() == SPKCOMPRESS_7ZIP)
2112
			{
2111
			{
2113
				if (file->uncompressToFile(dir, this, includedir, progress))
2112
				if (file->uncompressToFile(dir, this, includedir, progress))
2114
					return true;
2113
					return true;
2115
			}
2114
			}
2116
			return false;
2115
			return false;
2117
		}
2116
		}
2118
 
2117
 
2119
		if (!file->writeToDir(dir, this, includedir, Utils::String::Null(), data, len))
2118
		if (!file->writeToDir(dir, this, includedir, Utils::String::Null(), data, len))
2120
			return false;
2119
			return false;
2121
 
2120
 
2122
		return true;
2121
		return true;
2123
 
2122
 
2124
	}
2123
	}
2125
	else
2124
	else
2126
		return false;
2125
		return false;
2127
}
2126
}
2128
bool CBaseFile::extractFile(C_File *file, const Utils::String &dir, unsigned int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
2127
bool CBaseFile::extractFile(C_File *file, const Utils::String &dir, unsigned int game, const Utils::WStringList &gameAddons, bool includedir, CProgressInfo *progress)
2129
{
2128
{
2130
	if (ReadFileToMemory(file))
2129
	if (ReadFileToMemory(file))
2131
	{
2130
	{
2132
		CDirIO Dir(dir);
2131
		CDirIO Dir(dir);
2133
		Utils::String addonDir;
2132
		Utils::WString addonDir;
2134
		if (file->isFileInAddon())
2133
		if (file->isFileInAddon())
2135
		{
2134
		{
2136
			int addonGame = file->getForSingleGame();
2135
			int addonGame = file->getForSingleGame();
2137
			if (!addonGame) addonGame = game;
2136
			if (!addonGame) addonGame = game;
2138
 
2137
 
2139
			if (addonGame > 0)
2138
			if (addonGame > 0)
2140
				addonDir = gameAddons.findString(Utils::String::Number(addonGame));
2139
				addonDir = gameAddons.findString(Utils::WString::Number(addonGame));
2141
		}
2140
		}
2142
 
2141
 
2143
		if (!addonDir.empty())
2142
		if (!addonDir.empty())
2144
			Dir.cd(addonDir);
2143
			Dir.cd(addonDir);
2145
 
2144
 
Line 2168... Line 2167...
2168
	}
2167
	}
2169
	else
2168
	else
2170
		return false;
2169
		return false;
2171
}
2170
}
2172
 
2171
 
2173
bool CBaseFile::extractFile(int filenum, const Utils::String &dir, unsigned int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
2172
bool CBaseFile::extractFile(int filenum, const Utils::String &dir, unsigned int game, const Utils::WStringList &gameAddons, bool includedir, CProgressInfo *progress)
2174
{
2173
{
2175
	// invalid valus
2174
	// invalid valus
2176
	if (filenum < 0)
2175
	if (filenum < 0)
2177
		return false;
2176
		return false;
2178
	// out of range
2177
	// out of range
Line 2200... Line 2199...
2200
 
2199
 
2201
bool CBaseFile::extractAll(const Utils::String &dir, int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
2200
bool CBaseFile::extractAll(const Utils::String &dir, int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
2202
{
2201
{
2203
	// no file to read from
2202
	// no file to read from
2204
	if (this->filename().empty())
2203
	if (this->filename().empty())
2205
		return false;
2204
		return false;
2206
 
2205
 
2207
	// now open the file
2206
	// now open the file
2208
	CFileIO *File = _startRead();
2207
	CFileIO *File = _startRead();
2209
	if (!File) return false;
2208
	if (!File) return false;
2210
 
2209
 
Line 2288... Line 2287...
2288
	m_bSigned = computeSigned(updateFiles);
2287
	m_bSigned = computeSigned(updateFiles);
2289
	return m_bSigned;
2288
	return m_bSigned;
2290
}
2289
}
2291
 
2290
 
2292
bool CBaseFile::IsPackageNeeded(const Utils::String &scriptName, const Utils::String &author)
2291
bool CBaseFile::IsPackageNeeded(const Utils::String &scriptName, const Utils::String &author)
2293
{
2292
{
2294
	for ( CListNode<SNeededLibrary> *node = m_lNeededLibrarys.Front(); node; node = node->next() )
2293
	for ( CListNode<SNeededLibrary> *node = m_lNeededLibrarys.Front(); node; node = node->next() )
2295
	{
2294
	{
2296
		SNeededLibrary *l = node->Data();
2295
		SNeededLibrary *l = node->Data();
2297
		if ( l->sName.Compare(scriptName) && l->sAuthor.Compare(author) )
2296
		if ( l->sName.Compare(scriptName) && l->sAuthor.Compare(author) )
2298
			return true;
2297
			return true;
2299
	}
2298
	}
2300
 
2299
 
2301
	return false;
2300
	return false;
2302
}
2301
}
2303
 
2302
 
2304
SNeededLibrary *CBaseFile::FindPackageNeeded(const Utils::String &scriptName, const Utils::String &author)
2303
SNeededLibrary *CBaseFile::FindPackageNeeded(const Utils::String &scriptName, const Utils::String &author)
2305
{
2304
{
2306
	for ( CListNode<SNeededLibrary> *node = m_lNeededLibrarys.Front(); node; node = node->next() )
2305
	for ( CListNode<SNeededLibrary> *node = m_lNeededLibrarys.Front(); node; node = node->next() )
2307
	{
2306
	{
Line 2309... Line 2308...
2309
		if ( l->sName.Compare(scriptName) && l->sAuthor.Compare(author) )
2308
		if ( l->sName.Compare(scriptName) && l->sAuthor.Compare(author) )
2310
			return l;
2309
			return l;
2311
	}
2310
	}
2312
 
2311
 
2313
	return NULL;
2312
	return NULL;
2314
}
2313
}
2315
 
2314
 
2316
void CBaseFile::removeFakePatchOrder(const Utils::String &scriptName, const Utils::String &author)
2315
void CBaseFile::removeFakePatchOrder(const Utils::String &scriptName, const Utils::String &author)
2317
{
2316
{
2318
	removeFakePatchOrder(true, scriptName, author);
2317
	removeFakePatchOrder(true, scriptName, author);
2319
	removeFakePatchOrder(false, scriptName, author);
2318
	removeFakePatchOrder(false, scriptName, author);
2320
}
2319
}
2321
void CBaseFile::removeFakePatchOrder(bool after, const Utils::String &scriptName, const Utils::String &author)
2320
void CBaseFile::removeFakePatchOrder(bool after, const Utils::String &scriptName, const Utils::String &author)
2322
{
2321
{
2323
	Utils::CStringList *list;
2322
	Utils::CStringList *list;
2324
	if ( after )
2323
	if ( after )
2325
		list = &_lFakePatchAfter;
2324
		list = &_lFakePatchAfter;
2326
	else
2325
	else
2327
		list = &_lFakePatchBefore;
2326
		list = &_lFakePatchBefore;
2328
 
2327
 
2329
	int found = list->findStringAndData(scriptName, author);
2328
	int found = list->findStringAndData(scriptName, author);
2330
	while (found != -1)
2329
	while (found != -1)
Line 2337... Line 2336...
2337
void CBaseFile::addFakePatchOrder(bool after, const Utils::String &scriptName, const Utils::String &author)
2336
void CBaseFile::addFakePatchOrder(bool after, const Utils::String &scriptName, const Utils::String &author)
2338
{
2337
{
2339
	Utils::CStringList *list;
2338
	Utils::CStringList *list;
2340
	if ( after )
2339
	if ( after )
2341
		list = &_lFakePatchAfter;
2340
		list = &_lFakePatchAfter;
2342
	else
2341
	else
2343
		list = &_lFakePatchBefore;
2342
		list = &_lFakePatchBefore;
2344
 
2343
 
2345
	// check if the package already exists
2344
	// check if the package already exists
2346
	if (!list->containsStringAndData(scriptName, author))
2345
	if (!list->containsStringAndData(scriptName, author))
2347
	{
2346
	{
Line 2360... Line 2359...
2360
		l->sName = scriptName;
2359
		l->sName = scriptName;
2361
		l->sAuthor = author;
2360
		l->sAuthor = author;
2362
		m_lNeededLibrarys.push_back(l);
2361
		m_lNeededLibrarys.push_back(l);
2363
	}
2362
	}
2364
	l->sMinVersion = minVersion;
2363
	l->sMinVersion = minVersion;
2365
}
2364
}
2366
 
2365
 
2367
void CBaseFile::RemovePackageNeeded(const Utils::String &scriptName, const Utils::String &author)
2366
void CBaseFile::RemovePackageNeeded(const Utils::String &scriptName, const Utils::String &author)
2368
{
2367
{
2369
	SNeededLibrary *l = this->FindPackageNeeded(scriptName, author);
2368
	SNeededLibrary *l = this->FindPackageNeeded(scriptName, author);
2370
	if ( l )
2369
	if ( l )
Line 2383... Line 2382...
2383
	for ( CListNode<SNeededLibrary> *node = m_lNeededLibrarys.Front(); node; node = node->next() )
2382
	for ( CListNode<SNeededLibrary> *node = m_lNeededLibrarys.Front(); node; node = node->next() )
2384
		node->DeleteData();
2383
		node->DeleteData();
2385
	m_lNeededLibrarys.clear();
2384
	m_lNeededLibrarys.clear();
2386
 
2385
 
2387
	if ( !version.empty() )	this->AddNeededLibrary("<package>", "<author>", version);
2386
	if ( !version.empty() )	this->AddNeededLibrary("<package>", "<author>", version);
2388
}
2387
}
2389
 
2388
 
2390
 
2389
 
2391
bool CBaseFile::GeneratePackagerScript(bool wildcard, Utils::CStringList *list, int game, const Utils::CStringList &gameAddons, bool datafile)
2390
bool CBaseFile::GeneratePackagerScript(bool wildcard, Utils::CStringList *list, int game, const Utils::CStringList &gameAddons, bool datafile)
2392
{
2391
{
2393
	list->pushBack("#");
2392
	list->pushBack("#");
Line 2412... Line 2411...
2412
	if ( datafile )
2411
	if ( datafile )
2413
		list->pushBack("Date: " + this->creationDate());
2412
		list->pushBack("Date: " + this->creationDate());
2414
	else {
2413
	else {
2415
		list->pushBack("# $DATE variable is used to get the current date");
2414
		list->pushBack("# $DATE variable is used to get the current date");
2416
		list->pushBack("Date: $DATE");
2415
		list->pushBack("Date: $DATE");
2417
	}
2416
	}
2418
	list->pushBack("");
2417
	list->pushBack("");
2419
	list->pushBack("# The version of script");
2418
	list->pushBack("# The version of script");
2420
	if ( datafile )
2419
	if ( datafile )
2421
		list->pushBack("Version: " + this->version());
2420
		list->pushBack("Version: " + this->version());
2422
	else
2421
	else
Line 2430... Line 2429...
2430
		list->pushBack("# The game version the script is for <game> <version> (can have multiple games)");
2429
		list->pushBack("# The game version the script is for <game> <version> (can have multiple games)");
2431
		for ( SGameCompat *g = m_lGames.First(); g; g = m_lGames.Next() ) {
2430
		for ( SGameCompat *g = m_lGames.First(); g; g = m_lGames.Next() ) {
2432
			if (game > 0 && g->iGame != game)
2431
			if (game > 0 && g->iGame != game)
2433
				continue;
2432
				continue;
2434
 
2433
 
2435
			Utils::String game = CBaseFile::ConvertGameToString(g->iGame);
2434
			Utils::WString game = CBaseFile::ConvertGameToString(g->iGame);
2436
 
2435
 
2437
			if ( !g->sVersion.empty() )
2436
			if ( !g->sVersion.empty() )
2438
			{
2437
			{
2439
				game += " ";
2438
				game += L" ";
2440
				game += g->sVersion;
2439
				game += g->sVersion;
2441
			}
2440
			}
2442
			else
2441
			else
2443
			{
2442
			{
2444
				game += " ";
2443
				game += L" ";
2445
				game += (long)g->iVersion;
2444
				game += (long)g->iVersion;
2446
			}
2445
			}
2447
 
2446
 
2448
			list->pushBack("Game: " + game);
2447
			list->pushBack("Game: " + game.toString());
2449
		}
2448
		}
2450
 
2449
 
2451
		list->pushBack("");
2450
		list->pushBack("");
2452
	}
2451
	}
2453
 
2452
 
Line 2559... Line 2558...
2559
}
2558
}
2560
 
2559
 
2561
bool CBaseFile::GeneratePackagerScriptFile(bool wildcard, Utils::CStringList *list, int game, const Utils::CStringList &gameAddons)
2560
bool CBaseFile::GeneratePackagerScriptFile(bool wildcard, Utils::CStringList *list, int game, const Utils::CStringList &gameAddons)
2562
{
2561
{
2563
	// now do files and wildcards
2562
	// now do files and wildcards
2564
	Utils::CStringList files;
2563
	Utils::WStringList files;
2565
	for ( CListNode<C_File> *f = m_lFiles.Front(); f; f = f->next() )
2564
	for ( CListNode<C_File> *f = m_lFiles.Front(); f; f = f->next() )
2566
	{
2565
	{
2567
		if (game && !(f->Data()->game() & 1 << game))
2566
		if (game && !(f->Data()->game() & 1 << game))
2568
			continue;
2567
			continue;
2569
 
2568
 
2570
		Utils::String name = "$GAMEDIR/";
2569
		Utils::WString name = L"$GAMEDIR/";
2571
 
2570
 
2572
		// addon directory?
2571
		// addon directory?
2573
		unsigned int checkGame = f->Data()->game() & ~(1 << 31);
2572
		unsigned int checkGame = f->Data()->game() & ~(1 << 31);
2574
		unsigned int foundGame = 0;
2573
		unsigned int foundGame = 0;
2575
		for (int i = 0; i < 31; ++i)
2574
		for (int i = 0; i < 31; ++i)
2576
		{
2575
		{
2577
			if (checkGame == 1 << i)
2576
			if (checkGame == 1 << i)
2578
			{
2577
			{
2579
				foundGame = i;
2578
				foundGame = i;
2580
				break;
2579
				break;
2581
			}
2580
			}
2582
		}
2581
		}
2583
 
2582
 
2584
		if (foundGame)
2583
		if (foundGame)
2585
		{
2584
		{
2586
			Utils::String str = gameAddons.findString(Utils::String::Number(foundGame));
2585
			Utils::WString str = gameAddons.findString(Utils::String::Number(foundGame));
2587
			if(!str.empty())
2586
			if(!str.empty())
2588
				name += str + "/";
2587
				name += str + L"/";
2589
		}
2588
		}
2590
 
2589
 
2591
		bool done = false;
2590
		bool done = false;
2592
		if ( wildcard )
2591
		if ( wildcard )
2593
		{
2592
		{
2594
			Utils::String base = f->Data()->baseName();
2593
			Utils::WString base = f->Data()->baseName();
2595
			if ( f->Data()->fileType() == FILETYPE_SCRIPT )
2594
			if ( f->Data()->fileType() == FILETYPE_SCRIPT )
2596
			{
2595
			{
2597
				if ( base.token(".", 1).Compare("plugin") || base.token(".", 1).Compare("lib") )
2596
				if ( base.token(L".", 1).Compare(L"plugin") || base.token(L".", 1).Compare(L"lib") )
2598
				{
2597
				{
2599
					name += f->Data()->getDirectory(this) + "/" + base.tokens(".", 1, 2) + ".*";
2598
					name += f->Data()->getDirectory(this) + "/" + base.tokens(L".", 1, 2) + L".*";
2600
					done = true;
2599
					done = true;
2601
				}
2600
				}
2602
				else if ( base.token(".", 1).Compare("al") && !base.token(".", 2).Compare("plugin") )
2601
				else if ( base.token(L".", 1).Compare(L"al") && !base.token(L".", 2).Compare(L"plugin") )
2603
				{
2602
				{
2604
					name += f->Data()->getDirectory(this) + "/" + base.tokens(".", 1, 2) + ".*";
2603
					name += f->Data()->getDirectory(this) + L"/" + base.tokens(L".", 1, 2) + L".*";
2605
					done = true;
2604
					done = true;
2606
				}
2605
				}
2607
			}
2606
			}
2608
			else if ( f->Data()->fileType() == FILETYPE_TEXT )
2607
			else if ( f->Data()->fileType() == FILETYPE_TEXT )
2609
			{
2608
			{
2610
				if ( base.contains("-L") )
2609
				if ( base.contains(L"-L") )
2611
				{
2610
				{
2612
					name += f->Data()->getDirectory(this) + "/" + base.token(&quot;-L", 1) + "-L*";
2611
					name += f->Data()->getDirectory(this) + L"/" + base.token(L&quot;-L", 1) + L"-L*";
2613
					done = true;
2612
					done = true;
2614
				}
2613
				}
2615
				else
2614
				else
2616
				{
2615
				{
2617
					name += f->Data()->getDirectory(this) + "/*" + base.right(4) + ".*";
2616
					name += f->Data()->getDirectory(this) + L"/*" + base.right(4) + L".*";
2618
					done = true;
2617
					done = true;
2619
				}
2618
				}
2620
			}
2619
			}
2621
		}
2620
		}
2622
 
2621
 
2623
		if ( !done )
2622
		if ( !done )
2624
			name += f->Data()->getNameDirectory(this);
2623
			name += f->Data()->getNameDirectory(this);
2625
 
2624
 
2626
		if ( !f->Data()->dir().empty() )
2625
		if ( !f->Data()->dir().empty() )
2627
		{
2626
		{
2628
			name += "|";
2627
			name += L"|";
2629
			name += f->Data()->dir();
2628
			name += f->Data()->dir();
2630
		}
2629
		}
2631
		Utils::String s = "GAME ";
2630
		Utils::WString s = L"GAME ";
2632
		if (!f->Data()->game() || f->Data()->game() == GAME_ALLNEW)
2631
		if (!f->Data()->game() || f->Data()->game() == GAME_ALLNEW)
2633
			s += CBaseFile::ConvertGameToString(f->Data()->game());
2632
			s += CBaseFile::ConvertGameToString(f->Data()->game());
2634
		else
2633
		else
2635
		{
2634
		{
2636
			bool first = true;
2635
			bool first = true;
Line 2645... Line 2644...
2645
					s += CBaseFile::ConvertGameToString(i);
2644
					s += CBaseFile::ConvertGameToString(i);
2646
				}
2645
				}
2647
			}
2646
			}
2648
		}
2647
		}
2649
 
2648
 
2650
		s += " " + name;
2649
		s += L" " + name;
2651
		if(!files.contains(s))
2650
		if(!files.contains(s))
2652
			files.pushBack(s, f->Data()->fileTypeString());
2651
			files.pushBack(s, f->Data()->fileTypeString());
2653
	}
2652
	}
2654
 
2653
 
2655
 
2654
 
2656
	if ( !files.empty() )
2655
	if ( !files.empty() )
2657
	{
2656
	{
2658
		list->pushBack("# Files List, all the files to add, can include wild cards");
2657
		list->pushBack("# Files List, all the files to add, can include wild cards");
2659
		for(auto itr = files.begin(); itr != files.end(); itr++)
2658
		for(auto itr = files.begin(); itr != files.end(); itr++)
2660
			list->pushBack((*itr)->data + ": " + (*itr)->str);
2659
			list->pushBack((*itr)->data.toString() + ": " + (*itr)->str.toString());
2661
		list->pushBack("");
2660
		list->pushBack("");
2662
	}
2661
	}
2663
 
2662
 
2664
	return true;
2663
	return true;
2665
}
2664
}
Line 2679... Line 2678...
2679
			return true;
2678
			return true;
2680
	}
2679
	}
2681
	return false;
2680
	return false;
2682
}
2681
}
2683
 
2682
 
2684
bool CBaseFile::checkGameVersionCompatability(int game, const Utils::String &sVersion, int iVersion) const
2683
bool CBaseFile::checkGameVersionCompatability(int game, const Utils::WString &sVersion, int iVersion) const
2685
{
2684
{
2686
	if (m_lGames.empty())
2685
	if (m_lGames.empty())
2687
		return true; // no game compatability added, assume its ok for all
2686
		return true; // no game compatability added, assume its ok for all
2688
 
2687
 
2689
	bool foundAll = false;
2688
	bool foundAll = false;
Line 2742... Line 2741...
2742
	Found->iGame = game;
2741
	Found->iGame = game;
2743
	Found->iVersion = -1;
2742
	Found->iVersion = -1;
2744
	Found->sVersion = "";
2743
	Found->sVersion = "";
2745
 
2744
 
2746
	if ( version.isin(".") || !version.isNumber() )
2745
	if ( version.isin(".") || !version.isNumber() )
2747
		Found->sVersion = version;
2746
		Found->sVersion = version.toWString();
2748
	else
2747
	else
2749
		Found->iVersion = version;
2748
		Found->iVersion = version.toWString();
2750
	_changed();
2749
	_changed();
2751
}
2750
}
2752
 
2751
 
2753
Utils::WString CBaseFile::_replaceFilename(const Utils::WString &fname)
2752
Utils::WString CBaseFile::_replaceFilename(const Utils::WString &fname)
2754
{
2753
{
Line 2767... Line 2766...
2767
	filename = filename.findReplace("L$CDATE", cdate);
2766
	filename = filename.findReplace("L$CDATE", cdate);
2768
	filename = filename.findReplace("L$VERSION", this->version());
2767
	filename = filename.findReplace("L$VERSION", this->version());
2769
 
2768
 
2770
	return filename;
2769
	return filename;
2771
}
2770
}
2772
bool CBaseFile::LoadPackageData(const Utils::String &sFirst, const Utils::String &sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames, Utils::CStringList &gameAddons, CProgressInfo *progress)
2771
bool CBaseFile::loadPackageData(const Utils::WString &sFirst, const Utils::WString &sRest, const Utils::WString &sMainGame, Utils::WStringList &otherGames, Utils::WStringList &gameAddons, CProgressInfo *progress)
2773
{
2772
{
2774
	if (sFirst.Compare("Name"))					this->setName(sRest);
2773
	if (sFirst.Compare(L"Name"))					this->setName(sRest.toString());
2775
	else if (sFirst.Compare("Author"))			this->setAuthor(sRest);
2774
	else if (sFirst.Compare(L"Author"))				this->setAuthor(sRest.toString());
2776
	else if (sFirst.Compare("ScriptName"))		addName(ParseLanguage(sRest.token(" ";, 1)), sRest.tokens(&quot; &quot;, 2));
2775
	else if (sFirst.Compare(L"ScriptName"))			addName(ParseLanguage(sRest.token(L" ";, 1).toString()), sRest.tokens(L" ", 2).toString());
2777
	else if (sFirst.Compare("UninstallBefore"))	this->addUninstallText(ParseLanguage(sRest.token(" ", 1)), true, sRest.tokens(&quot; &quot;, 2));
2776
	else if (sFirst.Compare(L"UninstallBefore"))	this->addUninstallText(ParseLanguage(sRest.token(L" ", 1).toString()), true, sRest.tokens(L" ", 2).toString());
2778
	else if (sFirst.Compare("UninstallAfter"))	this->addUninstallText(ParseLanguage(sRest.token(" ", 1)), false, sRest.tokens(" ", 2));
2777
	else if (sFirst.Compare(L"UninstallAfter"))		this->addUninstallText(ParseLanguage(sRest.token(L" ", 1).toString()), false, sRest.tokens(L" ", 2).toString());
2779
	else if (sFirst.Compare("InstallBefore"))		this->addInstallText(ParseLanguage(sRest.token(" ", 1)), true, sRest.tokens(&quot; &quot;, 2));
2778
	else if (sFirst.Compare(L"InstallBefore"))		this->addInstallText(ParseLanguage(sRest.token(L" ", 1).toString()), true, sRest.tokens(L" ", 2).toString());
2780
	else if (sFirst.Compare("InstallAfter"))		this->addInstallText(ParseLanguage(sRest.token(" ", 1)), false, sRest.tokens(&quot; &quot;, 2));
2779
	else if (sFirst.Compare(L"InstallAfter"))		this->addInstallText(ParseLanguage(sRest.token(L" ", 1).toString()), false, sRest.tokens(L" ", 2).toString());
2781
	else if (sFirst.Compare("Date"))				this->setCreationDate(sRest);
2780
	else if (sFirst.Compare(L"Date"))				this->setCreationDate(sRest.toString());
2782
	else if (sFirst.Compare("Version"))			this->setVersion(sRest);
2781
	else if (sFirst.Compare(L"Version"))			this->setVersion(sRest.toString());
2783
	else if (sFirst.Compare("GameVersion"))
2782
	else if (sFirst.Compare(L"GameVersion"))
2784
		this->AddGameCompatability(-1, sRest);
2783
		this->AddGameCompatability(-1, sRest.toString());
2785
	else if (sFirst.Compare("PluginType")) {
2784
	else if (sFirst.Compare(L"PluginType")) {
2786
		if (sRest.isNumber())						this->setPluginType(sRest);
2785
		if (sRest.isNumber())						this->setPluginType(sRest);
2787
		else if (sRest.Compare("Normal"))			this->setPluginType(PLUGIN_NORMAL);
2786
		else if (sRest.Compare(L"Normal"))			this->setPluginType(PLUGIN_NORMAL);
2788
		else if (sRest.Compare("Stable"))			this->setPluginType(PLUGIN_STABLE);
2787
		else if (sRest.Compare(L"Stable"))			this->setPluginType(PLUGIN_STABLE);
2789
		else if (sRest.Compare("Experimental"))	this->setPluginType(PLUGIN_EXPERIMENTAL);
2788
		else if (sRest.Compare(L"Experimental"))	this->setPluginType(PLUGIN_EXPERIMENTAL);
2790
		else if (sRest.Compare("Cheat"))			this->setPluginType(PLUGIN_CHEAT);
2789
		else if (sRest.Compare(L"Cheat"))			this->setPluginType(PLUGIN_CHEAT);
2791
		else if (sRest.Compare("Mod"))			this->setPluginType(PLUGIN_MOD);
2790
		else if (sRest.Compare(L"Mod"))				this->setPluginType(PLUGIN_MOD);
2792
	}
2791
	}
2793
	// new version
2792
	// new version
2794
	else if (sFirst.Compare("GenerateUpdateFile"))
2793
	else if (sFirst.Compare(L"GenerateUpdateFile"))
2795
		m_bAutoGenerateUpdateFile = true;
2794
		m_bAutoGenerateUpdateFile = true;
2796
	else if (sFirst.Compare("Game"))
2795
	else if (sFirst.Compare(L"Game"))
2797
	{
2796
	{
2798
		Utils::String sGame = sRest.token(" ", 1);
2797
		Utils::WString sGame = sRest.token(L" ", 1);
2799
		this->AddGameCompatability(CBaseFile::GetGameFromString(sGame), sRest.token(" ", 2));
2798
		this->AddGameCompatability(CBaseFile::GetGameFromString(sGame.toString()), sRest.token(L" ", 2).toString());
2800
	}
2799
	}
2801
	else if (sFirst.Compare("Description"))		this->setDescription(sRest);
2800
	else if (sFirst.Compare(L"Description"))		this->setDescription(sRest.toString());
2802
	else if (sFirst.Compare("AutoSave") || sFirst.Compare("AutoExport") || sFirst.Compare("AutoRarExport") || sFirst.Compare("AutoZipExport"))
2801
	else if (sFirst.Compare(L"AutoSave") || sFirst.Compare(L"AutoExport") || sFirst.Compare(L"AutoRarExport") || sFirst.Compare(L"AutoZipExport"))
2803
	{
2802
	{
2804
		Utils::WString filename = _replaceFilename(sRest);
2803
		Utils::WString filename = _replaceFilename(sRest);
2805
 
2804
 
2806
		if (sFirst.Compare("AutoZipExport") || sFirst.Compare("AutoExport"))
2805
		if (sFirst.Compare(L"AutoZipExport") || sFirst.Compare(L"AutoExport"))
2807
			this->setExportFilename(CFileIO(filename).changeFileExtension(L"zip").toString());
2806
			this->setExportFilename(CFileIO(filename).changeFileExtension(L"zip").toString());
2808
		else if (sFirst.Compare("AutoRarExport"))
2807
		else if (sFirst.Compare(L"AutoRarExport"))
2809
			this->setExportFilename(CFileIO(filename).changeFileExtension(L"rar").toString());
2808
			this->setExportFilename(CFileIO(filename).changeFileExtension(L"rar").toString());
2810
		else
2809
		else
2811
			this->setFilename(filename.toString());
2810
			this->setFilename(filename);
2812
	}
2811
	}
2813
	else if (sFirst.Compare("WebSite"))		this->setWebSite(sRest);
2812
	else if (sFirst.Compare(L"WebSite"))		this->setWebSite(sRest.toString());
2814
	else if (sFirst.Compare("ForumLink") || sFirst.Compare("Forum")) this->setForumLink(sRest);
2813
	else if (sFirst.Compare(L"ForumLink") || sFirst.Compare("Forum")) this->setForumLink(sRest.toString());
2815
	else if (sFirst.Compare("Email"))			this->setEmail(sRest);
2814
	else if (sFirst.Compare(L"Email"))			this->setEmail(sRest.toString());
2816
	else if (sFirst.Compare("WebAddress"))	this->setWebAddress(sRest);
2815
	else if (sFirst.Compare(L"WebAddress"))		this->setWebAddress(sRest.toString());
2817
	else if (sFirst.Compare("WebMirror"))
2816
	else if (sFirst.Compare(L"WebMirror"))
2818
		this->addWebMirror(sRest);
2817
		this->addWebMirror(sRest.toString());
2819
	else if (sFirst.Compare("WebMirror1"))
2818
	else if (sFirst.Compare(L"WebMirror1"))
2820
		this->addWebMirror(sRest);
2819
		this->addWebMirror(sRest.toString());
2821
	else if (sFirst.Compare("WebMirror2"))
2820
	else if (sFirst.Compare(L"WebMirror2"))
2822
		this->addWebMirror(sRest);
2821
		this->addWebMirror(sRest.toString());
2823
	else if (sFirst.Compare("Ftp"))
2822
	else if (sFirst.Compare(L"Ftp"))
2824
		_sFtpAddr = sRest;
2823
		_sFtpAddr = sRest.toString();
2825
	else if (sFirst.Compare("Ratings"))		_setRatings(sRest.token(" ", 1), sRest.token(" ", 2), sRest.token(" ", 3));
2824
	else if (sFirst.Compare(L"Ratings"))		_setRatings(sRest.token(L" ", 1), sRest.token(L" ", 2), sRest.token(L" ", 3));
2826
	else if (sFirst.Compare("EaseOfUse"))		setEaseOfUse(sRest);
2825
	else if (sFirst.Compare(L"EaseOfUse"))		setEaseOfUse(sRest);
2827
	else if (sFirst.Compare("GameChanging"))	setGameChanging(sRest);
2826
	else if (sFirst.Compare(L"GameChanging"))	setGameChanging(sRest);
2828
	else if (sFirst.Compare("Recommended"))	setRecommended(sRest);
2827
	else if (sFirst.Compare(L"Recommended"))	setRecommended(sRest);
2829
	else if (sFirst.Compare("Depend"))
2828
	else if (sFirst.Compare(L"Depend"))
2830
	{
2829
	{
2831
		Utils::String version = sRest.token("|", 2);
2830
		Utils::WString version = sRest.token(L"|", 2);
2832
		Utils::String name = sRest.token("|", 1);
2831
		Utils::WString name = sRest.token(L"|", 1);
2833
		Utils::String author = sRest.tokens("|", 3);
2832
		Utils::WString author = sRest.tokens(L"|", 3);
2834
 
2833
 
2835
		this->AddNeededLibrary(name, author, version);
2834
		this->AddNeededLibrary(name.toString(), author.toString(), version.toString());
2836
	}
2835
	}
2837
	else if (sFirst.Compare("DependPackage"))
2836
	else if (sFirst.Compare(L"DependPackage"))
2838
	{
2837
	{
2839
		CPackages p;
2838
		CPackages p;
2840
		CBaseFile *spk = p.openPackage(sRest, 0, 0, SPKREAD_VALUES);
2839
		CBaseFile *spk = p.openPackage(sRest, 0, 0, SPKREAD_VALUES);
2841
		if (spk)
2840
		if (spk)
2842
		{
2841
		{
2843
			this->AddNeededLibrary(spk->name(), spk->author(), spk->version());
2842
			this->AddNeededLibrary(spk->name(), spk->author(), spk->version());
2844
			delete spk;
2843
			delete spk;
2845
		}
2844
		}
2846
	}
2845
	}
2847
	else if (sFirst.Compare("Icon"))
2846
	else if (sFirst.Compare(L"Icon"))
2848
	{
2847
	{
2849
		C_File *icon = new C_File(sRest.c_str());
2848
		C_File *icon = new C_File(sRest);
2850
		if (icon->ReadFromFile())
2849
		if (icon->ReadFromFile())
2851
			this->setIcon(icon, CFileIO(sRest).extension().toString());
2850
			this->setIcon(icon, CFileIO(sRest).extension().toString());
2852
	}
2851
	}
2853
	else if (sFirst.Compare("CombineGameFiles"))
2852
	else if (sFirst.Compare(L"CombineGameFiles"))
2854
		_bCombineFiles = sRest.Compare("true") || sRest.Compare("yes") || sRest.toInt();
2853
		_bCombineFiles = sRest.Compare(L"true") || sRest.Compare(L"yes") || sRest.toInt();
2855
	else if (sFirst.Compare("UpdateFile"))
2854
	else if (sFirst.Compare(L"UpdateFile"))
2856
		this->createUpdateFile(sRest);
2855
		this->createUpdateFile(sRest);
2857
	else if (sFirst.Compare("ExportZip"))
2856
	else if (sFirst.Compare(L"ExportZip"))
2858
	{
2857
	{
2859
		Utils::WString ext = L"zip";
2858
		Utils::WString ext = L"zip";
2860
		Utils::String game = sRest.word(1);
2859
		Utils::WString game = sRest.word(1);
2861
		Utils::WString file = _replaceFilename(CFileIO(sRest.words(2)).fullFilename());
2860
		Utils::WString file = _replaceFilename(CFileIO(sRest.words(2)).fullFilename());
2862
		if (game.contains("|"))
2861
		if (game.contains(L"|"))
2863
		{
2862
		{
2864
			int max;
-
 
2865
			Utils::String *games = game.tokenise("|", &amp;max);
2863
			std::vector<Utils::WString&gt; games;
2866
			if (games)
2864
			if(game.tokenise(L"|", games))
2867
			{
2865
			{
2868
				for (int i = 0; i < max; ++i)
2866
				for (size_t i = 0; i < games.size(); ++i)
2869
				{
2867
				{
2870
					unsigned int g = CBaseFile::GetGameFromString(games[i]);
2868
					unsigned int g = CBaseFile::GetGameFromString(games[i].toString());
2871
					Utils::WString filename = CFileIO(file).dir() + L"/" + CFileIO(file).baseName() + L"_" + CBaseFile::ConvertGameToString(g).toWString() + L"." + ext;
2869
					Utils::WString filename = CFileIO(file).dir() + L"/" + CFileIO(file).baseName() + L"_" + CBaseFile::ConvertGameToString(g) + L"." + ext;
2872
					this->addAutoExport(g, filename.toString());
2870
					this->addAutoExport(g, filename.toString());
2873
				}
2871
				}
2874
				CLEANSPLIT(games, max);
-
 
2875
			}
2872
			}
2876
		}
2873
		}
2877
		else
2874
		else
2878
		{
2875
		{
2879
			unsigned int g = CBaseFile::GetGameFromString(game);
2876
			unsigned int g = CBaseFile::GetGameFromString(game.toString());
2880
			Utils::WString filename = CFileIO(file).dir() + L"/" + CFileIO(file).baseName() + L"_" + CBaseFile::ConvertGameToString(g).toWString() + L"." + ext;
2877
			Utils::WString filename = CFileIO(file).dir() + L"/" + CFileIO(file).baseName() + L"_" + CBaseFile::ConvertGameToString(g) + L"." + ext;
2881
			this->addAutoExport(g, filename.toString());
2878
			this->addAutoExport(g, filename.toString());
2882
		}
2879
		}
2883
	}
2880
	}
2884
	else if (sFirst.Compare("Extract"))
2881
	else if (sFirst.Compare(L"Extract"))
2885
	{
2882
	{
2886
		Utils::String game = sRest.word(1);
2883
		Utils::WString game = sRest.word(1);
2887
		Utils::WString dir = CDirIO(sRest.words(2)).dir();
2884
		Utils::WString dir = CDirIO(sRest.words(2)).dir();
2888
		if (game.contains("|"))
2885
		if (game.contains(L"|"))
2889
		{
2886
		{
2890
			int max;
-
 
2891
			Utils::String *games = game.tokenise("|", &amp;max);
2887
			std::vector<Utils::WString&gt; games;
2892
			if (games)
2888
			if (game.tokenise(L"|", games))
2893
			{
2889
			{
2894
				for(int i = 0; i < max; ++i)
2890
				for(size_t i = 0; i < games.size(); ++i)
2895
					this->addAutoExtract(CBaseFile::GetGameFromString(games[i]), dir.toString());
2891
					this->addAutoExtract(CBaseFile::GetGameFromString(games[i].toString()), dir.toString());
2896
				CLEANSPLIT(games, max);
-
 
2897
			}
2892
			}
2898
		}
2893
		}
2899
		else
2894
		else
2900
			this->addAutoExtract(CBaseFile::GetGameFromString(game), dir.toString());
2895
			this->addAutoExtract(CBaseFile::GetGameFromString(game.toString()), dir.toString());
2901
	}
2896
	}
2902
	else
2897
	else
2903
	{
2898
	{
2904
		Utils::String checkType = sFirst;
2899
		Utils::WString checkType = sFirst;
2905
		bool shared = false;
2900
		bool shared = false;
2906
		if (checkType.left(6).Compare("Shared"))
2901
		if (checkType.left(6).Compare(L"Shared"))
2907
		{
2902
		{
2908
			checkType = sFirst.right(-6);
2903
			checkType = sFirst.right(-6);
2909
			shared = true;
2904
			shared = true;
2910
		}
2905
		}
2911
		bool packed = false;
2906
		bool packed = false;
2912
		if (checkType.right(3).Compare("PCK"))
2907
		if (checkType.right(3).Compare(L"PCK"))
2913
		{
2908
		{
2914
			checkType = sFirst.left(-3);
2909
			checkType = sFirst.left(-3);
2915
			packed = true;
2910
			packed = true;
2916
		}
2911
		}
2917
 
2912
 
2918
		// now check type name
2913
		// now check type name
2919
		FileType filetype = GetFileTypeFromString(checkType);
2914
		FileType filetype = GetFileTypeFromString(checkType);
2920
		if (filetype != FILETYPE_UNKNOWN)
2915
		if (filetype != FILETYPE_UNKNOWN)
2921
			this->AddFileScript(filetype, shared, packed, sRest, sMainGame, otherGames, gameAddons, progress);
2916
			this->addFileScript(filetype, shared, packed, sRest, sMainGame, otherGames, gameAddons, progress);
2922
		else if ( !checkType.Compare("changelog") )
2917
		else if ( !checkType.Compare("changelog") )
2923
			return false;
2918
			return false;
2924
	}
2919
	}
2925
 
2920
 
2926
	return true;
2921
	return true;
2927
}
2922
}
2928
 
2923
 
2929
void CBaseFile::AddFileScript(FileType filetype, bool shared, bool packed, const Utils::String &sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames, Utils::CStringList &gameAddons, CProgressInfo *progress)
2924
void CBaseFile::addFileScript(FileType filetype, bool shared, bool packed, const Utils::WString &sRest, const Utils::WString &sMainGame, Utils::WStringList &otherGames, Utils::WStringList &gameAddons, CProgressInfo *progress)
2930
{
2925
{
2931
	Utils::String dir;
2926
	Utils::WString dir;
2932
	Utils::String rest = sRest;
2927
	Utils::WString rest = sRest;
2933
 
2928
 
2934
	unsigned int mainGame = CBaseFile::GetGameFromString(sMainGame);
2929
	unsigned int mainGame = CBaseFile::GetGameFromString(sMainGame.toString());
2935
	unsigned int game = 0;
2930
	unsigned int game = 0;
2936
	if ( rest.token(" ", 1).left(4).Compare("GAME") ) {
2931
	if ( rest.token(L" ", 1).left(4).Compare(L"GAME") ) {
2937
		Utils::String gameStr = rest.token(" ", 2);
2932
		Utils::WString gameStr = rest.token(L" ", 2);
2938
		if (gameStr.contains("|"))
2933
		if (gameStr.contains(L"|"))
2939
		{
2934
		{
2940
			int max = 0;
2935
			std::vector<Utils::WString> games;
2941
			Utils::String *games = gameStr.tokenise(";|", &max);
2936
			gameStr.tokenise(L"|";, games);
2942
			for (int i = 0; i < max; ++i)
2937
			for (size_t i = 0; i < games.size(); ++i)
2943
			{
2938
			{
2944
				unsigned int g = CBaseFile::GetGameFromString(games[i]);
2939
				unsigned int g = CBaseFile::GetGameFromString(games[i].toString());
2945
				if (g)
2940
				if (g)
2946
					game |= 1 << g;
2941
					game |= 1 << g;
2947
			}
2942
			}
2948
			CLEANSPLIT(games, max);
-
 
2949
		}
2943
		}
2950
		else
2944
		else
2951
		{
2945
		{
2952
			unsigned int g = CBaseFile::GetGameFromString(gameStr);
2946
			unsigned int g = CBaseFile::GetGameFromString(gameStr.toString());
2953
			if (g)
2947
			if (g)
2954
				game = 1 << g;
2948
				game = 1 << g;
2955
		}
2949
		}
2956
		rest = rest.tokens(" ", 3);
2950
		rest = rest.tokens(L" ", 3);
2957
	}
2951
	}
2958
	if (game)
2952
	if (game)
2959
		game |= 1 << 31;
2953
		game |= 1 << 31;
2960
 
2954
 
2961
	if (rest.contains("|"))
2955
	if (rest.contains(L"|"))
2962
	{
2956
	{
2963
		dir = rest.tokens("|", 2);
2957
		dir = rest.tokens(L"|", 2);
2964
		rest = rest.token("|", 1);
2958
		rest = rest.token(L"|", 1);
2965
	}
2959
	}
2966
 
2960
 
2967
	rest = rest.findReplace("\\", "/");
2961
	rest = rest.findReplace(L"\\", L"/");
2968
 
2962
 
2969
	// wild cards
2963
	// wild cards
2970
	if ( rest.containsAny("*?") )
2964
	if ( rest.containsAny(L"*?") )
2971
	{
2965
	{
2972
		CDirIO Dir(CFileIO(rest).dir());
2966
		CDirIO Dir(CFileIO(rest).dir());
2973
		Utils::CStringList dirList;
2967
		Utils::WStringList dirList;
2974
		if(Dir.dirList(dirList))
2968
		if(Dir.dirList(dirList))
2975
		{
2969
		{
2976
			for(auto itr = dirList.begin(); itr != dirList.end(); itr++)
2970
			for(auto itr = dirList.begin(); itr != dirList.end(); itr++)
2977
			{
2971
			{
2978
				Utils::WString file = Dir.file((*itr)->str);
2972
				Utils::WString file = Dir.file((*itr)->str);
Line 2980... Line 2974...
2980
				{
2974
				{
2981
					int addGame = game;
2975
					int addGame = game;
2982
					// check if the file exists in the subdirectory too, if it does, add for each game
2976
					// check if the file exists in the subdirectory too, if it does, add for each game
2983
					if ( game == GAME_ALL && !sMainGame.empty() && !otherGames.empty() ) {
2977
					if ( game == GAME_ALL && !sMainGame.empty() && !otherGames.empty() ) {
2984
						CFileIO F(file);
2978
						CFileIO F(file);
2985
						for(Utils::String g = otherGames.firstString(); !g.empty(); g = otherGames.nextString()) {
2979
						for(Utils::WString g = otherGames.firstString(); !g.empty(); g = otherGames.nextString()) {
2986
							Utils::WString checkDir = F.dir() + L"/" + g.toWString();
2980
							Utils::WString checkDir = F.dir() + L"/" + g;
2987
							if ( CDirIO(checkDir).exists(F.filename()) ) {
2981
							if ( CDirIO(checkDir).exists(F.filename()) ) {
2988
								addGame = mainGame;
2982
								addGame = mainGame;
2989
								C_File *newfile = this->appendFile(CDirIO(checkDir).file(F.filename()).toString(), filetype, CBaseFile::GetGameFromString(g), packed, dir);
2983
								C_File *newfile = this->appendFile(CDirIO(checkDir).file(F.filename()), filetype, CBaseFile::GetGameFromString(g.toString()), packed, dir);
2990
								if (newfile && progress)
2984
								if (newfile && progress)
2991
									progress->UpdateFile(newfile);
2985
									progress->UpdateFile(newfile);
2992
								if ( newfile ) newfile->SetShared(shared);
2986
								if ( newfile ) newfile->SetShared(shared);
2993
							}
2987
							}
2994
						}
2988
						}
2995
					}
2989
					}
2996
 
2990
 
2997
					C_File *newfile = this->appendFile(file.toString(), filetype, addGame, packed, dir);
2991
					C_File *newfile = this->appendFile(file, filetype, addGame, packed, dir);
2998
					if (newfile && progress)
2992
					if (newfile && progress)
2999
						progress->UpdateFile(newfile);
2993
						progress->UpdateFile(newfile);
3000
					if ( newfile )
2994
					if ( newfile )
3001
						newfile->SetShared(shared);
2995
						newfile->SetShared(shared);
3002
				}
2996
				}
Line 3007... Line 3001...
3007
	{
3001
	{
3008
		unsigned int addGame = game;
3002
		unsigned int addGame = game;
3009
		// check if the file exists in the subdirectory too, if it does, add for each game
3003
		// check if the file exists in the subdirectory too, if it does, add for each game
3010
		if ( game == GAME_ALL && !sMainGame.empty() && !otherGames.empty() ) {
3004
		if ( game == GAME_ALL && !sMainGame.empty() && !otherGames.empty() ) {
3011
			CFileIO F(rest);
3005
			CFileIO F(rest);
3012
			for(Utils::String g = otherGames.firstString(); !g.empty(); g = otherGames.nextString()) {
3006
			for(Utils::WString g = otherGames.firstString(); !g.empty(); g = otherGames.nextString()) {
3013
				Utils::WString checkDir = F.dir() + L"/" + g.toWString();
3007
				Utils::WString checkDir = F.dir() + L"/" + g;
3014
				if ( CDirIO(checkDir).exists(F.filename()) ) {
3008
				if ( CDirIO(checkDir).exists(F.filename()) ) {
3015
					addGame = mainGame;
3009
					addGame = mainGame;
3016
					C_File *newfile = this->appendFile(CDirIO(checkDir).file(F.filename()).toString(), filetype, CBaseFile::GetGameFromString(g), packed, dir);
3010
					C_File *newfile = this->appendFile(CDirIO(checkDir).file(F.filename()), filetype, CBaseFile::GetGameFromString(g.toString()), packed, dir);
3017
					if (newfile && progress)
3011
					if (newfile && progress)
3018
						progress->UpdateFile(newfile);
3012
						progress->UpdateFile(newfile);
3019
					if ( newfile ) newfile->SetShared(shared);
3013
					if ( newfile ) newfile->SetShared(shared);
3020
				}
3014
				}
3021
			}
3015
			}
Line 3033... Line 3027...
3033
		}
3027
		}
3034
 
3028
 
3035
		C_File *file = NULL;
3029
		C_File *file = NULL;
3036
		if (foundGame)
3030
		if (foundGame)
3037
		{
3031
		{
3038
			Utils::String addon = gameAddons.findString(Utils::String::Number(foundGame));
3032
			Utils::WString addon = gameAddons.findString(Utils::WString::Number(foundGame));
3039
			if (!addon.empty())
3033
			if (!addon.empty())
3040
			{
3034
			{
3041
				Utils::String dir = C_File::GetDirectory(filetype, rest, this);
3035
				Utils::WString dir = C_File::GetDirectory(filetype, rest, this);
3042
				Utils::String filename = rest;
3036
				Utils::WString filename = rest;
3043
				if (CCatFile::IsAddonDir(dir) && !filename.contains(addon))
3037
				if (CCatFile::IsAddonDir(dir) && !filename.contains(addon))
3044
				{
3038
				{
3045
					filename = filename.findReplace(dir + "/", addon + "/" + dir + "/");
3039
					filename = filename.findReplace(dir + L"/", addon + L"/" + dir + L"/");
3046
					file = this->appendFile(filename, filetype, addGame, packed, dir);
3040
					file = this->appendFile(filename, filetype, addGame, packed, dir);
3047
				}
3041
				}
3048
			}
3042
			}
3049
		}
3043
		}
3050
 
3044
 
Line 3057... Line 3051...
3057
			file->SetShared(shared);
3051
			file->SetShared(shared);
3058
	}
3052
	}
3059
}
3053
}
3060
 
3054
 
3061
 
3055
 
3062
Utils::String CBaseFile::fileSizeString() const { return SPK::GetSizeString ( this->fileSize() ); }
3056
Utils::WString CBaseFile::fileSizeString() const { return SPK::GetSizeString ( this->fileSize() ); }
3063
 
3057
 
3064
// used for a multiple spk file
3058
// used for a multiple spk file
3065
unsigned char *CBaseFile::CreateData(size_t *size, CProgressInfo *progress)
3059
unsigned char *CBaseFile::createData(size_t *size, CProgressInfo *progress)
3066
{
3060
{
3067
	if ( this->writeFile("temp.dat", progress) ) {
3061
	if ( this->writeFile("temp.dat", progress) ) {
3068
		CFileIO File("temp.dat");
3062
		CFileIO File(L"temp.dat");
3069
		File.setAutoDelete(true);
3063
		File.setAutoDelete(true);
3070
		return File.readAll(size);
3064
		return File.readAll(size);
3071
	}
3065
	}
3072
	return NULL;
3066
	return NULL;
3073
}
3067
}
Line 3091... Line 3085...
3091
	f->changeBaseName(to);
3085
	f->changeBaseName(to);
3092
}
3086
}
3093
 
3087
 
3094
void CBaseFile::convertAutoText(C_File *f) const
3088
void CBaseFile::convertAutoText(C_File *f) const
3095
{
3089
{
3096
	Utils::String to;
3090
	Utils::WString to;
3097
	if ( f->baseName().contains("-L") )
3091
	if ( f->baseName().contains(L"-L") )
3098
		to = "0000-L"; + f->baseName().token("-L", 2);
3092
		to = L";0000-L" + f->baseName().token(L"-L", 2);
3099
	else if ( f->baseName().contains("-l") )
3093
	else if ( f->baseName().contains("-l") )
3100
		to = "0000-L"; + f->baseName().token("-l", 2);
3094
		to = L";0000-L" + f->baseName().token(L"-l", 2);
3101
	else
3095
	else
3102
		to = f->baseName().left(-4) + "0000";
3096
		to = f->baseName().left(-4) + L"0000";
3103
 
3097
 
3104
	// file link
3098
	// file link
3105
	if ( !f->GetData() )
3099
	if ( !f->GetData() )
3106
		f->ReadFromFile();
3100
		f->ReadFromFile();
3107
 
3101
 
Line 3198... Line 3192...
3198
	_changed(); 
3192
	_changed(); 
3199
}
3193
}
3200
 
3194
 
3201
Utils::WString CBaseFile::createUpdateFile(const Utils::WString &dir) const
3195
Utils::WString CBaseFile::createUpdateFile(const Utils::WString &dir) const
3202
{
3196
{
3203
	Utils::WString file = this->getNameValidFile() + "_" + this->author() + ".dat";
3197
	Utils::WString file = this->getNameValidFile() + L"_" + this->author().toWString() + L".dat";
3204
	file.removeChar(' ');
3198
	file.removeChar(' ');
3205
 
3199
 
3206
	Utils::CStringList write;
3200
	Utils::CStringList write;
3207
	write.pushBack("Package: " + this->name());
3201
	write.pushBack("Package: " + this->name());
3208
	write.pushBack("Author: " + this->author());
3202
	write.pushBack("Author: " + this->author());
3209
	write.pushBack("Version: " + this->version());
3203
	write.pushBack("Version: " + this->version());
3210
	write.pushBack("File: " + CFileIO(this->filename()).filename().toString());
3204
	write.pushBack("File: " + CFileIO(this->filename()).filename().toString());
3211
 
3205
 
3212
	CFileIO File(dir + "/" + file);
3206
	CFileIO File(dir + L"/" + file);
3213
	if (File.writeFile(&write))
3207
	if (File.writeFile(&write))
3214
		return File.fullFilename();
3208
		return File.fullFilename();
3215
	return Utils::WString::Null();
3209
	return Utils::WString::Null();
3216
}
3210
}
3217
 
3211
 
3218
Utils::String CBaseFile::ErrorString(int error, const Utils::String &errorStr)
3212
Utils::WString CBaseFile::ErrorString(int error, const Utils::WString &errorStr)
3219
{
3213
{
3220
	if (error == SPKERR_NONE) return Utils::String::Null();
3214
	if (error == SPKERR_NONE) return Utils::WString::Null();
3221
 
3215
 
3222
	Utils::String err;
3216
	Utils::WString err;
3223
 
3217
 
3224
	switch (error)
3218
	switch (error)
3225
	{
3219
	{
3226
	case SPKERR_MALLOC:
3220
	case SPKERR_MALLOC:
3227
		err = "Memory Failed";
3221
		err = L"Memory Failed";
3228
		break;
3222
		break;
3229
	case SPKERR_FILEOPEN:
3223
	case SPKERR_FILEOPEN:
3230
		err = "Failed to open file";
3224
		err = L"Failed to open file";
3231
		break;
3225
		break;
3232
	case SPKERR_FILEREAD:
3226
	case SPKERR_FILEREAD:
3233
		err = "Failed to read file";
3227
		err = L"Failed to read file";
3234
		break;
3228
		break;
3235
	case SPKERR_UNCOMPRESS:
3229
	case SPKERR_UNCOMPRESS:
3236
		err = "Failed to Uncompress";
3230
		err = L"Failed to Uncompress";
3237
		break;
3231
		break;
3238
	case SPKERR_WRITEFILE:
3232
	case SPKERR_WRITEFILE:
3239
		err = "Failed to write file";
3233
		err = L"Failed to write file";
3240
		break;
3234
		break;
3241
	case SPKERR_CREATEDIRECTORY:
3235
	case SPKERR_CREATEDIRECTORY:
3242
		err = "Failed to create directory";
3236
		err = L"Failed to create directory";
3243
		break;
3237
		break;
3244
	case SPKERR_FILEMISMATCH:
3238
	case SPKERR_FILEMISMATCH:
3245
		err = "File count mismatch";
3239
		err = L"File count mismatch";
3246
		break;
3240
		break;
3247
	}
3241
	}
3248
 
3242
 
3249
	if (!err.empty())
3243
	if (!err.empty())
3250
	{
3244
	{
3251
		if (!errorStr.empty())
3245
		if (!errorStr.empty())
3252
		{
3246
		{
3253
			err += " (";
3247
			err += L" (";
3254
			err += errorStr + ")";
3248
			err += errorStr + L")";
3255
		}
3249
		}
3256
		return err;
3250
		return err;
3257
	}
3251
	}
3258
 
3252
 
3259
	return Utils::String::Number((long)error);
3253
	return Utils::WString::Number((long)error);
3260
}
3254
}
3261
 
3255
 
3262
bool CBaseFile::saveToArchive(const Utils::String &filename, int game, const CGameExe *exes, CProgressInfo *progress)
3256
bool CBaseFile::saveToArchive(const Utils::String &filename, int game, const CGameExe *exes, CProgressInfo *progress)
3263
{
3257
{
3264
	CDirIO Dir(CFileIO(filename).dir());
3258
	CDirIO Dir(CFileIO(filename).dir());
Line 3286... Line 3280...
3286
				continue;
3280
				continue;
3287
			// extracting for all games, so ignore files that have a game set
3281
			// extracting for all games, so ignore files that have a game set
3288
			if (!game && node->Data()->game() && node->Data()->game() != GAME_ALLNEW)
3282
			if (!game && node->Data()->game() && node->Data()->game() != GAME_ALLNEW)
3289
				continue;
3283
				continue;
3290
		}
3284
		}
3291
		Utils::String fname = node->Data()->getNameDirectory(this);
3285
		Utils::WString fname = node->Data()->getNameDirectory(this);
3292
 
3286
 
3293
		// use the addon directory
3287
		// use the addon directory
3294
		if (node->Data()->isFileInAddon() && exes)
3288
		if (node->Data()->isFileInAddon() && exes)
3295
		{
3289
		{
3296
			unsigned int whatGame = game;
3290
			unsigned int whatGame = game;
Line 3308... Line 3302...
3308
				}
3302
				}
3309
			}
3303
			}
3310
 
3304
 
3311
			if (whatGame > 0)
3305
			if (whatGame > 0)
3312
			{
3306
			{
3313
				SGameExe *e = exes->GetGame(whatGame - 1);
3307
				SGameExe *e = exes->game(whatGame - 1);
3314
				if (e)
3308
				if (e)
3315
				{
3309
				{
3316
					if (e->iFlags & EXEFLAG_ADDON)
3310
					if (e->iFlags & EXEFLAG_ADDON)
3317
						fname = e->sAddon + "/" + fname;
3311
						fname = e->sAddon + L"/" + fname;
3318
				}
3312
				}
3319
			}
3313
			}
3320
		}
3314
		}
3321
 
3315
 
3322
		// create the directory
3316
		// create the directory
3323
		wsprintf(buf, L"%hs", fname.c_str());
3317
		//wsprintf(buf, L"%hs", fname.c_str());
3324
		if (node->Data()->isExternalFile())
3318
		if (node->Data()->isExternalFile())
3325
		{
3319
		{
3326
			CFileIO file(node->Data()->filePointer());
3320
			CFileIO file(node->Data()->filePointer());
3327
			size_t size = 0;
3321
			size_t size = 0;
3328
			unsigned char *data = file.readAll(&size);
3322
			unsigned char *data = file.readAll(&size);
3329
			ZipAdd(hz, buf, data, size);
3323
			ZipAdd(hz, fname.c_str(), data, size);
3330
			delete data;
3324
			delete data;
3331
		}
3325
		}
3332
		else
3326
		else
3333
			ZipAdd(hz, buf, node->Data()->GetData(), node->Data()->GetDataSize());
3327
			ZipAdd(hz, fname.c_str(), node->Data()->GetData(), node->Data()->GetDataSize());
3334
	}
3328
	}
3335
 
3329
 
3336
	// if its a ship, then add any generated files
3330
	// if its a ship, then add any generated files
3337
	this->addGeneratedFiles(hz);
3331
	this->addGeneratedFiles(hz);
3338
 
3332
 
Line 3372... Line 3366...
3372
		iGame = sGame;
3366
		iGame = sGame;
3373
 
3367
 
3374
	return iGame;
3368
	return iGame;
3375
}
3369
}
3376
 
3370
 
3377
Utils::String CBaseFile::ConvertGameToString(int iGame)
3371
Utils::WString CBaseFile::ConvertGameToString(int iGame)
3378
{
3372
{
3379
	Utils::String game = "ALL";
3373
	Utils::WString game = L"ALL";
3380
 
3374
 
3381
	switch(iGame) {
3375
	switch(iGame) {
3382
		case GAME_ALL:
3376
		case GAME_ALL:
3383
		case GAME_ALLNEW:
3377
		case GAME_ALLNEW:
3384
			game = "ALL";
3378
			game = L"ALL";
3385
			break;
3379
			break;
3386
		case GAME_X2:
3380
		case GAME_X2:
3387
			game = "X2";
3381
			game = L"X2";
3388
			break;
3382
			break;
3389
		case GAME_X3:
3383
		case GAME_X3:
3390
			game = "X3";
3384
			game = L"X3";
3391
			break;
3385
			break;
3392
		case GAME_X3TC:
3386
		case GAME_X3TC:
3393
			game = "X3TC";
3387
			game = L"X3TC";
3394
			break;
3388
			break;
3395
		case GAME_X3AP:
3389
		case GAME_X3AP:
3396
			game = "X3AP";
3390
			game = L"X3AP";
3397
			break;
3391
			break;
3398
		case GAME_X3FL:
3392
		case GAME_X3FL:
3399
			game = "X3FL";
3393
			game = L"X3FL";
3400
			break;
3394
			break;
3401
		default:
3395
		default:
3402
			game = (long)iGame;
3396
			game = (long)iGame;
3403
	}
3397
	}
3404
 
3398
 
Line 3456... Line 3450...
3456
	str += "28;0;0;0;0;90;15093;0;105;1;5;0;105;0;1043;0;SS_WARE_SW_X3TC_6;\n";
3450
	str += "28;0;0;0;0;90;15093;0;105;1;5;0;105;0;1043;0;SS_WARE_SW_X3TC_6;\n";
3457
 
3451
 
3458
	return str;
3452
	return str;
3459
}
3453
}
3460
 
3454
 
3461
void CBaseFile::_addWaresToList(int iLang, CLinkList<SWareEntry> &list, const Utils::String &wares, enum WareTypes eType)
3455
void CBaseFile::_addWaresToList(int iLang, CLinkList<SWareEntry> &list, const Utils::WString &wares, enum WareTypes eType)
3462
{
3456
{
3463
	int totalWares = 0;
3457
	std::vector<Utils::WString> w;
3464
	Utils::String *w = wares.tokenise(";\n", &totalWares);
3458
	wares.tokenise(L"\n";, w);
3465
	
3459
	
3466
	for(int i = 0; i < totalWares; i++) {
3460
	for(size_t i = 0; i < w.size(); i++) {
3467
		int textId = w[i].token(";", 7).toLong();
3461
		int textId = w[i].token(L";", 7).toLong();
3468
		int useLang = iLang;
3462
		int useLang = iLang;
3469
		if ( !_pTextDB->exists(useLang, 17, textId) )
3463
		if ( !_pTextDB->exists(useLang, 17, textId) )
3470
			useLang = 44;
3464
			useLang = 44;
3471
		if ( !_pTextDB->exists(useLang, 17, textId) )
3465
		if ( !_pTextDB->exists(useLang, 17, textId) )
3472
			useLang = 49;
3466
			useLang = 49;
3473
		if ( _pTextDB->exists(useLang, 17, textId) ) {	
3467
		if ( _pTextDB->exists(useLang, 17, textId) ) {	
3474
			SWareEntry *ware = new SWareEntry;
3468
			SWareEntry *ware = new SWareEntry;
3475
			ware->name = _pTextDB->get(useLang, 17, textId);
3469
			ware->name = _pTextDB->get(useLang, 17, textId);
3476
			ware->description = _pTextDB->get(useLang, 17, textId + 1);
3470
			ware->description = _pTextDB->get(useLang, 17, textId + 1);
3477
			ware->id = w[i].token(";", -2);
3471
			ware->id = w[i].token(L";", -2);
3478
			ware->relval = w[i].token(";", 9).toLong();
3472
			ware->relval = w[i].token(L";", 9).toLong();
3479
			ware->notority = w[i].token(";", 14).toLong();
3473
			ware->notority = w[i].token(L";", 14).toLong();
3480
			ware->type = eType;
3474
			ware->type = eType;
3481
			ware->position = i;
3475
			ware->position = i;
3482
			ware->package = this;
3476
			ware->package = this;
3483
			list.push_back(ware);
3477
			list.push_back(ware);
3484
		}
3478
		}
3485
	}
3479
	}
3486
 
-
 
3487
	CLEANSPLIT(w, totalWares);
-
 
3488
}
3480
}
3489
 
3481
 
3490
bool CBaseFile::readWares(int iLang, CLinkList<SWareEntry> &list, const Utils::String &empWares)
3482
bool CBaseFile::readWares(int iLang, CLinkList<SWareEntry> &list, const Utils::WString &empWares)
3491
{
3483
{
3492
	_pTextDB->setLanguage(iLang);
3484
	_pTextDB->setLanguage(iLang);
3493
 
3485
 
3494
	// now go through all emp wares and get the ones we have text for
3486
	// now go through all emp wares and get the ones we have text for
3495
	_addWaresToList(iLang, list, empWares, Ware_EMP);
3487
	_addWaresToList(iLang, list, empWares, Ware_EMP);