Subversion Repositories spk

Rev

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