Subversion Repositories spk

Rev

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

Rev 46 Rev 48
Line 26... Line 26...
26
 
26
 
27
 
27
 
28
CSpkFile::CSpkFile() : CBaseFile ()
28
CSpkFile::CSpkFile() : CBaseFile ()
29
{
29
{
30
	SetDefaults ();
30
	SetDefaults ();
31
 
-
 
32
	m_iType = TYPE_SPK;
-
 
33
}
31
}
34
 
32
 
35
CSpkFile::~CSpkFile()
33
CSpkFile::~CSpkFile()
36
{
34
{
37
	Delete ();
35
	Delete ();
Line 108... Line 106...
108
	}
106
	}
109
	else
107
	else
110
		return CBaseFile::ParseValueLine ( line );
108
		return CBaseFile::ParseValueLine ( line );
111
 
109
 
112
	return true;
110
	return true;
113
}
111
}
114
 
112
 
115
/*
113
/*
116
	Func:   CreateValuesLine
114
	Func:   CreateValuesLine
117
	Return: String - returns the full string for values
115
	Return: String - returns the full string for values
118
	Desc:   Creates a single string for all values, this is used when compressing to write to the spk file
116
	Desc:   Creates a single string for all values, this is used when compressing to write to the spk file
119
*/
117
*/
Line 159... Line 157...
159
				Utils::String str = split[i];
157
				Utils::String str = split[i];
160
				int num = str.token(":", 1);
158
				int num = str.token(":", 1);
161
				Utils::String name = str.tokens(":", 2);
159
				Utils::String name = str.tokens(":", 2);
162
 
160
 
163
				if ( num == lang )
161
				if ( num == lang )
164
				{
162
				{
165
					CLEANSPLIT(split, max)
163
					CLEANSPLIT(split, max)
166
					return name;
164
					return name;
167
				}
165
				}
168
			}
166
			}
169
 
167
 
Line 223... Line 221...
223
}
221
}
224
 
222
 
225
 
223
 
226
 
224
 
227
bool CSpkFile::ReadFileToMemory ( C_File *file )
225
bool CSpkFile::ReadFileToMemory ( C_File *file )
228
{
226
{
229
	if ( !file )
227
	if ( !file )
230
		return false;
228
		return false;
231
 
229
 
232
	// check if data is already extracted
230
	// check if data is already extracted
233
	if ( (file->GetDataSize ()) && (file->GetData()) )
231
	if ( (file->GetDataSize ()) && (file->GetData()) )
234
		return true;
232
		return true;
235
 
233
 
236
	// no file to read from
234
	// no file to read from
237
	if ( m_sFilename.Empty() )
235
	if ( m_sFilename.Empty() )
238
		return false;
236
		return false;
239
 
237
 
240
	// now open the file
238
	// now open the file
241
	FILE *id = fopen ( m_sFilename.c_str(), "rb" );
239
	FILE *id = fopen ( m_sFilename.c_str(), "rb" );
242
	if ( !id )
240
	if ( !id )
243
		return false;
241
		return false;
244
 
242
 
245
	// read the header
243
	// read the header
246
	GetEndOfLine ( id, NULL, false );
244
	GetEndOfLine ( id, NULL, false );
247
	// skip past values
245
	// skip past values
248
	fseek ( id, m_SHeader.lValueCompressSize, SEEK_CUR );
246
	fseek ( id, m_SHeader.lValueCompressSize, SEEK_CUR );
249
 
247
 
Line 288... Line 286...
288
{
286
{
289
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
287
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
290
	{
288
	{
291
		C_File *file = node->Data();
289
		C_File *file = node->Data();
292
		if ( file->GetFileType() != FILETYPE_README )
290
		if ( file->GetFileType() != FILETYPE_README )
293
			continue;
291
			continue;
294
		if ( !file->CheckValidFilePointer() )
292
		if ( !file->CheckValidFilePointer() )
295
			continue;
293
			continue;
296
		return true;
294
		return true;
297
	}
295
	}
298
 
296
 
299
	return false;
297
	return false;
300
}
298
}
301
 
299
 
302
 
300
 
303
 
301
 
304
void CSpkFile::ClearWares()
302
void CSpkFile::ClearWares()
305
{
303
{
306
	for ( CListNode<SWares> *node = m_lWares.Front(); node; node = node->next() ) {
304
	for ( CListNode<SWares> *node = m_lWares.Front(); node; node = node->next() ) {
307
		node->Data()->lText.clear(true);
305
		node->Data()->lText.clear(true);
308
		node->DeleteData();
306
		node->DeleteData();
309
	}
307
	}
310
	m_bChanged = true;
308
	m_bChanged = true;
311
	m_lWares.clear(true);
309
	m_lWares.clear(true);
312
}
310
}
313
 
311
 
314
SWares *CSpkFile::FindWare(const Utils::String &id) const
312
SWares *CSpkFile::FindWare(const Utils::String &id) const
315
{
313
{
316
	for ( CListNode<SWares> *node = m_lWares.Front(); node; node = node->next() ) {
314
	for ( CListNode<SWares> *node = m_lWares.Front(); node; node = node->next() ) {
317
		SWares *w = node->Data();
315
		SWares *w = node->Data();
318
		if ( w->sID.Compare(id) ) {
316
		if ( w->sID.Compare(id) ) {
Line 340... Line 338...
340
	ware->sID.remove(' ');
338
	ware->sID.remove(' ');
341
 
339
 
342
	SWares *newware = this->FindWare(ware->sID);
340
	SWares *newware = this->FindWare(ware->sID);
343
	if ( newware ) {
341
	if ( newware ) {
344
		m_lWares.remove(newware);
342
		m_lWares.remove(newware);
345
	}
343
	}
346
 
344
 
347
	m_lWares.push_back(ware);
345
	m_lWares.push_back(ware);
348
	m_bChanged = true;
346
	m_bChanged = true;
349
}
347
}
350
 
348
 
351
void CSpkFile::AddWareText(SWares *pWare, int iLang, const Utils::String &sName, const Utils::String &sDesc)
349
void CSpkFile::AddWareText(SWares *pWare, int iLang, const Utils::String &sName, const Utils::String &sDesc)
352
{
350
{
353
	SWaresText *wt;
351
	SWaresText *wt;
354
	for ( CListNode<SWaresText> *node = pWare->lText.Front(); node; node = node->next() ) {
352
	for ( CListNode<SWaresText> *node = pWare->lText.Front(); node; node = node->next() ) {
355
		wt = node->Data();
353
		wt = node->Data();
356
		if ( wt->iLang == iLang ) {
354
		if ( wt->iLang == iLang ) {
357
			wt->sDesc = sDesc;
355
			wt->sDesc = sDesc;
358
			wt->sName = sName;
356
			wt->sName = sName;
359
			return;
357
			return;
360
		}
358
		}
361
	}
359
	}
362
 
360
 
363
	wt = new SWaresText;
361
	wt = new SWaresText;
364
	wt->iLang = iLang;
362
	wt->iLang = iLang;
365
	wt->sName = sName;
363
	wt->sName = sName;
366
	wt->sDesc = sDesc;
364
	wt->sDesc = sDesc;
367
 
365
 
368
	pWare->lText.push_back(wt);
366
	pWare->lText.push_back(wt);
369
	m_bChanged = true;
367
	m_bChanged = true;
370
}
368
}
371
 
369
 
372
 
370
 
373
void CSpkFile::ClearWareText(const Utils::String &id)
371
void CSpkFile::ClearWareText(const Utils::String &id)
374
{
372
{
375
	SWares *w = FindWare(id);
373
	SWares *w = FindWare(id);
376
	ClearWareText(w);
374
	ClearWareText(w);
377
}
375
}
378
 
376
 
379
void CSpkFile::ClearWareText(SWares *w)
377
void CSpkFile::ClearWareText(SWares *w)
380
{
378
{
381
	if ( !w ) return;
379
	if ( !w ) return;
382
 
380
 
383
	w->lText.clear(true);
381
	w->lText.clear(true);
Line 406... Line 404...
406
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
404
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
407
	{
405
	{
408
		C_File *file = node->Data();
406
		C_File *file = node->Data();
409
		if ( file->GetFileType() != FILETYPE_SCRIPT )
407
		if ( file->GetFileType() != FILETYPE_SCRIPT )
410
			continue;
408
			continue;
411
 
409
 
412
		Utils::String basename = file->GetName().GetToken ( 1, file->GetName().NumToken('.') - 1, '.' ).ToString();
410
		Utils::String basename = file->GetName().GetToken ( 1, file->GetName().NumToken('.') - 1, '.' ).ToString();
413
		if ( basename.right(15).Compare(".initplayership") )
411
		if ( basename.right(15).Compare(".initplayership") )
414
			return 0;
412
			return 0;
415
	}
413
	}
416
	if ( !IsAnotherMod() )
414
	if ( !IsAnotherMod() )
Line 422... Line 420...
422
bool CSpkFile::UpdateSigned (bool updateFiles)
420
bool CSpkFile::UpdateSigned (bool updateFiles)
423
{
421
{
424
	// check for any custom wares
422
	// check for any custom wares
425
	// patch mods and custom starts are also not signed
423
	// patch mods and custom starts are also not signed
426
	if ( (!m_lWares.empty()) || (this->IsPatch()) || (this->IsCustomStart()) )
424
	if ( (!m_lWares.empty()) || (this->IsPatch()) || (this->IsCustomStart()) )
427
	{
425
	{
428
		m_bSigned = false;
426
		m_bSigned = false;
429
		return false;
427
		return false;
430
	}
428
	}
431
 
429
 
432
	return CBaseFile::UpdateSigned(updateFiles);
430
	return CBaseFile::UpdateSigned(updateFiles);
Line 451... Line 449...
451
		case SETTING_INTEGER:
449
		case SETTING_INTEGER:
452
			t = new SSettingInteger;
450
			t = new SSettingInteger;
453
			break;
451
			break;
454
		case SETTING_CHECK:
452
		case SETTING_CHECK:
455
			t = new SSettingCheck;
453
			t = new SSettingCheck;
456
			break;
454
			break;
457
	}
455
	}
458
 
456
 
459
	if ( !t )
457
	if ( !t )
460
		return NULL;
458
		return NULL;
461
 
459
 
462
	t->sKey = sKey;
460
	t->sKey = sKey;
463
	t->iType = type;
461
	t->iType = type;
464
 
462
 
465
	m_lSettings.push_back ( t );
463
	m_lSettings.push_back ( t );
466
	m_bChanged = true;
464
	m_bChanged = true;
467
 
465
 
468
	return t;
466
	return t;
469
}
467
}
470
 
468
 
471
void CSpkFile::ConvertSetting ( SSettingType *t, const Utils::String &set ) const
469
void CSpkFile::ConvertSetting ( SSettingType *t, const Utils::String &set ) const
472
{
470
{
473
	if ( !t )
471
	if ( !t )
474
		return;
472
		return;
475
 
473
 
476
	switch ( t->iType )
474
	switch ( t->iType )
477
	{
475
	{
478
		case SETTING_STRING:
476
		case SETTING_STRING:
479
			((SSettingString *)t)->sValue = set;
477
			((SSettingString *)t)->sValue = set;
480
			break;
478
			break;
481
		case SETTING_INTEGER:
479
		case SETTING_INTEGER:
Line 554... Line 552...
554
		if ( this->IsFakePatch() )
552
		if ( this->IsFakePatch() )
555
			return "Fake Patch";
553
			return "Fake Patch";
556
	}
554
	}
557
 
555
 
558
	Utils::String sType = CSpkFile::GetScriptTypeStringStatic(m_iScriptType);
556
	Utils::String sType = CSpkFile::GetScriptTypeStringStatic(m_iScriptType);
559
 
557
 
560
	if ( sType.empty() )
558
	if ( sType.empty() )
561
		return "Other";
559
		return "Other";
562
 
560
 
563
	return sType;	
561
	return sType;	
564
}
562
}
565
 
563
 
566
int CSpkFile::ConvertScriptType(const Utils::String &sType)
564
int CSpkFile::ConvertScriptType(const Utils::String &sType)
567
{
565
{
568
	for ( int i = 0; i < SCRIPTTYPE_MAX; i++ )
566
	for ( int i = 0; i < SCRIPTTYPE_MAX; i++ )
569
	{
567
	{
570
		if ( sType.Compare(CSpkFile::GetScriptTypeStringStatic(i)) )
568
		if ( sType.Compare(CSpkFile::GetScriptTypeStringStatic(i)) )
571
			return i;
569
			return i;
572
	}
570
	}
573
 
571
 
574
	return -1;
572
	return -1;
575
}
573
}
576
 
574
 
577
Utils::String CSpkFile::GetScriptTypeStringStatic(int type)
575
Utils::String CSpkFile::GetScriptTypeStringStatic(int type)
578
{
576
{
579
	switch ( type )
577
	switch ( type )
580
	{
578
	{
Line 636... Line 634...
636
		else
634
		else
637
		{
635
		{
638
			int check = sRest;
636
			int check = sRest;
639
			if ( check || sRest == "0" )
637
			if ( check || sRest == "0" )
640
				m_iScriptType = check;
638
				m_iScriptType = check;
641
			else
639
			else
642
			{
640
			{
643
				m_iScriptType = CSpkFile::ConvertScriptType(sRest);
641
				m_iScriptType = CSpkFile::ConvertScriptType(sRest);
644
				if ( m_iScriptType == -1 )
642
				if ( m_iScriptType == -1 )
645
					m_sScriptType = sRest;
643
					m_sScriptType = sRest;
646
			}
644
			}
Line 669... Line 667...
669
		if ( useWare )
667
		if ( useWare )
670
		{
668
		{
671
			int lang = sRest.token(" ", 2);
669
			int lang = sRest.token(" ", 2);
672
			SWaresText *wt = NULL;
670
			SWaresText *wt = NULL;
673
			for ( CListNode<SWaresText> *tNode = useWare->lText.Front(); tNode; tNode = tNode->next() )
671
			for ( CListNode<SWaresText> *tNode = useWare->lText.Front(); tNode; tNode = tNode->next() )
674
			{
672
			{
675
				if ( tNode->Data()->iLang == lang )
673
				if ( tNode->Data()->iLang == lang )
676
				{
674
				{
677
					wt = tNode->Data();
675
					wt = tNode->Data();
678
					break;
676
					break;
679
				}
677
				}
680
			}
678
			}
681
 
679
 
682
			if ( !wt )
680
			if ( !wt )
683
			{
681
			{
684
				wt = new SWaresText;
682
				wt = new SWaresText;
685
				wt->iLang = lang;
683
				wt->iLang = lang;
686
				useWare->lText.push_back(wt);
684
				useWare->lText.push_back(wt);
687
			}
685
			}
688
 
686
 
689
			if ( sFirst.Compare("WareName") )
687
			if ( sFirst.Compare("WareName") )
690
				wt->sName = sRest.tokens(" ", 3);
688
				wt->sName = sRest.tokens(" ", 3);
691
			else
689
			else
692
				wt->sDesc = sRest.tokens(" ", 3);
690
				wt->sDesc = sRest.tokens(" ", 3);
693
		}
691
		}
694
	}
692
	}
695
	else if ( sFirst.left(4).Compare("Ware") )
693
	else if ( sFirst.left(4).Compare("Ware") )
696
	{
694
	{
Line 702... Line 700...
702
		ware->iSize = sRest.token(" ", 3);
700
		ware->iSize = sRest.token(" ", 3);
703
		ware->iVolumn = sRest.token(" ", 4);
701
		ware->iVolumn = sRest.token(" ", 4);
704
		ware->sID = sRest.token(" ", 1);
702
		ware->sID = sRest.token(" ", 1);
705
		ware->iNotority = sRest.token(" ", 5);
703
		ware->iNotority = sRest.token(" ", 5);
706
		if ( !sRest.token(" ", 6).empty() )
704
		if ( !sRest.token(" ", 6).empty() )
707
		{
705
		{
708
			ware->iTextID = sRest.token(" ", 6).token(",", 2);
706
			ware->iTextID = sRest.token(" ", 6).token(",", 2);
709
			ware->iTextPage = sRest.token(" ", 6).token(",", 1);
707
			ware->iTextPage = sRest.token(" ", 6).token(",", 1);
710
		}
708
		}
711
		m_lWares.push_back ( ware );
709
		m_lWares.push_back ( ware );
712
		m_pLastWare = ware;
710
		m_pLastWare = ware;
Line 735... Line 733...
735
	else if ( this->IsPatch() )
733
	else if ( this->IsPatch() )
736
		list->PushBack("ScriptType: Patch");
734
		list->PushBack("ScriptType: Patch");
737
	else
735
	else
738
		list->PushBack(CyString("ScriptType: ") + this->GetScriptTypeString(44));
736
		list->PushBack(CyString("ScriptType: ") + this->GetScriptTypeString(44));
739
	list->PushBack("");
737
	list->PushBack("");
740
 
738
 
741
	if ( this->IsAnotherMod() )
739
	if ( this->IsAnotherMod() )
742
	{
740
	{
743
		list->PushBack("# For another mod/package, this is a child package");
741
		list->PushBack("# For another mod/package, this is a child package");
744
		list->PushBack(CyString("AnotherMod: ") + m_sOtherName + "|" + m_sOtherAuthor);
742
		list->PushBack(CyString("AnotherMod: ") + m_sOtherName + "|" + m_sOtherAuthor);
745
		list->PushBack("");
743
		list->PushBack("");
Line 800... Line 798...
800
}
798
}
801
Utils::String CSpkFile::GetWareDesc(SWares *w, int lang)
799
Utils::String CSpkFile::GetWareDesc(SWares *w, int lang)
802
{
800
{
803
	// return the text page if being used
801
	// return the text page if being used
804
	if ( w->iTextID > 0 && w->iTextPage > 0 )
802
	if ( w->iTextID > 0 && w->iTextPage > 0 )
805
		return Utils::String("{") + (long)w->iTextPage + "," + ((long)w->iTextID + 1) + "}";
803
		return Utils::String("{") + (long)w->iTextPage + "," + ((long)w->iTextID + 1) + "}";
806
 
804
 
807
	Utils::String name;
805
	Utils::String name;
808
	for ( CListNode<SWaresText> *wt = w->lText.Front(); wt; wt = wt->next() )
806
	for ( CListNode<SWaresText> *wt = w->lText.Front(); wt; wt = wt->next() )
809
	{
807
	{
810
		if ( wt->Data()->sDesc.empty() )
808
		if ( wt->Data()->sDesc.empty() )
Line 817... Line 815...
817
		else if ( name.empty() )
815
		else if ( name.empty() )
818
			name = wt->Data()->sDesc;
816
			name = wt->Data()->sDesc;
819
	}
817
	}
820
 
818
 
821
	return name;
819
	return name;
822
}
820
}
823
 
821
 
824
Utils::String CSpkFile::GetCustomStartName() const
822
Utils::String CSpkFile::GetCustomStartName() const
825
{
823
{
826
	if ( !this->IsCustomStart() )
824
	if ( !this->IsCustomStart() )
827
		return "";
825
		return "";
Line 843... Line 841...
843
void CSpkFile::MergePackage(CBaseFile *base)
841
void CSpkFile::MergePackage(CBaseFile *base)
844
{
842
{
845
	// update version information
843
	// update version information
846
	m_sVersion = base->GetVersion();
844
	m_sVersion = base->GetVersion();
847
	m_sCreationDate = base->GetCreationDate();
845
	m_sCreationDate = base->GetCreationDate();
848
	m_iPluginType = base->GetPluginType();
-
 
849
 
846
 
850
	// update possible changes
847
	// update possible changes
851
	if ( base->GetType() == TYPE_SPK )
848
	if ( base->GetType() == TYPE_SPK )
852
	{
849
	{
853
		CSpkFile *spk = (CSpkFile *)base;
850
		CSpkFile *spk = (CSpkFile *)base;
Line 892... Line 889...
892
	if ( !base->GetEmail().Empty() )
889
	if ( !base->GetEmail().Empty() )
893
		m_sEmail = base->GetEmail();
890
		m_sEmail = base->GetEmail();
894
	if ( !base->GetForumLink().Empty() )
891
	if ( !base->GetForumLink().Empty() )
895
		m_sForumLink = base->GetForumLink();
892
		m_sForumLink = base->GetForumLink();
896
 
893
 
897
	m_sDescription = base->GetDescription();
-
 
898
 
894
 
899
	// copy over needed librarys
895
	// copy over needed librarys
900
	for ( CListNode<SNeededLibrary> *lNode = base->GetNeededLibraries()->Front(); lNode; lNode = lNode->next() )
896
	for ( CListNode<SNeededLibrary> *lNode = base->GetNeededLibraries()->Front(); lNode; lNode = lNode->next() )
901
		this->AddNeededLibrary(lNode->Data()->sName, lNode->Data()->sAuthor, lNode->Data()->sMinVersion);
897
		this->AddNeededLibrary(lNode->Data()->sName, lNode->Data()->sAuthor, lNode->Data()->sMinVersion);
902
 
898
 
Line 1083... Line 1079...
1083
	else if ( sCmd == "Date:" )
1079
	else if ( sCmd == "Date:" )
1084
	{
1080
	{
1085
		this->SetCreationDate ( sRest );
1081
		this->SetCreationDate ( sRest );
1086
		CLog::logf(CLog::Log_EditPackage, "\tScript Creation Date: %s", sRest.c_str() );
1082
		CLog::logf(CLog::Log_EditPackage, "\tScript Creation Date: %s", sRest.c_str() );
1087
	}
1083
	}
1088
	else if ( sCmd == "Desc:" )
1084
	else if ( sCmd == "Desc:" ) {
1089
	{
-
 
1090
		this->SetDescription(sRest.findReplace("<br>", "\n") );
1085
		this->setDescription(sRest.findReplace("<br>", "\n") );
1091
		CLog::logf(CLog::Log_EditPackage, "\tScript Description: %s", this->GetDescription().c_str() );
1086
		CLog::logf(CLog::Log_EditPackage, "\tScript Description: %s", this->description().c_str() );
1092
	}
1087
	}
1093
	else if ( sCmd == "WebAddress:" )
1088
	else if ( sCmd == "WebAddress:" )
1094
	{
1089
	{
1095
		this->SetWebAddress ( sRest );
1090
		this->SetWebAddress ( sRest );
1096
		CLog::logf(CLog::Log_EditPackage, "\tWeb Address: %s", sRest.c_str() );
1091
		CLog::logf(CLog::Log_EditPackage, "\tWeb Address: %s", sRest.c_str() );