Subversion Repositories spk

Rev

Rev 102 | Rev 126 | 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
 
50 cycrow 26
		m_pPackage->adjustChanged(false);
1 cycrow 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
 
50 cycrow 73
		m_pPackage->adjustChanged(false);
1 cycrow 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;
50 cycrow 290
		this->TextName->Text = _US(m_pPackage->name());
291
		this->TextAuthor->Text = _US(m_pPackage->author());
292
		this->TextVersion->Text = _US(m_pPackage->version());
48 cycrow 293
		Utils::String desc = m_pPackage->description();
294
		desc = desc.findReplace("<br>", "\n");
295
		desc = desc.findReplace("<newline>", "\n");
296
		desc = desc.stripHtml();
297
		this->TextDesc->Text = _US(desc);
1 cycrow 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
 
48 cycrow 337
			this->ComboPluginType->SelectedIndex = spk->pluginType();
1 cycrow 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
 
50 cycrow 371
		if ( !m_pPackage->creationDate().empty() ) {
372
			int day = m_pPackage->creationDate().token("/", 1);
373
			int month = m_pPackage->creationDate().token("/", 2);
374
			int year = m_pPackage->creationDate().token("/", 3);
1 cycrow 375
			if ( month > 12 && day <= 12 ) { int temp = day; day = month; month = temp; }
376
			if ( month < 1 ) month = 1;
377
			if ( month > 12 ) month = 12;
378
			if ( day < 1 ) day = 1;
379
			if ( day > 31 ) day = 1;
380
			if ( year < 1900 ) year += 2000;
381
			try {
382
				this->CreationDate->Value = DateTime(year, month, day);
383
			} catch(System::ArgumentOutOfRangeException ^) {
384
				this->CreationDate->Value = DateTime::Today;
385
			}
386
		}
387
		else
388
			this->CreationDate->Value = DateTime::Today;
389
 
49 cycrow 390
		this->TextForum->Text = _US(m_pPackage->forumLink());
391
		this->TextEmail->Text = _US(m_pPackage->email());
392
		this->TextWebsite->Text = _US(m_pPackage->webSite());
393
		this->TextWebAddress->Text = _US(m_pPackage->webAddress());
1 cycrow 394
 
395
		this->UpdateGamesList();
396
		this->UpdateFileList();
397
		this->UpdateMirrors();
398
		this->UpdatePackageNames();
399
 
400
		m_bSortingAsc = true;
401
		m_iSortingCol = 1;
402
		this->ListFiles->ListViewItemSorter = gcnew ListViewItemComparer(m_iSortingCol, !m_bSortingAsc);
403
 
404
		this->UpdateDisplayPic();
405
		this->UpdateDisplayIcon();
406
		this->UpdateRatings();
407
		this->UpdateText();
408
		this->UpdateDependacies();
409
 
410
		// delete the pages
411
		if ( m_pPackage->GetType() != TYPE_XSP )
412
		{
413
			delete this->PageShip;
414
			delete this->PageRaw;
415
			delete this->PageShipComp;
416
			this->PageShip = nullptr;
417
			this->PageRaw = nullptr;
418
			this->PageShipComp = nullptr;
419
			this->PanelShip->Hide();
420
			this->ToolCustomise->Visible = false;
421
		}
422
		else if ( m_pPackage->GetType() != TYPE_SPK )
423
		{
424
			delete this->PagePackage;
425
			delete this->PageWares;
426
			this->PageWares = nullptr;
427
			this->PagePackage = nullptr;
428
		}
429
 
430
		m_bLoading = false;
431
	}
432
 
433
	void PackageForm::UpdateDependacies()
434
	{
435
		this->ListDep->Items->Clear();
436
		for ( SNeededLibrary *nl = m_pPackage->GetNeededLibraries()->First(); nl; nl = m_pPackage->GetNeededLibraries()->Next() )
437
		{
438
			ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(nl->sName));
439
			item->SubItems->Add(SystemStringFromCyString(nl->sAuthor));
440
			item->SubItems->Add(SystemStringFromCyString(nl->sMinVersion));
441
			item->ImageIndex = 3;
442
			this->ListDep->Items->Add(item);
443
		}
444
		this->ListDep->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
445
	}
446
 
447
	void PackageForm::UpdateShipPartList()
448
	{
449
		if ( !m_pPackage )
450
			return;
451
		CXspFile *xsp = (CXspFile *)m_pPackage;
452
 
453
		// first lets adjust out columns
454
		int numColums = 1;
455
		this->ListShipPart->Visible = true;
456
		this->ListShipPart->Items->Clear();
457
		switch ( this->ComboShipPart->SelectedIndex )
458
		{
459
			case 0: // componants
460
				numColums = 3;
461
				this->ColumnPart1->Text = "Section";
462
				this->ColumnPart2->Text = "ID";
463
				this->ColumnPart3->Text = "Data";
464
				for ( SComponent *c = xsp->GetComponents()->First(); c; c = xsp->GetComponents()->Next() )
465
				{
466
					ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(c->sSection));
467
					item->ImageKey = "components";
468
					item->SubItems->Add(SystemStringFromCyString(c->sSection2));
469
					item->SubItems->Add(SystemStringFromCyString(c->sData));
470
					this->ListShipPart->Items->Add(item);
471
				}
472
				break;
473
			case 1: // dummies
474
				numColums = 2;
475
				this->ColumnPart1->Text = "Section";
476
				this->ColumnPart2->Text = "Data";
477
				for ( SDummy *d = xsp->GetDummies()->First(); d; d = xsp->GetDummies()->Next() )
478
				{
479
					ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(d->sSection));
480
					item->SubItems->Add(SystemStringFromCyString(d->sData));
481
					item->ImageKey = "dummies";
482
					this->ListShipPart->Items->Add(item);
483
				}
484
				break;
485
			case 2: // Cockpit
486
				numColums = 3;
487
				this->ColumnPart1->Text = "ID";
488
				this->ColumnPart2->Text = "Index";
489
				this->ColumnPart3->Text = "Data";
490
				for ( SCockpit *c = xsp->GetCockpits()->First(); c; c = xsp->GetCockpits()->Next() )
491
				{
492
					CyString cName = c->sCockpit;
493
					cName = cName.GetToken(";", -2);
494
					while ( cName.Right(1) == ";" )
495
						cName.Truncate(-1);
496
					ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(cName));
497
					if ( c->iIndex == -1 )
498
						item->SubItems->Add("<PACKAGE>");
499
					else
500
						item->SubItems->Add(Convert::ToString(c->iIndex));
501
					item->SubItems->Add(SystemStringFromCyString(c->sCockpit));
502
					item->ImageKey = "cockpit";
503
					this->ListShipPart->Items->Add(item);
504
				}
505
				break;
506
			case 3: // CutData
507
				numColums = 1;
508
				this->ColumnPart1->Text = "Cuts";
509
				for ( SStringList *cut = xsp->GetCutData()->Head(); cut; cut = cut->next )
510
				{
511
					ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(cut->str));
512
					item->ImageKey = "cutdata";
513
					this->ListShipPart->Items->Add(item);
514
				}
515
				break;
516
			case 4: // Bodies
517
				numColums = 2;
518
				this->ColumnPart1->Text = "Section";
519
				this->ColumnPart2->Text = "Bodies";
520
				for ( SStringList *b = xsp->GetBodies()->Head(); b; b = b->next )
521
				{
522
					ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(b->str.GetToken(";", 1, 1)));
523
					item->SubItems->Add(SystemStringFromCyString(b->str.GetToken(";", 2)));
524
					item->ImageKey = "bodies";
525
					this->ListShipPart->Items->Add(item);
526
				}
527
				break;
528
			case 5: // Animations
529
				numColums = 1;
530
				this->ColumnPart1->Text = "Animations";
531
				for ( SStringList *a = xsp->GetAnimations()->Head(); a; a = a->next )
532
				{
533
					ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(a->str));
534
					item->ImageKey = "animations";
535
					this->ListShipPart->Items->Add(item);
536
				}
537
				break;
538
 
539
			// dont know what we are supposed to be displaying
540
			default:
541
				this->ListShipPart->Visible = false;
542
		}
543
 
544
		this->ListShipPart->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
545
		// adjust size of columns
546
		if ( numColums < 3 )
547
			this->ColumnPart3->Width = 0;
548
		if ( numColums < 2 )
549
			this->ColumnPart2->Width = 0;
550
	}
551
 
552
	void PackageForm::UpdateShipText()
553
	{
554
		CXspFile *xsp = (CXspFile *)m_pPackage;
555
 
556
		this->ListShipText->Items->Clear();
557
 
558
		for ( SText *t = xsp->GetTexts()->First(); t; t = xsp->GetTexts()->Next() )
559
		{
560
			ListViewItem ^item = gcnew ListViewItem(System::Convert::ToString(t->iId));
561
			item->ImageIndex = 0;
562
			item->SubItems->Add(SystemStringFromCyString(t->sName));
563
			item->SubItems->Add(SystemStringFromCyString(t->sDesc));
564
			this->ListShipText->Items->Add(item);
565
		}
566
 
567
		this->ListShipText->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
568
	}
569
 
570
	void PackageForm::UpdateDisplayPic()
571
	{
572
		System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(PackageForm::typeid));
573
		this->ButPicBack->Enabled = false;
574
		this->ButPicNext->Enabled = false;
575
		if ( m_pDisplayFile )
576
		{
577
			CyString filePointer = m_pDisplayFile->GetFilePointer();
578
			filePointer = filePointer.FindReplace("/", "\\");
579
			filePointer = filePointer.FindReplace("\\\\", "\\");
580
			if ( System::IO::File::Exists(SystemStringFromCyString(filePointer)) )
581
			{
582
				Bitmap ^myBitmap = gcnew Bitmap(SystemStringFromCyString(filePointer));
583
				if ( myBitmap )
584
					this->DisplayPicture->Image = dynamic_cast<Image ^>(myBitmap);
585
			}
586
			this->ButPicDel->Enabled = true;
587
 
588
			if ( m_pPackage->GetFirstFile(FILETYPE_ADVERT) != m_pDisplayFile )
589
				this->ButPicBack->Enabled = true;
590
			if ( m_pPackage->GetNextFile(m_pDisplayFile)  )
591
				this->ButPicNext->Enabled = true;
592
		}
593
		else
594
		{
595
			this->ButPicDel->Enabled = false;
596
			this->DisplayPicture->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"DisplayPicture.Image")));
597
		}
598
 
599
	}
600
 
601
	void PackageForm::UpdateDisplayIcon()
602
	{
603
		System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(PackageForm::typeid));
604
 
605
		m_pTabPage->ImageIndex = 0;
606
 
607
		if ( m_pPackage->GetType() == TYPE_XSP )
608
			this->DisplayIcon->Image = this->imageList1->Images[1];
609
		else
610
		{
611
			this->DisplayIcon->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"DisplayIcon.Image")));
612
 
613
			int num = -1;
614
			if ( m_pPackage->GetType() == TYPE_SPK )
615
			{
616
				CSpkFile *spk = (CSpkFile *)m_pPackage;
617
				if ( spk->IsLibrary() )
618
					num = 3;
619
				else if ( spk->IsPackageUpdate() )
620
					num = 6;
621
				else if ( spk->IsPatch() )
622
					num = 7;
623
				else if ( spk->IsCustomStart() )
624
					num = 8;
625
			}
626
 
627
			if ( num == -1 && m_pPackage->IsFakePatch() )
628
				num = 2;
629
 
630
			if ( num != -1 )
631
			{
632
				this->DisplayIcon->Image = this->imageList1->Images[num];
633
				m_pTabPage->ImageIndex = num;
634
			}
635
		}
636
 
637
		this->ButIconDel->Enabled = false;
638
 
639
		if ( m_pPackage->GetIcon() )
640
		{
641
			this->ButIconDel->Enabled = true;
642
			CyString filePointer = m_pPackage->GetIcon()->GetFilePointer();
643
			filePointer = filePointer.FindReplace("/", "\\");
644
			filePointer = filePointer.FindReplace("\\\\", "\\");
645
			String ^file = SystemStringFromCyString(filePointer);
646
			if ( System::IO::File::Exists(file) )
647
			{
648
				Bitmap ^myBitmap = gcnew Bitmap(file);
649
				if ( myBitmap )
650
				{
651
					this->DisplayIcon->Image = dynamic_cast<Image ^>(myBitmap);
652
					this->imageList1->Images->Add(file, myBitmap);
653
					m_pTabPage->ImageIndex = this->imageList1->Images->IndexOfKey(file);
654
					if ( m_pTabPage->ImageIndex == -1 )
655
						m_pTabPage->ImageIndex = 0;
656
				}
657
			}
658
		}
659
 
660
		if ( m_pTabPage->ImageIndex == 0 )
661
		{
662
			if ( m_pPackage->GetType() == TYPE_XSP )
663
				m_pTabPage->ImageIndex = 1;
664
		}
665
 
666
		m_pMenuItem->Image = this->imageList1->Images[m_pTabPage->ImageIndex];
667
	}
668
 
669
	void PackageForm::UpdateGameVersion()
670
	{
671
		bool restoreLoad = m_bLoading;
672
		m_bLoading = true;
673
 
674
		ComboVersion->BeginUpdate();
675
		ComboVersion->Items->Clear();
676
 
677
		this->TextExactVersion->Hide();
678
 
679
		SGameExe *exe = NULL;
680
		if ( ButGame->ImageIndex >= 0 )
681
			exe = m_pP->GetGameExe()->GetGame((m_pPackage) ? ButGame->ImageIndex : -1);
682
		if ( exe )
683
		{			
684
			ComboVersion->Items->Add("Original");
685
			for ( int i = 0; i < exe->lVersions.size(); i++ )
686
			{
687
				SGameExeVersion *v = exe->lVersions[i];
688
				ComboVersion->Items->Add(SystemStringFromCyString(v->sName));
689
			}
690
			ComboVersion->Items->Add("Exact (Custom)");
691
			ComboVersion->Enabled = true;
692
		}
693
		else
694
		{
695
			ComboVersion->Enabled = false;
696
		}
697
 
698
 
699
		ComboVersion->EndUpdate();
700
 
701
		if ( !restoreLoad )
702
			m_bLoading = false;
703
	}
704
 
705
	void PackageForm::UpdateRatings()
706
	{
707
		this->PicEase1->BackColor = System::Drawing::Color::Transparent;
708
		this->PicEase2->BackColor = System::Drawing::Color::Transparent;
709
		this->PicEase3->BackColor = System::Drawing::Color::Transparent;
710
		this->PicEase4->BackColor = System::Drawing::Color::Transparent;
711
		this->PicEase5->BackColor = System::Drawing::Color::Transparent;
712
 
713
		this->PicChange1->BackColor = System::Drawing::Color::Transparent;
714
		this->PicChange2->BackColor = System::Drawing::Color::Transparent;
715
		this->PicChange3->BackColor = System::Drawing::Color::Transparent;
716
		this->PicChange4->BackColor = System::Drawing::Color::Transparent;
717
		this->PicChange5->BackColor = System::Drawing::Color::Transparent;
718
 
719
		this->PicRec1->BackColor = System::Drawing::Color::Transparent;
720
		this->PicRec2->BackColor = System::Drawing::Color::Transparent;
721
		this->PicRec3->BackColor = System::Drawing::Color::Transparent;
722
		this->PicRec4->BackColor = System::Drawing::Color::Transparent;
723
		this->PicRec5->BackColor = System::Drawing::Color::Transparent;
724
 
46 cycrow 725
		if ( m_pPackage->easeOfUse() >= 1 )
1 cycrow 726
			this->PicEase1->BackColor = System::Drawing::Color::Red;
46 cycrow 727
		if ( m_pPackage->easeOfUse() >= 2 )
1 cycrow 728
			this->PicEase2->BackColor = System::Drawing::Color::Red;
46 cycrow 729
		if ( m_pPackage->easeOfUse() >= 3 )
1 cycrow 730
			this->PicEase3->BackColor = System::Drawing::Color::Red;
46 cycrow 731
		if ( m_pPackage->easeOfUse() >= 4 )
1 cycrow 732
			this->PicEase4->BackColor = System::Drawing::Color::Red;
46 cycrow 733
		if ( m_pPackage->easeOfUse() >= 5 )
1 cycrow 734
			this->PicEase5->BackColor = System::Drawing::Color::Red;
735
 
46 cycrow 736
		if ( m_pPackage->recommended() >= 1 )
1 cycrow 737
			this->PicRec1->BackColor = System::Drawing::Color::Red;
46 cycrow 738
		if ( m_pPackage->recommended() >= 2 )
1 cycrow 739
			this->PicRec2->BackColor = System::Drawing::Color::Red;
46 cycrow 740
		if ( m_pPackage->recommended() >= 3 )
1 cycrow 741
			this->PicRec3->BackColor = System::Drawing::Color::Red;
46 cycrow 742
		if ( m_pPackage->recommended() >= 4 )
1 cycrow 743
			this->PicRec4->BackColor = System::Drawing::Color::Red;
46 cycrow 744
		if ( m_pPackage->recommended() >= 5 )
1 cycrow 745
			this->PicRec5->BackColor = System::Drawing::Color::Red;
746
 
46 cycrow 747
		if ( m_pPackage->gameChanging() >= 1 )
1 cycrow 748
			this->PicChange1->BackColor = System::Drawing::Color::Red;
46 cycrow 749
		if ( m_pPackage->gameChanging() >= 2 )
1 cycrow 750
			this->PicChange2->BackColor = System::Drawing::Color::Red;
46 cycrow 751
		if ( m_pPackage->gameChanging() >= 3 )
1 cycrow 752
			this->PicChange3->BackColor = System::Drawing::Color::Red;
46 cycrow 753
		if ( m_pPackage->gameChanging() >= 4 )
1 cycrow 754
			this->PicChange4->BackColor = System::Drawing::Color::Red;
46 cycrow 755
		if ( m_pPackage->gameChanging() >= 5 )
1 cycrow 756
			this->PicChange5->BackColor = System::Drawing::Color::Red;
757
 
46 cycrow 758
		if ( m_pPackage->easeOfUse() < 0 )
1 cycrow 759
			this->GroupEase->Text = "Ease of Use";
760
		else
46 cycrow 761
			this->GroupEase->Text = "Ease of Use (" + System::Convert::ToString(m_pPackage->easeOfUse()) + ")";
1 cycrow 762
 
46 cycrow 763
		if ( m_pPackage->gameChanging() < 0 )
1 cycrow 764
			this->GroupChange->Text = "Game Changing";
765
		else
46 cycrow 766
			this->GroupChange->Text = "Game Changing (" + System::Convert::ToString(m_pPackage->gameChanging()) + ")";
1 cycrow 767
 
46 cycrow 768
		if ( m_pPackage->recommended() < 0 )
1 cycrow 769
			this->GroupRec->Text = "Recommended";
770
		else
46 cycrow 771
			this->GroupRec->Text = "Recommended (" + System::Convert::ToString(m_pPackage->recommended()) + ")";
1 cycrow 772
	}
773
 
774
	void PackageForm::Setup()
775
	{
776
		m_bLoading = true;
777
 
778
		this->ComboFileType->Items->Add("All Files");
779
		for ( int i = 0; i < FILETYPE_MAX; i++ )
780
			this->ComboFileType->Items->Add(SystemStringFromCyString(GetFileTypeString(i)));
781
		this->ComboFileType->SelectedIndex = 0;
782
 
783
		this->PanelShip->Hide();
784
 
785
		m_bSortingAsc = true;
786
		m_iSortingCol = 1;
787
 
788
		this->ListFiles->ColumnClick += gcnew ColumnClickEventHandler(this, &Creator::PackageForm::SortList);
789
		this->ListFiles->ItemChecked += gcnew ItemCheckedEventHandler(this, &PackageForm::Event_FileChecked);
790
 
791
		this->ContextGames->Items->Clear();
792
 
793
		this->ComboGameFilter->Items->Clear();
794
		this->ToolGame->DropDownItems->Clear();
795
 
796
		this->ComboGameFilter->Items->Add("- None -");
797
		this->ComboGameFilter->Items->Add("- All Games -");
798
 
799
		for ( int i = 0; i < m_pP->GetGameExe()->GetNumGames(); i++ )
800
		{
801
			SGameExe *gameExe = m_pP->GetGameExe()->GetGame(i);
802
			if ( gameExe )
803
			{
804
				System::Windows::Forms::ToolStripMenuItem ^newItem = gcnew System::Windows::Forms::ToolStripMenuItem;
805
				newItem->Text = SystemStringFromCyString(gameExe->sName);
806
				newItem->Tag = Convert::ToString(i + 1);
807
				newItem->Image = this->imageListGames->Images[i];
808
				newItem->Click += gcnew System::EventHandler(this, &PackageForm::ContextGame_Selected);
809
				this->ContextGames->Items->Add(newItem);
810
 
811
				System::Windows::Forms::ToolStripMenuItem ^newItem2 = gcnew System::Windows::Forms::ToolStripMenuItem;
812
				newItem2->Text = SystemStringFromCyString(gameExe->sName);
813
				newItem2->Tag = Convert::ToString(i + 1);
814
				newItem2->Image = this->imageListGames->Images[i];
815
				newItem2->Click += gcnew System::EventHandler(this, &PackageForm::SetGame_Selected);
816
				this->ToolGame->DropDownItems->Add(newItem2);
817
 
818
				this->ComboGameFilter->Items->Add(SystemStringFromCyString(gameExe->sName));
819
			}
820
		}
821
 
822
		this->ComboGameFilter->SelectedIndex = 0;
823
 
824
		this->ButGame->Text = "- Select Game -";
825
		this->ButGameAdd->Enabled = false;
826
 
827
		m_pTypeList->Clear();
6 cycrow 828
		for ( int i = 0; i < CSpkFile::SCRIPTTYPE_MAX; i++ )
1 cycrow 829
		{
10 cycrow 830
			m_pTypeList->PushBack(CSpkFile::GetScriptTypeStringStatic(i).c_str());
1 cycrow 831
			ComboType->Items->Add(SystemStringFromCyString(CSpkFile::GetScriptTypeStringStatic(i)));
832
		}
833
 
834
		this->CreationDate->Value = DateTime::Today;
835
 
836
		m_bLoading = false;
837
	}
838
 
839
	void PackageForm::UpdateGamesList()
840
	{
841
		this->ListGames->Items->Clear();
842
		for ( SGameCompat *game = m_pPackage->GetGameCompatabilityList()->First(); game; game = m_pPackage->GetGameCompatabilityList()->Next() ) {
843
			ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(m_pP->GetGameNameFromType(game->iGame)));
844
			item->ImageIndex = (game->iGame < 0) ? -1 : (game->iGame - 1);
46 cycrow 845
			if ( !game->sVersion.empty() ) {
1 cycrow 846
				item->SubItems->Add("Exact: " + SystemStringFromCyString(game->sVersion));
847
			}
848
			else {
849
				item->SubItems->Add(SystemStringFromCyString(m_pP->GetGameVersionFromType(game->iGame, game->iVersion, game->sVersion)));
850
			}
851
			item->Tag = game->iGame;
852
			this->ListGames->Items->Add(item);
853
		}
854
 
855
		this->ListGames->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
856
	}
857
 
858
	void PackageForm::UpdateFileList()
859
	{
860
		this->ButRemoveFile->Enabled = false;
861
 
862
		int pos = 0;
863
		this->ListFiles->Items->Clear();
864
		if ( m_pPackage ) {
865
			for ( C_File *file = m_pPackage->GetFileList()->First(); file; file = m_pPackage->GetFileList()->Next() )
866
			{
867
				file->SetPos(pos++);
868
				if ( this->ComboGameFilter->SelectedIndex > 0 ) {
869
					if ( this->ComboGameFilter->SelectedIndex - 1 != file->GetGame() )
870
						continue;
871
				}
872
				if ( this->ComboFileType->SelectedIndex == 0 || (this->ComboFileType->SelectedIndex - 1) == file->GetFileType() )
873
					this->AddFile(file);
874
			}
875
			((Form1 ^)this->MdiParent)->UpdateStatus();
876
		}
877
 
878
		this->ListFiles->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
879
	}
880
 
881
	void PackageForm::AddFile(C_File *file)
882
	{
883
		ListViewItem ^item = gcnew ListViewItem("");
884
 
885
		if ( file->GetData() )
886
		{
887
			item->SubItems->Add(SystemStringFromCyString(CyString("<PACKAGE>/") + file->GetNameDirectory(NULL)));
888
			item->SubItems->Add(SystemStringFromCyString(file->GetUncompressedSizeString()));
889
		}
890
		else
891
		{
892
			item->SubItems->Add(SystemStringFromCyString(file->GetFullFilename()));
893
			item->SubItems->Add(SystemStringFromCyString(SPK::GetSizeString(file->GetSize())));
894
		}
895
 
896
		if ( file->IsFakePatch() )
897
			item->SubItems->Add("Mod (Fakepatch)");
898
		else
899
			item->SubItems->Add(SystemStringFromCyString(file->GetFileTypeString()));
900
 
901
		if ( !file->GetDir().Empty() )
902
			item->SubItems->Add(SystemStringFromCyString(file->GetDir()));
903
		else
904
			item->SubItems->Add("");
905
 
906
		if ( file->IsSigned() )
907
			item->SubItems->Add("Yes");
908
		else
909
			item->SubItems->Add("No");
910
 
911
		if ( !file->GetGame() )
912
			item->SubItems->Add("All Games");
913
		else {
914
			CPackages p;
915
			p.Startup(".", ".", ".");
916
			SGameExe *exe = p.GetGameExe()->GetGame(file->GetGame() - 1);
917
			if ( exe ) {
918
				item->SubItems->Add(SystemStringFromCyString(exe->sName));
919
			}
920
			else {
921
				item->SubItems->Add("Game: " + file->GetGame());
922
			}
923
		}
924
 
925
		item->Tag = SystemStringFromCyString(CyString::Number(file->GetPos()));
926
		if ( file->IsFakePatch() )
927
			item->ImageKey = "fakepatch";
928
		else
929
			item->ImageIndex = file->GetFileType();
930
 
931
		item->Checked = file->IsShared();
932
 
933
		this->ListFiles->Items->Add(item);
934
	}
935
 
936
	void PackageForm::AddNewFile()
937
	{
938
		// add filters
939
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
940
 
941
		System::String ^filter;
942
		for ( int i = 0; i < FILETYPE_MAX; i++ )
943
		{
944
			if ( filter )
945
				filter += "|";
946
			filter += SystemStringFromCyString(GetFileTypeString(i));
947
			filter += "|";
948
			// add extensions
949
			switch ( i )
950
			{
951
				case FILETYPE_SCRIPT:
952
				case FILETYPE_UNINSTALL:
953
				case FILETYPE_MAP:
954
				case FILETYPE_TEXT:
955
				case FILETYPE_MISSION:
956
					filter += "*.pck;*.xml";
957
					break;
958
 
959
				case FILETYPE_README:
960
					filter += "*.txt;*.doc;*.docx;*.pdf";
961
					break;
962
 
963
				case FILETYPE_MOD:
964
					filter += "*.cat";
965
					break;
966
 
967
				case FILETYPE_SOUND:
968
					filter += "*.wav";
969
					break;
970
 
971
				case FILETYPE_SCREEN:
972
				case FILETYPE_ADVERT:
973
					filter += "*.jpg;*.png";
974
					break;
975
 
976
				case FILETYPE_SHIPSCENE:
977
				case FILETYPE_COCKPITSCENE:
978
					filter += "*.pbd;*.bod";
979
					break;
980
 
981
				case FILETYPE_SHIPMODEL:
982
					filter += "*.pbd;*.bod;*.bob;*.pbb";
983
					break;
984
 
985
				default:
986
					filter += "*.*";
987
			}
988
		}
989
		ofd->Filter = filter;
990
		ofd->FilterIndex = 1;
991
		ofd->RestoreDirectory = true;
992
		ofd->Multiselect = true;
993
		ofd->Title = "Select File(s) to add to package";
994
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
995
		{
996
			CyString dir;
997
			if ( C_File::DoesTypeHaveExtraDir(ofd->FilterIndex - 1) )
998
			{
999
				InputBox ^input = gcnew InputBox("Enter the directory to add files to", ((ofd->FilterIndex - 1) == FILETYPE_EXTRA) ? "PluginManager/Extras/$scriptname" : "");
1000
				if ( input->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1001
					dir = CyStringFromSystemString(input->GetInput());
1002
			}
1003
			array<System::String ^> ^fileArray = ofd->FileNames;
1004
			for ( int i = 0; i < fileArray->Length; i++ )
1005
			{
1006
				System::String ^file = fileArray[i];
1007
				int filetype = m_pP->AdjustFileType(CyStringFromSystemString(file), ofd->FilterIndex - 1);
1008
				C_File *f = m_pPackage->AddFile(CyStringFromSystemString(file), dir, filetype);
1009
				if ( (ofd->FilterIndex - 1) == FILETYPE_MOD )
1010
					m_pPackage->AddFile(CFileIO(CyStringFromSystemString(file)).ChangeFileExtension("dat"), dir, filetype);
1011
			}
1012
			m_pPackage->UpdateSigned(false);
1013
			this->UpdateFileList();
1014
			this->UpdateDisplayPic();
1015
			this->UpdateChanged();
1016
		}
1017
	}
1018
 
1019
	bool PackageForm::CheckSave()
1020
	{
50 cycrow 1021
		if ( m_pPackage->name().empty() )
1 cycrow 1022
		{
1023
			MessageBox::Show(this, "You must specify a package name", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1024
			return false;
1025
		}
50 cycrow 1026
		if ( m_pPackage->author().empty() )
1 cycrow 1027
		{
1028
			MessageBox::Show(this, "You must specify an Author", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1029
			return false;
1030
		}
50 cycrow 1031
		if ( m_pPackage->version().empty() )
1 cycrow 1032
		{
1033
			MessageBox::Show(this, "You must specify a version number", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1034
			return false;
1035
		}
1036
 
1037
		if ( m_pPackage->GetType() == TYPE_SPK )
1038
		{
1039
			if ( ((CSpkFile *)m_pPackage)->IsPackageUpdate() )
1040
			{
1041
				SNeededLibrary *n = m_pPackage->FindPackageNeeded("<package>", "<author>");
1042
				if ( !n )
1043
					m_pPackage->AddNeededLibrary("<package>", "<author>", "1.00");
1044
				n = m_pPackage->FindPackageNeeded("<package>", "<author>");
1045
 
1046
				if ( n )
1047
				{
50 cycrow 1048
					if ( ((CSpkFile *)m_pPackage)->version().compareVersion(n->sMinVersion) != COMPARE_OLDER )
1 cycrow 1049
					{
50 cycrow 1050
						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 1051
						return false;
1052
					}
1053
				}
1054
			}
1055
			else if ( ((CSpkFile *)m_pPackage)->IsCustomStart() )
1056
			{
1057
				if ( !((CSpkFile *)m_pPackage)->CheckValidCustomStart() )
1058
				{
1059
					MessageBox::Show(this, "For a custom start, you must include an initplayer script", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1060
					return false;
1061
				}
1062
			}
1063
			else if ( ((CSpkFile *)m_pPackage)->IsPatch() )
1064
			{
10 cycrow 1065
				if ( ((CSpkFile *)m_pPackage)->GetOtherAuthor().empty() || ((CSpkFile *)m_pPackage)->GetOtherName().empty() )
1 cycrow 1066
				{
1067
					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);
1068
					return false;
1069
				}
1070
			}
1071
		}
1072
 
1073
		 System::DateTime ^time = DateTime(this->CreationDate->Value);
50 cycrow 1074
		 m_pPackage->setCreationDate(_S(System::Convert::ToString(time->Day) + "/" + System::Convert::ToString(time->Month) + "/" + System::Convert::ToString(time->Year)));
1 cycrow 1075
 
1076
		return true;
1077
	}
1078
 
1079
	void PackageForm::Save()
1080
	{
1081
		if ( !this->CheckSave() )
1082
			return;
1083
 
50 cycrow 1084
		if ( m_pPackage->filename().empty() )
1 cycrow 1085
		{
1086
			this->SaveAs();
1087
			return;
1088
		}
1089
 
1090
		if ( m_pPackage->GetType() == TYPE_XSP )
1091
			((CXspFile *)m_pPackage)->AdjustCockpits();
1092
 
50 cycrow 1093
		SaveDialog ^save = gcnew SaveDialog(m_pPackage, _US(m_pPackage->filename()));
1 cycrow 1094
		if ( save->ShowDialog(this) == Windows::Forms::DialogResult::Cancel )
1095
			return;
1096
 
1097
		this->UpdateFileList();
50 cycrow 1098
		m_pPackage->adjustChanged(false);
1 cycrow 1099
		this->UpdateChanged();
1100
 
1101
		if ( m_pSettings->bGenerateUpdate )
102 cycrow 1102
			m_pPackage->CreateUpdateFile(CFileIO(m_pPackage->filename()).dir());
1 cycrow 1103
 
50 cycrow 1104
		MessageBox::Show("Package: " + _US(m_pPackage->filename()) + "\nHas been saved!", "Saved", MessageBoxButtons::OK, MessageBoxIcon::Information);
1 cycrow 1105
	}
1106
 
1107
	void PackageForm::SaveAs()
1108
	{
1109
		if ( !this->CheckSave() )
1110
			return;
1111
 
1112
		SaveFileDialog ^ofd = gcnew SaveFileDialog();
1113
		if ( m_pPackage->GetType() == TYPE_XSP )
1114
			ofd->Filter = "Ship Files (*.xsp)|*.xsp";
1115
		else
1116
			ofd->Filter = "Package Files (*.spk)|*.spk";
1117
		ofd->AddExtension = true;
50 cycrow 1118
		CyString filename = m_pPackage->filename();
1 cycrow 1119
		if ( filename.Empty() )
1120
			filename = m_pPackage->GetAutosaveName();
1121
		filename = filename.FindReplace("/", "\\");
1122
		ofd->FileName = SystemStringFromCyString(filename);
1123
		ofd->FilterIndex = 1;
1124
		ofd->RestoreDirectory = true;
1125
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1126
		{
50 cycrow 1127
			m_pPackage->setFilename(_S(ofd->FileName));
1 cycrow 1128
			m_sFilename = ofd->FileName;
50 cycrow 1129
			m_pTabPage->Text = SystemStringFromCyString(CFileIO(m_pPackage->filename()).GetFilename());
1 cycrow 1130
			m_pMenuItem->Text = m_pTabPage->Text;
1131
			this->Save();
1132
		}
1133
	}
1134
 
1135
	System::Void PackageForm::PackageForm_Closing(System::Object^  sender, CancelEventArgs^  e)	{
50 cycrow 1136
		if ( m_pPackage->hasChanged() )
1 cycrow 1137
		{
1138
			String ^name = m_pTabPage->Text;
1139
			if ( name[name->Length - 1] == '*' )
1140
				name = name->Remove(name->Length - 1);
1141
			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);
1142
 
1143
			if ( result == System::Windows::Forms::DialogResult::Cancel )
1144
			{
1145
				e->Cancel = true;
1146
				return;
1147
			}
1148
			else if ( result == System::Windows::Forms::DialogResult::Yes )
1149
			{
1150
				if ( !this->CheckSave() )
1151
				{
1152
					e->Cancel = true;
1153
					return;
1154
				}
1155
 
50 cycrow 1156
				if ( m_pPackage->filename().empty() )
1 cycrow 1157
				{
1158
					SaveFileDialog ^ofd = gcnew SaveFileDialog();
1159
					if ( m_pPackage->GetType() == TYPE_XSP )
1160
						ofd->Filter = "Ship Files (*.xsp)|*.xsp";
1161
					else
1162
						ofd->Filter = "Package Files (*.spk)|*.spk";
1163
					ofd->FilterIndex = 1;
1164
					ofd->RestoreDirectory = true;
1165
					if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
50 cycrow 1166
						m_pPackage->setFilename(_S(ofd->FileName));
1 cycrow 1167
					else
1168
					{
1169
						 e->Cancel = true;
1170
						 return;
1171
					}
1172
				}
1173
 
50 cycrow 1174
				if ( !m_pPackage->WriteFile(m_pPackage->filename()) )
1 cycrow 1175
				{
1176
					e->Cancel = true;
50 cycrow 1177
					MessageBox::Show("Unable to save package\n" + _US(m_pPackage->filename()), "Save Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
1 cycrow 1178
					return;
1179
				}
1180
			}
1181
		}
1182
 
1183
		delete m_pPackage;
1184
		m_pPackage = NULL;
1185
	}
1186
 
1187
	void PackageForm::UpdateMirrors()
1188
	{
1189
		this->ListMirrors->Items->Clear();
1190
		for ( int i = 0; i < m_pPackage->GetMaxWebMirrors(); i++ )
1191
		{
1192
			ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(m_pPackage->GetWebMirror(i)));
1193
			this->ListMirrors->Items->Add(item);
1194
			item->ImageIndex = 1;
1195
		}
1196
 
1197
		this->ListMirrors->AutoResizeColumns(ColumnHeaderAutoResizeStyle::ColumnContent);
1198
		if ( this->ListMirrors->Columns[0]->Width < 100 )
1199
			this->ListMirrors->Columns[0]->Width = 100;
1200
	}
1201
 
1202
	void PackageForm::UpdatePackageNames()
1203
	{
1204
		this->ListNames->Items->Clear();
1205
		for ( SNames *n = m_pPackage->GetNamesList()->First(); n; n = m_pPackage->GetNamesList()->Next() )
1206
		{
1207
			ListViewItem ^item = gcnew ListViewItem(Convert::ToString(n->iLanguage));
1208
			item->SubItems->Add(SystemStringFromCyString(n->sName));
1209
			item->ImageIndex = 0;
1210
			this->ListNames->Items->Add(item);
1211
		}
1212
		this->ListNames->AutoResizeColumns(ColumnHeaderAutoResizeStyle::ColumnContent);
1213
		if ( this->ListNames->Columns[0]->Width < 100 )
1214
			this->ListNames->Columns[0]->Width = 100;
1215
		if ( this->ListNames->Columns[1]->Width < 100 )
1216
			this->ListNames->Columns[1]->Width = 100;
1217
	}
1218
 
1219
	void PackageForm::AddDisplayPic()
1220
	{
1221
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
1222
		ofd->Filter = "Display Images|*.gif;*.png;*.jpg";
1223
		ofd->FilterIndex = 1;
1224
		ofd->RestoreDirectory = true;
1225
		ofd->Multiselect = true;
1226
		ofd->Title = "Select the Display image to add";
1227
 
1228
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1229
		{
1230
			array<System::String ^> ^fileArray = ofd->FileNames;
1231
			for ( int i = 0; i < fileArray->Length; i++ )
1232
			{
1233
				CyString file = CyStringFromSystemString(fileArray[i]);
1234
				m_pDisplayFile = m_pPackage->AddFile(file, "", FILETYPE_ADVERT);
1235
			}
1236
 
1237
			this->UpdateDisplayPic();
1238
			this->UpdateFileList();
1239
		}
1240
	}
1241
 
1242
	void PackageForm::AddDisplayIcon()
1243
	{
1244
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
1245
		ofd->Filter = "Icon Files|*.ico;*.png;*.bmp";
1246
		ofd->FilterIndex = 1;
1247
		ofd->RestoreDirectory = true;
1248
		ofd->Multiselect = false;
1249
		ofd->Title = "Select the Icon file to add";
1250
 
1251
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1252
		{
1253
			CyString file = CyStringFromSystemString(ofd->FileName);
1254
			C_File *icon = new C_File(file);
1255
			if ( icon->ReadFromFile() )
1256
				m_pPackage->SetIcon(icon, CFileIO(file).GetFileExtension());
1257
 
1258
			this->UpdateDisplayIcon();
1259
			this->UpdateChanged();
1260
		}
1261
	}
1262
 
1263
	void PackageForm::SaveText()
1264
	{
1265
		if ( this->TextText->Text->Length )
1266
		{
1267
			if ( this->ListLang->SelectedIndex >= 0 )
1268
			{
1269
				int lang = CyStringFromSystemString(this->ListLang->Text).ToInt();
46 cycrow 1270
				if ( this->RadioInstallAfter->Checked )			m_pPackage->addInstallText(lang, false, _S(this->TextText->Text));
1271
				else if ( this->RadioInstallBefore->Checked )	m_pPackage->addInstallText(lang, true, _S(this->TextText->Text));
1272
				else if ( this->RadioUninstallBefore->Checked )	m_pPackage->addUninstallText(lang, true, _S(this->TextText->Text));
1273
				else if ( this->RadioUninstallAfter->Checked )	m_pPackage->addUninstallText(lang, false, _S(this->TextText->Text));
1 cycrow 1274
				this->UpdateChanged();
1275
			}
1276
		}
1277
	}
1278
 
1279
	void PackageForm::LoadShipData()
1280
	{
1281
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
1282
		ofd->Filter = "All (*.cat, tships)|*.cat;tships.txt;tships.pck|TShips Files (tships.txt/pck)|tships.txt;tships.pck|Mod Files (*.cat)|*.cat";
1283
		ofd->FilterIndex = 1;
1284
		ofd->RestoreDirectory = true;
1285
		ofd->Multiselect = false;
1286
		ofd->Title = "Select the TShips/Mod file to load ship data from";
1287
 
1288
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1289
		{
1290
			// if its a cat file, lets load the text
1291
			Hashtable ^catText = gcnew Hashtable();
1292
 
1293
			if ( String::Compare(IO::FileInfo(ofd->FileName).Extension, ".cat") == 0 )
1294
			{
1295
				CyStringList readText;
1296
				if ( m_pP->ReadTextPage(CyStringFromSystemString(ofd->FileName), &readText, false, 17) )
1297
				{
1298
					for ( SStringList *str = readText.Head(); str; str = str->next )
1299
					{
1300
						String ^key = SystemStringFromCyString(str->str);
1301
						if ( catText->ContainsKey(key) )
1302
							catText[key] = SystemStringFromCyString(str->data);
1303
						else
1304
							catText->Add(key, SystemStringFromCyString(str->data));
1305
					}
1306
				}
1307
			}
1308
 
1309
			CyStringList list;
1310
			if ( m_pP->LoadShipData(CyStringFromSystemString(ofd->FileName), &list) )
1311
			{
1312
				LoadShip ^ls = gcnew LoadShip();
1313
				for ( SStringList *str = list.Head(); str; str = str->next )
1314
				{
1315
					int tId = str->data.GetToken(";", 7, 7).ToInt();
1316
					String ^name;
1317
					if ( catText->ContainsKey(Convert::ToString(tId)) )
1318
						name = Convert::ToString(catText[Convert::ToString(tId)]);
1319
					else
1320
						name = ((Form1 ^)this->MdiParent)->FindText(-1, 17, tId);
1321
					String ^text = ((Form1 ^)this->MdiParent)->FindText(-1, 1266, str->data.GetToken(";", 46, 46).ToInt()) + " " + name;
1322
					int variation = str->data.GetToken(";", 51, 51).ToInt();
1323
					if ( variation )
1324
						text = text + " " + ((Form1 ^)this->MdiParent)->FindText(-1, 17, 10000 + variation);
1325
					ls->AddShip(SystemStringFromCyString(str->str), text);
1326
				}
1327
 
1328
				if ( ls->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1329
				{
1330
					SStringList *str = list.FindString(CyStringFromSystemString(ls->GetData()));
1331
					if ( str )
1332
					{
14 cycrow 1333
						((CXspFile *)m_pPackage)->SetShipData(str->data.ToString());
1334
						if ( ((CXspFile *)m_pPackage)->GetShipID().empty() )
1 cycrow 1335
						{
1336
							CyString id = str->data.GetToken(";", -2);
1337
							while ( id.Right(1) == ";" )
1338
								id.Truncate((int)id.Length() - 1);
14 cycrow 1339
							((CXspFile *)m_pPackage)->SetShipID(id.ToString());
1 cycrow 1340
							this->TextShipID->Text = SystemStringFromCyString(id);
1341
						}
1342
 
14 cycrow 1343
						((CXspFile *)m_pPackage)->SetShipData(str->data.ToString());
1 cycrow 1344
						this->TextShipData->Text = SystemStringFromCyString(str->data);
1345
						this->NumTextID->Value = str->data.GetToken(";", 7, 7).ToInt();
1346
						this->UpdateChanged();
1347
					}
1348
				}
1349
			}
1350
			else
1351
				MessageBox::Show(this, "Unable to find any ship entries, invalid/missing TShips?", "Error Loading", MessageBoxButtons::OK, MessageBoxIcon::Error);
1352
		}
1353
	}
1354
 
1355
	void PackageForm::EditShipParts(bool edit)
1356
	{
1357
		 CXspFile *xsp = (CXspFile *)m_pPackage;
1358
		 switch ( this->ComboShipPart->SelectedIndex )
1359
		 {
1360
			case 0:
1361
				{
1362
					AddShipPart ^component = gcnew AddShipPart((Form1 ^)this->MdiParent);
1363
					component->SetComponent(edit);
1364
 
1365
					if ( edit )
1366
					{
1367
						component->SetSection(m_pSelectedItem->Text);
1368
						component->SetSection2(m_pSelectedItem->SubItems[1]->Text);
1369
						component->SetData(m_pSelectedItem->SubItems[2]->Text);
1370
					}
1371
 
1372
					if ( component->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1373
					{
1374
						if ( edit )
39 cycrow 1375
							xsp->RemoveComponent(_S(m_pSelectedItem->Text), _S(m_pSelectedItem->SubItems[1]->Text), _S(m_pSelectedItem->SubItems[2]->Text));
1376
						xsp->AddComponent(_S(component->GetSection()), _S(component->GetSection2()), _S(component->GetData()));
1 cycrow 1377
						if ( !edit )
1378
							this->UpdateShipPartList();
1379
						else
1380
						{
1381
							m_pSelectedItem->Text = component->GetSection();
1382
							m_pSelectedItem->SubItems[1]->Text = component->GetSection2();
1383
							m_pSelectedItem->SubItems[2]->Text = component->GetData();
1384
						}
1385
					}
1386
				}
1387
				break;
1388
			case 1:
1389
				{
1390
					AddShipPart ^dummy = gcnew AddShipPart((Form1 ^)this->MdiParent);
1391
					dummy->SetDummy(edit);
1392
 
1393
					if ( edit )
1394
					{
1395
						dummy->SetSection(m_pSelectedItem->Text);
1396
						dummy->SetData(m_pSelectedItem->SubItems[1]->Text);
1397
					}
1398
 
1399
					if ( dummy->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1400
					{
1401
						if ( edit )
39 cycrow 1402
							xsp->RemoveDummy(_S(m_pSelectedItem->Text), _S(m_pSelectedItem->SubItems[1]->Text));
1403
						xsp->AddDummy(_S(dummy->GetSection()), _S(dummy->GetData()));
1 cycrow 1404
						if ( !edit )
1405
							this->UpdateShipPartList();
1406
						else
1407
						{
1408
							m_pSelectedItem->Text = dummy->GetSection();
1409
							m_pSelectedItem->SubItems[1]->Text = dummy->GetData();
1410
						}
1411
					}
1412
				}
1413
				break;
1414
 
1415
			case 2:
1416
				{
1417
					AddCockpit ^cockpit = gcnew AddCockpit();
1418
					if ( edit )
1419
						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());
1420
					if ( cockpit->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1421
					{
1422
						if ( !edit )
1423
						{
39 cycrow 1424
							xsp->NewCockpit(_S(cockpit->GetID()), _S(cockpit->GetScene()), cockpit->GetMask());
1 cycrow 1425
							this->UpdateShipPartList();
1426
						}
1427
						else
1428
						{
39 cycrow 1429
							xsp->EditCockpit(_S(cockpit->GetID()), _S(cockpit->GetScene()), cockpit->GetMask());
1430
							m_pSelectedItem->SubItems[2]->Text = SystemStringFromCyString(xsp->GetCockpitData(_S(cockpit->GetID())));
1 cycrow 1431
						}
1432
					}
1433
				}
1434
				break;
1435
 
1436
			case 3:
1437
				{
1438
					if ( edit )
1439
					{
1440
						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)));
1441
						if ( input2->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1442
						{
39 cycrow 1443
							xsp->RemoveCutData(_S(m_pSelectedItem->Text));
1444
							xsp->AddCutData(_S(SystemStringFromCyString(CyStringFromSystemString(m_pSelectedItem->Text).GetToken(";", 1, 1)) + "; " + input2->GetInput()));
1 cycrow 1445
							this->UpdateShipPartList();
1446
						}
1447
					}
1448
					else
1449
					{
1450
						InputBox ^input = gcnew InputBox("Enter the cut id to add");
1451
						if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1452
						{
1453
							InputBox ^input2 = gcnew InputBox("Enter the filename for cut id: " + input->GetInput());
1454
							if ( input2->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1455
							{
39 cycrow 1456
								xsp->AddCutData(_S(input->GetInput() + "; " + input2->GetInput()));
1 cycrow 1457
								this->UpdateShipPartList();
1458
							}
1459
						}
1460
					}
1461
				}
1462
				break;
1463
 
1464
			case 4:
1465
				{
1466
					AddShipPart ^dummy = gcnew AddShipPart((Form1 ^)this->MdiParent);
1467
					dummy->SetBodies(edit);
1468
 
1469
					if ( edit )
1470
					{
1471
						dummy->SetSection(m_pSelectedItem->Text);
1472
						dummy->SetData(m_pSelectedItem->SubItems[1]->Text);
1473
					}
1474
 
1475
					if ( dummy->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1476
					{
1477
						if ( edit )
39 cycrow 1478
							xsp->RemoveBodies(_S(m_pSelectedItem->Text + ";" + m_pSelectedItem->SubItems[1]->Text));
1479
						xsp->AddBodies(_S(dummy->GetSection() + ";" + dummy->GetData()));
1 cycrow 1480
						if ( !edit )
1481
							this->UpdateShipPartList();
1482
						else
1483
						{
1484
							m_pSelectedItem->Text = dummy->GetSection();
1485
							m_pSelectedItem->SubItems[1]->Text = dummy->GetData();
1486
						}
1487
					}
1488
				}
1489
				break;
1490
 
1491
			case 5:
1492
				{
1493
					InputBox ^input = gcnew InputBox("Enter the animation data to add", (!edit) ? "" : m_pSelectedItem->Text);
1494
					input->Large();
1495
					if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1496
					{
1497
						if ( edit )
39 cycrow 1498
							xsp->RemoveAnimation(_S(m_pSelectedItem->Text));
1499
						xsp->AddAnimation(_S(input->GetInput()));
1 cycrow 1500
						this->UpdateShipPartList();
1501
					}
1502
				}
1503
				break;
1504
		 }
1505
	}
1506
 
1507
	void PackageForm::DropGetDirectories(String ^dir, CyStringList *list, bool packages)
1508
	{
1509
		cli::array<String ^> ^dirList = IO::Directory::GetFileSystemEntries(dir);
1510
		for ( int j = 0; j < dirList->Length; j++ )
1511
		{
1512
			if ( IO::DirectoryInfo(dirList[j]).Exists )
1513
				this->DropGetDirectories(dirList[j], list, packages);
1514
			else
1515
			{
1516
				if ( packages )
1517
					list->PushBack(CyStringFromSystemString(dirList[j]), "-1");
1518
				else
18 cycrow 1519
					list->PushBack(CyStringFromSystemString(dirList[j]), CyString::Number(SPK::GetAutomaticFiletype(CyStringFromSystemString(dirList[j]), NULL,false)));
1 cycrow 1520
			}
1521
		}
1522
	}
1523
 
1524
	void PackageForm::RemoveSelectedFiles()
1525
	{
1526
		CLinkList<C_File> removeFiles;
1527
		for ( int i = 0; i < ListFiles->SelectedItems->Count; i++ )
1528
		{
1529
			int id = CyStringFromSystemString(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).ToInt();
1530
			C_File *file = m_pPackage->GetFileList()->Get(id);
1531
			if ( m_pDisplayFile == file )
1532
				m_pDisplayFile = NULL;
1533
			removeFiles.push_back(file);
1534
		}
1535
 
1536
		if ( removeFiles.size() )
1537
		{
1538
			for ( C_File *f = removeFiles.First(); f; f = removeFiles.Next() )
1539
				m_pPackage->RemoveFile(f);
1540
			m_pPackage->UpdateSigned(false);
1541
			this->UpdateFileList();
1542
			this->UpdateDisplayPic();
1543
			this->UpdateChanged();
1544
		}
1545
 
1546
		if ( !ListFiles->SelectedItems->Count )
1547
			this->ButRemoveFile->Enabled = false;
1548
	}
1549
 
1550
	String ^PackageForm::ExtractImport(String ^file, String ^type)
1551
	{
1552
		if ( String::Compare(IO::FileInfo(file).Extension, ".xml") == 0 )
1553
			return file;
1554
 
1555
		if ( String::Compare(IO::FileInfo(file).Extension, ".pck") == 0 )
1556
		{
1557
			C_File F(CyStringFromSystemString(file));
1558
			F.UnPCKFile();
79 cycrow 1559
			if ( F.WriteToFile(CPackages::tempDirectory() + "tmp.dat") )
1560
				return _US(CPackages::tempDirectory() + "tmp.dat");
1 cycrow 1561
		}
1562
		else if ( String::Compare(IO::FileInfo(file).Extension, ".cat") == 0 )
1563
		{
1564
			CCatFile cat;
125 cycrow 1565
			if ( cat.open(_S(file), "", CATREAD_CATDECRYPT, false) == CATERR_NONE )
1 cycrow 1566
			{
79 cycrow 1567
				if ( cat.ExtractFile(CyStringFromSystemString("types\\" + type + ".pck"), CPackages::GetTempDirectory() + "tmp.dat") )
1568
					return _US(CPackages::tempDirectory() + "tmp.dat");
1 cycrow 1569
			}
1570
		}
1571
 
1572
		return "";
1573
	}
1574
 
94 cycrow 1575
	CGameDirectories *PackageForm::gameDirectories()
1 cycrow 1576
	{
94 cycrow 1577
		return ((Form1 ^)this->MdiParent)->gameDirectories();
1 cycrow 1578
	}
1579
 
1580
	void PackageForm::ImportData(String ^file, int type)
1581
	{
1582
		CFileIO F(CyStringFromSystemString(file));
52 cycrow 1583
		if ( !F.exists() )
1 cycrow 1584
			return;
1585
 
1586
		CyStringList *lines = F.ReadLinesStr();
1587
		if ( !lines )
1588
			return;
1589
 
1590
		LoadShip ^load = gcnew LoadShip();
1591
 
1592
		int entryPos = 1;
1593
		int dataPos = 1;
1594
		int dataPos2 = 0;
1595
		bool sections = false;
1596
		CyString section;
1597
		switch ( type )
1598
		{
1599
			case 2:
1600
				entryPos = 2;
1601
				dataPos = 19;
1602
				load->Cockpits();
1603
				break;
1604
			case 3:
1605
				dataPos2 = 2;
1606
				load->CutData();
1607
				break;
1608
			case 4:
1609
				sections = true;
1610
				entryPos = 2;
1611
				load->Bodies();
1612
				break;
1613
			case 1:
1614
				sections = true;
1615
				entryPos = 2;
1616
				dataPos = -1;
1617
				load->Dummies();
1618
				break;
1619
			case 0:
1620
				sections = true;
1621
				entryPos = 2;
1622
				dataPos = -1;
1623
				load->Components();
1624
				break;
1625
		}
1626
 
1627
		int entries2 = 0;
1628
		int entries = -1;
1629
		CyStringList list;
1630
		CyString data;
1631
		int e = 0;
1632
		for ( SStringList *str = lines->Head(); str; str = str->next )
1633
		{
1634
			str->str.RemoveChar(9);
1635
			str->str.RemoveChar('\r');
1636
			str->str.RemoveFirstSpace();
1637
			if ( str->str.Empty() )
1638
				continue;
1639
			if ( str->str[0] == '/' )
1640
				continue;
1641
 
1642
			if ( entries == -1 || (entries <= 0 && sections) )
1643
			{
1644
				entries = str->str.GetToken(";", entryPos, entryPos).ToInt();
1645
				if ( sections )
1646
				{
1647
					section = str->str.GetToken(";", 1, 1);
1648
					load->AddGroup(SystemStringFromCyString(section));
1649
				}
1650
			}
1651
			else
1652
			{
1653
				if ( type == 4 )
1654
				{
1655
					int max;
1656
					CyString *strs = str->str.SplitToken(";", &max);
1657
					if ( max && strs )
1658
					{
1659
						for ( int i = 0; i < max; i++ )
1660
						{
1661
							strs[i].RemoveFirstSpace();
1662
							if ( strs[i].Empty() ) continue;
1663
							CyString id = strs[i].GetToken(";", dataPos, dataPos);
1664
							load->AddShip(SystemStringFromCyString(id), "");
1665
							list.PushBack(id, CyString::Number(e) + " " + section + ";" + strs[i]);
1666
							++e;
1667
							--entries;
1668
						}
1669
					}
1670
 
1671
					CLEANSPLIT(strs, max)
1672
				}
1673
				else if ( type == 0 )
1674
				{
1675
					if ( entries2 )
1676
					{
1677
						load->AddShip(SystemStringFromCyString(data), SystemStringFromCyString(str->str));
1678
						list.PushBack(data, section + ";" + data + ";" + str->str);
1679
						--entries2;
1680
					}
1681
					else
1682
					{
1683
						data = str->str.GetToken(";", 1, 1);
1684
						entries2 = str->str.GetToken(";", 2, 2).ToInt();
1685
						++e;
1686
						--entries;
1687
					}
1688
				}
1689
				else
1690
				{
1691
					CyString id;
1692
					if ( dataPos == -1 )
1693
						id = str->str; 
1694
					else
1695
						id = str->str.GetToken(";", dataPos, dataPos); 
1696
 
1697
					if ( dataPos2 )
1698
						load->AddShip(SystemStringFromCyString(id), SystemStringFromCyString(str->str.GetToken(";", dataPos2, dataPos2)));
1699
					else
1700
						load->AddShip(SystemStringFromCyString(id), "");
1701
					if ( sections )
1702
						list.PushBack(id, CyString::Number(e) + " " + section + ";" + str->str);
1703
					else
1704
						list.PushBack(id, CyString::Number(e) + " " + str->str);
1705
					++e;
1706
					--entries;
1707
				}
1708
			}
1709
		}
1710
 
1711
		if ( load->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1712
		{
1713
			for ( SStringList *str = load->GetDataList()->Head(); str; str = str->next )
1714
			{
1715
				SStringList *s = list.FindString(str->str);
1716
				if ( s )
1717
				{
1718
					switch ( type )
1719
					{
1720
						case 0:
39 cycrow 1721
							((CXspFile *)m_pPackage)->AddComponent(s->data.GetToken(";", 1, 1).ToString(), s->data.GetToken(";", 2, 2).ToString(), s->data.GetToken(";", 3).ToString());
1 cycrow 1722
							break;
1723
						case 2:
39 cycrow 1724
							((CXspFile *)m_pPackage)->AddCockpit(s->data.GetToken(" ", 2).ToString(), 0, -1, s->data.GetToken(" ", 1, 1).ToInt());
1 cycrow 1725
							break;
1726
						case 3:
39 cycrow 1727
							((CXspFile *)m_pPackage)->AddCutData(s->data.GetToken(" ", 2).ToString());
1 cycrow 1728
							break;
1729
						case 4:
39 cycrow 1730
							((CXspFile *)m_pPackage)->AddBodies(s->data.GetToken(" ", 2).ToString());
1 cycrow 1731
							break;
1732
						case 1:
39 cycrow 1733
							((CXspFile *)m_pPackage)->AddDummy(s->data.GetToken(" ", 2).GetToken(";", 1, 1).ToString(), s->data.GetToken(" ", 2).GetToken(";", 2).ToString());
1 cycrow 1734
							break;
1735
					}
1736
				}
1737
			}
1738
 
1739
			this->UpdateShipPartList();
1740
			this->UpdateChanged();
1741
		}
1742
 
1743
		delete lines;
1744
	}
1745
 
1746
	void PackageForm::ImportAnimations(String ^file)
1747
	{
1748
		CFileIO F(CyStringFromSystemString(file));
52 cycrow 1749
		if ( !F.exists() )
1 cycrow 1750
			return;
1751
 
1752
		CyStringList *lines = F.ReadLinesStr();
1753
		if ( !lines )
1754
			return;
1755
 
1756
 
1757
		CyStringList lOut;
1758
		if ( CXspFile::ReadAnimations(lines, &lOut, 0) )
1759
		{
1760
			LoadShip ^load = gcnew LoadShip();
1761
			load->Animations();
1762
			for ( SStringList *str = lOut.Head(); str; str = str->next )
1763
			{
1764
				load->AddShip(SystemStringFromCyString(str->str), "");
1765
			}
1766
 
1767
			if ( load->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1768
			{
1769
				((CXspFile *)m_pPackage)->AddAnimation(load->GetDataList());
1770
				this->UpdateShipPartList();
1771
				this->UpdateChanged();
1772
			}
1773
		}
1774
 
1775
		delete lines;
1776
	}
1777
 
1778
	void PackageForm::EditDepend()
1779
	{
1780
		 AddDepend ^depend = gcnew AddDepend();
1781
		 depend->SetEdit(m_pSelectedItem->Text, m_pSelectedItem->SubItems[1]->Text, m_pSelectedItem->SubItems[2]->Text);
1782
 
1783
		 bool builtin = false;
1784
		 if ( String::Compare("<package>", m_pSelectedItem->Text) == 0 && String::Compare("<author>", m_pSelectedItem->SubItems[1]->Text) == 0 )
1785
		 {
1786
			 builtin = true;
1787
			 depend->BuiltIn();
1788
		 }
1789
 
1790
		 if ( depend->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1791
		 {
1792
			 if ( builtin )
1793
			 {
1794
				 SNeededLibrary *ns = m_pPackage->FindPackageNeeded("<package>", "<author>");
1795
				 if ( ns )
46 cycrow 1796
					 ns->sMinVersion = _S(depend->GetVersion());
1 cycrow 1797
			 }
1798
			 else
1799
			 {
46 cycrow 1800
				 m_pPackage->RemovePackageNeeded(_S(m_pSelectedItem->Text), _S(m_pSelectedItem->SubItems[1]->Text));
1801
				 m_pPackage->AddNeededLibrary(_S(depend->GetName()), _S(depend->GetAuthor()), _S(depend->GetVersion()));
1 cycrow 1802
			 }
1803
			 this->UpdateDependacies();
1804
			 this->UpdateChanged();
1805
		 }
1806
	}
1807
}