Subversion Repositories spk

Rev

Rev 125 | Rev 127 | 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);
126 cycrow 807
				if (i < this->imageListGames->Images->Count)
808
					newItem->Image = this->imageListGames->Images[i];
1 cycrow 809
				newItem->Click += gcnew System::EventHandler(this, &PackageForm::ContextGame_Selected);
810
				this->ContextGames->Items->Add(newItem);
811
 
812
				System::Windows::Forms::ToolStripMenuItem ^newItem2 = gcnew System::Windows::Forms::ToolStripMenuItem;
813
				newItem2->Text = SystemStringFromCyString(gameExe->sName);
814
				newItem2->Tag = Convert::ToString(i + 1);
126 cycrow 815
				if (i < this->imageListGames->Images->Count)
816
					newItem2->Image = this->imageListGames->Images[i];
1 cycrow 817
				newItem2->Click += gcnew System::EventHandler(this, &PackageForm::SetGame_Selected);
818
				this->ToolGame->DropDownItems->Add(newItem2);
819
 
820
				this->ComboGameFilter->Items->Add(SystemStringFromCyString(gameExe->sName));
821
			}
822
		}
823
 
824
		this->ComboGameFilter->SelectedIndex = 0;
825
 
826
		this->ButGame->Text = "- Select Game -";
827
		this->ButGameAdd->Enabled = false;
828
 
829
		m_pTypeList->Clear();
6 cycrow 830
		for ( int i = 0; i < CSpkFile::SCRIPTTYPE_MAX; i++ )
1 cycrow 831
		{
10 cycrow 832
			m_pTypeList->PushBack(CSpkFile::GetScriptTypeStringStatic(i).c_str());
1 cycrow 833
			ComboType->Items->Add(SystemStringFromCyString(CSpkFile::GetScriptTypeStringStatic(i)));
834
		}
835
 
836
		this->CreationDate->Value = DateTime::Today;
837
 
838
		m_bLoading = false;
839
	}
840
 
841
	void PackageForm::UpdateGamesList()
842
	{
843
		this->ListGames->Items->Clear();
844
		for ( SGameCompat *game = m_pPackage->GetGameCompatabilityList()->First(); game; game = m_pPackage->GetGameCompatabilityList()->Next() ) {
845
			ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(m_pP->GetGameNameFromType(game->iGame)));
846
			item->ImageIndex = (game->iGame < 0) ? -1 : (game->iGame - 1);
46 cycrow 847
			if ( !game->sVersion.empty() ) {
1 cycrow 848
				item->SubItems->Add("Exact: " + SystemStringFromCyString(game->sVersion));
849
			}
850
			else {
851
				item->SubItems->Add(SystemStringFromCyString(m_pP->GetGameVersionFromType(game->iGame, game->iVersion, game->sVersion)));
852
			}
853
			item->Tag = game->iGame;
854
			this->ListGames->Items->Add(item);
855
		}
856
 
857
		this->ListGames->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
858
	}
859
 
860
	void PackageForm::UpdateFileList()
861
	{
862
		this->ButRemoveFile->Enabled = false;
863
 
864
		int pos = 0;
865
		this->ListFiles->Items->Clear();
866
		if ( m_pPackage ) {
867
			for ( C_File *file = m_pPackage->GetFileList()->First(); file; file = m_pPackage->GetFileList()->Next() )
868
			{
869
				file->SetPos(pos++);
870
				if ( this->ComboGameFilter->SelectedIndex > 0 ) {
871
					if ( this->ComboGameFilter->SelectedIndex - 1 != file->GetGame() )
872
						continue;
873
				}
874
				if ( this->ComboFileType->SelectedIndex == 0 || (this->ComboFileType->SelectedIndex - 1) == file->GetFileType() )
875
					this->AddFile(file);
876
			}
877
			((Form1 ^)this->MdiParent)->UpdateStatus();
878
		}
879
 
880
		this->ListFiles->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
881
	}
882
 
883
	void PackageForm::AddFile(C_File *file)
884
	{
885
		ListViewItem ^item = gcnew ListViewItem("");
886
 
887
		if ( file->GetData() )
888
		{
889
			item->SubItems->Add(SystemStringFromCyString(CyString("<PACKAGE>/") + file->GetNameDirectory(NULL)));
890
			item->SubItems->Add(SystemStringFromCyString(file->GetUncompressedSizeString()));
891
		}
892
		else
893
		{
894
			item->SubItems->Add(SystemStringFromCyString(file->GetFullFilename()));
895
			item->SubItems->Add(SystemStringFromCyString(SPK::GetSizeString(file->GetSize())));
896
		}
897
 
898
		if ( file->IsFakePatch() )
899
			item->SubItems->Add("Mod (Fakepatch)");
900
		else
901
			item->SubItems->Add(SystemStringFromCyString(file->GetFileTypeString()));
902
 
903
		if ( !file->GetDir().Empty() )
904
			item->SubItems->Add(SystemStringFromCyString(file->GetDir()));
905
		else
906
			item->SubItems->Add("");
907
 
908
		if ( file->IsSigned() )
909
			item->SubItems->Add("Yes");
910
		else
911
			item->SubItems->Add("No");
912
 
913
		if ( !file->GetGame() )
914
			item->SubItems->Add("All Games");
915
		else {
916
			CPackages p;
917
			p.Startup(".", ".", ".");
918
			SGameExe *exe = p.GetGameExe()->GetGame(file->GetGame() - 1);
919
			if ( exe ) {
920
				item->SubItems->Add(SystemStringFromCyString(exe->sName));
921
			}
922
			else {
923
				item->SubItems->Add("Game: " + file->GetGame());
924
			}
925
		}
926
 
927
		item->Tag = SystemStringFromCyString(CyString::Number(file->GetPos()));
928
		if ( file->IsFakePatch() )
929
			item->ImageKey = "fakepatch";
930
		else
931
			item->ImageIndex = file->GetFileType();
932
 
933
		item->Checked = file->IsShared();
934
 
935
		this->ListFiles->Items->Add(item);
936
	}
937
 
938
	void PackageForm::AddNewFile()
939
	{
940
		// add filters
941
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
942
 
943
		System::String ^filter;
944
		for ( int i = 0; i < FILETYPE_MAX; i++ )
945
		{
946
			if ( filter )
947
				filter += "|";
948
			filter += SystemStringFromCyString(GetFileTypeString(i));
949
			filter += "|";
950
			// add extensions
951
			switch ( i )
952
			{
953
				case FILETYPE_SCRIPT:
954
				case FILETYPE_UNINSTALL:
955
				case FILETYPE_MAP:
956
				case FILETYPE_TEXT:
957
				case FILETYPE_MISSION:
958
					filter += "*.pck;*.xml";
959
					break;
960
 
961
				case FILETYPE_README:
962
					filter += "*.txt;*.doc;*.docx;*.pdf";
963
					break;
964
 
965
				case FILETYPE_MOD:
966
					filter += "*.cat";
967
					break;
968
 
969
				case FILETYPE_SOUND:
970
					filter += "*.wav";
971
					break;
972
 
973
				case FILETYPE_SCREEN:
974
				case FILETYPE_ADVERT:
975
					filter += "*.jpg;*.png";
976
					break;
977
 
978
				case FILETYPE_SHIPSCENE:
979
				case FILETYPE_COCKPITSCENE:
980
					filter += "*.pbd;*.bod";
981
					break;
982
 
983
				case FILETYPE_SHIPMODEL:
984
					filter += "*.pbd;*.bod;*.bob;*.pbb";
985
					break;
986
 
987
				default:
988
					filter += "*.*";
989
			}
990
		}
991
		ofd->Filter = filter;
992
		ofd->FilterIndex = 1;
993
		ofd->RestoreDirectory = true;
994
		ofd->Multiselect = true;
995
		ofd->Title = "Select File(s) to add to package";
996
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
997
		{
998
			CyString dir;
999
			if ( C_File::DoesTypeHaveExtraDir(ofd->FilterIndex - 1) )
1000
			{
1001
				InputBox ^input = gcnew InputBox("Enter the directory to add files to", ((ofd->FilterIndex - 1) == FILETYPE_EXTRA) ? "PluginManager/Extras/$scriptname" : "");
1002
				if ( input->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1003
					dir = CyStringFromSystemString(input->GetInput());
1004
			}
1005
			array<System::String ^> ^fileArray = ofd->FileNames;
1006
			for ( int i = 0; i < fileArray->Length; i++ )
1007
			{
1008
				System::String ^file = fileArray[i];
1009
				int filetype = m_pP->AdjustFileType(CyStringFromSystemString(file), ofd->FilterIndex - 1);
1010
				C_File *f = m_pPackage->AddFile(CyStringFromSystemString(file), dir, filetype);
1011
				if ( (ofd->FilterIndex - 1) == FILETYPE_MOD )
1012
					m_pPackage->AddFile(CFileIO(CyStringFromSystemString(file)).ChangeFileExtension("dat"), dir, filetype);
1013
			}
1014
			m_pPackage->UpdateSigned(false);
1015
			this->UpdateFileList();
1016
			this->UpdateDisplayPic();
1017
			this->UpdateChanged();
1018
		}
1019
	}
1020
 
1021
	bool PackageForm::CheckSave()
1022
	{
50 cycrow 1023
		if ( m_pPackage->name().empty() )
1 cycrow 1024
		{
1025
			MessageBox::Show(this, "You must specify a package name", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1026
			return false;
1027
		}
50 cycrow 1028
		if ( m_pPackage->author().empty() )
1 cycrow 1029
		{
1030
			MessageBox::Show(this, "You must specify an Author", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1031
			return false;
1032
		}
50 cycrow 1033
		if ( m_pPackage->version().empty() )
1 cycrow 1034
		{
1035
			MessageBox::Show(this, "You must specify a version number", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1036
			return false;
1037
		}
1038
 
1039
		if ( m_pPackage->GetType() == TYPE_SPK )
1040
		{
1041
			if ( ((CSpkFile *)m_pPackage)->IsPackageUpdate() )
1042
			{
1043
				SNeededLibrary *n = m_pPackage->FindPackageNeeded("<package>", "<author>");
1044
				if ( !n )
1045
					m_pPackage->AddNeededLibrary("<package>", "<author>", "1.00");
1046
				n = m_pPackage->FindPackageNeeded("<package>", "<author>");
1047
 
1048
				if ( n )
1049
				{
50 cycrow 1050
					if ( ((CSpkFile *)m_pPackage)->version().compareVersion(n->sMinVersion) != COMPARE_OLDER )
1 cycrow 1051
					{
50 cycrow 1052
						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 1053
						return false;
1054
					}
1055
				}
1056
			}
1057
			else if ( ((CSpkFile *)m_pPackage)->IsCustomStart() )
1058
			{
1059
				if ( !((CSpkFile *)m_pPackage)->CheckValidCustomStart() )
1060
				{
1061
					MessageBox::Show(this, "For a custom start, you must include an initplayer script", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1062
					return false;
1063
				}
1064
			}
1065
			else if ( ((CSpkFile *)m_pPackage)->IsPatch() )
1066
			{
10 cycrow 1067
				if ( ((CSpkFile *)m_pPackage)->GetOtherAuthor().empty() || ((CSpkFile *)m_pPackage)->GetOtherName().empty() )
1 cycrow 1068
				{
1069
					MessageBox::Show(this, "For a mod patch, you must specify the parent mod that this will be patching\nEnter the parent mod name and author", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
1070
					return false;
1071
				}
1072
			}
1073
		}
1074
 
1075
		 System::DateTime ^time = DateTime(this->CreationDate->Value);
50 cycrow 1076
		 m_pPackage->setCreationDate(_S(System::Convert::ToString(time->Day) + "/" + System::Convert::ToString(time->Month) + "/" + System::Convert::ToString(time->Year)));
1 cycrow 1077
 
1078
		return true;
1079
	}
1080
 
1081
	void PackageForm::Save()
1082
	{
1083
		if ( !this->CheckSave() )
1084
			return;
1085
 
50 cycrow 1086
		if ( m_pPackage->filename().empty() )
1 cycrow 1087
		{
1088
			this->SaveAs();
1089
			return;
1090
		}
1091
 
1092
		if ( m_pPackage->GetType() == TYPE_XSP )
1093
			((CXspFile *)m_pPackage)->AdjustCockpits();
1094
 
50 cycrow 1095
		SaveDialog ^save = gcnew SaveDialog(m_pPackage, _US(m_pPackage->filename()));
1 cycrow 1096
		if ( save->ShowDialog(this) == Windows::Forms::DialogResult::Cancel )
1097
			return;
1098
 
1099
		this->UpdateFileList();
50 cycrow 1100
		m_pPackage->adjustChanged(false);
1 cycrow 1101
		this->UpdateChanged();
1102
 
1103
		if ( m_pSettings->bGenerateUpdate )
102 cycrow 1104
			m_pPackage->CreateUpdateFile(CFileIO(m_pPackage->filename()).dir());
1 cycrow 1105
 
50 cycrow 1106
		MessageBox::Show("Package: " + _US(m_pPackage->filename()) + "\nHas been saved!", "Saved", MessageBoxButtons::OK, MessageBoxIcon::Information);
1 cycrow 1107
	}
1108
 
1109
	void PackageForm::SaveAs()
1110
	{
1111
		if ( !this->CheckSave() )
1112
			return;
1113
 
1114
		SaveFileDialog ^ofd = gcnew SaveFileDialog();
1115
		if ( m_pPackage->GetType() == TYPE_XSP )
1116
			ofd->Filter = "Ship Files (*.xsp)|*.xsp";
1117
		else
1118
			ofd->Filter = "Package Files (*.spk)|*.spk";
1119
		ofd->AddExtension = true;
50 cycrow 1120
		CyString filename = m_pPackage->filename();
1 cycrow 1121
		if ( filename.Empty() )
1122
			filename = m_pPackage->GetAutosaveName();
1123
		filename = filename.FindReplace("/", "\\");
1124
		ofd->FileName = SystemStringFromCyString(filename);
1125
		ofd->FilterIndex = 1;
1126
		ofd->RestoreDirectory = true;
1127
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1128
		{
50 cycrow 1129
			m_pPackage->setFilename(_S(ofd->FileName));
1 cycrow 1130
			m_sFilename = ofd->FileName;
50 cycrow 1131
			m_pTabPage->Text = SystemStringFromCyString(CFileIO(m_pPackage->filename()).GetFilename());
1 cycrow 1132
			m_pMenuItem->Text = m_pTabPage->Text;
1133
			this->Save();
1134
		}
1135
	}
1136
 
1137
	System::Void PackageForm::PackageForm_Closing(System::Object^  sender, CancelEventArgs^  e)	{
50 cycrow 1138
		if ( m_pPackage->hasChanged() )
1 cycrow 1139
		{
1140
			String ^name = m_pTabPage->Text;
1141
			if ( name[name->Length - 1] == '*' )
1142
				name = name->Remove(name->Length - 1);
1143
			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);
1144
 
1145
			if ( result == System::Windows::Forms::DialogResult::Cancel )
1146
			{
1147
				e->Cancel = true;
1148
				return;
1149
			}
1150
			else if ( result == System::Windows::Forms::DialogResult::Yes )
1151
			{
1152
				if ( !this->CheckSave() )
1153
				{
1154
					e->Cancel = true;
1155
					return;
1156
				}
1157
 
50 cycrow 1158
				if ( m_pPackage->filename().empty() )
1 cycrow 1159
				{
1160
					SaveFileDialog ^ofd = gcnew SaveFileDialog();
1161
					if ( m_pPackage->GetType() == TYPE_XSP )
1162
						ofd->Filter = "Ship Files (*.xsp)|*.xsp";
1163
					else
1164
						ofd->Filter = "Package Files (*.spk)|*.spk";
1165
					ofd->FilterIndex = 1;
1166
					ofd->RestoreDirectory = true;
1167
					if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
50 cycrow 1168
						m_pPackage->setFilename(_S(ofd->FileName));
1 cycrow 1169
					else
1170
					{
1171
						 e->Cancel = true;
1172
						 return;
1173
					}
1174
				}
1175
 
50 cycrow 1176
				if ( !m_pPackage->WriteFile(m_pPackage->filename()) )
1 cycrow 1177
				{
1178
					e->Cancel = true;
50 cycrow 1179
					MessageBox::Show("Unable to save package\n" + _US(m_pPackage->filename()), "Save Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
1 cycrow 1180
					return;
1181
				}
1182
			}
1183
		}
1184
 
1185
		delete m_pPackage;
1186
		m_pPackage = NULL;
1187
	}
1188
 
1189
	void PackageForm::UpdateMirrors()
1190
	{
1191
		this->ListMirrors->Items->Clear();
1192
		for ( int i = 0; i < m_pPackage->GetMaxWebMirrors(); i++ )
1193
		{
1194
			ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(m_pPackage->GetWebMirror(i)));
1195
			this->ListMirrors->Items->Add(item);
1196
			item->ImageIndex = 1;
1197
		}
1198
 
1199
		this->ListMirrors->AutoResizeColumns(ColumnHeaderAutoResizeStyle::ColumnContent);
1200
		if ( this->ListMirrors->Columns[0]->Width < 100 )
1201
			this->ListMirrors->Columns[0]->Width = 100;
1202
	}
1203
 
1204
	void PackageForm::UpdatePackageNames()
1205
	{
1206
		this->ListNames->Items->Clear();
1207
		for ( SNames *n = m_pPackage->GetNamesList()->First(); n; n = m_pPackage->GetNamesList()->Next() )
1208
		{
1209
			ListViewItem ^item = gcnew ListViewItem(Convert::ToString(n->iLanguage));
1210
			item->SubItems->Add(SystemStringFromCyString(n->sName));
1211
			item->ImageIndex = 0;
1212
			this->ListNames->Items->Add(item);
1213
		}
1214
		this->ListNames->AutoResizeColumns(ColumnHeaderAutoResizeStyle::ColumnContent);
1215
		if ( this->ListNames->Columns[0]->Width < 100 )
1216
			this->ListNames->Columns[0]->Width = 100;
1217
		if ( this->ListNames->Columns[1]->Width < 100 )
1218
			this->ListNames->Columns[1]->Width = 100;
1219
	}
1220
 
1221
	void PackageForm::AddDisplayPic()
1222
	{
1223
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
1224
		ofd->Filter = "Display Images|*.gif;*.png;*.jpg";
1225
		ofd->FilterIndex = 1;
1226
		ofd->RestoreDirectory = true;
1227
		ofd->Multiselect = true;
1228
		ofd->Title = "Select the Display image to add";
1229
 
1230
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1231
		{
1232
			array<System::String ^> ^fileArray = ofd->FileNames;
1233
			for ( int i = 0; i < fileArray->Length; i++ )
1234
			{
1235
				CyString file = CyStringFromSystemString(fileArray[i]);
1236
				m_pDisplayFile = m_pPackage->AddFile(file, "", FILETYPE_ADVERT);
1237
			}
1238
 
1239
			this->UpdateDisplayPic();
1240
			this->UpdateFileList();
1241
		}
1242
	}
1243
 
1244
	void PackageForm::AddDisplayIcon()
1245
	{
1246
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
1247
		ofd->Filter = "Icon Files|*.ico;*.png;*.bmp";
1248
		ofd->FilterIndex = 1;
1249
		ofd->RestoreDirectory = true;
1250
		ofd->Multiselect = false;
1251
		ofd->Title = "Select the Icon file to add";
1252
 
1253
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1254
		{
1255
			CyString file = CyStringFromSystemString(ofd->FileName);
1256
			C_File *icon = new C_File(file);
1257
			if ( icon->ReadFromFile() )
1258
				m_pPackage->SetIcon(icon, CFileIO(file).GetFileExtension());
1259
 
1260
			this->UpdateDisplayIcon();
1261
			this->UpdateChanged();
1262
		}
1263
	}
1264
 
1265
	void PackageForm::SaveText()
1266
	{
1267
		if ( this->TextText->Text->Length )
1268
		{
1269
			if ( this->ListLang->SelectedIndex >= 0 )
1270
			{
1271
				int lang = CyStringFromSystemString(this->ListLang->Text).ToInt();
46 cycrow 1272
				if ( this->RadioInstallAfter->Checked )			m_pPackage->addInstallText(lang, false, _S(this->TextText->Text));
1273
				else if ( this->RadioInstallBefore->Checked )	m_pPackage->addInstallText(lang, true, _S(this->TextText->Text));
1274
				else if ( this->RadioUninstallBefore->Checked )	m_pPackage->addUninstallText(lang, true, _S(this->TextText->Text));
1275
				else if ( this->RadioUninstallAfter->Checked )	m_pPackage->addUninstallText(lang, false, _S(this->TextText->Text));
1 cycrow 1276
				this->UpdateChanged();
1277
			}
1278
		}
1279
	}
1280
 
1281
	void PackageForm::LoadShipData()
1282
	{
1283
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
1284
		ofd->Filter = "All (*.cat, tships)|*.cat;tships.txt;tships.pck|TShips Files (tships.txt/pck)|tships.txt;tships.pck|Mod Files (*.cat)|*.cat";
1285
		ofd->FilterIndex = 1;
1286
		ofd->RestoreDirectory = true;
1287
		ofd->Multiselect = false;
1288
		ofd->Title = "Select the TShips/Mod file to load ship data from";
1289
 
1290
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1291
		{
1292
			// if its a cat file, lets load the text
1293
			Hashtable ^catText = gcnew Hashtable();
1294
 
1295
			if ( String::Compare(IO::FileInfo(ofd->FileName).Extension, ".cat") == 0 )
1296
			{
1297
				CyStringList readText;
1298
				if ( m_pP->ReadTextPage(CyStringFromSystemString(ofd->FileName), &readText, false, 17) )
1299
				{
1300
					for ( SStringList *str = readText.Head(); str; str = str->next )
1301
					{
1302
						String ^key = SystemStringFromCyString(str->str);
1303
						if ( catText->ContainsKey(key) )
1304
							catText[key] = SystemStringFromCyString(str->data);
1305
						else
1306
							catText->Add(key, SystemStringFromCyString(str->data));
1307
					}
1308
				}
1309
			}
1310
 
1311
			CyStringList list;
1312
			if ( m_pP->LoadShipData(CyStringFromSystemString(ofd->FileName), &list) )
1313
			{
1314
				LoadShip ^ls = gcnew LoadShip();
1315
				for ( SStringList *str = list.Head(); str; str = str->next )
1316
				{
1317
					int tId = str->data.GetToken(";", 7, 7).ToInt();
1318
					String ^name;
1319
					if ( catText->ContainsKey(Convert::ToString(tId)) )
1320
						name = Convert::ToString(catText[Convert::ToString(tId)]);
1321
					else
1322
						name = ((Form1 ^)this->MdiParent)->FindText(-1, 17, tId);
1323
					String ^text = ((Form1 ^)this->MdiParent)->FindText(-1, 1266, str->data.GetToken(";", 46, 46).ToInt()) + " " + name;
1324
					int variation = str->data.GetToken(";", 51, 51).ToInt();
1325
					if ( variation )
1326
						text = text + " " + ((Form1 ^)this->MdiParent)->FindText(-1, 17, 10000 + variation);
1327
					ls->AddShip(SystemStringFromCyString(str->str), text);
1328
				}
1329
 
1330
				if ( ls->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1331
				{
1332
					SStringList *str = list.FindString(CyStringFromSystemString(ls->GetData()));
1333
					if ( str )
1334
					{
14 cycrow 1335
						((CXspFile *)m_pPackage)->SetShipData(str->data.ToString());
1336
						if ( ((CXspFile *)m_pPackage)->GetShipID().empty() )
1 cycrow 1337
						{
1338
							CyString id = str->data.GetToken(";", -2);
1339
							while ( id.Right(1) == ";" )
1340
								id.Truncate((int)id.Length() - 1);
14 cycrow 1341
							((CXspFile *)m_pPackage)->SetShipID(id.ToString());
1 cycrow 1342
							this->TextShipID->Text = SystemStringFromCyString(id);
1343
						}
1344
 
14 cycrow 1345
						((CXspFile *)m_pPackage)->SetShipData(str->data.ToString());
1 cycrow 1346
						this->TextShipData->Text = SystemStringFromCyString(str->data);
1347
						this->NumTextID->Value = str->data.GetToken(";", 7, 7).ToInt();
1348
						this->UpdateChanged();
1349
					}
1350
				}
1351
			}
1352
			else
1353
				MessageBox::Show(this, "Unable to find any ship entries, invalid/missing TShips?", "Error Loading", MessageBoxButtons::OK, MessageBoxIcon::Error);
1354
		}
1355
	}
1356
 
1357
	void PackageForm::EditShipParts(bool edit)
1358
	{
1359
		 CXspFile *xsp = (CXspFile *)m_pPackage;
1360
		 switch ( this->ComboShipPart->SelectedIndex )
1361
		 {
1362
			case 0:
1363
				{
1364
					AddShipPart ^component = gcnew AddShipPart((Form1 ^)this->MdiParent);
1365
					component->SetComponent(edit);
1366
 
1367
					if ( edit )
1368
					{
1369
						component->SetSection(m_pSelectedItem->Text);
1370
						component->SetSection2(m_pSelectedItem->SubItems[1]->Text);
1371
						component->SetData(m_pSelectedItem->SubItems[2]->Text);
1372
					}
1373
 
1374
					if ( component->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1375
					{
1376
						if ( edit )
39 cycrow 1377
							xsp->RemoveComponent(_S(m_pSelectedItem->Text), _S(m_pSelectedItem->SubItems[1]->Text), _S(m_pSelectedItem->SubItems[2]->Text));
1378
						xsp->AddComponent(_S(component->GetSection()), _S(component->GetSection2()), _S(component->GetData()));
1 cycrow 1379
						if ( !edit )
1380
							this->UpdateShipPartList();
1381
						else
1382
						{
1383
							m_pSelectedItem->Text = component->GetSection();
1384
							m_pSelectedItem->SubItems[1]->Text = component->GetSection2();
1385
							m_pSelectedItem->SubItems[2]->Text = component->GetData();
1386
						}
1387
					}
1388
				}
1389
				break;
1390
			case 1:
1391
				{
1392
					AddShipPart ^dummy = gcnew AddShipPart((Form1 ^)this->MdiParent);
1393
					dummy->SetDummy(edit);
1394
 
1395
					if ( edit )
1396
					{
1397
						dummy->SetSection(m_pSelectedItem->Text);
1398
						dummy->SetData(m_pSelectedItem->SubItems[1]->Text);
1399
					}
1400
 
1401
					if ( dummy->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1402
					{
1403
						if ( edit )
39 cycrow 1404
							xsp->RemoveDummy(_S(m_pSelectedItem->Text), _S(m_pSelectedItem->SubItems[1]->Text));
1405
						xsp->AddDummy(_S(dummy->GetSection()), _S(dummy->GetData()));
1 cycrow 1406
						if ( !edit )
1407
							this->UpdateShipPartList();
1408
						else
1409
						{
1410
							m_pSelectedItem->Text = dummy->GetSection();
1411
							m_pSelectedItem->SubItems[1]->Text = dummy->GetData();
1412
						}
1413
					}
1414
				}
1415
				break;
1416
 
1417
			case 2:
1418
				{
1419
					AddCockpit ^cockpit = gcnew AddCockpit();
1420
					if ( edit )
1421
						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());
1422
					if ( cockpit->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1423
					{
1424
						if ( !edit )
1425
						{
39 cycrow 1426
							xsp->NewCockpit(_S(cockpit->GetID()), _S(cockpit->GetScene()), cockpit->GetMask());
1 cycrow 1427
							this->UpdateShipPartList();
1428
						}
1429
						else
1430
						{
39 cycrow 1431
							xsp->EditCockpit(_S(cockpit->GetID()), _S(cockpit->GetScene()), cockpit->GetMask());
1432
							m_pSelectedItem->SubItems[2]->Text = SystemStringFromCyString(xsp->GetCockpitData(_S(cockpit->GetID())));
1 cycrow 1433
						}
1434
					}
1435
				}
1436
				break;
1437
 
1438
			case 3:
1439
				{
1440
					if ( edit )
1441
					{
1442
						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)));
1443
						if ( input2->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1444
						{
39 cycrow 1445
							xsp->RemoveCutData(_S(m_pSelectedItem->Text));
1446
							xsp->AddCutData(_S(SystemStringFromCyString(CyStringFromSystemString(m_pSelectedItem->Text).GetToken(";", 1, 1)) + "; " + input2->GetInput()));
1 cycrow 1447
							this->UpdateShipPartList();
1448
						}
1449
					}
1450
					else
1451
					{
1452
						InputBox ^input = gcnew InputBox("Enter the cut id to add");
1453
						if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1454
						{
1455
							InputBox ^input2 = gcnew InputBox("Enter the filename for cut id: " + input->GetInput());
1456
							if ( input2->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1457
							{
39 cycrow 1458
								xsp->AddCutData(_S(input->GetInput() + "; " + input2->GetInput()));
1 cycrow 1459
								this->UpdateShipPartList();
1460
							}
1461
						}
1462
					}
1463
				}
1464
				break;
1465
 
1466
			case 4:
1467
				{
1468
					AddShipPart ^dummy = gcnew AddShipPart((Form1 ^)this->MdiParent);
1469
					dummy->SetBodies(edit);
1470
 
1471
					if ( edit )
1472
					{
1473
						dummy->SetSection(m_pSelectedItem->Text);
1474
						dummy->SetData(m_pSelectedItem->SubItems[1]->Text);
1475
					}
1476
 
1477
					if ( dummy->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1478
					{
1479
						if ( edit )
39 cycrow 1480
							xsp->RemoveBodies(_S(m_pSelectedItem->Text + ";" + m_pSelectedItem->SubItems[1]->Text));
1481
						xsp->AddBodies(_S(dummy->GetSection() + ";" + dummy->GetData()));
1 cycrow 1482
						if ( !edit )
1483
							this->UpdateShipPartList();
1484
						else
1485
						{
1486
							m_pSelectedItem->Text = dummy->GetSection();
1487
							m_pSelectedItem->SubItems[1]->Text = dummy->GetData();
1488
						}
1489
					}
1490
				}
1491
				break;
1492
 
1493
			case 5:
1494
				{
1495
					InputBox ^input = gcnew InputBox("Enter the animation data to add", (!edit) ? "" : m_pSelectedItem->Text);
1496
					input->Large();
1497
					if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1498
					{
1499
						if ( edit )
39 cycrow 1500
							xsp->RemoveAnimation(_S(m_pSelectedItem->Text));
1501
						xsp->AddAnimation(_S(input->GetInput()));
1 cycrow 1502
						this->UpdateShipPartList();
1503
					}
1504
				}
1505
				break;
1506
		 }
1507
	}
1508
 
1509
	void PackageForm::DropGetDirectories(String ^dir, CyStringList *list, bool packages)
1510
	{
1511
		cli::array<String ^> ^dirList = IO::Directory::GetFileSystemEntries(dir);
1512
		for ( int j = 0; j < dirList->Length; j++ )
1513
		{
1514
			if ( IO::DirectoryInfo(dirList[j]).Exists )
1515
				this->DropGetDirectories(dirList[j], list, packages);
1516
			else
1517
			{
1518
				if ( packages )
1519
					list->PushBack(CyStringFromSystemString(dirList[j]), "-1");
1520
				else
18 cycrow 1521
					list->PushBack(CyStringFromSystemString(dirList[j]), CyString::Number(SPK::GetAutomaticFiletype(CyStringFromSystemString(dirList[j]), NULL,false)));
1 cycrow 1522
			}
1523
		}
1524
	}
1525
 
1526
	void PackageForm::RemoveSelectedFiles()
1527
	{
1528
		CLinkList<C_File> removeFiles;
1529
		for ( int i = 0; i < ListFiles->SelectedItems->Count; i++ )
1530
		{
1531
			int id = CyStringFromSystemString(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).ToInt();
1532
			C_File *file = m_pPackage->GetFileList()->Get(id);
1533
			if ( m_pDisplayFile == file )
1534
				m_pDisplayFile = NULL;
1535
			removeFiles.push_back(file);
1536
		}
1537
 
1538
		if ( removeFiles.size() )
1539
		{
1540
			for ( C_File *f = removeFiles.First(); f; f = removeFiles.Next() )
1541
				m_pPackage->RemoveFile(f);
1542
			m_pPackage->UpdateSigned(false);
1543
			this->UpdateFileList();
1544
			this->UpdateDisplayPic();
1545
			this->UpdateChanged();
1546
		}
1547
 
1548
		if ( !ListFiles->SelectedItems->Count )
1549
			this->ButRemoveFile->Enabled = false;
1550
	}
1551
 
1552
	String ^PackageForm::ExtractImport(String ^file, String ^type)
1553
	{
1554
		if ( String::Compare(IO::FileInfo(file).Extension, ".xml") == 0 )
1555
			return file;
1556
 
1557
		if ( String::Compare(IO::FileInfo(file).Extension, ".pck") == 0 )
1558
		{
1559
			C_File F(CyStringFromSystemString(file));
1560
			F.UnPCKFile();
79 cycrow 1561
			if ( F.WriteToFile(CPackages::tempDirectory() + "tmp.dat") )
1562
				return _US(CPackages::tempDirectory() + "tmp.dat");
1 cycrow 1563
		}
1564
		else if ( String::Compare(IO::FileInfo(file).Extension, ".cat") == 0 )
1565
		{
1566
			CCatFile cat;
125 cycrow 1567
			if ( cat.open(_S(file), "", CATREAD_CATDECRYPT, false) == CATERR_NONE )
1 cycrow 1568
			{
79 cycrow 1569
				if ( cat.ExtractFile(CyStringFromSystemString("types\\" + type + ".pck"), CPackages::GetTempDirectory() + "tmp.dat") )
1570
					return _US(CPackages::tempDirectory() + "tmp.dat");
1 cycrow 1571
			}
1572
		}
1573
 
1574
		return "";
1575
	}
1576
 
94 cycrow 1577
	CGameDirectories *PackageForm::gameDirectories()
1 cycrow 1578
	{
94 cycrow 1579
		return ((Form1 ^)this->MdiParent)->gameDirectories();
1 cycrow 1580
	}
1581
 
1582
	void PackageForm::ImportData(String ^file, int type)
1583
	{
1584
		CFileIO F(CyStringFromSystemString(file));
52 cycrow 1585
		if ( !F.exists() )
1 cycrow 1586
			return;
1587
 
1588
		CyStringList *lines = F.ReadLinesStr();
1589
		if ( !lines )
1590
			return;
1591
 
1592
		LoadShip ^load = gcnew LoadShip();
1593
 
1594
		int entryPos = 1;
1595
		int dataPos = 1;
1596
		int dataPos2 = 0;
1597
		bool sections = false;
1598
		CyString section;
1599
		switch ( type )
1600
		{
1601
			case 2:
1602
				entryPos = 2;
1603
				dataPos = 19;
1604
				load->Cockpits();
1605
				break;
1606
			case 3:
1607
				dataPos2 = 2;
1608
				load->CutData();
1609
				break;
1610
			case 4:
1611
				sections = true;
1612
				entryPos = 2;
1613
				load->Bodies();
1614
				break;
1615
			case 1:
1616
				sections = true;
1617
				entryPos = 2;
1618
				dataPos = -1;
1619
				load->Dummies();
1620
				break;
1621
			case 0:
1622
				sections = true;
1623
				entryPos = 2;
1624
				dataPos = -1;
1625
				load->Components();
1626
				break;
1627
		}
1628
 
1629
		int entries2 = 0;
1630
		int entries = -1;
1631
		CyStringList list;
1632
		CyString data;
1633
		int e = 0;
1634
		for ( SStringList *str = lines->Head(); str; str = str->next )
1635
		{
1636
			str->str.RemoveChar(9);
1637
			str->str.RemoveChar('\r');
1638
			str->str.RemoveFirstSpace();
1639
			if ( str->str.Empty() )
1640
				continue;
1641
			if ( str->str[0] == '/' )
1642
				continue;
1643
 
1644
			if ( entries == -1 || (entries <= 0 && sections) )
1645
			{
1646
				entries = str->str.GetToken(";", entryPos, entryPos).ToInt();
1647
				if ( sections )
1648
				{
1649
					section = str->str.GetToken(";", 1, 1);
1650
					load->AddGroup(SystemStringFromCyString(section));
1651
				}
1652
			}
1653
			else
1654
			{
1655
				if ( type == 4 )
1656
				{
1657
					int max;
1658
					CyString *strs = str->str.SplitToken(";", &max);
1659
					if ( max && strs )
1660
					{
1661
						for ( int i = 0; i < max; i++ )
1662
						{
1663
							strs[i].RemoveFirstSpace();
1664
							if ( strs[i].Empty() ) continue;
1665
							CyString id = strs[i].GetToken(";", dataPos, dataPos);
1666
							load->AddShip(SystemStringFromCyString(id), "");
1667
							list.PushBack(id, CyString::Number(e) + " " + section + ";" + strs[i]);
1668
							++e;
1669
							--entries;
1670
						}
1671
					}
1672
 
1673
					CLEANSPLIT(strs, max)
1674
				}
1675
				else if ( type == 0 )
1676
				{
1677
					if ( entries2 )
1678
					{
1679
						load->AddShip(SystemStringFromCyString(data), SystemStringFromCyString(str->str));
1680
						list.PushBack(data, section + ";" + data + ";" + str->str);
1681
						--entries2;
1682
					}
1683
					else
1684
					{
1685
						data = str->str.GetToken(";", 1, 1);
1686
						entries2 = str->str.GetToken(";", 2, 2).ToInt();
1687
						++e;
1688
						--entries;
1689
					}
1690
				}
1691
				else
1692
				{
1693
					CyString id;
1694
					if ( dataPos == -1 )
1695
						id = str->str; 
1696
					else
1697
						id = str->str.GetToken(";", dataPos, dataPos); 
1698
 
1699
					if ( dataPos2 )
1700
						load->AddShip(SystemStringFromCyString(id), SystemStringFromCyString(str->str.GetToken(";", dataPos2, dataPos2)));
1701
					else
1702
						load->AddShip(SystemStringFromCyString(id), "");
1703
					if ( sections )
1704
						list.PushBack(id, CyString::Number(e) + " " + section + ";" + str->str);
1705
					else
1706
						list.PushBack(id, CyString::Number(e) + " " + str->str);
1707
					++e;
1708
					--entries;
1709
				}
1710
			}
1711
		}
1712
 
1713
		if ( load->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1714
		{
1715
			for ( SStringList *str = load->GetDataList()->Head(); str; str = str->next )
1716
			{
1717
				SStringList *s = list.FindString(str->str);
1718
				if ( s )
1719
				{
1720
					switch ( type )
1721
					{
1722
						case 0:
39 cycrow 1723
							((CXspFile *)m_pPackage)->AddComponent(s->data.GetToken(";", 1, 1).ToString(), s->data.GetToken(";", 2, 2).ToString(), s->data.GetToken(";", 3).ToString());
1 cycrow 1724
							break;
1725
						case 2:
39 cycrow 1726
							((CXspFile *)m_pPackage)->AddCockpit(s->data.GetToken(" ", 2).ToString(), 0, -1, s->data.GetToken(" ", 1, 1).ToInt());
1 cycrow 1727
							break;
1728
						case 3:
39 cycrow 1729
							((CXspFile *)m_pPackage)->AddCutData(s->data.GetToken(" ", 2).ToString());
1 cycrow 1730
							break;
1731
						case 4:
39 cycrow 1732
							((CXspFile *)m_pPackage)->AddBodies(s->data.GetToken(" ", 2).ToString());
1 cycrow 1733
							break;
1734
						case 1:
39 cycrow 1735
							((CXspFile *)m_pPackage)->AddDummy(s->data.GetToken(" ", 2).GetToken(";", 1, 1).ToString(), s->data.GetToken(" ", 2).GetToken(";", 2).ToString());
1 cycrow 1736
							break;
1737
					}
1738
				}
1739
			}
1740
 
1741
			this->UpdateShipPartList();
1742
			this->UpdateChanged();
1743
		}
1744
 
1745
		delete lines;
1746
	}
1747
 
1748
	void PackageForm::ImportAnimations(String ^file)
1749
	{
1750
		CFileIO F(CyStringFromSystemString(file));
52 cycrow 1751
		if ( !F.exists() )
1 cycrow 1752
			return;
1753
 
1754
		CyStringList *lines = F.ReadLinesStr();
1755
		if ( !lines )
1756
			return;
1757
 
1758
 
1759
		CyStringList lOut;
1760
		if ( CXspFile::ReadAnimations(lines, &lOut, 0) )
1761
		{
1762
			LoadShip ^load = gcnew LoadShip();
1763
			load->Animations();
1764
			for ( SStringList *str = lOut.Head(); str; str = str->next )
1765
			{
1766
				load->AddShip(SystemStringFromCyString(str->str), "");
1767
			}
1768
 
1769
			if ( load->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1770
			{
1771
				((CXspFile *)m_pPackage)->AddAnimation(load->GetDataList());
1772
				this->UpdateShipPartList();
1773
				this->UpdateChanged();
1774
			}
1775
		}
1776
 
1777
		delete lines;
1778
	}
1779
 
1780
	void PackageForm::EditDepend()
1781
	{
1782
		 AddDepend ^depend = gcnew AddDepend();
1783
		 depend->SetEdit(m_pSelectedItem->Text, m_pSelectedItem->SubItems[1]->Text, m_pSelectedItem->SubItems[2]->Text);
1784
 
1785
		 bool builtin = false;
1786
		 if ( String::Compare("<package>", m_pSelectedItem->Text) == 0 && String::Compare("<author>", m_pSelectedItem->SubItems[1]->Text) == 0 )
1787
		 {
1788
			 builtin = true;
1789
			 depend->BuiltIn();
1790
		 }
1791
 
1792
		 if ( depend->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1793
		 {
1794
			 if ( builtin )
1795
			 {
1796
				 SNeededLibrary *ns = m_pPackage->FindPackageNeeded("<package>", "<author>");
1797
				 if ( ns )
46 cycrow 1798
					 ns->sMinVersion = _S(depend->GetVersion());
1 cycrow 1799
			 }
1800
			 else
1801
			 {
46 cycrow 1802
				 m_pPackage->RemovePackageNeeded(_S(m_pSelectedItem->Text), _S(m_pSelectedItem->SubItems[1]->Text));
1803
				 m_pPackage->AddNeededLibrary(_S(depend->GetName()), _S(depend->GetAuthor()), _S(depend->GetVersion()));
1 cycrow 1804
			 }
1805
			 this->UpdateDependacies();
1806
			 this->UpdateChanged();
1807
		 }
1808
	}
1809
}