Subversion Repositories spk

Rev

Rev 39 | Rev 48 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
#include "../StdAfx.h"
2
#include "PackageForm.h"
3
#include "InputBox.h"
4
#include "Form1.h"
5
#include "AddWareText.h"
6
#include "AddCockpit.h"
7
#include "SaveDialog.h"
8
 
46 cycrow 9
#include <Package/InstallText.h>
10
 
1 cycrow 11
namespace Creator {
12
	bool PackageForm::LoadPackage(CBaseFile *base, System::String ^filename)
13
	{
14
		m_sFilename = filename;
15
 
16
		if ( !base )
17
		{
18
			int error;
19
			m_pPackage = m_pP->OpenPackage(CyStringFromSystemString(filename), &error);
20
			if ( !m_pPackage )
21
				return false;
22
		}
23
		else
24
			m_pPackage = base;
25
 
26
		m_pPackage->SetChanged(false);
27
		m_pPackage->UpdateSigned(true);
28
		this->UpdateChanged();
29
		m_bLoading = true;
30
 
31
		if ( m_pPackage->AnyFileType(FILETYPE_ADVERT) )
32
		{
33
			for ( C_File *f = m_pPackage->GetFirstFile(FILETYPE_ADVERT); f; f = m_pPackage->GetNextFile(f) )
34
			{
35
				f->SetFullDir(CyStringFromSystemString(System::IO::Path::GetTempPath()));
36
				long size;
37
				unsigned char *data = f->UncompressData(&size, 0);
38
				if ( data && size )
39
				{
40
					if ( f->WriteFilePointer(data, size) )
41
					{
42
						if ( !m_pDisplayFile )
43
							m_pDisplayFile = f;
44
					}
45
 
46
					if ( f->GetCompressionType() != SPKCOMPRESS_NONE )
47
						delete data;
48
				}
49
			}
50
		}
51
 
52
		if ( m_pPackage->GetIcon() )
53
		{
54
			C_File *f = m_pPackage->GetIcon();
55
			f->SetFilename(CyStringFromSystemString(System::IO::Path::GetTempPath()) + "/package_icon." + m_pPackage->GetIconExt());
56
			f->SetFullDir(CyStringFromSystemString(System::IO::Path::GetTempPath()));
57
			long size;
58
			unsigned char *data = f->UncompressData(&size, 0);
59
			if ( data && size )
60
			{
61
				f->WriteFilePointer(data, size);
62
				if ( f->GetCompressionType() != SPKCOMPRESS_NONE )
63
					delete data;
64
			}
65
		}
66
 
67
		this->RadioInstallBefore->Checked = true;
68
		this->RadioInstallAfter->Checked = false;
69
		this->RadioUninstallAfter->Checked = false;
70
		this->RadioUninstallBefore->Checked = false;
71
		this->UpdateView();
72
 
73
		m_pPackage->SetChanged(false);
74
 
75
		m_bLoading = false;
76
 
77
		return true;
78
	}
79
 
80
	void PackageForm::DoToolTips()
81
	{
82
		//tooltip1 for any controls with text to display
83
		this->toolTip1->SetToolTip(this->RadioTypeUpdate, "This allows you to create a small package to update an already installed one with new files.\nIn the Dependacy section you can set the minimum version required to install.\nAny mod files only need to contain the files you want to update, they will be added into the existing mod file when installed");
84
		this->toolTip1->SetToolTip(this->RadioTypeStart, "This allows you to create a custom start in the old format\nWhen installed, it will use the added initplayer script to create the maps and jobs file automatically\nThis allows it to always use the most up to date map automatically, so you only need to make changes to the script file\nIf set to use another mod, it'll use the map from the mod instead of the games one");
85
		this->toolTip1->SetToolTip(this->RadioTypePatch, "This allows you to create patchs to your mod files\nWhen installing, any files in the patch mod will overright the base mod files, allowing you to create different patchs allowing users to customise your mod without having to have seperate mod installs\nWhen the patch is uninstalled, any changed files will be restored back to the normal ones");
86
		this->toolTip1->SetToolTip(this->CheckShipID, "This allows you to replaing an existing ship when you install\nNormally, the ship is simply added into the game, at the end of the ships file, when set to replace, it will replace the ship with the same ship id.\nThis allows you to create an update to an existing ship without having to have both in the game");
87
		this->toolTip1->SetToolTip(this->groupBox3, "This allows you to set the parent package\nThis will need to be installed as well, unlike depencies, the child/parent packages are linked to each other\nThis allows you to release updates or addons for a certain package, one that will only work with the parent package");
88
		this->toolTip1->SetToolTip(this->ButFromFile, "This will read the details from an existing file\nWhen selected, you will be prompted to select a saved package file.\nThe package name and author is then read from the package and automatically filled in so you know its entered correctly");
89
		this->toolTip1->SetToolTip(this->RadioInstallBefore, "This is a message you can give to the user when they install your package\nThis will come before the installation starts and allows you to display information or warnings about the package they are about to install to help them decide if they want to continue installing or not");
90
		this->toolTip1->SetToolTip(this->RadioInstallAfter, "This message is displayed to the user once the package has been installed\nThis is usually used to give the user information about your package, like how to start using it in game, or important information before they start using it, etc");
91
		this->toolTip1->SetToolTip(this->RadioUninstallBefore, "This message is displayed when the user attempts to uninstall your package\nThis can be used to give the user instruction on what else they might need to do to uninstall, ie if theres something they need to do ingame first before removing the package");
92
		this->toolTip1->SetToolTip(this->RadioUninstallAfter, "This message is displayed after the user has uninstalled your package\nThis can give them information about anything else they might need to do to remove the package, ie to allow the uninstall scripts to function to remove anything from thier game");
93
		this->toolTip1->SetToolTip(this->GroupEase, "This is a rating allowing the user to see how easy it is to use the script\nThe ratings are displayed when installing the package and are from 1 to 5, 5 being easy to use, 1 being hard\nClicking on the stars will adjust the rating");
94
		this->toolTip1->SetToolTip(this->GroupChange, "This is a rating allowing the user to see how much the package changes the game\nThe ratings are displayed when installing the package and are from 1 to 5, 5 being alot of change, 1 being very little\nClicking on the stars will adjust the rating");
95
		this->toolTip1->SetToolTip(this->GroupRec, "This is a rating allowing the user to see how much you recommended this package\nThe ratings are displayed when installing the package and are from 1 to 5, 5 highly recommended\nClicking on the stars will adjust the rating");
96
 
97
		// controls that need custom title texts using tags
98
		this->ComboPluginType->Tag = "Plugin Type";
99
		this->toolTip2->SetToolTip(this->ComboPluginType, "The plugin type is used to display roughly what type the plugin comes under, this is displayed during installation\nNormal = Just a normal package\nStable = A stable or final release of a package\nExperimental = Potentinally unstable package\nCheat = Considered to be a cheat, ie breaks game balance\nMod = A Mod, can only run 1 at a time and not compatable with other mods");
100
	}
101
 
102
	void PackageForm::UpdateScriptType()
103
	{
6 cycrow 104
		if ( this->ComboType->SelectedIndex == CSpkFile::SCRIPTTYPE_CUSTOM )
105
		{
106
			this->TextCustomType->Visible = true;
107
			this->ComboType->Dock = Windows::Forms::DockStyle::Left;
108
			if ( !m_bLoading )
10 cycrow 109
				((CSpkFile *)m_pPackage)->SetScriptType(CyStringFromSystemString(this->TextCustomType->Text).ToString());
1 cycrow 110
		 }
111
		 else
112
		 {
113
			 this->TextCustomType->Visible = false;
114
			 this->ComboType->Dock = Windows::Forms::DockStyle::Fill;
115
		 }
116
	}
117
	void PackageForm::UpdateText()
118
	{
46 cycrow 119
		const SPK::Package::CInstallText *pText = NULL;
120
 
1 cycrow 121
		this->TextText->Tag = 1;
122
		if ( this->RadioInstallAfter->Checked || this->RadioInstallBefore->Checked )
46 cycrow 123
			pText = m_pPackage->installText();
1 cycrow 124
		else if ( this->RadioUninstallAfter->Checked || this->RadioUninstallBefore->Checked )
46 cycrow 125
			pText = m_pPackage->uninstallText();
1 cycrow 126
		else
127
		{
128
			this->ListLang->Enabled = false;
129
			this->ButTextAdd->Enabled = false;
130
			this->UpdateTextLang();
131
			return;
132
		}
133
 
134
		this->ListLang->Enabled = true;
135
		this->ButTextAdd->Enabled = true;
136
 
137
		int selected = this->ListLang->SelectedIndex;
46 cycrow 138
		if ( selected >= 1 )	selected = Convert::ToInt32(this->ListLang->Text);
139
		else					selected = -1;
1 cycrow 140
 
141
		this->ListLang->Items->Clear();
142
		this->ListLang->Items->Add("- Default -");
143
 
144
		// add languages
46 cycrow 145
		for ( unsigned int i = 0; i < pText->count(); i++ ) {
146
			int iLang = pText->language(i);
147
			if ( iLang <= 0 ) continue;
148
			this->ListLang->Items->Add(System::Convert::ToString(iLang));
1 cycrow 149
		}
150
 
151
		if ( selected == -1 )
152
			this->ListLang->SelectedIndex = 0;
153
		else
154
			this->ListLang->Text = Convert::ToString(selected);
46 cycrow 155
 
1 cycrow 156
		if ( this->ListLang->SelectedIndex == -1 )
157
			this->ListLang->SelectedIndex = 0;
158
 
159
		this->UpdateTextLang();
160
	}
161
 
162
	void PackageForm::UpdateTextLang()
163
	{
164
		this->TextText->Tag = 1;
165
		this->TextText->Enabled = false;
166
		this->TextText->Text = "";
167
 
168
		if ( this->ListLang->SelectedIndex >= 0 )
169
		{
170
			int lang = CyStringFromSystemString(this->ListLang->Text).ToInt();
46 cycrow 171
			Utils::String desc;
172
			if ( this->RadioInstallAfter->Checked )			desc = m_pPackage->installText(lang, false, false);
173
			else if ( this->RadioInstallBefore->Checked )	desc = m_pPackage->installText(lang, true, false);
174
			else if ( this->RadioUninstallAfter->Checked )	desc = m_pPackage->uninstallText(lang, false, false);
175
			else if ( this->RadioUninstallBefore->Checked )	desc = m_pPackage->uninstallText(lang, true, false);
176
 
177
			this->TextText->Text = _US(desc);
1 cycrow 178
			this->TextText->Enabled = true;
179
		}
180
 
181
		this->ButTextDel->Enabled = false;
182
		if ( this->ListLang->SelectedIndex >= 1 )
183
			this->ButTextDel->Enabled = true;
184
 
185
		this->TextText->Tag = nullptr;
186
	}
187
 
188
	void PackageForm::UpdateWares()
189
	{
190
		CSpkFile *spk = (CSpkFile *)m_pPackage;
191
 
192
		this->ListWares->Items->Clear();
193
		for ( SWares *w = spk->GetWaresList()->First(); w; w = spk->GetWaresList()->Next() )
194
		{
195
			ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(w->sID));
196
			switch ( tolower(w->cType) )
197
			{
198
				case 'b':
199
					item->SubItems->Add("Bio");
200
					break;
201
				case 'e':
202
					item->SubItems->Add("Energy");
203
					break;
204
				case 'f':
205
					item->SubItems->Add("Food");
206
					break;
207
				case 't':
208
					item->SubItems->Add("Tech");
209
					break;
210
				case 'm':
211
					item->SubItems->Add("Mineral");
212
					break;
213
				default:
214
					item->SubItems->Add("Other");
215
			}
216
			item->SubItems->Add(System::Convert::ToString(w->iPrice));
217
			switch ( w->iSize )
218
			{
219
				case 0:
220
					item->SubItems->Add("Tiny Containers");
221
					break;
222
				case 1:
223
					item->SubItems->Add("Small Containers (S)");
224
					break;
225
				case 2:
226
					item->SubItems->Add("Medium Containers (M)");
227
					break;
228
				case 3:
229
					item->SubItems->Add("Large Containers (L)");
230
					break;
231
				case 4:
232
					item->SubItems->Add("Extra Large Containers (XL)");
233
					break;
234
				case 5:
235
					item->SubItems->Add("Station Containers (ST)");
236
					break;
237
				default:
238
					item->SubItems->Add("Other Containers");
239
			}
240
 
241
			item->SubItems->Add(System::Convert::ToString(w->iVolumn));
242
			item->SubItems->Add(System::Convert::ToString(w->iNotority));
243
 
244
			if ( w->iTextPage > 0 && w->iTextID > 0 )
245
				item->SubItems->Add(System::Convert::ToString(w->iTextPage) + ", " + System::Convert::ToString(w->iTextID));
246
			item->ImageIndex = 2;
247
			this->ListWares->Items->Add(item);
248
		}
249
		this->ListWares->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
250
 
251
		this->UpdateWareText();
252
		m_pPackage->UpdateSigned(false);
253
		this->UpdateChanged();
254
	}
255
 
256
	void PackageForm::UpdateWareText()
257
	{
258
		this->ListWareText->Items->Clear();
259
		this->splitContainer1->Panel2Collapsed = true;
260
 
261
		if ( this->ListWares->SelectedItems->Count )
262
		{
10 cycrow 263
			SWares *w = ((CSpkFile *)m_pPackage)->FindWare(CyStringFromSystemString(this->ListWares->SelectedItems[0]->Text).ToString());
1 cycrow 264
			if ( w )
265
			{
266
				if ( w->iTextPage <= 0 && w->iTextID <= 0 )
267
				{			
268
					this->ListWareText->Items->Clear();
269
					this->splitContainer1->Panel2Collapsed = false;
270
					for ( SWaresText *wt = w->lText.First(); wt; wt = w->lText.Next() )
271
					{
272
						ListViewItem ^item = gcnew ListViewItem(System::Convert::ToString(wt->iLang));
273
						item->ImageIndex = 0;
274
						item->SubItems->Add(SystemStringFromCyString(wt->sName));
275
						item->SubItems->Add(SystemStringFromCyString(wt->sDesc));
276
						this->ListWareText->Items->Add(item);
277
					}
278
				}
279
			}
280
		}
281
	}
282
 
283
	void PackageForm::UpdateView()
284
	{
285
		m_bLoading = true;
286
 
287
		System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(PackageForm::typeid));
288
 
289
		this->LabelShipWarning->Visible = false;
290
		this->TextName->Text = SystemStringFromCyString(m_pPackage->GetName());
291
		this->TextAuthor->Text = SystemStringFromCyString(m_pPackage->GetAuthor());
292
		this->TextVersion->Text = SystemStringFromCyString(m_pPackage->GetVersion());
293
		CyString desc = m_pPackage->GetDescription();
294
		desc = desc.FindReplace("<br>", "\n");
295
		desc = desc.FindReplace("<newline>", "\n");
296
		desc = desc.StripHTML();
297
		this->TextDesc->Text = SystemStringFromCyString(desc);
298
 
299
		if ( m_pPackage->GetType() == TYPE_XSP )
300
		{
301
			CXspFile *xsp = (CXspFile *)m_pPackage;
302
			this->TextShipID->Text = SystemStringFromCyString(xsp->GetShipID());
303
			this->PanelShip->Show();
304
			this->LabelShipWarning->Visible = true;
305
			this->groupBox6->Visible = false;
306
 
307
			this->TextShipData->Text = SystemStringFromCyString(xsp->GetShipData());
308
 
309
			this->CheckShipID->Checked = xsp->IsExistingShip();
310
			this->CheckExistingText->Checked = (xsp->GetOriginalDescription()) ? true : false;
311
			if ( xsp->GetOriginalDescription() )
312
				this->NumTextID->Value = xsp->GetOriginalDescription();
313
 
314
			// shipyards
315
			this->CheckSYArgon->Checked = xsp->IsShipyard(SHIPYARD_ARGON);
316
			this->CheckSYBoron->Checked = xsp->IsShipyard(SHIPYARD_BORON);
317
			this->CheckSYTeladi->Checked = xsp->IsShipyard(SHIPYARD_TELADI);
318
			this->CheckSYParanid->Checked = xsp->IsShipyard(SHIPYARD_PARANID);
319
			this->CheckSYSplit->Checked = xsp->IsShipyard(SHIPYARD_SPLIT);
320
			this->CheckSYFriend->Checked = xsp->IsShipyard(SHIPYARD_FRIEND);
321
			this->CheckSYPirate->Checked = xsp->IsShipyard(SHIPYARD_PIRATES);
322
			this->CheckSYXenon->Checked = xsp->IsShipyard(SHIPYARD_XENON);
323
			this->CheckSYTerran->Checked = xsp->IsShipyard(SHIPYARD_TERRAN);
324
			this->CheckSYATF->Checked = xsp->IsShipyard(SHIPYARD_ATF);
325
			this->CheckSYYaki->Checked = xsp->IsShipyard(SHIPYARD_YAKI);
326
 
327
			this->UpdateShipText();
328
			this->UpdateShipPartList();
329
		}
330
		else if ( m_pPackage->GetType() == TYPE_SPK )
331
		{
332
			CSpkFile *spk = (CSpkFile *)m_pPackage;
333
 
334
			this->ComboType->Text = "Custom";
335
			this->ComboType->Enabled = false;
336
 
337
			this->ComboPluginType->SelectedIndex = spk->GetPluginType();
338
 
339
			if ( spk->IsLibrary() )
340
				this->RadioTypeLibrary->Checked = true;
341
			else if ( spk->IsCustomStart() )
342
				this->RadioTypeStart->Checked = true;
343
			else if ( spk->IsPackageUpdate() )
344
				this->RadioTypeUpdate->Checked = true;
345
			else if ( spk->IsPatch() )
346
				this->RadioTypePatch->Checked = true;
347
			else
348
			{
349
				this->RadioTypeScript->Checked = true;
350
				this->ComboType->SelectedIndex = spk->GetScriptType();
351
				this->ComboType->Enabled = true;
6 cycrow 352
				if ( this->ComboType->SelectedIndex == CSpkFile::SCRIPTTYPE_CUSTOM )
1 cycrow 353
					this->TextCustomType->Text = SystemStringFromCyString(spk->GetCustomScriptType(m_pP->GetLanguage()));
354
			}
355
 
356
			this->CheckOther->Checked = spk->IsAnotherMod();
357
			this->TextOtherAuthor->Enabled = this->CheckOther->Checked;
358
			this->TextOtherName->Enabled = this->CheckOther->Checked;
359
			this->ButFromFile->Enabled = this->CheckOther->Checked;
360
 
361
			if ( spk->IsAnotherMod() )
362
			{
363
				this->TextOtherAuthor->Text = SystemStringFromCyString(spk->GetOtherAuthor());
364
				this->TextOtherName->Text = SystemStringFromCyString(spk->GetOtherName());
365
			}
366
 
367
			this->UpdateWares();
368
			this->UpdateScriptType();
369
		}
370
 
371
		if ( !m_pPackage->GetCreationDate().Empty() )
372
		{
373
			CyString date = m_pPackage->GetCreationDate();
374
			int day = m_pPackage->GetCreationDate().GetToken("/", 1, 1).ToInt();
375
			int month = m_pPackage->GetCreationDate().GetToken("/", 2, 2).ToInt();
376
			int year = m_pPackage->GetCreationDate().GetToken("/", 3, 3).ToInt();
377
			if ( month > 12 && day <= 12 ) { int temp = day; day = month; month = temp; }
378
			if ( month < 1 ) month = 1;
379
			if ( month > 12 ) month = 12;
380
			if ( day < 1 ) day = 1;
381
			if ( day > 31 ) day = 1;
382
			if ( year < 1900 ) year += 2000;
383
			try {
384
				this->CreationDate->Value = DateTime(year, month, day);
385
			} catch(System::ArgumentOutOfRangeException ^) {
386
				this->CreationDate->Value = DateTime::Today;
387
			}
388
		}
389
		else
390
			this->CreationDate->Value = DateTime::Today;
391
 
392
		this->TextForum->Text = SystemStringFromCyString(m_pPackage->GetForumLink());
393
		this->TextEmail->Text = SystemStringFromCyString(m_pPackage->GetEmail());
394
		this->TextWebsite->Text = SystemStringFromCyString(m_pPackage->GetWebSite());
395
		this->TextWebAddress->Text = SystemStringFromCyString(m_pPackage->GetWebAddress());
396
 
397
		this->UpdateGamesList();
398
		this->UpdateFileList();
399
		this->UpdateMirrors();
400
		this->UpdatePackageNames();
401
 
402
		m_bSortingAsc = true;
403
		m_iSortingCol = 1;
404
		this->ListFiles->ListViewItemSorter = gcnew ListViewItemComparer(m_iSortingCol, !m_bSortingAsc);
405
 
406
		this->UpdateDisplayPic();
407
		this->UpdateDisplayIcon();
408
		this->UpdateRatings();
409
		this->UpdateText();
410
		this->UpdateDependacies();
411
 
412
		// delete the pages
413
		if ( m_pPackage->GetType() != TYPE_XSP )
414
		{
415
			delete this->PageShip;
416
			delete this->PageRaw;
417
			delete this->PageShipComp;
418
			this->PageShip = nullptr;
419
			this->PageRaw = nullptr;
420
			this->PageShipComp = nullptr;
421
			this->PanelShip->Hide();
422
			this->ToolCustomise->Visible = false;
423
		}
424
		else if ( m_pPackage->GetType() != TYPE_SPK )
425
		{
426
			delete this->PagePackage;
427
			delete this->PageWares;
428
			this->PageWares = nullptr;
429
			this->PagePackage = nullptr;
430
		}
431
 
432
		m_bLoading = false;
433
	}
434
 
435
	void PackageForm::UpdateDependacies()
436
	{
437
		this->ListDep->Items->Clear();
438
		for ( SNeededLibrary *nl = m_pPackage->GetNeededLibraries()->First(); nl; nl = m_pPackage->GetNeededLibraries()->Next() )
439
		{
440
			ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(nl->sName));
441
			item->SubItems->Add(SystemStringFromCyString(nl->sAuthor));
442
			item->SubItems->Add(SystemStringFromCyString(nl->sMinVersion));
443
			item->ImageIndex = 3;
444
			this->ListDep->Items->Add(item);
445
		}
446
		this->ListDep->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
447
	}
448
 
449
	void PackageForm::UpdateShipPartList()
450
	{
451
		if ( !m_pPackage )
452
			return;
453
		CXspFile *xsp = (CXspFile *)m_pPackage;
454
 
455
		// first lets adjust out columns
456
		int numColums = 1;
457
		this->ListShipPart->Visible = true;
458
		this->ListShipPart->Items->Clear();
459
		switch ( this->ComboShipPart->SelectedIndex )
460
		{
461
			case 0: // componants
462
				numColums = 3;
463
				this->ColumnPart1->Text = "Section";
464
				this->ColumnPart2->Text = "ID";
465
				this->ColumnPart3->Text = "Data";
466
				for ( SComponent *c = xsp->GetComponents()->First(); c; c = xsp->GetComponents()->Next() )
467
				{
468
					ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(c->sSection));
469
					item->ImageKey = "components";
470
					item->SubItems->Add(SystemStringFromCyString(c->sSection2));
471
					item->SubItems->Add(SystemStringFromCyString(c->sData));
472
					this->ListShipPart->Items->Add(item);
473
				}
474
				break;
475
			case 1: // dummies
476
				numColums = 2;
477
				this->ColumnPart1->Text = "Section";
478
				this->ColumnPart2->Text = "Data";
479
				for ( SDummy *d = xsp->GetDummies()->First(); d; d = xsp->GetDummies()->Next() )
480
				{
481
					ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(d->sSection));
482
					item->SubItems->Add(SystemStringFromCyString(d->sData));
483
					item->ImageKey = "dummies";
484
					this->ListShipPart->Items->Add(item);
485
				}
486
				break;
487
			case 2: // Cockpit
488
				numColums = 3;
489
				this->ColumnPart1->Text = "ID";
490
				this->ColumnPart2->Text = "Index";
491
				this->ColumnPart3->Text = "Data";
492
				for ( SCockpit *c = xsp->GetCockpits()->First(); c; c = xsp->GetCockpits()->Next() )
493
				{
494
					CyString cName = c->sCockpit;
495
					cName = cName.GetToken(";", -2);
496
					while ( cName.Right(1) == ";" )
497
						cName.Truncate(-1);
498
					ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(cName));
499
					if ( c->iIndex == -1 )
500
						item->SubItems->Add("<PACKAGE>");
501
					else
502
						item->SubItems->Add(Convert::ToString(c->iIndex));
503
					item->SubItems->Add(SystemStringFromCyString(c->sCockpit));
504
					item->ImageKey = "cockpit";
505
					this->ListShipPart->Items->Add(item);
506
				}
507
				break;
508
			case 3: // CutData
509
				numColums = 1;
510
				this->ColumnPart1->Text = "Cuts";
511
				for ( SStringList *cut = xsp->GetCutData()->Head(); cut; cut = cut->next )
512
				{
513
					ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(cut->str));
514
					item->ImageKey = "cutdata";
515
					this->ListShipPart->Items->Add(item);
516
				}
517
				break;
518
			case 4: // Bodies
519
				numColums = 2;
520
				this->ColumnPart1->Text = "Section";
521
				this->ColumnPart2->Text = "Bodies";
522
				for ( SStringList *b = xsp->GetBodies()->Head(); b; b = b->next )
523
				{
524
					ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(b->str.GetToken(";", 1, 1)));
525
					item->SubItems->Add(SystemStringFromCyString(b->str.GetToken(";", 2)));
526
					item->ImageKey = "bodies";
527
					this->ListShipPart->Items->Add(item);
528
				}
529
				break;
530
			case 5: // Animations
531
				numColums = 1;
532
				this->ColumnPart1->Text = "Animations";
533
				for ( SStringList *a = xsp->GetAnimations()->Head(); a; a = a->next )
534
				{
535
					ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(a->str));
536
					item->ImageKey = "animations";
537
					this->ListShipPart->Items->Add(item);
538
				}
539
				break;
540
 
541
			// dont know what we are supposed to be displaying
542
			default:
543
				this->ListShipPart->Visible = false;
544
		}
545
 
546
		this->ListShipPart->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
547
		// adjust size of columns
548
		if ( numColums < 3 )
549
			this->ColumnPart3->Width = 0;
550
		if ( numColums < 2 )
551
			this->ColumnPart2->Width = 0;
552
	}
553
 
554
	void PackageForm::UpdateShipText()
555
	{
556
		CXspFile *xsp = (CXspFile *)m_pPackage;
557
 
558
		this->ListShipText->Items->Clear();
559
 
560
		for ( SText *t = xsp->GetTexts()->First(); t; t = xsp->GetTexts()->Next() )
561
		{
562
			ListViewItem ^item = gcnew ListViewItem(System::Convert::ToString(t->iId));
563
			item->ImageIndex = 0;
564
			item->SubItems->Add(SystemStringFromCyString(t->sName));
565
			item->SubItems->Add(SystemStringFromCyString(t->sDesc));
566
			this->ListShipText->Items->Add(item);
567
		}
568
 
569
		this->ListShipText->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
570
	}
571
 
572
	void PackageForm::UpdateDisplayPic()
573
	{
574
		System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(PackageForm::typeid));
575
		this->ButPicBack->Enabled = false;
576
		this->ButPicNext->Enabled = false;
577
		if ( m_pDisplayFile )
578
		{
579
			CyString filePointer = m_pDisplayFile->GetFilePointer();
580
			filePointer = filePointer.FindReplace("/", "\\");
581
			filePointer = filePointer.FindReplace("\\\\", "\\");
582
			if ( System::IO::File::Exists(SystemStringFromCyString(filePointer)) )
583
			{
584
				Bitmap ^myBitmap = gcnew Bitmap(SystemStringFromCyString(filePointer));
585
				if ( myBitmap )
586
					this->DisplayPicture->Image = dynamic_cast<Image ^>(myBitmap);
587
			}
588
			this->ButPicDel->Enabled = true;
589
 
590
			if ( m_pPackage->GetFirstFile(FILETYPE_ADVERT) != m_pDisplayFile )
591
				this->ButPicBack->Enabled = true;
592
			if ( m_pPackage->GetNextFile(m_pDisplayFile)  )
593
				this->ButPicNext->Enabled = true;
594
		}
595
		else
596
		{
597
			this->ButPicDel->Enabled = false;
598
			this->DisplayPicture->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"DisplayPicture.Image")));
599
		}
600
 
601
	}
602
 
603
	void PackageForm::UpdateDisplayIcon()
604
	{
605
		System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(PackageForm::typeid));
606
 
607
		m_pTabPage->ImageIndex = 0;
608
 
609
		if ( m_pPackage->GetType() == TYPE_XSP )
610
			this->DisplayIcon->Image = this->imageList1->Images[1];
611
		else
612
		{
613
			this->DisplayIcon->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"DisplayIcon.Image")));
614
 
615
			int num = -1;
616
			if ( m_pPackage->GetType() == TYPE_SPK )
617
			{
618
				CSpkFile *spk = (CSpkFile *)m_pPackage;
619
				if ( spk->IsLibrary() )
620
					num = 3;
621
				else if ( spk->IsPackageUpdate() )
622
					num = 6;
623
				else if ( spk->IsPatch() )
624
					num = 7;
625
				else if ( spk->IsCustomStart() )
626
					num = 8;
627
			}
628
 
629
			if ( num == -1 && m_pPackage->IsFakePatch() )
630
				num = 2;
631
 
632
			if ( num != -1 )
633
			{
634
				this->DisplayIcon->Image = this->imageList1->Images[num];
635
				m_pTabPage->ImageIndex = num;
636
			}
637
		}
638
 
639
		this->ButIconDel->Enabled = false;
640
 
641
		if ( m_pPackage->GetIcon() )
642
		{
643
			this->ButIconDel->Enabled = true;
644
			CyString filePointer = m_pPackage->GetIcon()->GetFilePointer();
645
			filePointer = filePointer.FindReplace("/", "\\");
646
			filePointer = filePointer.FindReplace("\\\\", "\\");
647
			String ^file = SystemStringFromCyString(filePointer);
648
			if ( System::IO::File::Exists(file) )
649
			{
650
				Bitmap ^myBitmap = gcnew Bitmap(file);
651
				if ( myBitmap )
652
				{
653
					this->DisplayIcon->Image = dynamic_cast<Image ^>(myBitmap);
654
					this->imageList1->Images->Add(file, myBitmap);
655
					m_pTabPage->ImageIndex = this->imageList1->Images->IndexOfKey(file);
656
					if ( m_pTabPage->ImageIndex == -1 )
657
						m_pTabPage->ImageIndex = 0;
658
				}
659
			}
660
		}
661
 
662
		if ( m_pTabPage->ImageIndex == 0 )
663
		{
664
			if ( m_pPackage->GetType() == TYPE_XSP )
665
				m_pTabPage->ImageIndex = 1;
666
		}
667
 
668
		m_pMenuItem->Image = this->imageList1->Images[m_pTabPage->ImageIndex];
669
	}
670
 
671
	void PackageForm::UpdateGameVersion()
672
	{
673
		bool restoreLoad = m_bLoading;
674
		m_bLoading = true;
675
 
676
		ComboVersion->BeginUpdate();
677
		ComboVersion->Items->Clear();
678
 
679
		this->TextExactVersion->Hide();
680
 
681
		SGameExe *exe = NULL;
682
		if ( ButGame->ImageIndex >= 0 )
683
			exe = m_pP->GetGameExe()->GetGame((m_pPackage) ? ButGame->ImageIndex : -1);
684
		if ( exe )
685
		{			
686
			ComboVersion->Items->Add("Original");
687
			for ( int i = 0; i < exe->lVersions.size(); i++ )
688
			{
689
				SGameExeVersion *v = exe->lVersions[i];
690
				ComboVersion->Items->Add(SystemStringFromCyString(v->sName));
691
			}
692
			ComboVersion->Items->Add("Exact (Custom)");
693
			ComboVersion->Enabled = true;
694
		}
695
		else
696
		{
697
			ComboVersion->Enabled = false;
698
		}
699
 
700
 
701
		ComboVersion->EndUpdate();
702
 
703
		if ( !restoreLoad )
704
			m_bLoading = false;
705
	}
706
 
707
	void PackageForm::UpdateRatings()
708
	{
709
		this->PicEase1->BackColor = System::Drawing::Color::Transparent;
710
		this->PicEase2->BackColor = System::Drawing::Color::Transparent;
711
		this->PicEase3->BackColor = System::Drawing::Color::Transparent;
712
		this->PicEase4->BackColor = System::Drawing::Color::Transparent;
713
		this->PicEase5->BackColor = System::Drawing::Color::Transparent;
714
 
715
		this->PicChange1->BackColor = System::Drawing::Color::Transparent;
716
		this->PicChange2->BackColor = System::Drawing::Color::Transparent;
717
		this->PicChange3->BackColor = System::Drawing::Color::Transparent;
718
		this->PicChange4->BackColor = System::Drawing::Color::Transparent;
719
		this->PicChange5->BackColor = System::Drawing::Color::Transparent;
720
 
721
		this->PicRec1->BackColor = System::Drawing::Color::Transparent;
722
		this->PicRec2->BackColor = System::Drawing::Color::Transparent;
723
		this->PicRec3->BackColor = System::Drawing::Color::Transparent;
724
		this->PicRec4->BackColor = System::Drawing::Color::Transparent;
725
		this->PicRec5->BackColor = System::Drawing::Color::Transparent;
726
 
46 cycrow 727
		if ( m_pPackage->easeOfUse() >= 1 )
1 cycrow 728
			this->PicEase1->BackColor = System::Drawing::Color::Red;
46 cycrow 729
		if ( m_pPackage->easeOfUse() >= 2 )
1 cycrow 730
			this->PicEase2->BackColor = System::Drawing::Color::Red;
46 cycrow 731
		if ( m_pPackage->easeOfUse() >= 3 )
1 cycrow 732
			this->PicEase3->BackColor = System::Drawing::Color::Red;
46 cycrow 733
		if ( m_pPackage->easeOfUse() >= 4 )
1 cycrow 734
			this->PicEase4->BackColor = System::Drawing::Color::Red;
46 cycrow 735
		if ( m_pPackage->easeOfUse() >= 5 )
1 cycrow 736
			this->PicEase5->BackColor = System::Drawing::Color::Red;
737
 
46 cycrow 738
		if ( m_pPackage->recommended() >= 1 )
1 cycrow 739
			this->PicRec1->BackColor = System::Drawing::Color::Red;
46 cycrow 740
		if ( m_pPackage->recommended() >= 2 )
1 cycrow 741
			this->PicRec2->BackColor = System::Drawing::Color::Red;
46 cycrow 742
		if ( m_pPackage->recommended() >= 3 )
1 cycrow 743
			this->PicRec3->BackColor = System::Drawing::Color::Red;
46 cycrow 744
		if ( m_pPackage->recommended() >= 4 )
1 cycrow 745
			this->PicRec4->BackColor = System::Drawing::Color::Red;
46 cycrow 746
		if ( m_pPackage->recommended() >= 5 )
1 cycrow 747
			this->PicRec5->BackColor = System::Drawing::Color::Red;
748
 
46 cycrow 749
		if ( m_pPackage->gameChanging() >= 1 )
1 cycrow 750
			this->PicChange1->BackColor = System::Drawing::Color::Red;
46 cycrow 751
		if ( m_pPackage->gameChanging() >= 2 )
1 cycrow 752
			this->PicChange2->BackColor = System::Drawing::Color::Red;
46 cycrow 753
		if ( m_pPackage->gameChanging() >= 3 )
1 cycrow 754
			this->PicChange3->BackColor = System::Drawing::Color::Red;
46 cycrow 755
		if ( m_pPackage->gameChanging() >= 4 )
1 cycrow 756
			this->PicChange4->BackColor = System::Drawing::Color::Red;
46 cycrow 757
		if ( m_pPackage->gameChanging() >= 5 )
1 cycrow 758
			this->PicChange5->BackColor = System::Drawing::Color::Red;
759
 
46 cycrow 760
		if ( m_pPackage->easeOfUse() < 0 )
1 cycrow 761
			this->GroupEase->Text = "Ease of Use";
762
		else
46 cycrow 763
			this->GroupEase->Text = "Ease of Use (" + System::Convert::ToString(m_pPackage->easeOfUse()) + ")";
1 cycrow 764
 
46 cycrow 765
		if ( m_pPackage->gameChanging() < 0 )
1 cycrow 766
			this->GroupChange->Text = "Game Changing";
767
		else
46 cycrow 768
			this->GroupChange->Text = "Game Changing (" + System::Convert::ToString(m_pPackage->gameChanging()) + ")";
1 cycrow 769
 
46 cycrow 770
		if ( m_pPackage->recommended() < 0 )
1 cycrow 771
			this->GroupRec->Text = "Recommended";
772
		else
46 cycrow 773
			this->GroupRec->Text = "Recommended (" + System::Convert::ToString(m_pPackage->recommended()) + ")";
1 cycrow 774
	}
775
 
776
	void PackageForm::Setup()
777
	{
778
		m_bLoading = true;
779
 
780
		this->ComboFileType->Items->Add("All Files");
781
		for ( int i = 0; i < FILETYPE_MAX; i++ )
782
			this->ComboFileType->Items->Add(SystemStringFromCyString(GetFileTypeString(i)));
783
		this->ComboFileType->SelectedIndex = 0;
784
 
785
		this->PanelShip->Hide();
786
 
787
		m_bSortingAsc = true;
788
		m_iSortingCol = 1;
789
 
790
		this->ListFiles->ColumnClick += gcnew ColumnClickEventHandler(this, &Creator::PackageForm::SortList);
791
		this->ListFiles->ItemChecked += gcnew ItemCheckedEventHandler(this, &PackageForm::Event_FileChecked);
792
 
793
		this->ContextGames->Items->Clear();
794
 
795
		this->ComboGameFilter->Items->Clear();
796
		this->ToolGame->DropDownItems->Clear();
797
 
798
		this->ComboGameFilter->Items->Add("- None -");
799
		this->ComboGameFilter->Items->Add("- All Games -");
800
 
801
		for ( int i = 0; i < m_pP->GetGameExe()->GetNumGames(); i++ )
802
		{
803
			SGameExe *gameExe = m_pP->GetGameExe()->GetGame(i);
804
			if ( gameExe )
805
			{
806
				System::Windows::Forms::ToolStripMenuItem ^newItem = gcnew System::Windows::Forms::ToolStripMenuItem;
807
				newItem->Text = SystemStringFromCyString(gameExe->sName);
808
				newItem->Tag = Convert::ToString(i + 1);
809
				newItem->Image = this->imageListGames->Images[i];
810
				newItem->Click += gcnew System::EventHandler(this, &PackageForm::ContextGame_Selected);
811
				this->ContextGames->Items->Add(newItem);
812
 
813
				System::Windows::Forms::ToolStripMenuItem ^newItem2 = gcnew System::Windows::Forms::ToolStripMenuItem;
814
				newItem2->Text = SystemStringFromCyString(gameExe->sName);
815
				newItem2->Tag = Convert::ToString(i + 1);
816
				newItem2->Image = this->imageListGames->Images[i];
817
				newItem2->Click += gcnew System::EventHandler(this, &PackageForm::SetGame_Selected);
818
				this->ToolGame->DropDownItems->Add(newItem2);
819
 
820
				this->ComboGameFilter->Items->Add(SystemStringFromCyString(gameExe->sName));
821
			}
822
		}
823
 
824
		this->ComboGameFilter->SelectedIndex = 0;
825
 
826
		this->ButGame->Text = "- Select Game -";
827
		this->ButGameAdd->Enabled = false;
828
 
829
		m_pTypeList->Clear();
6 cycrow 830
		for ( int i = 0; i < CSpkFile::SCRIPTTYPE_MAX; i++ )
1 cycrow 831
		{
10 cycrow 832
			m_pTypeList->PushBack(CSpkFile::GetScriptTypeStringStatic(i).c_str());
1 cycrow 833
			ComboType->Items->Add(SystemStringFromCyString(CSpkFile::GetScriptTypeStringStatic(i)));
834
		}
835
 
836
		this->CreationDate->Value = DateTime::Today;
837
 
838
		m_bLoading = false;
839
	}
840
 
841
	void PackageForm::UpdateGamesList()
842
	{
843
		this->ListGames->Items->Clear();
844
		for ( SGameCompat *game = m_pPackage->GetGameCompatabilityList()->First(); game; game = m_pPackage->GetGameCompatabilityList()->Next() ) {
845
			ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(m_pP->GetGameNameFromType(game->iGame)));
846
			item->ImageIndex = (game->iGame < 0) ? -1 : (game->iGame - 1);
46 cycrow 847
			if ( !game->sVersion.empty() ) {
1 cycrow 848
				item->SubItems->Add("Exact: " + SystemStringFromCyString(game->sVersion));
849
			}
850
			else {
851
				item->SubItems->Add(SystemStringFromCyString(m_pP->GetGameVersionFromType(game->iGame, game->iVersion, game->sVersion)));
852
			}
853
			item->Tag = game->iGame;
854
			this->ListGames->Items->Add(item);
855
		}
856
 
857
		this->ListGames->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
858
	}
859
 
860
	void PackageForm::UpdateFileList()
861
	{
862
		this->ButRemoveFile->Enabled = false;
863
 
864
		int pos = 0;
865
		this->ListFiles->Items->Clear();
866
		if ( m_pPackage ) {
867
			for ( C_File *file = m_pPackage->GetFileList()->First(); file; file = m_pPackage->GetFileList()->Next() )
868
			{
869
				file->SetPos(pos++);
870
				if ( this->ComboGameFilter->SelectedIndex > 0 ) {
871
					if ( this->ComboGameFilter->SelectedIndex - 1 != file->GetGame() )
872
						continue;
873
				}
874
				if ( this->ComboFileType->SelectedIndex == 0 || (this->ComboFileType->SelectedIndex - 1) == file->GetFileType() )
875
					this->AddFile(file);
876
			}
877
			((Form1 ^)this->MdiParent)->UpdateStatus();
878
		}
879
 
880
		this->ListFiles->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
881
	}
882
 
883
	void PackageForm::AddFile(C_File *file)
884
	{
885
		ListViewItem ^item = gcnew ListViewItem("");
886
 
887
		if ( file->GetData() )
888
		{
889
			item->SubItems->Add(SystemStringFromCyString(CyString("<PACKAGE>/") + file->GetNameDirectory(NULL)));
890
			item->SubItems->Add(SystemStringFromCyString(file->GetUncompressedSizeString()));
891
		}
892
		else
893
		{
894
			item->SubItems->Add(SystemStringFromCyString(file->GetFullFilename()));
895
			item->SubItems->Add(SystemStringFromCyString(SPK::GetSizeString(file->GetSize())));
896
		}
897
 
898
		if ( file->IsFakePatch() )
899
			item->SubItems->Add("Mod (Fakepatch)");
900
		else
901
			item->SubItems->Add(SystemStringFromCyString(file->GetFileTypeString()));
902
 
903
		if ( !file->GetDir().Empty() )
904
			item->SubItems->Add(SystemStringFromCyString(file->GetDir()));
905
		else
906
			item->SubItems->Add("");
907
 
908
		if ( file->IsSigned() )
909
			item->SubItems->Add("Yes");
910
		else
911
			item->SubItems->Add("No");
912
 
913
		if ( !file->GetGame() )
914
			item->SubItems->Add("All Games");
915
		else {
916
			CPackages p;
917
			p.Startup(".", ".", ".");
918
			SGameExe *exe = p.GetGameExe()->GetGame(file->GetGame() - 1);
919
			if ( exe ) {
920
				item->SubItems->Add(SystemStringFromCyString(exe->sName));
921
			}
922
			else {
923
				item->SubItems->Add("Game: " + file->GetGame());
924
			}
925
		}
926
 
927
		item->Tag = SystemStringFromCyString(CyString::Number(file->GetPos()));
928
		if ( file->IsFakePatch() )
929
			item->ImageKey = "fakepatch";
930
		else
931
			item->ImageIndex = file->GetFileType();
932
 
933
		item->Checked = file->IsShared();
934
 
935
		this->ListFiles->Items->Add(item);
936
	}
937
 
938
	void PackageForm::AddNewFile()
939
	{
940
		// add filters
941
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
942
 
943
		System::String ^filter;
944
		for ( int i = 0; i < FILETYPE_MAX; i++ )
945
		{
946
			if ( filter )
947
				filter += "|";
948
			filter += SystemStringFromCyString(GetFileTypeString(i));
949
			filter += "|";
950
			// add extensions
951
			switch ( i )
952
			{
953
				case FILETYPE_SCRIPT:
954
				case FILETYPE_UNINSTALL:
955
				case FILETYPE_MAP:
956
				case FILETYPE_TEXT:
957
				case FILETYPE_MISSION:
958
					filter += "*.pck;*.xml";
959
					break;
960
 
961
				case FILETYPE_README:
962
					filter += "*.txt;*.doc;*.docx;*.pdf";
963
					break;
964
 
965
				case FILETYPE_MOD:
966
					filter += "*.cat";
967
					break;
968
 
969
				case FILETYPE_SOUND:
970
					filter += "*.wav";
971
					break;
972
 
973
				case FILETYPE_SCREEN:
974
				case FILETYPE_ADVERT:
975
					filter += "*.jpg;*.png";
976
					break;
977
 
978
				case FILETYPE_SHIPSCENE:
979
				case FILETYPE_COCKPITSCENE:
980
					filter += "*.pbd;*.bod";
981
					break;
982
 
983
				case FILETYPE_SHIPMODEL:
984
					filter += "*.pbd;*.bod;*.bob;*.pbb";
985
					break;
986
 
987
				default:
988
					filter += "*.*";
989
			}
990
		}
991
		ofd->Filter = filter;
992
		ofd->FilterIndex = 1;
993
		ofd->RestoreDirectory = true;
994
		ofd->Multiselect = true;
995
		ofd->Title = "Select File(s) to add to package";
996
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
997
		{
998
			CyString dir;
999
			if ( C_File::DoesTypeHaveExtraDir(ofd->FilterIndex - 1) )
1000
			{
1001
				InputBox ^input = gcnew InputBox("Enter the directory to add files to", ((ofd->FilterIndex - 1) == FILETYPE_EXTRA) ? "PluginManager/Extras/$scriptname" : "");
1002
				if ( input->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1003
					dir = CyStringFromSystemString(input->GetInput());
1004
			}
1005
			array<System::String ^> ^fileArray = ofd->FileNames;
1006
			for ( int i = 0; i < fileArray->Length; i++ )
1007
			{
1008
				System::String ^file = fileArray[i];
1009
				int filetype = m_pP->AdjustFileType(CyStringFromSystemString(file), ofd->FilterIndex - 1);
1010
				C_File *f = m_pPackage->AddFile(CyStringFromSystemString(file), dir, filetype);
1011
				if ( (ofd->FilterIndex - 1) == FILETYPE_MOD )
1012
					m_pPackage->AddFile(CFileIO(CyStringFromSystemString(file)).ChangeFileExtension("dat"), dir, filetype);
1013
			}
1014
			m_pPackage->UpdateSigned(false);
1015
			this->UpdateFileList();
1016
			this->UpdateDisplayPic();
1017
			this->UpdateChanged();
1018
		}
1019
	}
1020
 
1021
	bool PackageForm::CheckSave()
1022
	{
1023
		if ( m_pPackage->GetName().Empty() )
1024
		{
1025
			MessageBox::Show(this, "You must specify a package name", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1026
			return false;
1027
		}
1028
		if ( m_pPackage->GetAuthor().Empty() )
1029
		{
1030
			MessageBox::Show(this, "You must specify an Author", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1031
			return false;
1032
		}
1033
		if ( m_pPackage->GetVersion().Empty() )
1034
		{
1035
			MessageBox::Show(this, "You must specify a version number", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1036
			return false;
1037
		}
1038
 
1039
		if ( m_pPackage->GetType() == TYPE_SPK )
1040
		{
1041
			if ( ((CSpkFile *)m_pPackage)->IsPackageUpdate() )
1042
			{
1043
				SNeededLibrary *n = m_pPackage->FindPackageNeeded("<package>", "<author>");
1044
				if ( !n )
1045
					m_pPackage->AddNeededLibrary("<package>", "<author>", "1.00");
1046
				n = m_pPackage->FindPackageNeeded("<package>", "<author>");
1047
 
1048
				if ( n )
1049
				{
1050
					if ( ((CSpkFile *)m_pPackage)->GetVersion().CompareVersion(n->sMinVersion) != COMPARE_OLDER )
1051
					{
1052
						MessageBox::Show(this, "The depencay vesion (" + SystemStringFromCyString(n->sMinVersion) + ") is too high, it must be lower than the current version (" + SystemStringFromCyString(m_pPackage->GetVersion()) + ")", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1053
						return false;
1054
					}
1055
				}
1056
			}
1057
			else if ( ((CSpkFile *)m_pPackage)->IsCustomStart() )
1058
			{
1059
				if ( !((CSpkFile *)m_pPackage)->CheckValidCustomStart() )
1060
				{
1061
					MessageBox::Show(this, "For a custom start, you must include an initplayer script", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1062
					return false;
1063
				}
1064
			}
1065
			else if ( ((CSpkFile *)m_pPackage)->IsPatch() )
1066
			{
10 cycrow 1067
				if ( ((CSpkFile *)m_pPackage)->GetOtherAuthor().empty() || ((CSpkFile *)m_pPackage)->GetOtherName().empty() )
1 cycrow 1068
				{
1069
					MessageBox::Show(this, "For a mod patch, you must specify the parent mod that this will be patching\nEnter the parent mod name and author", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1070
					return false;
1071
				}
1072
			}
1073
		}
1074
 
1075
		 System::DateTime ^time = DateTime(this->CreationDate->Value);
1076
 
1077
		 String ^t = System::Convert::ToString(time->Day) + "/" + System::Convert::ToString(time->Month) + "/" + System::Convert::ToString(time->Year);
1078
		 m_pPackage->SetCreationDate(CyStringFromSystemString(t));
1079
 
1080
		return true;
1081
	}
1082
 
1083
	void PackageForm::Save()
1084
	{
1085
		if ( !this->CheckSave() )
1086
			return;
1087
 
1088
		if ( m_pPackage->GetFilename().Empty() )
1089
		{
1090
			this->SaveAs();
1091
			return;
1092
		}
1093
 
1094
		if ( m_pPackage->GetType() == TYPE_XSP )
1095
			((CXspFile *)m_pPackage)->AdjustCockpits();
1096
 
1097
		SaveDialog ^save = gcnew SaveDialog(m_pPackage, SystemStringFromCyString(m_pPackage->GetFilename()));
1098
		if ( save->ShowDialog(this) == Windows::Forms::DialogResult::Cancel )
1099
			return;
1100
 
1101
		this->UpdateFileList();
1102
		m_pPackage->SetChanged(false);
1103
		this->UpdateChanged();
1104
 
1105
		if ( m_pSettings->bGenerateUpdate )
1106
			m_pPackage->CreateUpdateFile(CFileIO(m_pPackage->GetFilename()).GetDir());
1107
 
1108
		MessageBox::Show("Package: " + SystemStringFromCyString(m_pPackage->GetFilename()) + "\nHas been saved!", "Saved", MessageBoxButtons::OK, MessageBoxIcon::Information);
1109
	}
1110
 
1111
	void PackageForm::SaveAs()
1112
	{
1113
		if ( !this->CheckSave() )
1114
			return;
1115
 
1116
		SaveFileDialog ^ofd = gcnew SaveFileDialog();
1117
		if ( m_pPackage->GetType() == TYPE_XSP )
1118
			ofd->Filter = "Ship Files (*.xsp)|*.xsp";
1119
		else
1120
			ofd->Filter = "Package Files (*.spk)|*.spk";
1121
		ofd->AddExtension = true;
1122
		CyString filename = m_pPackage->GetFilename();
1123
		if ( filename.Empty() )
1124
			filename = m_pPackage->GetAutosaveName();
1125
		filename = filename.FindReplace("/", "\\");
1126
		ofd->FileName = SystemStringFromCyString(filename);
1127
		ofd->FilterIndex = 1;
1128
		ofd->RestoreDirectory = true;
1129
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1130
		{
1131
			m_pPackage->SetFilename(CyStringFromSystemString(ofd->FileName));
1132
			m_sFilename = ofd->FileName;
1133
			m_pTabPage->Text = SystemStringFromCyString(CFileIO(m_pPackage->GetFilename()).GetFilename());
1134
			m_pMenuItem->Text = m_pTabPage->Text;
1135
			this->Save();
1136
		}
1137
	}
1138
 
1139
	System::Void PackageForm::PackageForm_Closing(System::Object^  sender, CancelEventArgs^  e)	{
1140
		if ( m_pPackage->IsChanged() )
1141
		{
1142
			String ^name = m_pTabPage->Text;
1143
			if ( name[name->Length - 1] == '*' )
1144
				name = name->Remove(name->Length - 1);
1145
			System::Windows::Forms::DialogResult result = MessageBox::Show("Would you like to save changes to the package?\n\n" + name, "Save Package", MessageBoxButtons::YesNoCancel, MessageBoxIcon::Question);
1146
 
1147
			if ( result == System::Windows::Forms::DialogResult::Cancel )
1148
			{
1149
				e->Cancel = true;
1150
				return;
1151
			}
1152
			else if ( result == System::Windows::Forms::DialogResult::Yes )
1153
			{
1154
				if ( !this->CheckSave() )
1155
				{
1156
					e->Cancel = true;
1157
					return;
1158
				}
1159
 
1160
				if ( m_pPackage->GetFilename().Empty() )
1161
				{
1162
					SaveFileDialog ^ofd = gcnew SaveFileDialog();
1163
					if ( m_pPackage->GetType() == TYPE_XSP )
1164
						ofd->Filter = "Ship Files (*.xsp)|*.xsp";
1165
					else
1166
						ofd->Filter = "Package Files (*.spk)|*.spk";
1167
					ofd->FilterIndex = 1;
1168
					ofd->RestoreDirectory = true;
1169
					if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1170
						m_pPackage->SetFilename(CyStringFromSystemString(ofd->FileName));
1171
					else
1172
					{
1173
						 e->Cancel = true;
1174
						 return;
1175
					}
1176
				}
1177
 
1178
				if ( !m_pPackage->WriteFile(m_pPackage->GetFilename()) )
1179
				{
1180
					e->Cancel = true;
1181
					MessageBox::Show("Unable to save package\n" + SystemStringFromCyString(m_pPackage->GetFilename()), "Save Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
1182
					return;
1183
				}
1184
			}
1185
		}
1186
 
1187
		delete m_pPackage;
1188
		m_pPackage = NULL;
1189
	}
1190
 
1191
	void PackageForm::UpdateMirrors()
1192
	{
1193
		this->ListMirrors->Items->Clear();
1194
		for ( int i = 0; i < m_pPackage->GetMaxWebMirrors(); i++ )
1195
		{
1196
			ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(m_pPackage->GetWebMirror(i)));
1197
			this->ListMirrors->Items->Add(item);
1198
			item->ImageIndex = 1;
1199
		}
1200
 
1201
		this->ListMirrors->AutoResizeColumns(ColumnHeaderAutoResizeStyle::ColumnContent);
1202
		if ( this->ListMirrors->Columns[0]->Width < 100 )
1203
			this->ListMirrors->Columns[0]->Width = 100;
1204
	}
1205
 
1206
	void PackageForm::UpdatePackageNames()
1207
	{
1208
		this->ListNames->Items->Clear();
1209
		for ( SNames *n = m_pPackage->GetNamesList()->First(); n; n = m_pPackage->GetNamesList()->Next() )
1210
		{
1211
			ListViewItem ^item = gcnew ListViewItem(Convert::ToString(n->iLanguage));
1212
			item->SubItems->Add(SystemStringFromCyString(n->sName));
1213
			item->ImageIndex = 0;
1214
			this->ListNames->Items->Add(item);
1215
		}
1216
		this->ListNames->AutoResizeColumns(ColumnHeaderAutoResizeStyle::ColumnContent);
1217
		if ( this->ListNames->Columns[0]->Width < 100 )
1218
			this->ListNames->Columns[0]->Width = 100;
1219
		if ( this->ListNames->Columns[1]->Width < 100 )
1220
			this->ListNames->Columns[1]->Width = 100;
1221
	}
1222
 
1223
	void PackageForm::AddDisplayPic()
1224
	{
1225
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
1226
		ofd->Filter = "Display Images|*.gif;*.png;*.jpg";
1227
		ofd->FilterIndex = 1;
1228
		ofd->RestoreDirectory = true;
1229
		ofd->Multiselect = true;
1230
		ofd->Title = "Select the Display image to add";
1231
 
1232
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1233
		{
1234
			array<System::String ^> ^fileArray = ofd->FileNames;
1235
			for ( int i = 0; i < fileArray->Length; i++ )
1236
			{
1237
				CyString file = CyStringFromSystemString(fileArray[i]);
1238
				m_pDisplayFile = m_pPackage->AddFile(file, "", FILETYPE_ADVERT);
1239
			}
1240
 
1241
			this->UpdateDisplayPic();
1242
			this->UpdateFileList();
1243
		}
1244
	}
1245
 
1246
	void PackageForm::AddDisplayIcon()
1247
	{
1248
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
1249
		ofd->Filter = "Icon Files|*.ico;*.png;*.bmp";
1250
		ofd->FilterIndex = 1;
1251
		ofd->RestoreDirectory = true;
1252
		ofd->Multiselect = false;
1253
		ofd->Title = "Select the Icon file to add";
1254
 
1255
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1256
		{
1257
			CyString file = CyStringFromSystemString(ofd->FileName);
1258
			C_File *icon = new C_File(file);
1259
			if ( icon->ReadFromFile() )
1260
				m_pPackage->SetIcon(icon, CFileIO(file).GetFileExtension());
1261
 
1262
			this->UpdateDisplayIcon();
1263
			this->UpdateChanged();
1264
		}
1265
	}
1266
 
1267
	void PackageForm::SaveText()
1268
	{
1269
		if ( this->TextText->Text->Length )
1270
		{
1271
			if ( this->ListLang->SelectedIndex >= 0 )
1272
			{
1273
				int lang = CyStringFromSystemString(this->ListLang->Text).ToInt();
46 cycrow 1274
				if ( this->RadioInstallAfter->Checked )			m_pPackage->addInstallText(lang, false, _S(this->TextText->Text));
1275
				else if ( this->RadioInstallBefore->Checked )	m_pPackage->addInstallText(lang, true, _S(this->TextText->Text));
1276
				else if ( this->RadioUninstallBefore->Checked )	m_pPackage->addUninstallText(lang, true, _S(this->TextText->Text));
1277
				else if ( this->RadioUninstallAfter->Checked )	m_pPackage->addUninstallText(lang, false, _S(this->TextText->Text));
1 cycrow 1278
				this->UpdateChanged();
1279
			}
1280
		}
1281
	}
1282
 
1283
	void PackageForm::LoadShipData()
1284
	{
1285
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
1286
		ofd->Filter = "All (*.cat, tships)|*.cat;tships.txt;tships.pck|TShips Files (tships.txt/pck)|tships.txt;tships.pck|Mod Files (*.cat)|*.cat";
1287
		ofd->FilterIndex = 1;
1288
		ofd->RestoreDirectory = true;
1289
		ofd->Multiselect = false;
1290
		ofd->Title = "Select the TShips/Mod file to load ship data from";
1291
 
1292
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1293
		{
1294
			// if its a cat file, lets load the text
1295
			Hashtable ^catText = gcnew Hashtable();
1296
 
1297
			if ( String::Compare(IO::FileInfo(ofd->FileName).Extension, ".cat") == 0 )
1298
			{
1299
				CyStringList readText;
1300
				if ( m_pP->ReadTextPage(CyStringFromSystemString(ofd->FileName), &readText, false, 17) )
1301
				{
1302
					for ( SStringList *str = readText.Head(); str; str = str->next )
1303
					{
1304
						String ^key = SystemStringFromCyString(str->str);
1305
						if ( catText->ContainsKey(key) )
1306
							catText[key] = SystemStringFromCyString(str->data);
1307
						else
1308
							catText->Add(key, SystemStringFromCyString(str->data));
1309
					}
1310
				}
1311
			}
1312
 
1313
			CyStringList list;
1314
			if ( m_pP->LoadShipData(CyStringFromSystemString(ofd->FileName), &list) )
1315
			{
1316
				LoadShip ^ls = gcnew LoadShip();
1317
				for ( SStringList *str = list.Head(); str; str = str->next )
1318
				{
1319
					int tId = str->data.GetToken(";", 7, 7).ToInt();
1320
					String ^name;
1321
					if ( catText->ContainsKey(Convert::ToString(tId)) )
1322
						name = Convert::ToString(catText[Convert::ToString(tId)]);
1323
					else
1324
						name = ((Form1 ^)this->MdiParent)->FindText(-1, 17, tId);
1325
					String ^text = ((Form1 ^)this->MdiParent)->FindText(-1, 1266, str->data.GetToken(";", 46, 46).ToInt()) + " " + name;
1326
					int variation = str->data.GetToken(";", 51, 51).ToInt();
1327
					if ( variation )
1328
						text = text + " " + ((Form1 ^)this->MdiParent)->FindText(-1, 17, 10000 + variation);
1329
					ls->AddShip(SystemStringFromCyString(str->str), text);
1330
				}
1331
 
1332
				if ( ls->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1333
				{
1334
					SStringList *str = list.FindString(CyStringFromSystemString(ls->GetData()));
1335
					if ( str )
1336
					{
14 cycrow 1337
						((CXspFile *)m_pPackage)->SetShipData(str->data.ToString());
1338
						if ( ((CXspFile *)m_pPackage)->GetShipID().empty() )
1 cycrow 1339
						{
1340
							CyString id = str->data.GetToken(";", -2);
1341
							while ( id.Right(1) == ";" )
1342
								id.Truncate((int)id.Length() - 1);
14 cycrow 1343
							((CXspFile *)m_pPackage)->SetShipID(id.ToString());
1 cycrow 1344
							this->TextShipID->Text = SystemStringFromCyString(id);
1345
						}
1346
 
14 cycrow 1347
						((CXspFile *)m_pPackage)->SetShipData(str->data.ToString());
1 cycrow 1348
						this->TextShipData->Text = SystemStringFromCyString(str->data);
1349
						this->NumTextID->Value = str->data.GetToken(";", 7, 7).ToInt();
1350
						this->UpdateChanged();
1351
					}
1352
				}
1353
			}
1354
			else
1355
				MessageBox::Show(this, "Unable to find any ship entries, invalid/missing TShips?", "Error Loading", MessageBoxButtons::OK, MessageBoxIcon::Error);
1356
		}
1357
	}
1358
 
1359
	void PackageForm::EditShipParts(bool edit)
1360
	{
1361
		 CXspFile *xsp = (CXspFile *)m_pPackage;
1362
		 switch ( this->ComboShipPart->SelectedIndex )
1363
		 {
1364
			case 0:
1365
				{
1366
					AddShipPart ^component = gcnew AddShipPart((Form1 ^)this->MdiParent);
1367
					component->SetComponent(edit);
1368
 
1369
					if ( edit )
1370
					{
1371
						component->SetSection(m_pSelectedItem->Text);
1372
						component->SetSection2(m_pSelectedItem->SubItems[1]->Text);
1373
						component->SetData(m_pSelectedItem->SubItems[2]->Text);
1374
					}
1375
 
1376
					if ( component->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1377
					{
1378
						if ( edit )
39 cycrow 1379
							xsp->RemoveComponent(_S(m_pSelectedItem->Text), _S(m_pSelectedItem->SubItems[1]->Text), _S(m_pSelectedItem->SubItems[2]->Text));
1380
						xsp->AddComponent(_S(component->GetSection()), _S(component->GetSection2()), _S(component->GetData()));
1 cycrow 1381
						if ( !edit )
1382
							this->UpdateShipPartList();
1383
						else
1384
						{
1385
							m_pSelectedItem->Text = component->GetSection();
1386
							m_pSelectedItem->SubItems[1]->Text = component->GetSection2();
1387
							m_pSelectedItem->SubItems[2]->Text = component->GetData();
1388
						}
1389
					}
1390
				}
1391
				break;
1392
			case 1:
1393
				{
1394
					AddShipPart ^dummy = gcnew AddShipPart((Form1 ^)this->MdiParent);
1395
					dummy->SetDummy(edit);
1396
 
1397
					if ( edit )
1398
					{
1399
						dummy->SetSection(m_pSelectedItem->Text);
1400
						dummy->SetData(m_pSelectedItem->SubItems[1]->Text);
1401
					}
1402
 
1403
					if ( dummy->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1404
					{
1405
						if ( edit )
39 cycrow 1406
							xsp->RemoveDummy(_S(m_pSelectedItem->Text), _S(m_pSelectedItem->SubItems[1]->Text));
1407
						xsp->AddDummy(_S(dummy->GetSection()), _S(dummy->GetData()));
1 cycrow 1408
						if ( !edit )
1409
							this->UpdateShipPartList();
1410
						else
1411
						{
1412
							m_pSelectedItem->Text = dummy->GetSection();
1413
							m_pSelectedItem->SubItems[1]->Text = dummy->GetData();
1414
						}
1415
					}
1416
				}
1417
				break;
1418
 
1419
			case 2:
1420
				{
1421
					AddCockpit ^cockpit = gcnew AddCockpit();
1422
					if ( edit )
1423
						cockpit->SetEdit(m_pSelectedItem->Text, SystemStringFromCyString(CyStringFromSystemString(m_pSelectedItem->SubItems[2]->Text).GetToken(";", 8, 8)), CyStringFromSystemString(m_pSelectedItem->SubItems[2]->Text).GetToken(";", 9, 9).ToInt());
1424
					if ( cockpit->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1425
					{
1426
						if ( !edit )
1427
						{
39 cycrow 1428
							xsp->NewCockpit(_S(cockpit->GetID()), _S(cockpit->GetScene()), cockpit->GetMask());
1 cycrow 1429
							this->UpdateShipPartList();
1430
						}
1431
						else
1432
						{
39 cycrow 1433
							xsp->EditCockpit(_S(cockpit->GetID()), _S(cockpit->GetScene()), cockpit->GetMask());
1434
							m_pSelectedItem->SubItems[2]->Text = SystemStringFromCyString(xsp->GetCockpitData(_S(cockpit->GetID())));
1 cycrow 1435
						}
1436
					}
1437
				}
1438
				break;
1439
 
1440
			case 3:
1441
				{
1442
					if ( edit )
1443
					{
1444
						InputBox ^input2 = gcnew InputBox("Enter the filename for cut id: " + SystemStringFromCyString(CyStringFromSystemString(m_pSelectedItem->Text).GetToken(";", 1, 1)), SystemStringFromCyString(CyStringFromSystemString(m_pSelectedItem->Text).GetToken(";", 2, 2)));
1445
						if ( input2->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1446
						{
39 cycrow 1447
							xsp->RemoveCutData(_S(m_pSelectedItem->Text));
1448
							xsp->AddCutData(_S(SystemStringFromCyString(CyStringFromSystemString(m_pSelectedItem->Text).GetToken(";", 1, 1)) + "; " + input2->GetInput()));
1 cycrow 1449
							this->UpdateShipPartList();
1450
						}
1451
					}
1452
					else
1453
					{
1454
						InputBox ^input = gcnew InputBox("Enter the cut id to add");
1455
						if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1456
						{
1457
							InputBox ^input2 = gcnew InputBox("Enter the filename for cut id: " + input->GetInput());
1458
							if ( input2->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1459
							{
39 cycrow 1460
								xsp->AddCutData(_S(input->GetInput() + "; " + input2->GetInput()));
1 cycrow 1461
								this->UpdateShipPartList();
1462
							}
1463
						}
1464
					}
1465
				}
1466
				break;
1467
 
1468
			case 4:
1469
				{
1470
					AddShipPart ^dummy = gcnew AddShipPart((Form1 ^)this->MdiParent);
1471
					dummy->SetBodies(edit);
1472
 
1473
					if ( edit )
1474
					{
1475
						dummy->SetSection(m_pSelectedItem->Text);
1476
						dummy->SetData(m_pSelectedItem->SubItems[1]->Text);
1477
					}
1478
 
1479
					if ( dummy->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1480
					{
1481
						if ( edit )
39 cycrow 1482
							xsp->RemoveBodies(_S(m_pSelectedItem->Text + ";" + m_pSelectedItem->SubItems[1]->Text));
1483
						xsp->AddBodies(_S(dummy->GetSection() + ";" + dummy->GetData()));
1 cycrow 1484
						if ( !edit )
1485
							this->UpdateShipPartList();
1486
						else
1487
						{
1488
							m_pSelectedItem->Text = dummy->GetSection();
1489
							m_pSelectedItem->SubItems[1]->Text = dummy->GetData();
1490
						}
1491
					}
1492
				}
1493
				break;
1494
 
1495
			case 5:
1496
				{
1497
					InputBox ^input = gcnew InputBox("Enter the animation data to add", (!edit) ? "" : m_pSelectedItem->Text);
1498
					input->Large();
1499
					if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1500
					{
1501
						if ( edit )
39 cycrow 1502
							xsp->RemoveAnimation(_S(m_pSelectedItem->Text));
1503
						xsp->AddAnimation(_S(input->GetInput()));
1 cycrow 1504
						this->UpdateShipPartList();
1505
					}
1506
				}
1507
				break;
1508
		 }
1509
	}
1510
 
1511
	void PackageForm::DropGetDirectories(String ^dir, CyStringList *list, bool packages)
1512
	{
1513
		cli::array<String ^> ^dirList = IO::Directory::GetFileSystemEntries(dir);
1514
		for ( int j = 0; j < dirList->Length; j++ )
1515
		{
1516
			if ( IO::DirectoryInfo(dirList[j]).Exists )
1517
				this->DropGetDirectories(dirList[j], list, packages);
1518
			else
1519
			{
1520
				if ( packages )
1521
					list->PushBack(CyStringFromSystemString(dirList[j]), "-1");
1522
				else
18 cycrow 1523
					list->PushBack(CyStringFromSystemString(dirList[j]), CyString::Number(SPK::GetAutomaticFiletype(CyStringFromSystemString(dirList[j]), NULL,false)));
1 cycrow 1524
			}
1525
		}
1526
	}
1527
 
1528
	void PackageForm::RemoveSelectedFiles()
1529
	{
1530
		CLinkList<C_File> removeFiles;
1531
		for ( int i = 0; i < ListFiles->SelectedItems->Count; i++ )
1532
		{
1533
			int id = CyStringFromSystemString(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).ToInt();
1534
			C_File *file = m_pPackage->GetFileList()->Get(id);
1535
			if ( m_pDisplayFile == file )
1536
				m_pDisplayFile = NULL;
1537
			removeFiles.push_back(file);
1538
		}
1539
 
1540
		if ( removeFiles.size() )
1541
		{
1542
			for ( C_File *f = removeFiles.First(); f; f = removeFiles.Next() )
1543
				m_pPackage->RemoveFile(f);
1544
			m_pPackage->UpdateSigned(false);
1545
			this->UpdateFileList();
1546
			this->UpdateDisplayPic();
1547
			this->UpdateChanged();
1548
		}
1549
 
1550
		if ( !ListFiles->SelectedItems->Count )
1551
			this->ButRemoveFile->Enabled = false;
1552
	}
1553
 
1554
	String ^PackageForm::ExtractImport(String ^file, String ^type)
1555
	{
1556
		if ( String::Compare(IO::FileInfo(file).Extension, ".xml") == 0 )
1557
			return file;
1558
 
1559
		if ( String::Compare(IO::FileInfo(file).Extension, ".pck") == 0 )
1560
		{
1561
			C_File F(CyStringFromSystemString(file));
1562
			F.UnPCKFile();
1563
			if ( F.WriteToFile("tmp") )
1564
				return "tmp";
1565
		}
1566
		else if ( String::Compare(IO::FileInfo(file).Extension, ".cat") == 0 )
1567
		{
1568
			CCatFile cat;
1569
			if ( cat.Open(CyStringFromSystemString(file), "", CATREAD_CATDECRYPT, false) == CATERR_NONE )
1570
			{
1571
				if ( cat.ExtractFile(CyStringFromSystemString("types\\" + type + ".pck"), "tmp") )
1572
					return "tmp";
1573
			}
1574
		}
1575
 
1576
		return "";
1577
	}
1578
 
1579
	int PackageForm::GetHighestGame()
1580
	{
1581
		return ((Form1 ^)this->MdiParent)->GetHighestGame();
1582
	}
1583
 
1584
 
1585
	void PackageForm::ImportData(String ^file, int type)
1586
	{
1587
		CFileIO F(CyStringFromSystemString(file));
1588
		if ( !F.Exists() )
1589
			return;
1590
 
1591
		CyStringList *lines = F.ReadLinesStr();
1592
		if ( !lines )
1593
			return;
1594
 
1595
		LoadShip ^load = gcnew LoadShip();
1596
 
1597
		int entryPos = 1;
1598
		int dataPos = 1;
1599
		int dataPos2 = 0;
1600
		bool sections = false;
1601
		CyString section;
1602
		switch ( type )
1603
		{
1604
			case 2:
1605
				entryPos = 2;
1606
				dataPos = 19;
1607
				load->Cockpits();
1608
				break;
1609
			case 3:
1610
				dataPos2 = 2;
1611
				load->CutData();
1612
				break;
1613
			case 4:
1614
				sections = true;
1615
				entryPos = 2;
1616
				load->Bodies();
1617
				break;
1618
			case 1:
1619
				sections = true;
1620
				entryPos = 2;
1621
				dataPos = -1;
1622
				load->Dummies();
1623
				break;
1624
			case 0:
1625
				sections = true;
1626
				entryPos = 2;
1627
				dataPos = -1;
1628
				load->Components();
1629
				break;
1630
		}
1631
 
1632
		int entries2 = 0;
1633
		int entries = -1;
1634
		CyStringList list;
1635
		CyString data;
1636
		int e = 0;
1637
		for ( SStringList *str = lines->Head(); str; str = str->next )
1638
		{
1639
			str->str.RemoveChar(9);
1640
			str->str.RemoveChar('\r');
1641
			str->str.RemoveFirstSpace();
1642
			if ( str->str.Empty() )
1643
				continue;
1644
			if ( str->str[0] == '/' )
1645
				continue;
1646
 
1647
			if ( entries == -1 || (entries <= 0 && sections) )
1648
			{
1649
				entries = str->str.GetToken(";", entryPos, entryPos).ToInt();
1650
				if ( sections )
1651
				{
1652
					section = str->str.GetToken(";", 1, 1);
1653
					load->AddGroup(SystemStringFromCyString(section));
1654
				}
1655
			}
1656
			else
1657
			{
1658
				if ( type == 4 )
1659
				{
1660
					int max;
1661
					CyString *strs = str->str.SplitToken(";", &max);
1662
					if ( max && strs )
1663
					{
1664
						for ( int i = 0; i < max; i++ )
1665
						{
1666
							strs[i].RemoveFirstSpace();
1667
							if ( strs[i].Empty() ) continue;
1668
							CyString id = strs[i].GetToken(";", dataPos, dataPos);
1669
							load->AddShip(SystemStringFromCyString(id), "");
1670
							list.PushBack(id, CyString::Number(e) + " " + section + ";" + strs[i]);
1671
							++e;
1672
							--entries;
1673
						}
1674
					}
1675
 
1676
					CLEANSPLIT(strs, max)
1677
				}
1678
				else if ( type == 0 )
1679
				{
1680
					if ( entries2 )
1681
					{
1682
						load->AddShip(SystemStringFromCyString(data), SystemStringFromCyString(str->str));
1683
						list.PushBack(data, section + ";" + data + ";" + str->str);
1684
						--entries2;
1685
					}
1686
					else
1687
					{
1688
						data = str->str.GetToken(";", 1, 1);
1689
						entries2 = str->str.GetToken(";", 2, 2).ToInt();
1690
						++e;
1691
						--entries;
1692
					}
1693
				}
1694
				else
1695
				{
1696
					CyString id;
1697
					if ( dataPos == -1 )
1698
						id = str->str; 
1699
					else
1700
						id = str->str.GetToken(";", dataPos, dataPos); 
1701
 
1702
					if ( dataPos2 )
1703
						load->AddShip(SystemStringFromCyString(id), SystemStringFromCyString(str->str.GetToken(";", dataPos2, dataPos2)));
1704
					else
1705
						load->AddShip(SystemStringFromCyString(id), "");
1706
					if ( sections )
1707
						list.PushBack(id, CyString::Number(e) + " " + section + ";" + str->str);
1708
					else
1709
						list.PushBack(id, CyString::Number(e) + " " + str->str);
1710
					++e;
1711
					--entries;
1712
				}
1713
			}
1714
		}
1715
 
1716
		if ( load->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1717
		{
1718
			for ( SStringList *str = load->GetDataList()->Head(); str; str = str->next )
1719
			{
1720
				SStringList *s = list.FindString(str->str);
1721
				if ( s )
1722
				{
1723
					switch ( type )
1724
					{
1725
						case 0:
39 cycrow 1726
							((CXspFile *)m_pPackage)->AddComponent(s->data.GetToken(";", 1, 1).ToString(), s->data.GetToken(";", 2, 2).ToString(), s->data.GetToken(";", 3).ToString());
1 cycrow 1727
							break;
1728
						case 2:
39 cycrow 1729
							((CXspFile *)m_pPackage)->AddCockpit(s->data.GetToken(" ", 2).ToString(), 0, -1, s->data.GetToken(" ", 1, 1).ToInt());
1 cycrow 1730
							break;
1731
						case 3:
39 cycrow 1732
							((CXspFile *)m_pPackage)->AddCutData(s->data.GetToken(" ", 2).ToString());
1 cycrow 1733
							break;
1734
						case 4:
39 cycrow 1735
							((CXspFile *)m_pPackage)->AddBodies(s->data.GetToken(" ", 2).ToString());
1 cycrow 1736
							break;
1737
						case 1:
39 cycrow 1738
							((CXspFile *)m_pPackage)->AddDummy(s->data.GetToken(" ", 2).GetToken(";", 1, 1).ToString(), s->data.GetToken(" ", 2).GetToken(";", 2).ToString());
1 cycrow 1739
							break;
1740
					}
1741
				}
1742
			}
1743
 
1744
			this->UpdateShipPartList();
1745
			this->UpdateChanged();
1746
		}
1747
 
1748
		delete lines;
1749
	}
1750
 
1751
	void PackageForm::ImportAnimations(String ^file)
1752
	{
1753
		CFileIO F(CyStringFromSystemString(file));
1754
		if ( !F.Exists() )
1755
			return;
1756
 
1757
		CyStringList *lines = F.ReadLinesStr();
1758
		if ( !lines )
1759
			return;
1760
 
1761
 
1762
		CyStringList lOut;
1763
		if ( CXspFile::ReadAnimations(lines, &lOut, 0) )
1764
		{
1765
			LoadShip ^load = gcnew LoadShip();
1766
			load->Animations();
1767
			for ( SStringList *str = lOut.Head(); str; str = str->next )
1768
			{
1769
				load->AddShip(SystemStringFromCyString(str->str), "");
1770
			}
1771
 
1772
			if ( load->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1773
			{
1774
				((CXspFile *)m_pPackage)->AddAnimation(load->GetDataList());
1775
				this->UpdateShipPartList();
1776
				this->UpdateChanged();
1777
			}
1778
		}
1779
 
1780
		delete lines;
1781
	}
1782
 
1783
	void PackageForm::EditDepend()
1784
	{
1785
		 AddDepend ^depend = gcnew AddDepend();
1786
		 depend->SetEdit(m_pSelectedItem->Text, m_pSelectedItem->SubItems[1]->Text, m_pSelectedItem->SubItems[2]->Text);
1787
 
1788
		 bool builtin = false;
1789
		 if ( String::Compare("<package>", m_pSelectedItem->Text) == 0 && String::Compare("<author>", m_pSelectedItem->SubItems[1]->Text) == 0 )
1790
		 {
1791
			 builtin = true;
1792
			 depend->BuiltIn();
1793
		 }
1794
 
1795
		 if ( depend->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1796
		 {
1797
			 if ( builtin )
1798
			 {
1799
				 SNeededLibrary *ns = m_pPackage->FindPackageNeeded("<package>", "<author>");
1800
				 if ( ns )
46 cycrow 1801
					 ns->sMinVersion = _S(depend->GetVersion());
1 cycrow 1802
			 }
1803
			 else
1804
			 {
46 cycrow 1805
				 m_pPackage->RemovePackageNeeded(_S(m_pSelectedItem->Text), _S(m_pSelectedItem->SubItems[1]->Text));
1806
				 m_pPackage->AddNeededLibrary(_S(depend->GetName()), _S(depend->GetAuthor()), _S(depend->GetVersion()));
1 cycrow 1807
			 }
1808
			 this->UpdateDependacies();
1809
			 this->UpdateChanged();
1810
		 }
1811
	}
1812
}