Subversion Repositories spk

Rev

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