Subversion Repositories spk

Rev

Rev 225 | Rev 237 | 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();
214 cycrow 31
		_pPackages->startup(L".", L".", L".");
127 cycrow 32
		m_pPackage = NULL;
214 cycrow 33
		m_pTypeList = new Utils::WStringList;
127 cycrow 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;
224 cycrow 88
			m_pPackage = m_pP->openPackage(_WS(filename), &error);
1 cycrow 89
			if ( !m_pPackage )
90
				return false;
91
		}
92
		else
93
			m_pPackage = base;
94
 
50 cycrow 95
		m_pPackage->adjustChanged(false);
175 cycrow 96
		m_pPackage->updateSigned(true);
1 cycrow 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
			{
224 cycrow 104
				f->setFullDir(_WS(System::IO::Path::GetTempPath()));
1 cycrow 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
 
170 cycrow 121
		if ( m_pPackage->icon() )
1 cycrow 122
		{
170 cycrow 123
			C_File *f = m_pPackage->icon();
197 cycrow 124
			f->setFilename(_WS(System::IO::Path::GetTempPath()) + L"/package_icon." + m_pPackage->iconExt());
125
			f->setFullDir(_WS(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 )
214 cycrow 178
				((CSpkFile *)m_pPackage)->setScriptType(_WS(this->TextCustomType->Text));
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
		{
206 cycrow 239
			int lang = _WS(this->ListLang->Text).toInt();
240
			Utils::WString desc;
46 cycrow 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
		{
191 cycrow 264
			ListViewItem ^item = gcnew ListViewItem(_US(w->sID));
1 cycrow 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();
175 cycrow 321
		m_pPackage->updateSigned(false);
1 cycrow 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
		{
216 cycrow 332
			SWares *w = ((CSpkFile *)m_pPackage)->findWare(_WS(this->ListWares->SelectedItems[0]->Text));
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;
191 cycrow 343
						item->SubItems->Add(_US(wt->sName));
344
						item->SubItems->Add(_US(wt->sDesc));
1 cycrow 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());
206 cycrow 362
		Utils::WString desc = m_pPackage->description();
363
		desc = desc.findReplace(L"<br>", L"\n");
364
		desc = desc.findReplace(L"<newline>", L"\n");
48 cycrow 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;
217 cycrow 371
			this->TextShipID->Text = _US(xsp->shipID());
1 cycrow 372
			this->PanelShip->Show();
373
			this->LabelShipWarning->Visible = true;
374
			this->groupBox6->Visible = false;
375
 
217 cycrow 376
			this->TextShipData->Text = _US(xsp->shipData());
1 cycrow 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 )
214 cycrow 422
					this->TextCustomType->Text = _US(spk->customScriptType(m_pP->GetLanguage()));
1 cycrow 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
			{
214 cycrow 432
				this->TextOtherAuthor->Text = _US(spk->otherAuthor());
433
				this->TextOtherName->Text = _US(spk->otherName());
1 cycrow 434
			}
435
 
436
			this->UpdateWares();
437
			this->UpdateScriptType();
438
		}
439
 
50 cycrow 440
		if ( !m_pPackage->creationDate().empty() ) {
204 cycrow 441
			int day = m_pPackage->creationDate().token(L"/", 1);
442
			int month = m_pPackage->creationDate().token(L"/", 2);
443
			int year = m_pPackage->creationDate().token(L"/", 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
		{
191 cycrow 509
			ListViewItem ^item = gcnew ListViewItem(_US(nl->sName));
510
			item->SubItems->Add(_US(nl->sAuthor));
511
			item->SubItems->Add(_US(nl->sMinVersion));
1 cycrow 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
				{
191 cycrow 537
					ListViewItem ^item = gcnew ListViewItem(_US(c->sSection));
1 cycrow 538
					item->ImageKey = "components";
191 cycrow 539
					item->SubItems->Add(_US(c->sSection2));
540
					item->SubItems->Add(_US(c->sData));
1 cycrow 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
				{
191 cycrow 550
					ListViewItem ^item = gcnew ListViewItem(_US(d->sSection));
551
					item->SubItems->Add(_US(d->sData));
1 cycrow 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
				{
216 cycrow 563
					Utils::WString cName = c->sCockpit;
564
					cName = cName.token(L";", -2);
565
					while ( cName.right(1) == L";" )
191 cycrow 566
						cName.truncate(-1);
567
					ListViewItem ^item = gcnew ListViewItem(_US(cName));
1 cycrow 568
					if ( c->iIndex == -1 )
569
						item->SubItems->Add("<PACKAGE>");
570
					else
571
						item->SubItems->Add(Convert::ToString(c->iIndex));
191 cycrow 572
					item->SubItems->Add(_US(c->sCockpit));
1 cycrow 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";
165 cycrow 580
				for(auto itr = xsp->getCutData().begin(); itr != xsp->getCutData().end(); itr++)
1 cycrow 581
				{
165 cycrow 582
					ListViewItem ^item = gcnew ListViewItem(_US((*itr)->str));
1 cycrow 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";
170 cycrow 591
				for(auto itr = xsp->getBodies().begin(); itr != xsp->getBodies().end(); itr++)
1 cycrow 592
				{
216 cycrow 593
					ListViewItem ^item = gcnew ListViewItem(_US((*itr)->str.token(L";", 1)));
594
					item->SubItems->Add(_US((*itr)->str.tokens(L";", 2)));
1 cycrow 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";
170 cycrow 602
				for(auto itr = xsp->getAnimations().begin(); itr != xsp->getAnimations().end(); itr++)
1 cycrow 603
				{
170 cycrow 604
					ListViewItem ^item = gcnew ListViewItem(_US((*itr)->str));
1 cycrow 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;
191 cycrow 633
			item->SubItems->Add(_US(t->sName));
634
			item->SubItems->Add(_US(t->sDesc));
1 cycrow 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
		{
197 cycrow 648
			Utils::WString filePointer = m_pDisplayFile->filePointer();
649
			filePointer = filePointer.findReplace(L"/", L"\\");
650
			filePointer = filePointer.findReplace(L"\\\\", L"\\");
178 cycrow 651
			if ( System::IO::File::Exists(_US(filePointer)) )
1 cycrow 652
			{
178 cycrow 653
				Bitmap ^myBitmap = gcnew Bitmap(_US(filePointer));
1 cycrow 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
 
170 cycrow 710
		if ( m_pPackage->icon() )
1 cycrow 711
		{
712
			this->ButIconDel->Enabled = true;
197 cycrow 713
			Utils::WString filePointer = m_pPackage->icon()->filePointer();
714
			filePointer = filePointer.findReplace(L"/", L"\\");
715
			filePointer = filePointer.findReplace(L"\\\\", L"\\");
178 cycrow 716
			String ^file = _US(filePointer);
1 cycrow 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 )
197 cycrow 752
			exe = m_pP->GetGameExe()->game((m_pPackage) ? ButGame->ImageIndex : -1);
1 cycrow 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];
191 cycrow 759
				ComboVersion->Items->Add(_US(v->sName));
1 cycrow 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
 
197 cycrow 894
		for ( int i = 0; i < m_pP->GetGameExe()->numGames(); i++ )
1 cycrow 895
		{
197 cycrow 896
			SGameExe *gameExe = m_pP->GetGameExe()->game(i);
1 cycrow 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
 
214 cycrow 939
		m_pTypeList->clear();
6 cycrow 940
		for ( int i = 0; i < CSpkFile::SCRIPTTYPE_MAX; i++ )
1 cycrow 941
		{
214 cycrow 942
			m_pTypeList->pushBack(CSpkFile::GetScriptTypeStringStatic(i));
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() ) {
182 cycrow 955
			ListViewItem ^item = gcnew ListViewItem(_US(m_pP->getGameNameFromType(game->iGame)));
1 cycrow 956
			item->ImageIndex = (game->iGame < 0) ? -1 : (game->iGame - 1);
46 cycrow 957
			if ( !game->sVersion.empty() ) {
182 cycrow 958
				item->SubItems->Add("Exact: " + _US(game->sVersion));
1 cycrow 959
			}
960
			else {
182 cycrow 961
				item->SubItems->Add(_US(m_pP->getGameVersionFromType(game->iGame, game->iVersion, game->sVersion)));
1 cycrow 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
		{
178 cycrow 1005
			item->SubItems->Add(_US("<PACKAGE>/" + file->getNameDirectory(NULL)));
1006
			item->SubItems->Add(_US(file->uncompressedSizeString()));
1 cycrow 1007
		}
1008
		else
1009
		{
178 cycrow 1010
			item->SubItems->Add(_US(file->fullFilename()));
1011
			item->SubItems->Add(_US(SPK::GetSizeString(file->GetSize())));
1 cycrow 1012
		}
1013
 
1014
		if ( file->IsFakePatch() )
1015
			item->SubItems->Add("Mod (Fakepatch)");
1016
		else
178 cycrow 1017
			item->SubItems->Add(_US(file->fileTypeString()));
1 cycrow 1018
 
178 cycrow 1019
		if ( !file->dir().empty() )
1020
			item->SubItems->Add(_US(file->dir()));
1 cycrow 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
			{			
197 cycrow 1035
				Utils::WString sGames = L"";
127 cycrow 1036
				for (int i = 0; i < 31; ++i)
1037
				{
1038
					int gameMask = 1 << i;
1039
					if (file->game() & gameMask)
1040
					{
197 cycrow 1041
						Utils::WString sGame;
1042
						SGameExe *exe = _pPackages->GetGameExe()->game(i - 1);
127 cycrow 1043
						if (exe)
1044
							sGame = exe->sName;
1045
						else
197 cycrow 1046
							sGame = L"Game: " + Utils::WString::Number(i);
127 cycrow 1047
 
1048
						if (sGames.empty())
1049
							sGames = sGame;
1050
						else
197 cycrow 1051
							sGames = sGames + L", " + sGame;
127 cycrow 1052
					}
1053
				}
1054
				item->SubItems->Add(_US(sGames));
1 cycrow 1055
			}
127 cycrow 1056
			else
1057
			{
197 cycrow 1058
				SGameExe *exe = _pPackages->GetGameExe()->game(file->game() - 1);
127 cycrow 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
 
191 cycrow 1068
		item->Tag = _US(Utils::WString::Number(file->GetPos()));
1 cycrow 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 += "|";
191 cycrow 1089
			filter += _US(GetFileTypeString(i));
1 cycrow 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
		{
224 cycrow 1139
			Utils::WString dir;
1 cycrow 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 )
224 cycrow 1144
					dir = _WS(input->GetInput());
1 cycrow 1145
			}
1146
			array<System::String ^> ^fileArray = ofd->FileNames;
1147
			for ( int i = 0; i < fileArray->Length; i++ )
1148
			{
1149
				System::String ^file = fileArray[i];
224 cycrow 1150
				FileType filetype = m_pP->adjustFileType(_WS(file), static_cast<FileType>(ofd->FilterIndex - 1));
1151
				C_File *f = m_pPackage->addFile(_WS(file), dir, filetype, this->ComboGameFilter->SelectedIndex > 1 ? (1 << (this->ComboGameFilter->SelectedIndex - 1) | 1 << 31) : 0);
1 cycrow 1152
				if ( (ofd->FilterIndex - 1) == FILETYPE_MOD )
224 cycrow 1153
					m_pPackage->addFile(CFileIO(_WS(file)).changeFileExtension(L"dat"), dir, filetype);
1 cycrow 1154
			}
175 cycrow 1155
			m_pPackage->updateSigned(false);
1 cycrow 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
			{
203 cycrow 1184
				SNeededLibrary *n = m_pPackage->findPackageNeeded(L"<package>", L"<author>");
1 cycrow 1185
				if ( !n )
203 cycrow 1186
					m_pPackage->addNeededLibrary(L"<package>", L"<author>", L"1.00");
1187
				n = m_pPackage->findPackageNeeded(L"<package>", L"<author>");
1 cycrow 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
			{
214 cycrow 1208
				if ( ((CSpkFile *)m_pPackage)->otherAuthor().empty() || ((CSpkFile *)m_pPackage)->otherName().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);
214 cycrow 1217
		 m_pPackage->setCreationDate(_WS(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;
197 cycrow 1261
		Utils::WString filename = m_pPackage->filename();
170 cycrow 1262
		if (filename.empty())
203 cycrow 1263
			filename = m_pPackage->getAutosaveName();
197 cycrow 1264
		filename = filename.findReplace(L"/", L"\\");
170 cycrow 1265
		ofd->FileName = _US(filename);
1 cycrow 1266
		ofd->FilterIndex = 1;
1267
		ofd->RestoreDirectory = true;
1268
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1269
		{
197 cycrow 1270
			m_pPackage->setFilename(_WS(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 )
224 cycrow 1309
						m_pPackage->setFilename(_WS(ofd->FileName));
1 cycrow 1310
					else
1311
					{
1312
						 e->Cancel = true;
1313
						 return;
1314
					}
1315
				}
1316
 
224 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();
170 cycrow 1348
		for(auto itr = m_pPackage->namesList()->begin(); itr != m_pPackage->namesList()->end(); itr++)
1 cycrow 1349
		{
170 cycrow 1350
			ListViewItem ^item = gcnew ListViewItem(Convert::ToString((*itr)->iLanguage));
1351
			item->SubItems->Add(_US((*itr)->sName));
1 cycrow 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++ )
224 cycrow 1375
				m_pDisplayFile = m_pPackage->addFile(_WS(fileArray[i]), L"", FILETYPE_ADVERT);
1 cycrow 1376
 
1377
			this->UpdateDisplayPic();
1378
			this->UpdateFileList();
1379
		}
1380
	}
1381
 
1382
	void PackageForm::AddDisplayIcon()
1383
	{
1384
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
1385
		ofd->Filter = "Icon Files|*.ico;*.png;*.bmp";
1386
		ofd->FilterIndex = 1;
1387
		ofd->RestoreDirectory = true;
1388
		ofd->Multiselect = false;
1389
		ofd->Title = "Select the Icon file to add";
1390
 
1391
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1392
		{
224 cycrow 1393
			Utils::WString file = _WS(ofd->FileName);
1 cycrow 1394
			C_File *icon = new C_File(file);
1395
			if ( icon->ReadFromFile() )
224 cycrow 1396
				m_pPackage->setIcon(icon, CFileIO(file).extension());
1 cycrow 1397
 
1398
			this->UpdateDisplayIcon();
1399
			this->UpdateChanged();
1400
		}
1401
	}
1402
 
1403
	void PackageForm::SaveText()
1404
	{
1405
		if ( this->TextText->Text->Length )
1406
		{
1407
			if ( this->ListLang->SelectedIndex >= 0 )
1408
			{
224 cycrow 1409
				int lang = _WS(this->ListLang->Text).toInt();
1410
				if ( this->RadioInstallAfter->Checked )			m_pPackage->addInstallText(lang, false, _WS(this->TextText->Text));
1411
				else if ( this->RadioInstallBefore->Checked )	m_pPackage->addInstallText(lang, true, _WS(this->TextText->Text));
1412
				else if ( this->RadioUninstallBefore->Checked )	m_pPackage->addUninstallText(lang, true, _WS(this->TextText->Text));
1413
				else if ( this->RadioUninstallAfter->Checked )	m_pPackage->addUninstallText(lang, false, _WS(this->TextText->Text));
1 cycrow 1414
				this->UpdateChanged();
1415
			}
1416
		}
1417
	}
1418
 
1419
	void PackageForm::LoadShipData()
1420
	{
1421
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
1422
		ofd->Filter = "All (*.cat, tships)|*.cat;tships.txt;tships.pck|TShips Files (tships.txt/pck)|tships.txt;tships.pck|Mod Files (*.cat)|*.cat";
1423
		ofd->FilterIndex = 1;
1424
		ofd->RestoreDirectory = true;
1425
		ofd->Multiselect = false;
1426
		ofd->Title = "Select the TShips/Mod file to load ship data from";
1427
 
1428
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1429
		{
1430
			// if its a cat file, lets load the text
1431
			Hashtable ^catText = gcnew Hashtable();
1432
 
1433
			if ( String::Compare(IO::FileInfo(ofd->FileName).Extension, ".cat") == 0 )
1434
			{
197 cycrow 1435
				Utils::WStringList readText;
224 cycrow 1436
				if ( m_pP->readTextPage(_WS(ofd->FileName), readText, false, 17) )
1 cycrow 1437
				{
182 cycrow 1438
					for(auto itr = readText.begin(); itr != readText.end(); itr++)
1 cycrow 1439
					{
182 cycrow 1440
						String ^key = _US((*itr)->str);
1 cycrow 1441
						if ( catText->ContainsKey(key) )
182 cycrow 1442
							catText[key] = _US((*itr)->data);
1 cycrow 1443
						else
182 cycrow 1444
							catText->Add(key, _US((*itr)->data));
1 cycrow 1445
					}
1446
				}
1447
			}
1448
 
217 cycrow 1449
			Utils::WStringList list;
224 cycrow 1450
			if (m_pP->loadShipData(_WS(ofd->FileName), list))
1 cycrow 1451
			{
1452
				LoadShip ^ls = gcnew LoadShip();
182 cycrow 1453
				for(auto itr = list.begin(); itr != list.end(); itr++)
1 cycrow 1454
				{
217 cycrow 1455
					int tId = (*itr)->data.token(L";", 7).toInt();
1 cycrow 1456
					String ^name;
1457
					if ( catText->ContainsKey(Convert::ToString(tId)) )
1458
						name = Convert::ToString(catText[Convert::ToString(tId)]);
1459
					else
1460
						name = ((Form1 ^)this->MdiParent)->FindText(-1, 17, tId);
217 cycrow 1461
					String ^text = ((Form1 ^)this->MdiParent)->FindText(-1, 1266, (*itr)->data.token(L";", 46).toInt()) + " " + name;
1462
					int variation = (*itr)->data.token(L";", 51).toInt();
1 cycrow 1463
					if ( variation )
1464
						text = text + " " + ((Form1 ^)this->MdiParent)->FindText(-1, 17, 10000 + variation);
182 cycrow 1465
					ls->AddShip(_US((*itr)->str), text);
1 cycrow 1466
				}
1467
 
1468
				if ( ls->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1469
				{
217 cycrow 1470
					Utils::WString data = list.findString(_WS(ls->GetData()));
182 cycrow 1471
					if (data.empty())
1 cycrow 1472
					{
217 cycrow 1473
						((CXspFile *)m_pPackage)->setShipData(data);
1474
						if ( ((CXspFile *)m_pPackage)->shipID().empty() )
1 cycrow 1475
						{
217 cycrow 1476
							Utils::WString id = data.tokens(L";", -2);
226 cycrow 1477
							while ( id.right(1) == L";" )
182 cycrow 1478
								id.truncate((int)id.length() - 1);
217 cycrow 1479
							((CXspFile *)m_pPackage)->setShipID(id);
182 cycrow 1480
							this->TextShipID->Text = _US(id);
1 cycrow 1481
						}
1482
 
217 cycrow 1483
						((CXspFile *)m_pPackage)->setShipData(data);
182 cycrow 1484
						this->TextShipData->Text = _US(data);
217 cycrow 1485
						this->NumTextID->Value = data.token(L";", 7).toInt();
1 cycrow 1486
						this->UpdateChanged();
1487
					}
1488
				}
1489
			}
1490
			else
1491
				MessageBox::Show(this, "Unable to find any ship entries, invalid/missing TShips?", "Error Loading", MessageBoxButtons::OK, MessageBoxIcon::Error);
1492
		}
1493
	}
1494
 
1495
	void PackageForm::EditShipParts(bool edit)
1496
	{
1497
		 CXspFile *xsp = (CXspFile *)m_pPackage;
1498
		 switch ( this->ComboShipPart->SelectedIndex )
1499
		 {
1500
			case 0:
1501
				{
1502
					AddShipPart ^component = gcnew AddShipPart((Form1 ^)this->MdiParent);
1503
					component->SetComponent(edit);
1504
 
1505
					if ( edit )
1506
					{
1507
						component->SetSection(m_pSelectedItem->Text);
1508
						component->SetSection2(m_pSelectedItem->SubItems[1]->Text);
1509
						component->SetData(m_pSelectedItem->SubItems[2]->Text);
1510
					}
1511
 
1512
					if ( component->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1513
					{
1514
						if ( edit )
216 cycrow 1515
							xsp->removeComponent(_WS(m_pSelectedItem->Text), _WS(m_pSelectedItem->SubItems[1]->Text), _WS(m_pSelectedItem->SubItems[2]->Text));
1516
						xsp->addComponent(_WS(component->GetSection()), _WS(component->GetSection2()), _WS(component->GetData()));
1 cycrow 1517
						if ( !edit )
1518
							this->UpdateShipPartList();
1519
						else
1520
						{
1521
							m_pSelectedItem->Text = component->GetSection();
1522
							m_pSelectedItem->SubItems[1]->Text = component->GetSection2();
1523
							m_pSelectedItem->SubItems[2]->Text = component->GetData();
1524
						}
1525
					}
1526
				}
1527
				break;
1528
			case 1:
1529
				{
1530
					AddShipPart ^dummy = gcnew AddShipPart((Form1 ^)this->MdiParent);
1531
					dummy->SetDummy(edit);
1532
 
1533
					if ( edit )
1534
					{
1535
						dummy->SetSection(m_pSelectedItem->Text);
1536
						dummy->SetData(m_pSelectedItem->SubItems[1]->Text);
1537
					}
1538
 
1539
					if ( dummy->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1540
					{
1541
						if ( edit )
216 cycrow 1542
							xsp->removeDummy(_WS(m_pSelectedItem->Text), _WS(m_pSelectedItem->SubItems[1]->Text));
1543
						xsp->addDummy(_WS(dummy->GetSection()), _WS(dummy->GetData()));
1 cycrow 1544
						if ( !edit )
1545
							this->UpdateShipPartList();
1546
						else
1547
						{
1548
							m_pSelectedItem->Text = dummy->GetSection();
1549
							m_pSelectedItem->SubItems[1]->Text = dummy->GetData();
1550
						}
1551
					}
1552
				}
1553
				break;
1554
 
1555
			case 2:
1556
				{
1557
					AddCockpit ^cockpit = gcnew AddCockpit();
1558
					if ( edit )
191 cycrow 1559
						cockpit->SetEdit(m_pSelectedItem->Text, _US(_WS(m_pSelectedItem->SubItems[2]->Text).token(L";", 8)), _WS(m_pSelectedItem->SubItems[2]->Text).token(L";", 9).toInt());
1 cycrow 1560
					if ( cockpit->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1561
					{
1562
						if ( !edit )
1563
						{
218 cycrow 1564
							xsp->newCockpit(_WS(cockpit->GetID()), _WS(cockpit->GetScene()), cockpit->GetMask());
1 cycrow 1565
							this->UpdateShipPartList();
1566
						}
1567
						else
1568
						{
218 cycrow 1569
							xsp->editCockpit(_WS(cockpit->GetID()), _WS(cockpit->GetScene()), cockpit->GetMask());
1570
							m_pSelectedItem->SubItems[2]->Text = _US(xsp->getCockpitData(_WS(cockpit->GetID())));
1 cycrow 1571
						}
1572
					}
1573
				}
1574
				break;
1575
 
1576
			case 3:
1577
				{
1578
					if ( edit )
1579
					{
191 cycrow 1580
						InputBox ^input2 = gcnew InputBox("Enter the filename for cut id: " + _US(_WS(m_pSelectedItem->Text).token(L";", 1)), _US(_WS(m_pSelectedItem->Text).token(L";", 2)));
1 cycrow 1581
						if ( input2->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1582
						{
216 cycrow 1583
							xsp->removeCutData(_WS(m_pSelectedItem->Text));
1584
							xsp->addCutData(_WS(m_pSelectedItem->Text).token(L";", 1) + L"; " + _WS(input2->GetInput()));
1 cycrow 1585
							this->UpdateShipPartList();
1586
						}
1587
					}
1588
					else
1589
					{
1590
						InputBox ^input = gcnew InputBox("Enter the cut id to add");
1591
						if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1592
						{
1593
							InputBox ^input2 = gcnew InputBox("Enter the filename for cut id: " + input->GetInput());
1594
							if ( input2->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1595
							{
216 cycrow 1596
								xsp->addCutData(_WS(input->GetInput() + L"; " + input2->GetInput()));
1 cycrow 1597
								this->UpdateShipPartList();
1598
							}
1599
						}
1600
					}
1601
				}
1602
				break;
1603
 
1604
			case 4:
1605
				{
1606
					AddShipPart ^dummy = gcnew AddShipPart((Form1 ^)this->MdiParent);
1607
					dummy->SetBodies(edit);
1608
 
1609
					if ( edit )
1610
					{
1611
						dummy->SetSection(m_pSelectedItem->Text);
1612
						dummy->SetData(m_pSelectedItem->SubItems[1]->Text);
1613
					}
1614
 
1615
					if ( dummy->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1616
					{
1617
						if ( edit )
224 cycrow 1618
							xsp->removeBodies(_WS(m_pSelectedItem->Text + ";" + m_pSelectedItem->SubItems[1]->Text));
1619
						xsp->addBodies(_WS(dummy->GetSection() + ";" + dummy->GetData()));
1 cycrow 1620
						if ( !edit )
1621
							this->UpdateShipPartList();
1622
						else
1623
						{
1624
							m_pSelectedItem->Text = dummy->GetSection();
1625
							m_pSelectedItem->SubItems[1]->Text = dummy->GetData();
1626
						}
1627
					}
1628
				}
1629
				break;
1630
 
1631
			case 5:
1632
				{
1633
					InputBox ^input = gcnew InputBox("Enter the animation data to add", (!edit) ? "" : m_pSelectedItem->Text);
1634
					input->Large();
1635
					if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1636
					{
1637
						if ( edit )
216 cycrow 1638
							xsp->removeAnimation(_WS(m_pSelectedItem->Text));
224 cycrow 1639
						xsp->addAnimation(_WS(input->GetInput()));
1 cycrow 1640
						this->UpdateShipPartList();
1641
					}
1642
				}
1643
				break;
1644
		 }
1645
	}
1646
 
197 cycrow 1647
	void PackageForm::DropGetDirectories(String ^dir, Utils::WStringList *list, bool packages)
1 cycrow 1648
	{
1649
		cli::array<String ^> ^dirList = IO::Directory::GetFileSystemEntries(dir);
1650
		for ( int j = 0; j < dirList->Length; j++ )
1651
		{
1652
			if ( IO::DirectoryInfo(dirList[j]).Exists )
1653
				this->DropGetDirectories(dirList[j], list, packages);
1654
			else
1655
			{
1656
				if ( packages )
197 cycrow 1657
					list->pushBack(_WS(dirList[j]), L"-1");
1 cycrow 1658
				else
197 cycrow 1659
					list->pushBack(_WS(dirList[j]), Utils::WString::Number(SPK::GetAutomaticFiletype(_WS(dirList[j]), NULL,false)));
1 cycrow 1660
			}
1661
		}
1662
	}
1663
 
1664
	void PackageForm::RemoveSelectedFiles()
1665
	{
1666
		CLinkList<C_File> removeFiles;
1667
		for ( int i = 0; i < ListFiles->SelectedItems->Count; i++ )
1668
		{
225 cycrow 1669
			int id = _WS(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).toInt();
1 cycrow 1670
			C_File *file = m_pPackage->GetFileList()->Get(id);
1671
			if ( m_pDisplayFile == file )
1672
				m_pDisplayFile = NULL;
1673
			removeFiles.push_back(file);
1674
		}
1675
 
1676
		if ( removeFiles.size() )
1677
		{
1678
			for ( C_File *f = removeFiles.First(); f; f = removeFiles.Next() )
172 cycrow 1679
				m_pPackage->removeFile(f);
175 cycrow 1680
			m_pPackage->updateSigned(false);
1 cycrow 1681
			this->UpdateFileList();
1682
			this->UpdateDisplayPic();
1683
			this->UpdateChanged();
1684
		}
1685
 
1686
		if ( !ListFiles->SelectedItems->Count )
1687
			this->ButRemoveFile->Enabled = false;
1688
	}
1689
 
1690
	String ^PackageForm::ExtractImport(String ^file, String ^type)
1691
	{
1692
		if ( String::Compare(IO::FileInfo(file).Extension, ".xml") == 0 )
1693
			return file;
1694
 
1695
		if ( String::Compare(IO::FileInfo(file).Extension, ".pck") == 0 )
1696
		{
224 cycrow 1697
			C_File F(_WS(file));
1 cycrow 1698
			F.UnPCKFile();
224 cycrow 1699
			if ( F.writeToFile(CPackages::tempDirectory() + L"tmp.dat"))
197 cycrow 1700
				return _US(CPackages::tempDirectory() + L"tmp.dat");
1 cycrow 1701
		}
1702
		else if ( String::Compare(IO::FileInfo(file).Extension, ".cat") == 0 )
1703
		{
1704
			CCatFile cat;
224 cycrow 1705
			if ( cat.open(_WS(file), L"", CATREAD_CATDECRYPT, false) == CATERR_NONE )
1 cycrow 1706
			{
224 cycrow 1707
				if ( cat.extractFile(_WS("types\\" + type + L".pck"), CPackages::tempDirectory() + L"tmp.dat"))
197 cycrow 1708
					return _US(CPackages::tempDirectory() + L"tmp.dat");
1 cycrow 1709
			}
1710
		}
1711
 
1712
		return "";
1713
	}
1714
 
94 cycrow 1715
	CGameDirectories *PackageForm::gameDirectories()
1 cycrow 1716
	{
94 cycrow 1717
		return ((Form1 ^)this->MdiParent)->gameDirectories();
1 cycrow 1718
	}
1719
 
1720
	void PackageForm::ImportData(String ^file, int type)
1721
	{
224 cycrow 1722
		CFileIO F(_WS(file));
52 cycrow 1723
		if ( !F.exists() )
1 cycrow 1724
			return;
1725
 
218 cycrow 1726
		std::vector<Utils::WString> lines;
173 cycrow 1727
		if(!F.readLines(lines))
1 cycrow 1728
			return;
1729
 
1730
		LoadShip ^load = gcnew LoadShip();
1731
 
1732
		int entryPos = 1;
1733
		int dataPos = 1;
1734
		int dataPos2 = 0;
1735
		bool sections = false;
218 cycrow 1736
		Utils::WString section;
1 cycrow 1737
		switch ( type )
1738
		{
1739
			case 2:
1740
				entryPos = 2;
1741
				dataPos = 19;
1742
				load->Cockpits();
1743
				break;
1744
			case 3:
1745
				dataPos2 = 2;
1746
				load->CutData();
1747
				break;
1748
			case 4:
1749
				sections = true;
1750
				entryPos = 2;
1751
				load->Bodies();
1752
				break;
1753
			case 1:
1754
				sections = true;
1755
				entryPos = 2;
1756
				dataPos = -1;
1757
				load->Dummies();
1758
				break;
1759
			case 0:
1760
				sections = true;
1761
				entryPos = 2;
1762
				dataPos = -1;
1763
				load->Components();
1764
				break;
1765
		}
1766
 
1767
		int entries2 = 0;
1768
		int entries = -1;
218 cycrow 1769
		Utils::WStringList list;
1770
		Utils::WString data;
1 cycrow 1771
		int e = 0;
173 cycrow 1772
		for(auto itr = lines.begin(); itr != lines.end(); itr++)
1 cycrow 1773
		{
218 cycrow 1774
			Utils::WString str = itr->remove(9).remove('\r');
173 cycrow 1775
			str = str.removeFirstSpace();
1776
			if (str.empty())
1 cycrow 1777
				continue;
173 cycrow 1778
			if (str[0] == '/')
1 cycrow 1779
				continue;
1780
 
1781
			if ( entries == -1 || (entries <= 0 && sections) )
1782
			{
218 cycrow 1783
				entries = str.token(L";", entryPos).toInt();
1 cycrow 1784
				if ( sections )
1785
				{
218 cycrow 1786
					section = str.token(L";", 1);
173 cycrow 1787
					load->AddGroup(_US(section));
1 cycrow 1788
				}
1789
			}
1790
			else
1791
			{
1792
				if ( type == 4 )
1793
				{
218 cycrow 1794
					std::vector<Utils::WString> strs;
1795
					if(str.tokenise(L";", strs))
1 cycrow 1796
					{
218 cycrow 1797
						for (size_t i = 0; i < strs.size(); i++ )
1 cycrow 1798
						{
173 cycrow 1799
							strs[i].removeFirstSpace();
1800
							if ( strs[i].empty() ) continue;
218 cycrow 1801
							Utils::WString id = strs[i].token(L";", dataPos);
173 cycrow 1802
							load->AddShip(_US(id), "");
218 cycrow 1803
							list.pushBack(id, Utils::WString::Number(e) + L" " + section + L";" + strs[i]);
1 cycrow 1804
							++e;
1805
							--entries;
1806
						}
1807
					}
1808
				}
1809
				else if ( type == 0 )
1810
				{
1811
					if ( entries2 )
1812
					{
173 cycrow 1813
						load->AddShip(_US(data), _US(str));
218 cycrow 1814
						list.pushBack(data, section + L";" + data + L";" + str);
1 cycrow 1815
						--entries2;
1816
					}
1817
					else
1818
					{
218 cycrow 1819
						data = str.token(L";", 1);
1820
						entries2 = str.token(L";", 2).toInt();
1 cycrow 1821
						++e;
1822
						--entries;
1823
					}
1824
				}
1825
				else
1826
				{
218 cycrow 1827
					Utils::WString id;
1 cycrow 1828
					if ( dataPos == -1 )
173 cycrow 1829
						id = str; 
1 cycrow 1830
					else
218 cycrow 1831
						id = str.token(L";", dataPos); 
1 cycrow 1832
 
1833
					if ( dataPos2 )
218 cycrow 1834
						load->AddShip(_US(id), _US(str.token(L";", dataPos2)));
1 cycrow 1835
					else
173 cycrow 1836
						load->AddShip(_US(id), "");
1 cycrow 1837
					if ( sections )
218 cycrow 1838
						list.pushBack(id, Utils::WString::Number(e) + L" " + section + L";" + str);
1 cycrow 1839
					else
218 cycrow 1840
						list.pushBack(id, Utils::WString::Number(e) + L" " + str);
1 cycrow 1841
					++e;
1842
					--entries;
1843
				}
1844
			}
1845
		}
1846
 
1847
		if ( load->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1848
		{
170 cycrow 1849
			for(auto itr = load->GetDataList()->begin(); itr != load->GetDataList()->end(); itr++)
1 cycrow 1850
			{
216 cycrow 1851
				Utils::WString data = list.findString((*itr)->str);
173 cycrow 1852
				if (!data.empty())
1 cycrow 1853
				{
1854
					switch ( type )
1855
					{
1856
						case 0:
216 cycrow 1857
							((CXspFile *)m_pPackage)->addComponent(data.token(L";", 1), data.token(L";", 2), data.tokens(L";", 3));
1 cycrow 1858
							break;
1859
						case 2:
216 cycrow 1860
							((CXspFile *)m_pPackage)->addCockpit(data.tokens(L" ", 2), 0, -1, data.token(L" ", 1).toInt());
1 cycrow 1861
							break;
1862
						case 3:
216 cycrow 1863
							((CXspFile *)m_pPackage)->addCutData(data.tokens(L" ", 2));
1 cycrow 1864
							break;
1865
						case 4:
216 cycrow 1866
							((CXspFile *)m_pPackage)->addBodies(data.tokens(L" ", 2));
1 cycrow 1867
							break;
1868
						case 1:
216 cycrow 1869
							((CXspFile *)m_pPackage)->addDummy(data.tokens(L" ", 2).token(L";", 1), data.tokens(L" ", 2).tokens(L";", 2));
1 cycrow 1870
							break;
1871
					}
1872
				}
1873
			}
1874
 
1875
			this->UpdateShipPartList();
1876
			this->UpdateChanged();
1877
		}
1878
	}
1879
 
1880
	void PackageForm::ImportAnimations(String ^file)
1881
	{
224 cycrow 1882
		CFileIO F(_WS(file));
52 cycrow 1883
		if ( !F.exists() )
1 cycrow 1884
			return;
1885
 
212 cycrow 1886
		Utils::WStringList lines;
170 cycrow 1887
		if(!F.readLines(lines))
1 cycrow 1888
			return;
1889
 
212 cycrow 1890
		Utils::WStringList lOut;
170 cycrow 1891
		if ( CXspFile::ReadAnimations(lines, lOut, 0) )
1 cycrow 1892
		{
1893
			LoadShip ^load = gcnew LoadShip();
1894
			load->Animations();
170 cycrow 1895
			for(auto itr = lOut.begin(); itr != lOut.end(); itr++)
1896
				load->AddShip(_US((*itr)->str), "");
1 cycrow 1897
 
1898
			if ( load->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1899
			{
170 cycrow 1900
				((CXspFile *)m_pPackage)->addAnimation(*load->GetDataList());
1 cycrow 1901
				this->UpdateShipPartList();
1902
				this->UpdateChanged();
1903
			}
1904
		}
1905
	}
1906
 
1907
	void PackageForm::EditDepend()
1908
	{
1909
		 AddDepend ^depend = gcnew AddDepend();
1910
		 depend->SetEdit(m_pSelectedItem->Text, m_pSelectedItem->SubItems[1]->Text, m_pSelectedItem->SubItems[2]->Text);
1911
 
1912
		 bool builtin = false;
1913
		 if ( String::Compare("<package>", m_pSelectedItem->Text) == 0 && String::Compare("<author>", m_pSelectedItem->SubItems[1]->Text) == 0 )
1914
		 {
1915
			 builtin = true;
1916
			 depend->BuiltIn();
1917
		 }
1918
 
1919
		 if ( depend->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1920
		 {
1921
			 if ( builtin )
1922
			 {
203 cycrow 1923
				 SNeededLibrary *ns = m_pPackage->findPackageNeeded(L"<package>", L"<author>");
1 cycrow 1924
				 if ( ns )
204 cycrow 1925
					 ns->sMinVersion = _WS(depend->GetVersion());
1 cycrow 1926
			 }
1927
			 else
1928
			 {
203 cycrow 1929
				 m_pPackage->removePackageNeeded(_WS(m_pSelectedItem->Text), _WS(m_pSelectedItem->SubItems[1]->Text));
204 cycrow 1930
				 m_pPackage->addNeededLibrary(_WS(depend->GetName()), _WS(depend->GetAuthor()), _WS(depend->GetVersion()));
1 cycrow 1931
			 }
1932
			 this->UpdateDependacies();
1933
			 this->UpdateChanged();
1934
		 }
1935
	}
127 cycrow 1936
 
1937
	System::Void PackageForm::SetGame_Selected(System::Object^  sender, System::EventArgs^  e)
1938
	{
1939
		System::Windows::Forms::ToolStripMenuItem ^item = cli::safe_cast<System::Windows::Forms::ToolStripMenuItem ^>(sender);
1940
 
1941
		int done = 0;
1942
		if (ListFiles->SelectedItems->Count)
1943
		{
1944
			for (int i = 0; i < ListFiles->SelectedItems->Count; i++)
1945
			{
224 cycrow 1946
				int id = _WS(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).toInt();
127 cycrow 1947
				C_File *file = m_pPackage->GetFileList()->Get(id);
1948
				if (file) {
1949
					int iGame = Convert::ToInt32(item->Tag);
1950
					if(!iGame)
1951
						file->setGame(0);
1952
					else
1953
						file->setGame(1 << 31 | 1 << iGame);
1954
					++done;
1955
				}
1956
			}
1957
		}
1958
 
1959
		if (done) {
1960
			this->UpdateFileList();
1961
			this->UpdateChanged();
1962
		}
1963
	}
1964
	System::Void PackageForm::AddGame_Selected(System::Object^  sender, System::EventArgs^  e)
1965
	{
1966
		System::Windows::Forms::ToolStripMenuItem ^item = cli::safe_cast<System::Windows::Forms::ToolStripMenuItem ^>(sender);
1967
 
1968
		int done = 0;
1969
		if (ListFiles->SelectedItems->Count)
1970
		{
1971
			for (int i = 0; i < ListFiles->SelectedItems->Count; i++)
1972
			{
224 cycrow 1973
				int id = _WS(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).toInt();
127 cycrow 1974
				C_File *file = m_pPackage->GetFileList()->Get(id);
1975
				if (file) {
1976
					int iGame = Convert::ToInt32(item->Tag);
1977
					if (iGame)
1978
						file->setGame(file->game() | 1 << iGame | 1 << 31);
1979
					++done;
1980
				}
1981
			}
1982
		}
1983
 
1984
		if (done) {
1985
			this->UpdateFileList();
1986
			this->UpdateChanged();
1987
		}
1988
	}
1989
	System::Void PackageForm::RemoveGame_Selected(System::Object^  sender, System::EventArgs^  e)
1990
	{
1991
		System::Windows::Forms::ToolStripMenuItem ^item = cli::safe_cast<System::Windows::Forms::ToolStripMenuItem ^>(sender);
1992
 
1993
		int done = 0;
1994
		if (ListFiles->SelectedItems->Count)
1995
		{
1996
			for (int i = 0; i < ListFiles->SelectedItems->Count; i++)
1997
			{
224 cycrow 1998
				int id = _WS(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).toInt();
127 cycrow 1999
				C_File *file = m_pPackage->GetFileList()->Get(id);
2000
				if (file) {
2001
					int iGame = Convert::ToInt32(item->Tag);
2002
					if (iGame)
2003
						file->setGame(file->game() & ~(1 << iGame));
2004
					++done;
2005
				}
2006
			}
2007
		}
2008
 
2009
		if (done) {
2010
			this->UpdateFileList();
2011
			this->UpdateChanged();
2012
		}
2013
	}
2014
}