Subversion Repositories spk

Rev

Rev 86 | Rev 89 | 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 "MainGui.h"
3
#include "ModSelector.h"
4
#include "PackageBrowser.h"
5
#include "InstallPackageDialog.h"
6
#include "CompareList.h"
7
#include "EditGlobals.h"
88 cycrow 8
#include "EditWares.h"
1 cycrow 9
#include "DownloadPackageList.h"
10
#include "FileLog.h"
11
#include "MessageBoxDetails.h"
12
#include <shellapi.h>
13
 
14
using System::Configuration::ApplicationSettingsBase;
15
 
16
#undef GetEnvironmentVariable
17
 
18
enum {LISTGROUP_INSTALLED, LISTGROUP_SHIP, LISTGROUP_FAKE, LISTGROUP_LIBRARY, LISTGROUP_MOD, LISTGROUP_ARCHIVE};
19
 
20
namespace PluginManager {
21
 
22
	void MainGui::CheckProtectedDir()
23
	{
24
		CyString dir;
25
		if ( m_pDirList->Head() ) {
26
			m_bDirLocked = false;
27
			dir = m_pDirList->Head()->str;
28
 
29
			// write a file in the directory
30
			String ^sDir = SystemStringFromCyString(dir.findreplace("/", "\\"));
31
			bool written = true;
32
			StreamWriter ^sw = nullptr;
33
			try {
34
				sw = System::IO::File::CreateText(sDir + "\\checklock.xpmtest");
35
				sw->WriteLine("can write");
36
			}	
37
			catch (System::Exception ^) {
38
				written = false;
39
			}
40
			finally	{
41
				if ( sw )
42
					delete (IDisposable ^)sw;
43
			}
44
 
45
			// check its there
46
			if ( written ) {
47
				written = false;
48
				cli::array<String ^> ^dirList = IO::Directory::GetFiles(sDir, "*.xpmtest");
49
				if ( dirList && dirList->Length ) {
50
					for ( int i = 0; i < dirList->Length; i++ ) {
51
						if ( IO::FileInfo(dirList[i]).Name == "checklock.xpmtest" ) {
52
							written = true;
53
							break;
54
						}
55
					}
56
				}
57
			}
58
 
59
			// remove it
60
			if ( !IO::File::Exists(sDir + "\\checklock.xpmtest") )
61
				written = false;
62
			else {
63
				try {
64
					IO::File::Delete(sDir + "\\checklock.xpmtest");
65
					if ( IO::File::Exists(sDir + "\\checklock.xpmtest") )
66
						written = false;
67
				}
68
				catch (System::Exception ^) {
69
					written = false;
70
				}
71
			}
72
 
73
			if ( !written ) {
74
				MessageBox::Show(this, "ERROR: The game directory:\n" + SystemStringFromCyString(dir) + "\n\nIs locked and unable to add/remove any plugins", "Directory Locked", MessageBoxButtons::OK, MessageBoxIcon::Error);
75
				m_bDirLocked = true;
76
			}
77
			else {
78
				dir = dir.findreplace("/", "\\");
79
				bool found = false;
80
 
81
				String ^folder = Environment::GetFolderPath(Environment::SpecialFolder::ProgramFiles);
82
				if ( dir.IsIn(CyStringFromSystemString(folder)) )
83
					found = true;
84
				else {
85
					folder = Environment::GetEnvironmentVariable("ProgramFiles(x86)");
86
					if ( dir.IsIn(CyStringFromSystemString(folder)) )
87
						found = true;
88
				}
89
				if ( !found ) {
90
					folder = Environment::GetEnvironmentVariable("ProgramFiles");
91
					if ( dir.IsIn(CyStringFromSystemString(folder)) )
92
						found = true;
93
				}
94
 
95
				if ( found ) {
96
					if ( !m_pPackages->IsSupressProtectedWarning() ) {
97
						if ( MessageBox::Show(this, "WARNING: The game directory:\n" + SystemStringFromCyString(dir) + "\n\nIs in a protected directory (" + SystemStringFromCyString(CFileIO(dir).GetDir().GetToken("/", 1, 2).findreplace("/", "\\")) + ")\n\nThis might cause problems with installing anything, its better to move to game elsewhere, or you may need to run the Plugin Manager with admin access rights\n\nWould you like to surpress this warning in the future?", "Protected Directory", MessageBoxButtons::YesNo, MessageBoxIcon::Warning) == Windows::Forms::DialogResult::Yes ) {
98
							m_pPackages->SurpressProtectedWarning();
99
						}
100
					}
101
				}
102
			}
103
		}
104
	}
105
 
106
	void MainGui::GetGameDirs(CyString &dir, bool askDir, bool askDirAddon)
107
	{
108
		if ( CDirIO(dir).Exists() )
109
		{
110
			CyString gameName = m_pPackages->GetGameName(dir);
111
			if ( !gameName.Empty() )
112
			{
113
				if ( !m_pDirList->FindString(dir) && !m_pRemovedDirList->FindString(dir) ) {
114
					int lang = m_pPackages->GetGameLanguage(dir);
115
					if ( !askDir || MessageBox::Show(this, "New Game Directory Found:\n" + SystemStringFromCyString(dir) + " [" + SystemStringFromCyString(gameName) + "]\n\nDo you wish to add this?", "Add New Game", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == Windows::Forms::DialogResult::Yes ) {
116
						if ( lang )
117
							m_pDirList->PushFront(dir, CyString::Number(lang) + "|" + gameName);
118
						else
119
							m_pDirList->PushFront(dir, gameName);
120
					}
121
					else {
122
						m_pRemovedDirList->PushBack(dir);
123
					}
124
				}
125
 
126
				// check for any addons
127
				CyStringList addons;
128
				if ( m_pPackages->GetGameAddons(addons, dir) ) {
129
					for ( SStringList *str = addons.Head(); str; str = str->next ) {
130
						CyString exe = CDirIO(dir).File(str->str);
131
						dir = CDirIO(dir).Dir(str->data);
132
						if ( CDirIO(dir).Exists() && !m_pDirList->FindString(dir) && !m_pRemovedDirList->FindString(dir) ) {
133
							gameName = m_pPackages->GetGameName(exe);
134
							if ( !gameName.Empty() ) {
135
								int lang = m_pPackages->GetGameLanguage(dir);
136
								if ( !askDirAddon || MessageBox::Show(this, "New Game Directory Found:\n" + SystemStringFromCyString(dir) + " [" + SystemStringFromCyString(gameName) + "]\n\nDo you wish to add this?", "Add New Game", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == Windows::Forms::DialogResult::Yes ) {
137
									if ( lang )
138
										m_pDirList->PushFront(dir, CyString::Number(lang) + "|" + gameName);
139
									else
140
										m_pDirList->PushFront(dir, gameName);
141
								}
142
								else {
143
									m_pRemovedDirList->PushBack(dir);
144
								}
145
							}
146
						}
147
					}
148
				}
149
			}
150
		}
151
	}
152
 
153
	void MainGui::UpdateDirList()
154
	{
155
		ComboDir->Items->Clear();
156
 
157
		if ( !m_pDirList || !m_pDirList->Head() )
158
			return;
159
 
160
		for ( SStringList *node = m_pDirList->Head(); node; node = node->next )
161
		{
162
			System::String ^str;
163
			if ( node->data.IsIn("|") )
164
				str = SystemStringFromCyString(node->str + " [" + node->data.GetToken("|", 2) + "] (Language: " + CPackages::ConvertLanguage(node->data.GetToken("|", 1, 1).ToInt()) + ")");
165
			else
166
				str = SystemStringFromCyString(node->str + " [" + node->data + "]");
167
			ComboDir->Items->Add(str);
168
 
169
			// first item 
170
			if ( node == m_pDirList->Head() )
171
				ComboDir->Text = str;
172
		}
173
 
174
		this->UpdateRunButton();
175
	}
176
 
177
	void MainGui::UpdateRunButton()
178
	{
179
		ButRun->Text = "Run: " + SystemStringFromCyString(m_pPackages->GetGameName());
180
 
56 cycrow 181
		CyString exe = m_pPackages->GetGameExe()->GetGameRunExe(m_pPackages->GetCurrentDirectory().ToString());
52 cycrow 182
		if ( CFileIO(exe).ExistsOld() )
1 cycrow 183
		{
184
			exe = exe.FindReplace("/", "\\");
185
			wchar_t wText[200];
186
			::MultiByteToWideChar(CP_ACP, NULL, (char *)exe.c_str(), -1, wText, exe.Length() + 1);
187
 
188
			System::Drawing::Icon ^myIcon;
189
			SHFILEINFO *shinfo = new SHFILEINFO();
190
 
191
			if ( FAILED(SHGetFileInfo(wText, 0, shinfo, sizeof(shinfo), SHGFI_ICON | SHGFI_LARGEICON)) )
192
			{
193
				if ( FAILED(SHGetFileInfo(wText, 0, shinfo, sizeof(shinfo), SHGFI_ICON | SHGFI_SMALLICON)) )
194
				{
195
					System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(MainGui::typeid));
196
					this->ButRun->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"ButRun.Image")));
197
				}
198
				else
199
				{
200
					myIcon = System::Drawing::Icon::FromHandle(IntPtr(shinfo->hIcon));
201
					ButRun->Image = myIcon->ToBitmap();
202
				}
203
			}
204
			else
205
			{
206
				myIcon = System::Drawing::Icon::FromHandle(IntPtr(shinfo->hIcon));
207
				ButRun->Image = myIcon->ToBitmap();
208
			}
209
 
210
			delete shinfo;
211
		}
212
	}
213
 
214
	void MainGui::_DisplayPackages(CBaseFile *currentParent, ListViewGroup ^useGroup)
215
	{
216
		CLinkList<CBaseFile> packageList;
217
 
218
		for ( CBaseFile *p = m_pPackages->FirstPackage(); p; p = m_pPackages->NextPackage() )
219
		{
220
			if ( p->IsMod() )
221
				continue;
50 cycrow 222
			if ( p->author().Compare("PluginManager") )
1 cycrow 223
				continue;
224
			// if thier parent is a library dont add unless top level
225
			if ( currentParent && p->GetParent() && p->GetParent()->GetType() == TYPE_SPK && ((CSpkFile *)p->GetParent())->IsLibrary() )
226
				continue;
227
			else if ( p->GetParent() == currentParent )
228
				packageList.push_back(p);
229
			// add any mod addons as the top level
230
			else if ( p->GetParent() && p->GetParent()->IsMod() && !currentParent && p->GetParent() == m_pPackages->GetEnabledMod() )
231
				packageList.push_back(p);
232
			// if thier parent is a library add at top level
233
			else if ( !currentParent && p->GetParent() && p->GetParent()->GetType() == TYPE_SPK && ((CSpkFile *)p->GetParent())->IsLibrary() )
234
				packageList.push_back(p);
235
		}
236
 
237
		array<SortPackage ^> ^aPackages = gcnew array<SortPackage ^>(packageList.size());
238
		array<System::String ^> ^aNames = gcnew array<System::String ^>(packageList.size());
239
 
240
		int i = 0;
241
		for ( CBaseFile *p = packageList.First(); p; p = packageList.Next(), i++ )
242
		{
243
			aPackages[i] = gcnew SortPackage(p);
244
			if ( m_iSortingColumn == SORT_AUTHOR ) // sort by author
50 cycrow 245
				aNames[i] = _US(p->author())->ToLower();
1 cycrow 246
			else if ( m_iSortingColumn == SORT_VERSION ) // sort by author
50 cycrow 247
				aNames[i] = _US(p->version())->ToLower();
1 cycrow 248
			else if ( m_iSortingColumn == SORT_CREATED ) // sort by author
50 cycrow 249
				aNames[i] = _US(p->creationDate().token("/", 3) + p->creationDate().token("/", 2) + p->creationDate().token("/", 1));
1 cycrow 250
			else if ( m_iSortingColumn == SORT_ENABLE ) // sort by author
251
			{
252
				if ( p->IsEnabled() )
253
					aNames[i] = SystemStringFromCyString(CyString::Number(1));
254
				else
255
					aNames[i] = SystemStringFromCyString(CyString::Number(0));
256
			}
257
			else if ( m_iSortingColumn == SORT_SIGNED ) // sort by author
258
			{
259
				if ( p->IsEnabled() )
260
					aNames[i] = SystemStringFromCyString(CyString::Number(1));
261
				else
262
					aNames[i] = SystemStringFromCyString(CyString::Number(0));
263
			}
264
			else if ( m_iSortingColumn == SORT_TYPE ) // sort by type
265
			{
266
				if ( p->GetType() == TYPE_XSP )
267
					aNames[i] = "Ship";
268
				else if ( p->GetType() == TYPE_ARCHIVE )
269
					aNames[i] = "- Archive -";
270
				else if ( p->GetType() == TYPE_SPK )
271
					aNames[i] = SystemStringFromCyString(((CSpkFile *)p)->GetScriptTypeString(m_pPackages->GetLanguage()));
272
				else
273
					aNames[i] = "";
274
			}
275
			else
276
				aNames[i] = SystemStringFromCyString(p->GetLanguageName(m_pPackages->GetLanguage()))->ToLower();
277
		}
278
 
279
		Array::Sort(aNames, aPackages);
280
 
281
		// now display
282
		for ( i = 0; i < aPackages->Length; i++ )
283
		{
284
			CBaseFile *p = (m_bSortingAsc) ? aPackages[i]->Package : aPackages[(aPackages->Length - 1 - i)]->Package;
285
			CyString name;
286
			if ( p->GetType() == TYPE_ARCHIVE )
50 cycrow 287
				name = CFileIO(p->filename()).GetFilename();
1 cycrow 288
			else
289
				name = p->GetLanguageName(m_pPackages->GetLanguage());
290
 
291
			int indent = 0;
292
			CBaseFile *parent = p;
293
 
294
			if ( p->GetParent() && p->GetParent()->GetType() == TYPE_SPK && ((CSpkFile *)p->GetParent())->IsLibrary() )
295
				indent = 0;
296
			else
297
			{
298
				while ( parent->GetParent() )
299
				{
300
					parent = parent->GetParent();
301
					++indent;
302
				}
303
 
304
				if ( p->GetParent() && p->GetParent() == m_pPackages->GetEnabledMod() )
305
					--indent;
306
			}
307
 
308
			ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(name));
86 cycrow 309
			item->UseItemStyleForSubItems = false;
1 cycrow 310
			item->IndentCount = (indent * 2);
50 cycrow 311
			item->SubItems->Add(_US(p->author()));
312
			item->SubItems->Add(_US(p->version()));
313
			item->SubItems->Add(_US(p->creationDate()));
1 cycrow 314
			if ( p->GetType() == TYPE_XSP )
315
				item->SubItems->Add("Ship");
316
			else if ( p->GetType() == TYPE_ARCHIVE )
317
				item->SubItems->Add("- Archive -");
318
			else if ( p->GetType() == TYPE_SPK )
319
			{
320
				CSpkFile *spk = (CSpkFile *)p;
321
				item->SubItems->Add(SystemStringFromCyString(spk->GetScriptTypeString(m_pPackages->GetLanguage())));
322
			}
323
			else
324
				item->SubItems->Add("");
325
 
86 cycrow 326
			if ( p->IsEnabled() ) {
1 cycrow 327
				item->SubItems->Add("Yes");
86 cycrow 328
				item->SubItems[item->SubItems->Count - 1]->ForeColor = Color::Green;
329
			}
330
			else {
1 cycrow 331
				item->SubItems->Add("No");
86 cycrow 332
				item->SubItems[item->SubItems->Count - 1]->ForeColor = Color::Red;
333
			}
1 cycrow 334
			if ( p->IsSigned() )
335
				item->SubItems->Add("Yes");
336
			else
337
				item->SubItems->Add("No");
338
			item->Tag = SystemStringFromCyString(CyString::Number(p->GetNum()));
339
 
340
			ListPackages->Items->Add(item);
341
 
342
			if ( useGroup )
343
				item->Group = useGroup;
344
			else
345
			{
346
				int addGroup = LISTGROUP_INSTALLED;
347
				if ( p->GetParent() && p->GetParent() == m_pPackages->GetEnabledMod() )
348
					addGroup = LISTGROUP_MOD;
349
				else if ( p->GetType() == TYPE_SPK && ((CSpkFile *)p)->IsLibrary() )
350
					addGroup = LISTGROUP_LIBRARY;
351
				else if ( p->GetType() == TYPE_SPK && ((CSpkFile *)p)->IsFakePatch() )
352
					addGroup = LISTGROUP_FAKE;
353
				else if ( p->GetType() == TYPE_XSP )
354
					addGroup = LISTGROUP_SHIP;
355
				else if ( p->GetType() == TYPE_ARCHIVE )
356
					addGroup = LISTGROUP_ARCHIVE;
357
 
358
				item->Group = ListPackages->Groups[addGroup];
359
			}
360
 
361
			CyString groupName = CyStringFromSystemString(item->Group->Header);
362
			if ( groupName.IsIn(" [") )
363
			{
364
				int enabled = groupName.GetToken(" [", 2, 2).GetToken("/", 1, 1).ToInt();
365
				int total = groupName.GetToken(" [", 2, 2).GetToken("/", 2, 2).GetToken("]", 1, 1).ToInt() + 1;
366
				if ( p->IsEnabled() ) ++enabled;
367
				groupName = groupName.GetToken(" [", 1, 1) + " [" + CyString::Number(enabled) + "/" + CyString::Number(total) + "]";
368
			}
369
			else
370
			{
371
				if ( p->IsEnabled() )
372
					groupName = groupName + " [1/1]";
373
				else
374
					groupName = groupName + " [0/1]";
375
			}
376
			item->Group->Header = SystemStringFromCyString(groupName);
377
 
378
			// get the icon
379
			item->ImageIndex = -1;
380
			if ( p->GetIcon() )
381
				PluginManager::DisplayListIcon(p, ListPackages, item);
382
 
383
			if ( item->ImageIndex == -1 )
384
			{
385
				if ( p->GetType() == TYPE_XSP )
386
					item->ImageKey = "ship";
387
				else if ( p->GetType() == TYPE_ARCHIVE )
388
					item->ImageKey = "archive";
389
				else if ( p->GetType() == TYPE_SPK && ((CSpkFile *)p)->IsLibrary() )
390
					item->ImageKey = "library";
391
				else if ( p->IsFakePatch() )
392
					item->ImageKey = "fake";
393
				else
394
					item->ImageKey = "package";
395
			}
396
 
397
			// check for any children
398
			this->_DisplayPackages(p, item->Group);
399
		}
400
	}
401
 
86 cycrow 402
	void MainGui::AddIconToPackages(String ^icon)
403
	{
404
		int index = this->imageList1->Images->IndexOfKey(icon + ".png");
405
		if ( index != -1 )
406
		{
407
			ListPackages->SmallImageList->Images->Add(icon, this->imageList1->Images[index]);
408
			ListPackages->LargeImageList->Images->Add(icon, this->imageList1->Images[index]);
409
		}
410
	}
411
 
1 cycrow 412
	void MainGui::UpdatePackages()
413
	{
414
		ListPackages->Items->Clear();
415
		ListPackages->Groups->Clear();
416
		ListPackages->SmallImageList = gcnew ImageList();
417
		ListPackages->LargeImageList = gcnew ImageList();
418
		ListPackages->LargeImageList->ImageSize = System::Drawing::Size(32, 32);
419
		ListPackages->LargeImageList->ColorDepth = Windows::Forms::ColorDepth::Depth32Bit;
420
		ListPackages->SmallImageList->ImageSize = System::Drawing::Size(16, 16);
421
		ListPackages->SmallImageList->ColorDepth = Windows::Forms::ColorDepth::Depth32Bit;
422
 
423
		int index = this->imageList1->Images->IndexOfKey("package.png");
424
		if ( index != -1 )
425
		{
426
			ListPackages->SmallImageList->Images->Add("package", this->imageList1->Images[index]);
427
			ListPackages->LargeImageList->Images->Add("package", this->imageList1->Images[index]);
428
		}
429
		index = this->imageList1->Images->IndexOfKey("ship.png");
430
		if ( index != -1 )
431
		{
432
			ListPackages->SmallImageList->Images->Add("ship", this->imageList1->Images[index]);
433
			ListPackages->LargeImageList->Images->Add("ship", this->imageList1->Images[index]);
434
		}
435
		index = this->imageList1->Images->IndexOfKey("fake.png");
436
		if ( index != -1 )
437
		{
438
			ListPackages->SmallImageList->Images->Add("fake", this->imageList1->Images[index]);
439
			ListPackages->LargeImageList->Images->Add("fake", this->imageList1->Images[index]);
440
		}
441
		index = this->imageList1->Images->IndexOfKey("library.png");
442
		if ( index != -1 )
443
		{
444
			ListPackages->SmallImageList->Images->Add("library", this->imageList1->Images[index]);
445
			ListPackages->LargeImageList->Images->Add("library", this->imageList1->Images[index]);
446
		}
447
 
448
		index = this->imageList1->Images->IndexOfKey("archive.png");
449
		if ( index != -1 )
450
		{
451
			ListPackages->SmallImageList->Images->Add("archive", this->imageList1->Images[index]);
452
			ListPackages->LargeImageList->Images->Add("archive", this->imageList1->Images[index]);
453
		}
454
 
86 cycrow 455
		AddIconToPackages("tick");
456
		AddIconToPackages("no");
457
 
1 cycrow 458
		ListViewGroup ^group = gcnew ListViewGroup("Installed Scripts", HorizontalAlignment::Left);
459
		ListPackages->Groups->Add(group);
460
		ListViewGroup ^shipGroup = gcnew ListViewGroup("Installed Ships", HorizontalAlignment::Left);
461
		ListPackages->Groups->Add(shipGroup);
462
		ListViewGroup ^fakeGroup = gcnew ListViewGroup("Fake Patches", HorizontalAlignment::Left);
463
		ListPackages->Groups->Add(fakeGroup);
464
		ListViewGroup ^libGroup = gcnew ListViewGroup("Script Libraries", HorizontalAlignment::Left);
465
		ListPackages->Groups->Add(libGroup);
466
		ListViewGroup ^modGroup = gcnew ListViewGroup("Current Mod Addons", HorizontalAlignment::Left);
467
		ListPackages->Groups->Add(modGroup);
468
		ListViewGroup ^arcGroup = gcnew ListViewGroup("Installed Archives", HorizontalAlignment::Left);
469
		ListPackages->Groups->Add(arcGroup);
470
 
471
		// sort the items
472
		if ( m_pPackages )
473
		{
474
			m_pPackages->AssignPackageNumbers();
475
			this->_DisplayPackages(NULL, nullptr);
476
		}
477
 
478
		PackageListSelected(ListPackages, gcnew System::EventArgs());
479
		ListPackages->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
480
 
481
		// update the status bar
482
		LabelStatus->Text = "Plugins Available: " + (m_pPackages->CountPackages(TYPE_BASE, false) - m_pPackages->CountBuiltInPackages(false))+ " (" + (m_pPackages->CountPackages(TYPE_BASE, true) - m_pPackages->CountBuiltInPackages(true)) + " Enabled)";
483
	}
484
 
485
	void MainGui::StartCheckTimer()
486
	{
487
		System::Windows::Forms::Timer ^timer = gcnew System::Windows::Forms::Timer();
488
		timer->Interval = 5000;
489
		timer->Tick += gcnew System::EventHandler(this, &MainGui::TimerEvent_CheckFile);
490
		timer->Start();
491
	}
492
 
493
 
494
	//
495
	// Update Controls
496
	// Updates any additional controls, ie adding columns to package list
497
	//
498
	void MainGui::UpdateControls()
499
	{
500
		// Package List Columns
501
		int csize = ListPackages->Width - 200 - 5;
502
		int psize = ((csize * 7) / 10);
503
		int asize = ((csize * 3) / 10);
504
		if ( psize < 60 ) psize = 60;
505
		if ( asize < 60 ) asize = 60;
506
		ListPackages->Columns->Clear();
507
		ListPackages->Columns->Add("Package", psize, HorizontalAlignment::Left);
508
		ListPackages->Columns->Add("Author", asize, HorizontalAlignment::Left);
509
		ListPackages->Columns->Add("Version", 60, HorizontalAlignment::Right);
510
		ListPackages->Columns->Add("Updated", 80, HorizontalAlignment::Left);
511
		ListPackages->Columns->Add("Type", 100, HorizontalAlignment::Left);
512
		ListPackages->Columns->Add("Enabled", 60, HorizontalAlignment::Right);
513
		ListPackages->Columns->Add("Signed", 60, HorizontalAlignment::Right);
514
		ListPackages->FullRowSelect = true;
515
		ListPackages->Focus();
516
 
517
		if ( m_pPackages->IsVanilla() )
518
			m_pMenuBar->Vanilla();
519
		else
520
			m_pMenuBar->Modified();
521
	}
522
 
523
	//
524
	// Install a package
525
	// Called from either install button, or from command line
526
	//
527
	bool MainGui::InstallPackage(System::String ^file, bool straightAway, bool builtin, bool background)
528
	{
529
		bool errored = false;
530
 
531
		if ( file->Length )
532
		{
533
			int error;
534
			CBaseFile *package = m_pPackages->OpenPackage(CyStringFromSystemString(file), &error, 0, SPKREAD_NODATA, READFLAG_NOUNCOMPRESS);
535
			if ( error == INSTALLERR_NOMULTI )
536
			{
537
				CLinkList<CBaseFile> erroredList;
538
				m_pPackages->PrepareMultiPackage(CyStringFromSystemString(file), &erroredList, &error, 0);
539
				if ( erroredList.size() )
540
				{
541
					System::String ^modified;
542
					for ( CBaseFile *p = erroredList.First(); p; p = erroredList.Next() )
543
					{
544
						p->SetOverrideFiles(builtin);
545
						if ( m_pPackages->PrepareInstallPackage(p, false, false, IC_MODIFIED) != INSTALLCHECK_OK )
546
						{
547
							modified += SystemStringFromCyString(p->GetFullPackageName(m_pPackages->GetLanguage()));
548
							modified += "\n";
549
							errored = true;
550
						}
551
					}
552
 
553
					if ( errored )
554
						this->DisplayMessageBox(false, "Installing", "Currently in Vanilla Mode, Package is not an Vanilla Package\n\n" + modified + "\nSwitch to modified mode if you wish to install this package", MessageBoxButtons::OK, MessageBoxIcon::Question);
555
				}
556
			}
557
			else if ( !package )
558
			{
559
				System::String ^errorStr;
560
				switch ( error )
561
				{
562
					case INSTALLERR_OLD:
563
						errorStr = "File is in old format no longer supported";
564
						break;
565
					case INSTALLERR_NOEXIST:
566
						errorStr = "file doesn't exist";
567
						break;
568
					case INSTALLERR_INVALID:
569
						errorStr = "Invalid package file";
570
						break;
571
					case INSTALLERR_NOSHIP:
572
						errorStr = "Ship Packages are currently not supported";
573
						break;
574
					case INSTALLERR_VERSION:
575
						errorStr = "Package file was created in a newer version, unable to open";
576
						break;
577
 
578
					default:
579
						errorStr = "Unknown Error";
580
				}
581
 
582
				if ( !builtin )
583
					this->DisplayMessageBox(false, "Open Package Error", "Error Opening: " + file + "\n" + errorStr, MessageBoxButtons::OK, MessageBoxIcon::Stop);
584
				errored = true;
585
			}
586
			else
587
			{
588
				if ( builtin )
589
				{
590
					package->SetOverrideFiles(builtin);
591
					if ( m_pPackages->PrepareInstallPackage(package, false, false, IC_WRONGGAME|IC_WRONGVERSION|IC_OLDVERSION) != INSTALLCHECK_OK )
592
						errored = true;
593
				}
594
				else
595
				{
596
					int errorNum = m_pPackages->PrepareInstallPackage(package, false, false, IC_ALL);
597
					if ( errorNum != INSTALLCHECK_OK )
598
					{
599
						if ( errorNum == INSTALLCHECK_NOSHIP )
600
						{
601
							this->DisplayMessageBox(false, "No Ships", "Ships are not supported for " + SystemStringFromCyString(m_pPackages->GetGameName()), MessageBoxButtons::OK, MessageBoxIcon::Stop);
602
							errored = true;
603
						}
604
						else if ( m_pPackages->PrepareInstallPackage(package, false, false, IC_MODIFIED) != INSTALLCHECK_OK )
605
						{
606
							this->DisplayMessageBox(false, "Installing", "Currently in Vanilla Mode, Package is not an Vanilla Package\n" + SystemStringFromCyString(package->GetLanguageName(m_pPackages->GetLanguage())) + "\n\nSwitch to modified mode if you wish to install this package", MessageBoxButtons::OK, MessageBoxIcon::Question);
607
							errored = true;
608
						}
609
					}
610
 
611
					// check for compatabilities
612
					CLinkList<CBaseFile> packages;
613
					int compat = m_pPackages->CheckCompatabilityAgainstPackages(package, NULL, &packages);
614
					if ( compat )
615
					{
616
						String ^message = "\nConflicts with:\n";
617
						for ( CBaseFile *p = packages.First(); p; p = packages.Next() )
618
							message += SystemStringFromCyString(p->GetFullPackageName(m_pPackages->GetLanguage())) + "\n";
619
 
620
						if ( MessageBox::Show(this, SystemStringFromCyString(package->GetFullPackageName(m_pPackages->GetLanguage())) + ":\nIncompatabilities found with installed fake patches\n" + message + "\n\nDo you still wish to install?", "Packages Incompatable", MessageBoxButtons::YesNo, MessageBoxIcon::Warning) != Windows::Forms::DialogResult::Yes )
621
						{
622
							m_pPackages->RemovePreparedInstall(package);
623
							errored = true;
624
						}
625
					}
626
				}
627
 
628
				// not installing
629
				if ( errored )
630
				{
631
					delete package;
632
					package = NULL;
633
				}
634
			}
635
		}
636
 
637
		if ( errored )
638
		{
639
			this->Enabled= true;
640
			this->ProgressBar->Hide();
641
			return false;
642
		}
643
 
644
		// start installing
645
		if ( straightAway )
646
			return this->StartInstalling(builtin, background);
647
 
648
		return true;
649
	}
650
 
651
	void MainGui::DoUninstall()
652
	{
653
		m_pPi = gcnew PackageInstalled("Uninstall Packages");
654
 
655
		CLinkList<CBaseFile> packageList;
656
		CLinkList<CBaseFile> disableList;
657
 
658
		if ( m_pPackages->UninstallPreparedPackages(m_pFileErrors, 0, &packageList, &disableList) )
659
		{
660
			CyString sDisplay;
661
			CyString sAfterText;
662
			for ( CBaseFile *p = packageList.First(); p; p = packageList.Next() )
663
			{
664
				sAfterText = m_pPackages->GetUninstallAfterText(p);
50 cycrow 665
				m_pPi->AddPackageWithGroup(SystemStringFromCyString(p->GetLanguageName(m_pPackages->GetLanguage())), _US(p->author()), _US(p->version()), (sAfterText.Empty() ? "Uninstalled" : SystemStringFromCyString(sAfterText)), "Uninstalled");
1 cycrow 666
				sDisplay = p->GetFullPackageName(m_pPackages->GetLanguage());
667
				delete p;
668
			}
669
			for ( CBaseFile *p = disableList.First(); p; p = disableList.Next() )
50 cycrow 670
				m_pPi->AddPackageWithGroup(SystemStringFromCyString(p->GetLanguageName(m_pPackages->GetLanguage())), _US(p->author()), _US(p->version()), "Disabled", "Dependants Disabled");
1 cycrow 671
			packageList.clear();			
672
 
673
			if ( m_pPi->PackageCount() == 1 )
674
			{
675
				if ( sAfterText.Empty() )
676
					this->DisplayMessageBox(true, "Uninstalled", "Package Uninstalled\n" + SystemStringFromCyString(sDisplay), MessageBoxButtons::OK, MessageBoxIcon::Information);
677
				else
678
					this->DisplayMessageBox(true, "Uninstalled", "Package Uninstalled\n" + SystemStringFromCyString(sDisplay) + "\n\n" + SystemStringFromCyString(sAfterText), MessageBoxButtons::OK, MessageBoxIcon::Information);
679
			}
680
			else
681
				m_bDisplayDialog = true;
682
		}
683
		else
684
			this->DisplayMessageBox(true, "Uninstall Error", "Error Uninstalling", MessageBoxButtons::OK, MessageBoxIcon::Stop);
685
	}
686
 
687
	void MainGui::DoDisable()
688
	{
689
		CLinkList<CBaseFile> packageList;
690
 
691
		System::String ^display;
692
		m_pPi = gcnew PackageInstalled("Enabled/Disabled Packages");
693
 
694
		if ( m_pPackages->GetNumPackagesInDisabledQueue() )
695
		{
696
			if ( m_pPackages->DisablePreparedPackages(0, 0, &packageList) )
697
			{
698
				for ( CBaseFile *p = packageList.First(); p; p = packageList.Next() )
699
				{
50 cycrow 700
					m_pPi->AddPackageWithGroup(SystemStringFromCyString(p->GetLanguageName(m_pPackages->GetLanguage())), _US(p->author()), _US(p->version()), "Disabled", "Disabled Packages");
1 cycrow 701
					display = "Package Disabled\n\n" + SystemStringFromCyString(p->GetFullPackageName(m_pPackages->GetLanguage()));
702
				}
703
			}
704
			else
705
				this->DisplayMessageBox(true, "Disable Error", "Error Disabling packages", MessageBoxButtons::OK, MessageBoxIcon::Stop);
706
		}
707
 
708
		packageList.clear();
709
		if ( m_pPackages->GetNumPackagesInEnabledQueue() )
710
		{
711
			if ( m_pPackages->EnablePreparedPackages(0, 0, &packageList) )
712
			{
713
				for ( CBaseFile *p = packageList.First(); p; p = packageList.Next() )
714
				{
50 cycrow 715
					m_pPi->AddPackageWithGroup(SystemStringFromCyString(p->GetLanguageName(m_pPackages->GetLanguage())), _US(p->author()), _US(p->version()), "Enabled", "Enable Packages");
1 cycrow 716
					display = "Package Enabled\n\n" + SystemStringFromCyString(p->GetFullPackageName(m_pPackages->GetLanguage()));
717
				}
718
			}
719
			else
720
				this->DisplayMessageBox(true, "Enable Error", "Error Enabling packages", MessageBoxButtons::OK, MessageBoxIcon::Stop);
721
		}
722
 
723
		if ( m_pPi->PackageCount() == 1 )
724
			this->DisplayMessageBox(true, "Packages Enabled/Disabled", display, MessageBoxButtons::OK, MessageBoxIcon::Information);
725
		else
726
		{
727
			m_bDisplayDialog = true;
728
		}
729
	}
730
 
731
	void MainGui::DoInstall(bool builtin, bool frombackground)
732
	{
733
		CLinkList<CBaseFile> erroredPackages;
734
		CLinkList<CBaseFile> installedPackages;
735
		if ( m_pPackages->InstallPreparedPackages(m_pFileErrors, 0, &erroredPackages, &installedPackages) )
736
		{
737
			if ( !builtin )
738
			{
739
				if ( installedPackages.size() == 1 && erroredPackages.size() == 0 )
740
				{
741
					CBaseFile *p = installedPackages.Front()->Data();
742
					CyString packageName = p->GetFullPackageName(m_pPackages->GetLanguage());
743
					CyString afterText = m_pPackages->GetInstallAfterText(p);
744
					if ( afterText.Empty() )
745
						this->DisplayMessageBox(frombackground, "Installed", "Package: " + SystemStringFromCyString(packageName) + " installed!\n\n", MessageBoxButtons::OK, MessageBoxIcon::Information);
746
					else
747
					{
748
						afterText.StripHTML();
749
						this->DisplayMessageBox(frombackground, "Installed", "Package: " + SystemStringFromCyString(packageName) + " installed!\n\n" + SystemStringFromCyString(afterText), MessageBoxButtons::OK, MessageBoxIcon::Information);
750
					}
751
				}
752
				else
753
				{
754
					m_pPi = gcnew PackageInstalled("Packages Installed");
755
 
756
					CyStringList packages;
757
					for ( CListNode<CBaseFile> *node = installedPackages.Front(); node; node = node->next() )
758
					{
759
						CBaseFile *p = node->Data();
760
						CyString packageName = p->GetFullPackageName(m_pPackages->GetLanguage());
761
						CyString afterText = m_pPackages->GetInstallAfterText(p);
762
 
763
						if ( afterText.Empty() )
764
							afterText = "Installed";
50 cycrow 765
						m_pPi->AddPackage(SystemStringFromCyString(packageName), _US(p->author()), _US(p->version()), SystemStringFromCyString(afterText));
1 cycrow 766
					}
767
					for ( CListNode<CBaseFile> *node = erroredPackages.Front(); node; node = node->next() )
768
					{
769
						CBaseFile *p = node->Data();
770
						CyString packageName = p->GetFullPackageName(m_pPackages->GetLanguage());
50 cycrow 771
						m_pPi->AddPackage(SystemStringFromCyString(packageName), _US(p->author()), _US(p->version()), SystemStringFromCyString("Failed to Install"));
1 cycrow 772
					}
773
 
774
					m_bDisplayDialog = true;
775
				}
776
			}
777
		}
778
		// no packages were installed
779
		else 
780
		{
781
			if ( !builtin )
782
			{
783
				if ( erroredPackages.size() == 1 )
784
				{
785
					CBaseFile *p = erroredPackages.Front()->Data();
786
					CyString packageName = p->GetFullPackageName(m_pPackages->GetLanguage());
787
					this->DisplayMessageBox(frombackground, "Error Installing", "Package: " + SystemStringFromCyString(packageName) + " failed to install!\nError: " + SystemStringFromCyString(CBaseFile::ErrorString(p->GetLastError(), p->GetLastErrorString())) + "\n", MessageBoxButtons::OK, MessageBoxIcon::Error);
788
				}
789
				else
790
				{
791
					m_pPi = gcnew PackageInstalled("Packages Failed To Install");
792
 
793
					CyStringList packages;
794
					for ( CListNode<CBaseFile> *node = erroredPackages.Front(); node; node = node->next() )
795
					{
796
						CBaseFile *p = node->Data();
797
						CyString packageName = p->GetFullPackageName(m_pPackages->GetLanguage());
50 cycrow 798
						m_pPi->AddPackage(SystemStringFromCyString(packageName), _US(p->author()), _US(p->version()), "Failed: " + SystemStringFromCyString(CBaseFile::ErrorString(p->GetLastError(), p->GetLastErrorString())));
1 cycrow 799
					}
800
 
801
					m_bDisplayDialog = true;
802
				}
803
			}
804
		}
805
 
806
		if ( !frombackground )
807
			this->Background_Finished();
808
	}
809
 
810
	void MainGui::ClearSelectedItems()
811
	{
812
		for ( int i = 0; i < this->ListPackages->Items->Count; i++ )
813
			this->ListPackages->Items[i]->Selected = false;
814
		PackageListSelected(ListPackages, gcnew System::EventArgs());
815
	}
816
 
817
	bool MainGui::StartInstalling(bool builtin, bool background, bool archive)
818
	{
819
		// no packages to install
820
		if ( !m_pPackages->GetNumPackagesInQueue() )
821
			return false;
822
 
823
		// clear selected
824
		this->ClearSelectedItems();
825
 
826
		// lets install them now
827
		CLinkList<CBaseFile> lCheckPackages;
828
		if ( m_pPackages->CheckPreparedInstallRequired(&lCheckPackages) )
829
		{
830
			for ( CListNode<CBaseFile> *pNode = lCheckPackages.Front(); pNode; pNode = pNode->next() )
831
			{
832
				CBaseFile *package = pNode->Data();
833
				CSpkFile *spk = (CSpkFile *)package;
834
 
835
				CyStringList missingList;
836
				if ( m_pPackages->GetMissingDependacies(package, &missingList) )
837
				{
838
					CyString requires;
839
					for ( SStringList *strNode = missingList.Head(); strNode; strNode = strNode->next )
840
					{
841
						if ( strNode->str.IsIn("|") )
842
							requires += strNode->str.GetToken("|", 1, 1) + " V" + strNode->str.GetToken("|", 2, 2) + " by " + strNode->data;
843
						else
844
							requires += strNode->str + " by " + strNode->data;
845
						requires += "\n";
846
					}
847
					this->DisplayMessageBox(false, "Installing", "Missing Package for " + SystemStringFromCyString(package->GetLanguageName(m_pPackages->GetLanguage())) + "\nRequires:\n" + SystemStringFromCyString(requires), MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
848
				}
849
			}
850
		}
851
 
852
		// no packages to install
853
		if ( !m_pPackages->GetNumPackagesInQueue() )
854
		{
855
			this->Enabled = true;
856
			this->ProgressBar->Hide();
857
			return false;
858
		}
859
 
860
		ProgressBar->Show();
861
		this->Enabled = false;
862
 
863
		if ( builtin )
864
		{
865
			if ( background )
866
				this->StartBackground(MGUI_BACKGROUND_INSTALLBUILTIN);
867
			else
868
				this->DoInstall(builtin, false);
869
		}
870
		else if ( archive )
871
		{
872
			if ( background )
873
				this->StartBackground(MGUI_BACKGROUND_INSTALL);
874
			else
875
				this->DoInstall(false, false);
876
		}
877
		else
878
		{
879
			InstallPackageDialog ^installDialog = gcnew InstallPackageDialog(m_pPackages);
880
			if ( installDialog->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
881
			{
882
				// no packages to install
883
				if ( !m_pPackages->GetNumPackagesInQueue() )
884
				{
885
					this->Enabled = true;
886
					this->ProgressBar->Hide();
887
					return false;
888
				}
889
				if ( background )
890
					this->StartBackground(MGUI_BACKGROUND_INSTALL);
891
				else
892
					this->DoInstall(false, false);
893
			}
894
			else
895
			{
896
				m_pPackages->RemovePreparedInstall(NULL);
897
				this->Enabled = true;
898
				this->ProgressBar->Hide();
899
				return false;
900
			}
901
		}
902
		return true;
903
	}
904
 
905
	bool MainGui::StartBackground(int type, System::String ^info)
906
	{
907
		if ( backgroundWorker1->IsBusy )
908
			return false;
909
		if ( m_bRunningBackground )
910
			return false;
911
 
912
		m_sBackgroundInfo = info;
913
		return this->StartBackground(type);
914
	}
915
 
916
	bool MainGui::StartBackground(int type)
917
	{
918
		if ( backgroundWorker1->IsBusy )
919
			return false;
920
		if ( m_bRunningBackground )
921
			return false;
922
 
923
		m_iBackgroundTask = type;
924
 
925
		backgroundWorker1->RunWorkerAsync();
926
		m_bRunningBackground = true;
927
		return true;
928
	}
929
 
930
	void MainGui::ChangeDirectory(CyString dir)
931
	{
932
		if ( m_pPackages->IsCurrentDir(dir) )
933
			return;
934
 
935
		if ( m_pPackages->IsLoaded() )
936
		{
937
			if ( m_pPackages->CloseDir(0, 0, true) )
938
			{
939
				// write the modname
940
				if ( !m_pPackages->GetModKey().Empty() )
941
					PluginManager::WriteRegistryValue(m_pPackages->GetModKey(), m_pPackages->GetSelectedModName());
942
				m_pPackages->Reset();
943
			}
944
			else
945
			{
946
				this->DisplayMessageBox(true, "Error", "unable to close directory", MessageBoxButtons::OK, MessageBoxIcon::Error);
947
				return;
948
			}
949
		}
950
 
951
		m_pPackages->Reset();
952
 
953
		if ( m_pPackages->Read(dir, 0) )
954
		{
955
			if ( m_iSaveGameManager == 1 )
956
				m_pPackages->RestoreSaves();
957
			m_pPackages->UpdatePackages();
958
			m_pPackages->ReadGameLanguage(true);
959
			this->UpdateRunButton();
960
			System::String ^mod = PluginManager::ReadRegistryValue(m_pPackages->GetModKey());
961
			m_pPackages->SetMod(CyStringFromSystemString(mod));
962
		}
963
		else
964
		{
965
			this->DisplayMessageBox(true, "Error", "unable to open new directory", MessageBoxButtons::OK, MessageBoxIcon::Error);
966
			this->Close();
967
		}
968
	}
969
 
970
	CBaseFile *MainGui::FindPackageFromList(ListViewItem ^item)
971
	{
972
		if ( !item )
973
			return NULL;
974
 
975
		System::String ^sNum = System::Convert::ToString(item->Tag);
976
		int iNum = CyStringFromSystemString(sNum).ToInt();
977
 
978
		CBaseFile *p = m_pPackages->GetPackageAt(iNum);
979
		return p;
980
	}
981
 
982
	void MainGui::FindPackagesOnline()
983
	{
984
		CyStringList servers;
985
		m_pPackages->FindAllServers(&servers);
986
		if ( servers.Empty() )
987
		{
988
			MessageBox::Show(this, "Found now web address to check for packages", "No Web Address", MessageBoxButtons::OK, MessageBoxIcon::Warning);
989
			return;
990
		}
991
 
992
		DownloadPackageList ^dpl = gcnew DownloadPackageList(m_pPackages, &servers);
993
		dpl->ShowDialog(this);
994
 
995
		if ( m_pPackages->AnyAvailablePackages() )
996
			MessageBox::Show(this, "Package update completed\n" + m_pPackages->GetAvailablePackageList()->size() + " packages have been added to the package browser", "Found Packages", MessageBoxButtons::OK, MessageBoxIcon::Information);
997
		else
998
			MessageBox::Show(this, "Unable to find any packages\n", "No Packages Found", MessageBoxButtons::OK, MessageBoxIcon::Warning);
999
	}
1000
 
1001
	//
1002
	// Event Handlers
1003
	//
1004
	void MainGui::SetupEventHandlers()
1005
	{
1006
		// setup Event Handlers
1007
		ButClose->Click += gcnew EventHandler(this, &PluginManager::MainGui::ClosedEvent);
1008
		ButInstall->Click += gcnew EventHandler(this, &PluginManager::MainGui::InstallEvent);
1009
		ButUninstall->Click += gcnew EventHandler(this, &PluginManager::MainGui::UninstallEvent);
1010
		ButDisable->Click += gcnew EventHandler(this, &PluginManager::MainGui::DisableEvent);
1011
		ListPackages->SelectedIndexChanged += gcnew EventHandler(this, &PluginManager::MainGui::PackageListSelected);
1012
		ListPackages->ColumnClick  += gcnew ColumnClickEventHandler(this, &PluginManager::MainGui::PackageListSort);
1013
		ComboDir->SelectedIndexChanged += gcnew EventHandler(this, &PluginManager::MainGui::ChangeDirectoryEvent);
1014
 
1015
 
1016
		// background worker
1017
		backgroundWorker1->DoWork += gcnew DoWorkEventHandler( this, &MainGui::Background_DoWork );
1018
		backgroundWorker1->RunWorkerCompleted += gcnew RunWorkerCompletedEventHandler( this, &MainGui::Background_Finished );
1019
		backgroundWorker1->ProgressChanged += gcnew ProgressChangedEventHandler( this, &MainGui::Background_Progress );
1020
 
1021
		// auto update
1022
		backgroundUpdater->DoWork += gcnew DoWorkEventHandler( this, &MainGui::Updater_DoWork );
1023
		backgroundUpdater->RunWorkerCompleted += gcnew RunWorkerCompletedEventHandler( this, &MainGui::Updater_Finished );
1024
	}
1025
 
1026
	void MainGui::PackageListSort(System::Object ^Sender, ColumnClickEventArgs ^E)
1027
	{
1028
		if ( E->Column != m_iSortingColumn )
1029
		{
1030
			m_iSortingColumn = E->Column;
1031
			m_bSortingAsc = true;
1032
		}
1033
		else
1034
			m_bSortingAsc = !m_bSortingAsc;
1035
		this->UpdatePackages();
1036
	}
1037
 
1038
	void MainGui::PackageListSelected(System::Object ^Sender, System::EventArgs ^E)
1039
	{
1040
		// is there any selected items
1041
		this->PictureDisplay->Image = nullptr;
1042
		this->PanelDisplay->Hide();
1043
		TextDesc->Text = "";
1044
		bool buttonEnabled = false;
1045
		if ( ListPackages->SelectedItems->Count )
1046
		{
1047
			buttonEnabled = true;
1048
 
1049
			ListView::SelectedListViewItemCollection^ selected = this->ListPackages->SelectedItems;
1050
			System::Collections::IEnumerator^ myEnum = selected->GetEnumerator();
1051
			while ( myEnum->MoveNext() )
1052
			{
1053
				CBaseFile *p = this->FindPackageFromList(safe_cast<ListViewItem ^>(myEnum->Current));
1054
				if ( p )
1055
				{
1056
					if ( p->IsEnabled() )
1057
						ButDisable->Text = "Disable";
1058
					else
1059
						ButDisable->Text = "Enable";
48 cycrow 1060
					if ( !p->description().empty() )	TextDesc->Text = _US(p->description().findReplace("<br>", "\n").stripHtml());
1 cycrow 1061
 
1062
					this->PictureDisplay->Show();
1063
					bool addedIcon = false;
1064
					C_File *picFile = p->GetFirstFile(FILETYPE_ADVERT);
1065
					if ( picFile )
1066
					{
1067
						System::String ^pic = SystemStringFromCyString(picFile->GetFilePointer());
1068
						if ( System::IO::File::Exists(pic) )
1069
						{
1070
							Bitmap ^myBitmap = gcnew Bitmap(pic);
1071
							if ( myBitmap )
1072
							{
1073
								this->PictureDisplay->Image = dynamic_cast<Image ^>(myBitmap);
1074
								addedIcon = true;
1075
							}
1076
						}
1077
					}
1078
 
1079
					if ( !addedIcon )
1080
					{
1081
 
1082
						System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(MainGui::typeid));
1083
						this->PictureDisplay->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"PictureDisplay.Image")));
1084
					}
1085
 
1086
					if ( p->GetType() != TYPE_ARCHIVE )
1087
						this->PanelDisplay->Show();
1088
				}	
1089
			}				
1090
		}
1091
 
1092
		// enable/disable the buttons connected to the package list
1093
		ButUninstall->Enabled = buttonEnabled;
1094
		ButDisable->Enabled = buttonEnabled;
1095
	}
1096
 
1097
	void MainGui::AddDirectoryEvent(System::Object ^Sender, System::EventArgs ^E)
1098
	{
1099
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
1100
		ofd->Filter = "X-Universe Executable|";
1101
		String ^games = "";
1102
		for ( int i = 0; i < m_pPackages->GetGameExe()->GetNumGames(); i++ )
1103
		{
1104
			SGameExe *exe = m_pPackages->GetGameExe()->GetGame(i);
1105
			if ( i ) ofd->Filter += ";";
1106
			ofd->Filter += SystemStringFromCyString(exe->sExe);
1107
			games += "|" + SystemStringFromCyString(exe->sName) + "|" + SystemStringFromCyString(exe->sExe);
1108
		}
1109
		ofd->Filter += games;
1110
		ofd->FilterIndex = 1;
1111
		ofd->RestoreDirectory = true;
1112
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1113
		{
68 cycrow 1114
			CyString file = CyStringFromSystemString(ofd->FileName);
1 cycrow 1115
			CyString dir = CyStringFromSystemString(IO::FileInfo(ofd->FileName).DirectoryName);
1116
			// check its a valid directory
1117
			if ( !dir.Empty() )
1118
			{
68 cycrow 1119
				CyString gameName = m_pPackages->GetGameName(file);
1 cycrow 1120
				if ( gameName.Empty() )
1121
					this->DisplayMessageBox(false, "Add Directory Error", "No X-Universe game found in folder:\n" + SystemStringFromCyString(dir), MessageBoxButtons::OK, MessageBoxIcon::Error);
1122
				else
1123
				{
1124
					// lets check if theres an old folder
83 cycrow 1125
					if ( m_pPackages->isOldDir(dir.ToString()) )
1 cycrow 1126
					{
1127
						if ( this->DisplayMessageBox(false, "Update Game Directory", "Game directory: " + SystemStringFromCyString(dir) + "\nIs currently being controled by the old plugin manager\nIf you continue, you will be unable to use the old version again\nDo you wish to continue?", MessageBoxButtons::YesNo, MessageBoxIcon::Question) != System::Windows::Forms::DialogResult::Yes )
1128
							return;
1129
					}
1130
					m_iBackgroundTask = MGUI_BACKGROUND_ADDDIR;
1131
					this->Enabled = false;
68 cycrow 1132
					CyString properDir = m_pPackages->GetProperDir(file);
1 cycrow 1133
					ComboDir->Items->Add(SystemStringFromCyString(properDir));
1134
					ComboDir->Text = SystemStringFromCyString(properDir);
1135
 
1136
					m_pRemovedDirList->Remove(properDir, true);
68 cycrow 1137
					GetGameDirs(dir, false, m_pPackages->GetAddonDir(file).Empty());
1 cycrow 1138
					/*int lang = m_pPackages->GetGameLanguage(dir);
1139
					if ( lang )
1140
						m_pDirList->PushFront(properDir, CyString::Number(lang) + "|" + gameName);
1141
					else
1142
						m_pDirList->PushFront(properDir, gameName);*/
1143
					this->StartBackground(MGUI_BACKGROUND_ADDDIR, SystemStringFromCyString(properDir));
1144
				}
1145
			}
1146
		}
1147
	}
1148
 
1149
	bool MainGui::EnablePackage(CBaseFile *p)
1150
	{
1151
		if ( !m_pPackages->PrepareEnablePackage(p) )
1152
		{
1153
			if ( m_pPackages->GetError() == PKERR_NOPARENT )
1154
				this->DisplayMessageBox(false, "Enable Error", "Error enabling package\n" + SystemStringFromCyString(p->GetFullPackageName(m_pPackages->GetLanguage())) + "\n\nParent mod is not enabled", MessageBoxButtons::OK, MessageBoxIcon::Warning);
1155
			else if ( m_pPackages->GetError() == PKERR_MODIFIED )
1156
				this->DisplayMessageBox(false, "Enable Error", "Error enabling package\n" + SystemStringFromCyString(p->GetFullPackageName(m_pPackages->GetLanguage())) + "\n\nPackage is modified and game is currently set to vanilla\nSwitch to modified mode to enable", MessageBoxButtons::OK, MessageBoxIcon::Warning);
1157
			else if ( m_pPackages->GetError() == PKERR_MISSINGDEP )
1158
			{
1159
				CyStringList depList;
1160
				m_pPackages->GetMissingDependacies(p, &depList, true);
1161
				CyString sDep;
1162
				for ( SStringList *strNode = depList.Head(); strNode; strNode = strNode->next )
1163
				{
1164
					if ( strNode->str.IsIn("|") )
1165
						sDep = strNode->str.GetToken("|", 1, 1) + " V" + strNode->str.GetToken("|", 2, 2) + " by " + strNode->data + "\n";
1166
					else
1167
						sDep = strNode->str + " by " + strNode->data + "\n";
1168
				}
1169
				this->DisplayMessageBox(false, "Enable Error", "Error enabling package\n" + SystemStringFromCyString(p->GetFullPackageName(m_pPackages->GetLanguage())) + "\n\nMissing Enabled Dependacies:\n" + SystemStringFromCyString(sDep), MessageBoxButtons::OK, MessageBoxIcon::Warning);
1170
			}
1171
			else
1172
				this->DisplayMessageBox(false, "Enable Error", "Error enabling package\n" + SystemStringFromCyString(p->GetFullPackageName(m_pPackages->GetLanguage())) + "\n\nUnknown Error", MessageBoxButtons::OK, MessageBoxIcon::Warning);
1173
			return false;
1174
		}
1175
		return true;
1176
	}
1177
 
1178
	void MainGui::DisableList(ArrayList ^List)
1179
	{
1180
		bool skipShips = false;
1181
		int count = 0;
1182
 
1183
		for ( int i = 0; i < List->Count; i++ )
1184
		{
1185
			CBaseFile *p = this->FindPackageFromList(cli::safe_cast<ListViewItem ^>(List[i]));
1186
			if ( p )
1187
			{
1188
				if ( p->IsEnabled() )
1189
				{
1190
					if ( p->GetType() == TYPE_SPK && ((CSpkFile *)p)->IsLibrary() )
1191
					{
1192
						if ( this->DisplayMessageBox(false, "Disable Library", "Package: " + SystemStringFromCyString(p->GetFullPackageName(m_pPackages->GetLanguage())) + "\nThis is a library package and might be required for other installed packages\nDo you still wish to disable it?", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::No )
1193
							continue;
1194
					}
1195
					if ( p->GetType() == TYPE_XSP )
1196
					{
1197
						if ( !this->DisplayTip(TIPSECTION_YESNO, TIP_SHIPDISABLE) )
1198
							skipShips = true;
1199
 
1200
						if ( skipShips )
1201
							continue;
1202
					}
1203
 
1204
					m_pPackages->PrepareDisablePackage(p);
1205
					++count;
1206
				}
1207
				else
1208
				{
1209
					this->EnablePackage(p);
1210
					++count;
1211
				}
1212
			}
1213
		}
1214
 
1215
		if ( count )
1216
		{
1217
			this->Enabled = false;
1218
			this->StartBackground(MGUI_BACKGROUND_DISABLE);
1219
		}
1220
	}
1221
 
1222
	void MainGui::DisableEvent(System::Object ^Sender, System::EventArgs ^E)
1223
	{
1224
		if ( !ListPackages->SelectedItems->Count )
1225
			return;
1226
 
1227
		bool skipShips = false;
1228
 
1229
		ListView::SelectedListViewItemCollection^ selected = this->ListPackages->SelectedItems;
1230
		System::Collections::IEnumerator^ myEnum = selected->GetEnumerator();
1231
		int count = 0;
1232
		ArrayList ^List = gcnew ArrayList();
1233
 
1234
		while ( myEnum->MoveNext() )
1235
			List->Add(safe_cast<ListViewItem ^>(myEnum->Current));
1236
 
1237
		if ( List->Count )
1238
			this->DisableList(List);
1239
	}
1240
 
1241
	void MainGui::PackageBrowserEvent(System::Object ^Sender, System::EventArgs ^E)
1242
	{
1243
		this->Enabled = false;
1244
		PackageBrowser ^mod = gcnew PackageBrowser(m_pPackages, this->imageList1);
1245
		if ( !mod->AnyPackages() )
1246
		{
1247
			System::String ^game;
1248
			if ( m_pDirList && m_pDirList->Count() && m_pDirList->Head() )
1249
			{
1250
				CyString sGame = m_pDirList->Head()->data;
1251
				if ( sGame.IsIn("|") )
1252
					sGame = sGame.GetToken("|", 2);
1253
				game = SystemStringFromCyString(sGame);
1254
			}
1255
			this->DisplayMessageBox(false, "No Available Packages", "No available packages found for " + game, MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
1256
 
1257
			this->Enabled = true;
1258
			return;
1259
		}
1260
 
1261
		if ( m_bDirLocked ) {
1262
			this->DisplayLocked(false);
1263
			this->Enabled = true;
1264
			return;
1265
		}
1266
 
1267
		mod->SetExperimental(m_bExperimental);
1268
		mod->SetCheat(m_bCheat);
1269
		mod->SetShips(m_bShips);
1270
		if ( m_pPackages->IsVanilla() )
1271
			mod->SetSigned(true);
1272
		else
1273
			mod->SetSigned(m_bSigned);
1274
		mod->SetDownload(m_bDownloadable);
1275
		mod->UpdatePackages();
1276
		System::Windows::Forms::DialogResult result = mod->ShowDialog(this);
1277
 
1278
		m_bDownloadable = mod->IsDownload();
1279
		m_bCheat = mod->IsCheat();
1280
		m_bExperimental = mod->IsExperimental();
1281
		m_bShips = mod->IsShips();
1282
		m_bSigned = mod->IsSigned();
1283
 
1284
		bool doenable = true;
1285
		CBaseFile *p = mod->SelectedMod();
1286
		if ( result == System::Windows::Forms::DialogResult::OK )
1287
		{
1288
			if ( p )
1289
			{
50 cycrow 1290
				if ( this->InstallPackage(_US(p->filename()), true, false, true) )
1 cycrow 1291
					doenable = false;
1292
			}
1293
		}
1294
		else if ( result == System::Windows::Forms::DialogResult::Yes )
1295
			this->StartInstalling(false, true);
1296
 
1297
		this->Enabled = doenable;
1298
	}
1299
 
1300
	void MainGui::CloseEvent(System::Object ^Sender, FormClosingEventArgs ^E)
1301
	{
1302
		int h = this->Size.Height;
1303
		int w = this->Size.Width;
1304
	}
1305
 
1306
	void MainGui::DisplayLocked(bool inthread) 
1307
	{
1308
		this->DisplayMessageBox(inthread, "Directory Locked", "The current directory is locked and unable to make any changes\nYou may need to adjust the directory permissions", MessageBoxButtons::OK, MessageBoxIcon::Error);
1309
	}
1310
 
1311
	void MainGui::ModSelectorEvent(System::Object ^Sender, System::EventArgs ^E)
1312
	{
1313
		if ( m_pPackages->IsVanilla() )
1314
		{
1315
			this->DisplayMessageBox(false, "Mod Selector", "Currently in Vanilla Mode, You can only enable mods when in Modified Mode\n\nSwitch to modified mode if you wish to install mods", MessageBoxButtons::OK, MessageBoxIcon::Question);
1316
			return;
1317
		}
1318
		this->Enabled = false;
1319
		ModSelector ^mod = gcnew ModSelector(m_pPackages, this->imageList1);
1320
 
1321
		if ( !mod->AnyPackages() )
1322
		{
1323
			this->DisplayMessageBox(false, "Mod Selector", "No available mods have been found", MessageBoxButtons::OK, MessageBoxIcon::Warning);
1324
			this->Enabled = true;
1325
			return;
1326
		}
1327
 
1328
		if ( m_bDirLocked ) {
1329
			this->DisplayLocked(false);
1330
			this->Enabled = true;
1331
			return;
1332
		}
1333
 
1334
		if ( !m_bModSelectorDetails )
1335
		{
1336
			mod->HideDetails();
1337
			mod->Update();
1338
		}
1339
 
1340
		System::Windows::Forms::DialogResult result = mod->ShowDialog(this);
1341
		m_bModSelectorDetails = mod->ShowingDetails();
1342
 
1343
		// install the selected mod
1344
		bool reEnable = true;
1345
 
1346
		CBaseFile *p = mod->SelectedMod();
1347
		if ( result == System::Windows::Forms::DialogResult::OK )
1348
		{
1349
			if ( p )
1350
			{
1351
				// from file
1352
				if ( p->GetNum() < 0 )
1353
				{
1354
					if ( m_pPackages->GetEnabledMod() )
1355
						m_pPackages->DisablePackage(m_pPackages->GetEnabledMod(), 0, 0);
50 cycrow 1356
					if ( this->InstallPackage(_US(p->filename()), true, false, true) )
1 cycrow 1357
						reEnable = false;
1358
				}
1359
				// otherwise just enable it
1360
				else
1361
				{
1362
					if ( this->EnablePackage(p) )
1363
					{
1364
						this->StartBackground(MGUI_BACKGROUND_DISABLE);
1365
						reEnable = false;
1366
					}
1367
				}
1368
			}
1369
		}
1370
 
1371
		// install downloaded mods
1372
		else if ( result == Windows::Forms::DialogResult::Yes )
1373
			this->StartInstalling(false, true);
1374
 
1375
		// remove the current mod
1376
		else if ( result == System::Windows::Forms::DialogResult::Abort )
1377
		{
1378
			if ( m_pPackages->GetEnabledMod() )
1379
			{
1380
				CBaseFile *mod = m_pPackages->GetEnabledMod();
1381
				CyString message = mod->GetFullPackageName(m_pPackages->GetLanguage());
1382
				m_pPackages->DisablePackage(m_pPackages->GetEnabledMod(), 0, 0);			
1383
				this->DisplayMessageBox(false, "Mod Disabed", SystemStringFromCyString(message) + " has been disabled\nYour game is no longer using any mods\n", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
1384
			}
1385
		}
1386
 
1387
		// uninstall the selected mod
1388
		else if ( result == System::Windows::Forms::DialogResult::Retry )
1389
		{
1390
			if ( p && p->GetNum() >= 0 )
1391
			{
1392
				m_pPackages->PrepareUninstallPackage(p);
1393
				if ( m_pPackages->GetNumPackagesInQueue() )
1394
				{
1395
					reEnable = false;
1396
					this->StartBackground(MGUI_BACKGROUND_UNINSTALL);
1397
				}
1398
			}
1399
		}
1400
 
1401
		if ( reEnable )
1402
			this->Enabled = true;
1403
 
1404
		mod->RemovePackages();
1405
	}
1406
 
1407
	void MainGui::UninstallList(ArrayList ^List)
1408
	{
1409
		bool skipShips = false;
1410
 
1411
		for ( int i = 0; i < List->Count; i++ )
1412
		{
1413
			CBaseFile *p = this->FindPackageFromList(safe_cast<ListViewItem ^>(List[i]));
1414
			if ( p )
1415
			{
1416
				if ( p->GetType() == TYPE_XSP )
1417
				{
1418
					if ( !this->DisplayTip(TIPSECTION_YESNO, TIP_SHIPUNINSTALL) )
1419
						skipShips = true;
1420
 
1421
					if ( skipShips )
1422
						continue;
1423
				}
1424
 
46 cycrow 1425
				// display uninstall text
1426
				Utils::String beforeText = m_pPackages->GetUninstallBeforeText(p).ToString();
1427
				if ( !beforeText.empty() ) {
1428
					if ( this->DisplayMessageBox(false, "Uninstall Package", _US(p->GetFullPackageName(m_pPackages->GetLanguage()).ToString() + "\n" + beforeText + "\n\nDo you want to uninstall this package?"), MessageBoxButtons::YesNo, MessageBoxIcon::Question) != System::Windows::Forms::DialogResult::Yes )
1429
						continue;
1430
				}
1431
 
1 cycrow 1432
				m_pPackages->PrepareUninstallPackage(p);
1433
			}
1434
		}
1435
 
1436
		if ( m_pPackages->GetNumPackagesInQueue() )
1437
		{
1438
			this->Enabled = false;
1439
			this->StartBackground(MGUI_BACKGROUND_UNINSTALL);
1440
		}
1441
	}
1442
	void MainGui::UninstallEvent(System::Object ^Sender, System::EventArgs ^E)
1443
	{
1444
		if ( !ListPackages->SelectedItems->Count )
1445
			return;
1446
 
1447
		ArrayList ^List = gcnew ArrayList();
1448
 
1449
		ListView::SelectedListViewItemCollection^ selected = this->ListPackages->SelectedItems;
1450
		System::Collections::IEnumerator^ myEnum = selected->GetEnumerator();
1451
 
1452
		while ( myEnum->MoveNext() )
1453
			List->Add(safe_cast<ListViewItem ^>(myEnum->Current));
1454
 
1455
		this->UninstallList(List);
1456
	}
1457
 
1458
	void MainGui::ModifiedEvent(System::Object ^Sender, System::EventArgs ^E)
1459
	{
1460
		if ( m_bDirLocked ) {
1461
			this->DisplayLocked(false);
1462
			return;
1463
		}
1464
		if ( m_pPackages->IsVanilla() )
1465
		{
1466
			this->Enabled = false;
1467
			if ( this->DisplayMessageBox(false, "Modified Mode", "Enabling modified mode will allow you to use any modified content\nThis will however mark any games you save as modified and you will be unable to participate in Uplink\nAny current save games wil also be backed up and kept seperate from your modified save games\n\nDo you wish to enable modified mode?", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes )
1468
			{
1469
				if ( m_iSaveGameManager == 1 )
1470
				{
1471
					m_pPackages->BackupSaves(true);
1472
					m_pPackages->RestoreSaves(false);
1473
				}
1474
				m_pPackages->SetVanilla(false);
1475
				m_pMenuBar->Modified();
1476
				m_pPackages->PrepareEnableLibrarys();
1477
				m_pPackages->PrepareEnableFromVanilla();
1478
				this->StartBackground(MGUI_BACKGROUND_DISABLE);
1479
			}
1480
			else
1481
				this->Enabled = true;
1482
		}
1483
	}
1484
 
1485
	void MainGui::VanillaEvent(System::Object ^Sender, System::EventArgs ^E)
1486
	{
1487
		if ( m_bDirLocked ) {
1488
			this->DisplayLocked(false);
1489
			return;
1490
		}
1491
		if ( !m_pPackages->IsVanilla() )
1492
		{
1493
			this->Enabled = false;
1494
			if ( this->DisplayMessageBox(false, "Vanilla Mode", "Switching back to vanilla mode you will no longer be able to use any modifying packages, these will be disabled\nYour current save games will be backed up as modified saves, and any vanilla save games will be restored\n\nDo you wish to go back to Vanilla?", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes )
1495
			{
1496
				if ( m_iSaveGameManager == 1 )
1497
				{
86 cycrow 1498
					m_pPackages->BackupSaves(false);
1 cycrow 1499
					m_pPackages->RestoreSaves(true);
1500
				}
1501
				m_pPackages->SetVanilla(true);
1502
				m_pMenuBar->Vanilla();
1503
				m_pPackages->PrepareDisableForVanilla();
1504
				this->StartBackground(MGUI_BACKGROUND_DISABLE);
1505
			}
1506
			else
1507
				this->Enabled = true;
1508
		}
1509
	}
1510
 
1511
	void MainGui::InstallEvent(System::Object ^Sender, System::EventArgs ^E)
1512
	{
1513
		if ( m_bDirLocked ) {
1514
			this->DisplayLocked(false);
1515
			return;
1516
		}
1517
 
1518
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
1519
		ofd->Filter = "All (*.spk, *.xsp)|*.spk;*.xsp|Package Files (*.spk)|*.spk|Ship Files (*.xsp)|*.xsp";
1520
		ofd->FilterIndex = 1;
1521
		ofd->RestoreDirectory = true;
1522
		ofd->Multiselect = true;
1523
 
1524
		this->Enabled = false;
1525
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1526
		{
1527
			bool anytoinstall = false;
1528
			array<System::String ^> ^fileArray = ofd->FileNames;
1529
			for ( int i = 0; i < fileArray->Length; i++ )
1530
			{
1531
				System::String ^file = fileArray[i];
1532
				if ( this->InstallPackage(file, false, false, true) )
1533
					anytoinstall = true;
1534
			}
1535
 
1536
			if ( anytoinstall )
1537
				this->StartInstalling(false, true);
1538
		}
1539
		else
1540
		{
1541
			ProgressBar->Hide();
1542
			this->Enabled = true;
1543
		}
1544
	}
1545
 
1546
	void MainGui::CheckUnusedShared()
1547
	{
1548
		if ( m_pPackages->AnyUnusedShared() )
1549
		{
1550
			if ( this->DisplayMessageBox(false, "Remove Shared Files", "You have some unused shared files, would you like to remove these?", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes)
1551
				m_pPackages->RemoveUnusedSharedFiles();
1552
		}
1553
	}
1554
 
1555
	void MainGui::ChangeDirectoryEvent(System::Object ^Sender, System::EventArgs ^E)
1556
	{
1557
		if ( m_iBackgroundTask == MGUI_BACKGROUND_ADDDIR )
1558
			return;
1559
 
1560
		CyString dir = CyStringFromSystemString(ComboDir->Text);
1561
		if ( dir.NumToken(" [") )
1562
			dir = dir.GetToken(" [", 1, dir.NumToken(" [") - 1);
1563
 
1564
		if ( !m_pPackages->IsCurrentDir(dir) )
1565
		{
1566
			this->Enabled = false;
1567
			this->CheckUnusedShared();
1568
			this->StartBackground(MGUI_BACKGROUND_CHANGEDIR, SystemStringFromCyString(dir));
1569
		}
1570
	}
1571
 
1572
	void MainGui::Background_DoWork(System::Object ^Sender, DoWorkEventArgs ^E)
1573
	{
1574
		m_bDisplayMessage = false;
1575
		m_bDisplayDialog = false;
1576
 
1577
		switch ( m_iBackgroundTask )
1578
		{
1579
			case MGUI_BACKGROUND_INSTALL:
1580
				this->DoInstall(false, true);
1581
				break;
1582
			case MGUI_BACKGROUND_INSTALLBUILTIN:
1583
				this->DoInstall(true, true);
1584
				break;
1585
			case MGUI_BACKGROUND_UNINSTALL:
1586
				this->DoUninstall();
1587
				break;
1588
			case MGUI_BACKGROUND_DISABLE:
1589
				this->DoDisable();
1590
				break;
1591
			case MGUI_BACKGROUND_CHANGEDIR:
1592
			case MGUI_BACKGROUND_ADDDIR:
1593
				this->ChangeDirectory(CyStringFromSystemString(m_sBackgroundInfo));
1594
				break;
1595
			case MGUI_BACKGROUND_REMOVEDIR:
1596
				this->RemoveCurrentDirectory();
1597
		}
1598
	}
1599
 
1600
	void MainGui::Background_Finished()
1601
	{
1602
		ProgressBar->Hide();
1603
 
1604
		if ( m_bDisplayMessage )
1605
			MessageBox::Show(this, m_sMessageText, m_sMessageTitle, m_messageButtons, m_messageIcon);
1606
 
1607
		if ( m_bDisplayDialog )
1608
		{
1609
			if ( m_pPi->PackageCount() )
1610
			{
1611
				m_pPi->AdjustColumns();
1612
				m_pPi->ShowDialog(this);
1613
			}
1614
		}
1615
 
1616
		m_bDisplayDialog = false;
1617
		m_bDisplayMessage = false;
1618
 
1619
		if ( m_iBackgroundTask == MGUI_BACKGROUND_CHANGEDIR || m_iBackgroundTask == MGUI_BACKGROUND_ADDDIR )
1620
		{
1621
			// switch the dir list
1622
			if ( ComboDir->Text )
1623
			{
1624
				CyString dir = CyStringFromSystemString(ComboDir->Text);
1625
				if ( !dir.Empty() )
1626
				{
1627
					if ( (m_iBackgroundTask == MGUI_BACKGROUND_CHANGEDIR) && (dir.NumToken(" [")) )
1628
						dir = dir.GetToken(" [", 1, dir.NumToken(" [") - 1);
1629
					if ( m_pDirList->FindString(dir) )
1630
					{
1631
						CyString data = m_pDirList->FindString(dir)->data;
1632
						m_pDirList->Remove(dir, false);
1633
						m_pDirList->PushFront(dir, data);
1634
					}
1635
					else
1636
					{
1637
						int lang = m_pPackages->GetGameLanguage(dir);
1638
						if ( lang )
1639
							m_pDirList->PushFront(dir, CyString::Number(lang) + "|" + m_pPackages->GetGameName(dir));
1640
						else
1641
							m_pDirList->PushFront(dir, m_pPackages->GetGameName(dir));
1642
					}
1643
 
1644
					this->UpdateDirList();
1645
				}
1646
			}
1647
		}
1648
 
1649
		// display any files that failed
1650
		if ( m_iBackgroundTask == MGUI_BACKGROUND_INSTALL )
1651
		{
1652
			String ^files = "";
1653
			for ( SStringList *str = m_pFileErrors->Head(); str; str = str->next )
1654
			{
1655
				if ( str->data.ToInt() == SPKINSTALL_WRITEFILE_FAIL )
1656
				{
1657
					files += "\n";
1658
					files += SystemStringFromCyString(str->str);
1659
				}
1660
			}
1661
 
1662
			if ( files->Length )
1663
				MessageBox::Show(this, "These files failed to install\n" + files, "Failed Files", MessageBoxButtons::OK, MessageBoxIcon::Warning);
1664
		}
1665
 
1666
		switch ( m_iBackgroundTask )
1667
		{
1668
			case MGUI_BACKGROUND_CHANGEDIR:
1669
			case MGUI_BACKGROUND_ADDDIR:
1670
				this->UpdateControls();
1671
				this->UpdatePackages();
1672
				this->CheckProtectedDir();
1673
				m_bRunningBackground = false;
1674
				if ( this->UpdateBuiltInPackages() )
1675
					return;
1676
				break;
1677
 
1678
			case MGUI_BACKGROUND_INSTALL:
1679
			case MGUI_BACKGROUND_INSTALLBUILTIN:
1680
			case MGUI_BACKGROUND_UNINSTALL:
1681
			case MGUI_BACKGROUND_DISABLE:
1682
				this->UpdatePackages();
1683
				break;
1684
			case MGUI_BACKGROUND_REMOVEDIR:
1685
				ComboDir->Items->RemoveAt(0);
1686
				this->DisplayMessageBox(false, "Remove Directory", "Directory has been removed\n" + SystemStringFromCyString(m_pRemovedDirList->Tail()->str), MessageBoxButtons::OK, MessageBoxIcon::Information);
1687
				break;
1688
		}
1689
 
1690
		if ( m_iBackgroundTask == MGUI_BACKGROUND_ADDDIR )
1691
			this->DisplayMessageBox(false, "Add Game Folder", "Folder \"" + m_sBackgroundInfo + "\" added\nGame: " + SystemStringFromCyString(m_pPackages->GetGameName(CyStringFromSystemString(m_sBackgroundInfo))), MessageBoxButtons::OK, MessageBoxIcon::Information);
1692
 
1693
		else if ( m_iBackgroundTask == MGUI_BACKGROUND_REMOVEDIR )
1694
		{
1695
			// no more directories left
1696
			if ( m_pDirList->Empty() )
1697
			{
1698
				m_bRunningBackground = false;
1699
				this->Close();
1700
			}
1701
			// otherwise, open the next directory
1702
			else
1703
			{
1704
				m_bRunningBackground = false;
1705
				ComboDir->SelectedItem = ComboDir->Items[0];
1706
//				this->StartBackground(MGUI_BACKGROUND_CHANGEDIR, SystemStringFromCyString(m_pDirList->Head()->str));
1707
				return;
1708
			}
1709
		}
1710
 
1711
		m_iBackgroundTask = MGUI_BACKGROUND_NONE;
1712
 
1713
		this->Enabled = true;
1714
 
1715
		m_bRunningBackground = false;
1716
	}
1717
 
1718
	void MainGui::Background_Progress(System::Object ^Sender, ProgressChangedEventArgs ^E)
1719
	{
1720
		this->ProgressBar->Value = E->ProgressPercentage;
1721
	}
1722
 
1723
	bool MainGui::UpdateBuiltInPackages()
1724
	{
1725
		// find all built-in packages
53 cycrow 1726
		System::String ^dir = ".\\Required";
78 cycrow 1727
 
53 cycrow 1728
		if ( System::IO::Directory::Exists(dir) ) 
1 cycrow 1729
		{
1730
			bool installing = false;
53 cycrow 1731
			array <System::String ^> ^Files = System::IO::Directory::GetFiles(dir, "*.spk");
1 cycrow 1732
 
1733
			for ( int i = 0; i < Files->Length; i++ )
1734
			{
1735
				CyString file = CyStringFromSystemString(Files[i]);
1736
				int error;
1737
				CBaseFile *p = m_pPackages->OpenPackage(file, &error, 0, SPKREAD_NODATA);
1738
				if ( !p )
1739
					continue;
1740
 
1741
				if ( !((CSpkFile *)p)->IsLibrary() )
1742
					continue;
1743
 
1744
				if ( !p->CheckGameCompatability(m_pPackages->GetGame()) )
1745
					continue;
1746
 
1747
				// if its installed, check if we have a newer version
50 cycrow 1748
				CBaseFile *check = m_pPackages->FindSpkPackage(p->name(), p->author());
1 cycrow 1749
				if ( check )
1750
				{
50 cycrow 1751
					if ( check->version().compareVersion(p->version()) != COMPARE_OLDER )
1 cycrow 1752
					{
1753
						this->InstallPackage(Files[i], false, true, true);
1754
						installing = true;
1755
					}
1756
				}
1757
				else
1758
				{
1759
					this->InstallPackage(Files[i], false, true, true);
1760
					installing = true;
1761
				}
1762
 
1763
				delete p;
1764
			}
1765
 
1766
			if ( installing )
1767
				this->StartInstalling(true, true);
1768
			return installing;
1769
		}
1770
 
1771
		return false;
1772
	}
1773
 
1774
	////
1775
	// Auto Update
1776
	////
1777
	void MainGui::AutoUpdate()
1778
	{
1779
		if ( !m_bAutoUpdate || !System::IO::File::Exists( ".\\AutoUpdater.exe") )
1780
			return;
1781
 
1782
		// load the dir list
1783
		if ( !m_pUpdateList )
1784
		{
1785
			m_pUpdateList = new CyStringList;
1786
 
1787
			// TODO: read addresses from data
1788
 
1789
			// hardcoded address
80 cycrow 1790
			m_pUpdateList->PushBack("http://xpluginmanager.co.uk/pmupdate.dat", "", true);
1 cycrow 1791
			if ( (int)PMLBETA )
80 cycrow 1792
				m_pUpdateList->PushBack("http://xpluginmanager/Beta/pmupdatebeta.dat", "", true);
1 cycrow 1793
		}
1794
 
1795
		backgroundUpdater->RunWorkerAsync();
1796
	}
1797
 
1798
	void MainGui::Updater_Finished(System::Object ^Sender, RunWorkerCompletedEventArgs ^E)
1799
	{
1800
		if ( !m_pUpdateList )
1801
			return;
1802
		if ( !m_pUpdateList->Head() )
1803
		{
1804
			delete m_pUpdateList;
1805
			m_pUpdateList = NULL;
1806
			return;
1807
		}
1808
 
1809
		this->Enabled = false;
1810
 
1811
		CyString server = m_pUpdateList->Head()->str;
1812
		CyString data = m_pUpdateList->Head()->data;
1813
 
1814
		m_pUpdateList->PopFront();
1815
 
1816
		// lets check if we have an update
1817
		if ( data.GetToken(" ", 1, 1) != "!ERROR!" )
1818
		{
1819
			CyString download;
1820
			CyString message;
1821
			int max;
1822
			CyString *strs = data.SplitToken("\n", &max);
1823
			if ( strs )
1824
			{
1825
				for ( int i = 0; i < max; i++ )
1826
				{
1827
					CyString cmd = strs[i].GetToken(":", 1, 1);
1828
					CyString rest = strs[i].GetToken(":", 2);
1829
					rest.RemoveFirstSpace();
1830
					if ( cmd.Compare("SPKVERSION") )
1831
					{
1832
						float v = rest.GetToken(" ", 1, 1).ToFloat();
1833
						if ( v > GetLibraryVersion() )
1834
						{
1835
							message += "New version of the SPK Libraries available\nCurrent = ";
1836
							message += CyString::CreateFromFloat(GetLibraryVersion(), 2);
1837
							message += "\nNew Version = ";
1838
							message += CyString::CreateFromFloat(v, 2);
1839
							message += "\n\n";
1840
 
1841
							CyString filename = rest.GetToken(" ", 2);
1842
							if ( download.Empty() )
1843
								download = filename;
1844
							else
1845
							{
1846
								download += "|";
1847
								download += filename;
1848
							}
1849
						}
1850
					}
1851
					else if ( cmd.Compare("PMLVERSION") )
1852
					{
1853
						float v = rest.GetToken(" ", 1, 1).ToFloat();
1854
						int beta = rest.GetToken(" ", 2, 2).ToInt();
1855
 
1856
						bool newVersion = false;
1857
						// new version
1858
						if ( v > (float)PMLVERSION )
1859
							newVersion = true;
1860
						// same version, check beta/rc
1861
						if ( v == (float)PMLVERSION )
1862
						{
1863
							// newer beta version
1864
							if ( beta > (int)PMLBETA && (int)PMLBETA > 0 )
1865
								newVersion = true;
1866
							// current is beta, new is an RC
1867
							else if ( (int)PMLBETA > 0 && beta < 0 )
1868
								newVersion = true;
1869
							// current is rc, new is an rc
1870
							else if ( (int)PMLBETA < 0 && beta < 0 && beta < (int)PMLBETA )
1871
								newVersion = true;
1872
							// current is beta or rc, new is not, so its newer
1873
							else if ( (int)PMLBETA != 0 && beta == 0 )
1874
								newVersion = true;
1875
						}
1876
 
1877
						if ( newVersion )
1878
						{
1879
							message += "New version of the ";
1880
							message += CyStringFromSystemString(GetProgramName(m_bAdvanced));
1881
							message += " available\nCurrent = ";
1882
							message += CyStringFromSystemString(PluginManager::GetVersionString());
1883
							message += "\nNew Version = ";
1884
							message += CyStringFromSystemString(PluginManager::GetVersionString(v, beta));
1885
							message += "\n\n";
1886
							if ( download.Empty() )
1887
								download = rest.GetToken(" ", 3);
1888
							else
1889
							{
1890
								download += "|";
1891
								download += rest.GetToken(" ", 3);
1892
							}
1893
						}
1894
					}
1895
				}
1896
			}
1897
 
1898
			CLEANSPLIT(strs, max)
1899
 
1900
			if ( !download.Empty() && !message.Empty() )
1901
			{
1902
				if ( this->DisplayMessageBox(false, "Updater", SystemStringFromCyString(message) + "Do You wish to download and install it?", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes )
1903
				{
1904
					// absolute address
1905
					CyString downloadFile;
1906
 
1907
					int max;
1908
					CyString *strs = download.SplitToken("|", &max);
1909
					for ( int i = 0; i < max; i++ )
1910
					{
1911
						CyString d = strs[i];
1912
						// relative address
1913
						if ( !d.Left(7).Compare("http://") && !d.Left(4).Compare("www.") )
1914
							d = server.DelToken("/", server.NumToken("/")) + "/" + d;
1915
 
1916
						if ( downloadFile.Empty() )
1917
							downloadFile = d;
1918
						else
1919
						{
1920
							downloadFile += "|";
1921
							downloadFile += d;
1922
						}
1923
					}
1924
 
1925
					CLEANSPLIT(strs, max);
1926
 
1927
					if ( !downloadFile.Empty() )
1928
					{
1929
						m_sDownload = SystemStringFromCyString(downloadFile);
1930
						this->Close();
1931
						return;
1932
					}
1933
				}
1934
			}
1935
		}
1936
 
1937
		// otherwise, lets continue with the next server
1938
		if ( m_pUpdateList->Head() )
1939
			backgroundUpdater->RunWorkerAsync();
1940
		else
1941
		{
1942
			delete m_pUpdateList;
1943
			m_pUpdateList = NULL;
1944
		}
1945
 
1946
		this->Enabled = true;
1947
	}
1948
 
1949
	void MainGui::TimerEvent_CheckFile(System::Object ^Sender, System::EventArgs ^E)
1950
	{
1951
		if ( m_bRunningBackground )
1952
			return;
1953
 
1954
		System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
1955
 
1956
		bool anytoinstall = false;
1957
 
1958
		if ( System::IO::File::Exists(mydoc + "\\Egosoft\\pluginmanager_load.dat") )
1959
		{
1960
			System::String ^lines = System::IO::File::ReadAllText(mydoc + "\\Egosoft\\pluginmanager_load.dat");
1961
			System::IO::File::Delete(mydoc + "\\Egosoft\\pluginmanager_load.dat");
1962
			if ( lines )
1963
			{
1964
				CyString strLines = CyStringFromSystemString(lines);
1965
				int num;
1966
				CyString *aLines = strLines.SplitToken("\n", &num);
1967
				if ( num && aLines )
1968
				{
1969
					for ( int i = 0; i < num; i++ )
1970
					{
1971
						CyString l = aLines[i];
1972
						l = l.Remove("\r");
1973
						CyString first = l.GetToken(":", 1, 1);
1974
						CyString rest = l.GetToken(":", 2);
1975
						rest.RemoveFirstSpace();
1976
 
1977
						if ( first.Compare("File") )
1978
						{
1979
							if ( m_bDirLocked ) {
1980
								this->DisplayLocked(false);
1981
								return;
1982
							}
1983
							if ( this->InstallPackage(SystemStringFromCyString(rest), false, false, true) )
1984
								anytoinstall = true;
1985
						}
1986
					}
1987
 
1988
					CLEANSPLIT(aLines, num);
1989
				}
1990
			}
1991
		}
1992
 
1993
		if ( anytoinstall )
1994
			this->StartInstalling(false, true);
1995
	}
1996
 
1997
	void MainGui::Updater_DoWork(System::Object ^Sender, DoWorkEventArgs ^E)
1998
	{
1999
		if ( !m_pUpdateList )
2000
			return;
2001
		if ( !m_pUpdateList->Head() )
2002
		{
2003
			delete m_pUpdateList;
2004
			m_pUpdateList = NULL;
2005
			return;
2006
		}
2007
 
2008
		try 
2009
		{
2010
			System::Net::WebClient ^Client = gcnew System::Net::WebClient();
2011
 
2012
			System::IO::Stream ^strm = Client->OpenRead(SystemStringFromCyString(m_pUpdateList->Head()->str));
2013
			System::IO::StreamReader ^sr = gcnew System::IO::StreamReader(strm);
2014
			System::String ^read = sr->ReadToEnd();
2015
			strm->Close();
2016
			sr->Close();
2017
 
2018
			m_pUpdateList->Head()->data = CyStringFromSystemString(read);
2019
		}
2020
		catch (System::Net::WebException ^ex)
2021
		{
2022
			m_pUpdateList->Head()->data = CyStringFromSystemString("!ERROR! " + ex->ToString());
2023
			if ( ex->Status == System::Net::WebExceptionStatus::ConnectFailure )
2024
			{
2025
				m_pUpdateList->Head()->data = CyStringFromSystemString("!ERROR! " + ex->ToString());
2026
 
2027
			}
2028
		}
2029
	}
2030
 
2031
	void MainGui::RemoveDirectory()
2032
	{
2033
		if ( !m_pPackages->IsLoaded() )
2034
			return;
2035
 
2036
		System::String ^remDir = SystemStringFromCyString(m_pPackages->GetCurrentDirectory());
2037
		this->Enabled = false;
2038
		if ( this->DisplayMessageBox(false, "Remove Directory", "Are you sure you want to remove this directory:\n" + remDir + "\n\nThis will remove all installed packages and clear any settings", MessageBoxButtons::YesNo, MessageBoxIcon::Question) != System::Windows::Forms::DialogResult::Yes)
2039
		{
2040
			this->Enabled = true;
2041
			return;
2042
		}
2043
 
2044
		this->StartBackground(MGUI_BACKGROUND_REMOVEDIR, remDir);
2045
	}
2046
 
2047
	bool MainGui::RemoveCurrentDirectory()
2048
	{
2049
		if ( !m_pPackages->RemoveCurrentDirectory() )
2050
			return false;
2051
 
2052
		// remove directory from list
2053
		m_pRemovedDirList->PushBack(m_pDirList->Head()->str, "", true);
2054
		m_pDirList->PopFront();
2055
 
2056
		return true;
2057
	}
2058
 
2059
	void MainGui::LaunchGame()
2060
	{
2061
		if ( !System::IO::File::Exists(".\\GameLauncher.exe") )
2062
			return;
2063
 
2064
		m_sRun = SystemStringFromCyString(m_pPackages->GetGameRunExe());
2065
		this->Close();
2066
	}
2067
 
2068
	bool MainGui::DisplayTip(int tipsection, int tip)
2069
	{
2070
		if ( tipsection < 0 || tipsection >= MAXTIPS )
2071
			return false;
2072
 
2073
		STips ^tips = (STips ^)m_lTips[tipsection];
2074
		if ( !(tips->iTips & tip) )
2075
		{
2076
			System::String ^sTip = cli::safe_cast<System::String ^>(tips->sTips[(tip >> 1)]);
2077
 
2078
			tips->iTips |= tip;
2079
 
2080
			if ( this->DisplayMessageBox(false, "Plugin Manager Tip", sTip, MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes )
2081
				return true;
2082
			else 
2083
				return false;
2084
		}
2085
 
2086
		return true;
2087
	}
2088
 
2089
	void MainGui::SetTipStrings(int section)
2090
	{
2091
		STips ^t = (STips ^)m_lTips[section];
2092
		t->sTips = gcnew ArrayList();
2093
 
2094
		switch ( section )
2095
		{
2096
			case TIPSECTION_YESNO:
2097
				t->sTips->Add("You are about to uninstall a ship, you need to make sure that there are no ships in the sector you was in when you saved, otherwise it could prevent the save from loading\n\nContinue Uninstalling Ship?");
2098
				t->sTips->Add("You are about to disable a ship, you need to make sure that there are no ships in the sector you was in when you saved, otherwise it could prevent the save from loading\n\nContinue Disabling Ship?");
2099
				break;
2100
		}
2101
	}
2102
 
2103
	System::Windows::Forms::DialogResult MainGui::DisplayMessageBox(bool inthread, System::String ^title, System::String ^text, MessageBoxButtons buttons, MessageBoxIcon icon)
2104
	{
2105
		if ( !inthread )
2106
			return MessageBox::Show(this, text, title, buttons, icon);
2107
		else
2108
		{
2109
			m_bDisplayMessage = true;
2110
			m_sMessageText = text;
2111
			m_sMessageTitle = title;
2112
			m_messageIcon = icon;
2113
			m_messageButtons = buttons;
2114
 
2115
			return System::Windows::Forms::DialogResult::Abort;
2116
		}
2117
	}
2118
 
2119
	ListViewItem ^MainGui::FindSelectedItem()
2120
	{
2121
		Point ^mousePoint = this->ListPackages->PointToClient(this->contextMenuStrip1->MousePosition);
2122
		return  this->ListPackages->GetItemAt(mousePoint->X, mousePoint->Y);
2123
	}
2124
 
2125
	CBaseFile *MainGui::GetFileFromItem(ListViewItem ^item)
2126
	{
2127
		int num = System::Convert::ToInt32(item->Tag);
2128
		return m_pPackages->GetPackageAt(num);
2129
	}
2130
 
2131
	System::Void MainGui::OpenContextMenu(System::Object ^Sender, CancelEventArgs ^E)
2132
	{
2133
		m_pListItem = nullptr;
2134
		E->Cancel = true;
2135
		bool showSep = false;
2136
		bool showSep2 = false;
2137
 
2138
		ListViewItem ^item = this->FindSelectedItem();
2139
		CBaseFile *p = NULL;
2140
		if ( item )
2141
				p = this->GetFileFromItem(item);
2142
 
2143
		this->emailAuthorToolStripMenuItem->Visible = false;
2144
		this->visitForumPageToolStripMenuItem->Visible = false;
2145
		this->visitWebSiteToolStripMenuItem->Visible = false;
2146
		this->ContextDisable->Visible = false;
2147
		this->ContextEnable->Visible = false;
2148
		this->ContextName->Image = nullptr;
2149
		this->UninstallSelectedContext->Visible = false;
2150
		this->viewReadmeToolStripMenuItem->Visible = false;
2151
		this->extrasToolStripMenuItem->Visible = false;
2152
		this->checkForUpdatesToolStripMenuItem->Visible = false;
2153
 
2154
		if ( p 	|| this->ListPackages->SelectedItems->Count )
2155
		{
2156
 
2157
			if ( item && p )
2158
			{
2159
				m_pListItem = item;
2160
				this->ContextName->Text = item->Text;
2161
				if ( item->ImageIndex != -1 )
2162
					this->ContextName->Image = this->ListPackages->LargeImageList->Images[item->ImageIndex];
2163
				else if ( item->ImageKey )
2164
				{
2165
					int key = this->ListPackages->LargeImageList->Images->IndexOfKey(item->ImageKey);
2166
					if ( key != -1 )
2167
						this->ContextName->Image = this->ListPackages->LargeImageList->Images[key];
2168
				}
2169
				else if ( p->GetIcon() )
2170
					PluginManager::DisplayContextIcon(p, this->ContextName, nullptr);
2171
 
2172
				this->uninstallToolStripMenuItem->Text = "Uninstall: " + item->Text;
2173
 
2174
				this->viewReadmeToolStripMenuItem->DropDownItems->Clear();
2175
				if ( p->CountFiles(FILETYPE_README) )
2176
				{
2177
					for ( C_File *f = p->GetFirstFile(FILETYPE_README); f; f = p->GetNextFile(f) )
2178
					{
2179
						if ( f->GetBaseName().GetToken(".", 1, 1).IsNumber() )
2180
						{
2181
							if ( f->GetBaseName().GetToken(".", 1, 1).ToInt() != m_pPackages->GetLanguage() )
2182
								continue;
2183
						}
2184
						if ( f->GetBaseName().IsIn("-L") )
2185
						{
2186
							int pos = f->GetBaseName().FindPos("-L");
2187
							int l = f->GetBaseName().Mid(pos + 2, 3).ToInt();
2188
							if ( l != m_pPackages->GetLanguage() )
2189
								continue;
2190
						}
2191
 
2192
						Windows::Forms::ToolStripMenuItem ^item = gcnew Windows::Forms::ToolStripMenuItem();
2193
						item->Text = SystemStringFromCyString(f->GetFilename());
2194
						item->Image = this->viewReadmeToolStripMenuItem->Image;
2195
						item->ImageScaling = ToolStripItemImageScaling::None;
2196
						item->Click += gcnew System::EventHandler(this, &MainGui::RunItem);
2197
						item->Tag = SystemStringFromCyString(f->GetFilePointer());
2198
						this->viewReadmeToolStripMenuItem->DropDownItems->Add(item);
2199
					}
2200
 
2201
					if ( this->viewReadmeToolStripMenuItem->DropDownItems->Count )
2202
					{
2203
						this->viewReadmeToolStripMenuItem->Visible = true;
2204
						showSep = true;
2205
					}
2206
				}
2207
 
2208
				this->extrasToolStripMenuItem->DropDownItems->Clear();
2209
				if ( p->CountFiles(FILETYPE_EXTRA) )
2210
				{
2211
					showSep = true;
2212
					for ( C_File *f = p->GetFirstFile(FILETYPE_EXTRA); f; f = p->GetNextFile(f) )
2213
					{
2214
						if ( !f->GetDir().Left(6).Compare("extras") )
2215
							continue;
2216
 
2217
						Windows::Forms::ToolStripMenuItem ^item = gcnew Windows::Forms::ToolStripMenuItem();
2218
						item->Text = SystemStringFromCyString(f->GetFilename());
2219
						if ( this->imageList2->Images->IndexOfKey(SystemStringFromCyString(f->GetFileExt().ToLower())) > -1 )
2220
							item->Image = this->imageList2->Images[this->imageList2->Images->IndexOfKey(SystemStringFromCyString(f->GetFileExt().ToLower()))];
2221
						else
2222
						{
2223
							CyString exe = f->GetFilePointer();
2224
							exe = exe.FindReplace("/", "\\");
2225
							wchar_t wText[200];
2226
							::MultiByteToWideChar(CP_ACP, NULL, (char *)exe.c_str(), -1, wText, exe.Length() + 1);
2227
 
2228
							System::Drawing::Icon ^myIcon;
2229
							SHFILEINFO *shinfo = new SHFILEINFO();
2230
 
2231
							if ( FAILED(SHGetFileInfo(wText, 0, shinfo, sizeof(shinfo), SHGFI_ICON | SHGFI_LARGEICON)) )
2232
							{
2233
								if ( FAILED(SHGetFileInfo(wText, 0, shinfo, sizeof(shinfo), SHGFI_ICON | SHGFI_SMALLICON)) )
2234
									item->Image = this->imageList2->Images[0];
2235
								else
2236
								{
2237
									myIcon = System::Drawing::Icon::FromHandle(IntPtr(shinfo->hIcon));
2238
									item->Image = myIcon->ToBitmap();
2239
								}
2240
							}
2241
							else
2242
							{
2243
								myIcon = System::Drawing::Icon::FromHandle(IntPtr(shinfo->hIcon));
2244
								item->Image = myIcon->ToBitmap();
2245
							}
2246
 
2247
							delete shinfo;
2248
						}
2249
						item->ImageScaling = ToolStripItemImageScaling::None;
2250
						item->Click += gcnew System::EventHandler(this, &MainGui::RunItem);
2251
						item->Tag = SystemStringFromCyString(f->GetFilePointer());
2252
						this->extrasToolStripMenuItem->DropDownItems->Add(item);
2253
					}
2254
				}
2255
 
2256
				if ( this->extrasToolStripMenuItem->DropDownItems->Count )
2257
					this->extrasToolStripMenuItem->Visible = true;
2258
 
2259
				// email/website/forum
49 cycrow 2260
				if ( !p->forumLink().empty() ) {
2261
					Utils::String web = p->forumLink();
2262
					if ( web.isNumber() )
2263
						web = Utils::String("http://forum.egosoft.com/viewtopic.php?t=") + web; 
1 cycrow 2264
 
2265
					this->visitForumPageToolStripMenuItem->Visible = true;
49 cycrow 2266
					if ( !web.isin("http://") )
2267
						this->visitForumPageToolStripMenuItem->Tag = "http://" + _US(web);
1 cycrow 2268
					else
49 cycrow 2269
						this->visitForumPageToolStripMenuItem->Tag = _US(web);
1 cycrow 2270
					showSep2 = true;
2271
				}
49 cycrow 2272
				if ( !p->email().empty() )
1 cycrow 2273
				{
2274
					this->emailAuthorToolStripMenuItem->Visible = true;
50 cycrow 2275
					this->emailAuthorToolStripMenuItem->Tag = "mailto://" + _US(p->email()) + "?subject=Re: " + _US(p->name().findReplace(" ", "%20"));
1 cycrow 2276
					showSep2 = true;
2277
				}
49 cycrow 2278
				if ( !p->webSite().empty() ) {
1 cycrow 2279
					this->visitWebSiteToolStripMenuItem->Visible = true;
49 cycrow 2280
					if ( !p->webSite().isin("http://") ) 
2281
						this->visitWebSiteToolStripMenuItem->Tag = "http://" + _US(p->webSite());
2282
					else	
2283
						this->visitWebSiteToolStripMenuItem->Tag = _US(p->webSite());
1 cycrow 2284
					showSep2 = true;
2285
				}
2286
 
49 cycrow 2287
				if ( !p->webAddress().empty() )
1 cycrow 2288
					this->checkForUpdatesToolStripMenuItem->Visible = true;
2289
			}
2290
			else
2291
				m_pListItem = nullptr;
2292
 
2293
			if ( this->ListPackages->SelectedItems->Count > 1 || !p )
2294
			{
2295
				this->UninstallSelectedContext->Visible = true;
2296
				this->UninstallSelectedContext->Text = "Uninstall Selected (" + System::Convert::ToString(this->ListPackages->SelectedItems->Count) + " packages)";
2297
			}
2298
 
2299
			if ( p )
2300
			{
2301
				if ( p->IsEnabled() )
2302
					this->ContextDisable->Visible = true;
2303
				else
2304
					this->ContextEnable->Visible = true;
2305
			}
2306
 
2307
			this->ContextSeperator->Visible = showSep;
2308
			this->ContextSeperator2->Visible = showSep2;
2309
			E->Cancel = false;
2310
		}
2311
	}
2312
 
2313
	System::Void MainGui::ListPackages_DragOver(System::Object^  sender, System::Windows::Forms::DragEventArgs^  e)
2314
	{
2315
		e->Effect = DragDropEffects::None;
2316
 
2317
		if (e->Data->GetDataPresent(DataFormats::FileDrop)) 
2318
		{
2319
			cli::array<String ^> ^a = (cli::array<String ^> ^)e->Data->GetData(DataFormats::FileDrop, false);
2320
			int i;
2321
			for(i = 0; i < a->Length; i++)
2322
			{
2323
				String ^s = a[i];
2324
				String ^ext = IO::FileInfo(s).Extension;
2325
				if ( String::Compare(IO::FileInfo(s).Extension, ".xsp", true) == 0 || String::Compare(IO::FileInfo(s).Extension, ".spk", true) == 0 )
2326
				{
2327
					e->Effect = DragDropEffects::Copy;
2328
					break;
2329
				}
2330
			}
2331
		}
2332
	}
2333
 
2334
	System::Void MainGui::ListPackages_DragDrop(System::Object^  sender, System::Windows::Forms::DragEventArgs^  e)
2335
	{
2336
		if (e->Data->GetDataPresent(DataFormats::FileDrop)) 
2337
		{
2338
			cli::array<String ^> ^a = (cli::array<String ^> ^)e->Data->GetData(DataFormats::FileDrop, false);
2339
			int i;
2340
			for(i = 0; i < a->Length; i++)
2341
			{
2342
				String ^s = a[i];
2343
				String ^ext = IO::FileInfo(s).Extension;
2344
				if ( String::Compare(IO::FileInfo(s).Extension, ".xsp", true) == 0 || String::Compare(IO::FileInfo(s).Extension, ".spk", true) == 0 )
2345
				{
2346
					if ( m_bDirLocked ) {
2347
						this->DisplayLocked(false);
2348
						return;
2349
					}
2350
					this->InstallPackage(s, false, false, true);
2351
				}
2352
			}
2353
 
2354
			this->StartInstalling(false, true);
2355
		}
2356
	}
2357
 
2358
	bool MainGui::CheckAccessRights(String ^dir)
2359
	{
2360
		/*
2361
		// check if already exists
2362
		String ^file = dir + "\\accessrightscheck.dat";
2363
		String ^writeStr = "testing file access";
2364
		if ( IO::File::Exists(file) )
2365
		{
2366
			// remove it
2367
			IO::File::Delete(file);
2368
			// still exists, cant delete it
2369
			if ( IO::File::Exists(file) )
2370
				return false;
2371
		}
2372
 
2373
		IO::DirectoryInfo ^dInfo = gcnew IO::DirectoryInfo(dir);
2374
		Security::AccessControl::DirectorySecurity ^dSecurity = dInfo->GetAccessControl();
2375
		dSecurity->
2376
 
2377
 
2378
		System::IO::FileStream ^writeStream = nullptr;
2379
		IO::BinaryWriter ^writer = nullptr;
2380
		try {
2381
			 writeStream = gcnew System::IO::FileStream(file, System::IO::FileMode::Create);
2382
			 writer = gcnew IO::BinaryWriter(writeStream);
2383
		}
2384
		catch (System::IO::IOException ^e)
2385
		{
2386
			MessageBox::Show("Error: " + e->ToString(), "Error", MessageBoxButtons::OK, MessageBoxIcon::Warning);
2387
		}
2388
		catch (System::Exception ^e)
2389
		{
2390
			MessageBox::Show("Error: " + e->ToString(), "Error", MessageBoxButtons::OK, MessageBoxIcon::Warning);
2391
		}
2392
		finally 
2393
		{
2394
			writer->Write(writeStr);
2395
			writer->Close();
2396
			writeStream->Close();
2397
		}
2398
 
2399
		// check if its written
2400
		if ( !IO::File::Exists(file) )
2401
			return false;
2402
 
2403
		// remove the file again
2404
		IO::File::Delete(file);
2405
		if ( IO::File::Exists(file) )
2406
			return false;
2407
*/
2408
		return true;
2409
	}
2410
 
2411
	System::Void MainGui::RunItem(System::Object ^sender, System::EventArgs ^e)
2412
	{
2413
		Windows::Forms::ToolStripMenuItem ^item = cli::safe_cast<ToolStripMenuItem ^>(sender);
2414
		String ^file = Convert::ToString(item->Tag);
2415
 
2416
		if ( IO::File::Exists(file) )
2417
		{
2418
			System::Diagnostics::Process::Start(file);
2419
		}
2420
	}
2421
 
2422
	void MainGui::RunFromToolItem(ToolStripMenuItem ^item)
2423
	{
2424
		if ( !item ) return;
2425
		if ( !item->Tag ) return;
2426
 
2427
		String ^file = Convert::ToString(item->Tag);
2428
		System::Diagnostics::Process::Start(file);
2429
	}
2430
 
2431
	void MainGui::FakePatchControlDialog()
2432
	{
2433
		FakePatchControl ^fpc = gcnew FakePatchControl(m_pPackages);
2434
		if ( fpc->ShowDialog(this) == Windows::Forms::DialogResult::OK )
2435
		{
2436
			m_pPackages->ApplyFakePatchOrder(fpc->GetPatchOrder());
2437
			m_pPackages->ShuffleFakePatches(0);
2438
		}
2439
	}
2440
 
2441
	void MainGui::CheckFakePatchCompatability()
2442
	{
2443
		CyStringList errorList;
2444
		int count = 0;
2445
		int packageCount = 0;
2446
		for ( CBaseFile *p = m_pPackages->GetFirstPackage(); p; p = m_pPackages->GetNextPackage(p) )
2447
		{
2448
			if ( !p->IsEnabled() ) continue;
2449
			if ( !p->AnyFileType(FILETYPE_MOD) ) continue;
2450
 
2451
			CyString packageName = p->GetFullPackageName(m_pPackages->GetLanguage());
2452
 
2453
			// compare this file against all other packages
2454
			for ( CBaseFile *comparePackage = m_pPackages->GetNextPackage(p); comparePackage; comparePackage = m_pPackages->GetNextPackage(comparePackage) )
2455
			{
2456
				if ( comparePackage == p ) continue; // dont include the same package
2457
				if ( !comparePackage->IsEnabled() ) continue;
2458
				if ( !comparePackage->AnyFileType(FILETYPE_MOD) ) continue;
2459
 
2460
				CyStringList list;
2461
				if ( m_pPackages->CheckCompatabilityBetweenMods(p, comparePackage, &list) )
2462
				{
2463
					CyString package2Name = comparePackage->GetFullPackageName(m_pPackages->GetLanguage());
2464
					for ( SStringList *str = list.Head(); str; str = str->next )
2465
					{
2466
						errorList.PushBack(str->str + " (" + packageName + ")", str->data + " (" + package2Name + ")");
2467
						++count;
2468
					}
2469
					++packageCount;
2470
				}
2471
			}
2472
		}
2473
 
2474
		if ( count )
2475
		{
2476
			if ( MessageBox::Show(this, "Found incompatability between fake patches\n" + count + " errors found\n\nDo you wish to view the errors?", "Fake Patch Compatability", MessageBoxButtons::YesNo, MessageBoxIcon::Information) == Windows::Forms::DialogResult::Yes )
2477
			{
2478
				CompareList ^cl = gcnew CompareList("Fake Patch Incompatabilities");
2479
				cl->AddStringList(errorList);
2480
				cl->ShowDialog(this);
2481
			}
2482
		}
2483
		else
2484
			MessageBox::Show(this, "No incompatabilities found between fake patches", "Fake Patch Compatability", MessageBoxButtons::OK, MessageBoxIcon::Information);
2485
	}
2486
 
88 cycrow 2487
	void MainGui::EditWaresDialog()
2488
	{
2489
		if ( m_bDirLocked ) {
2490
			this->DisplayLocked(false);
2491
			return;
2492
		}
2493
 
2494
		EditWares ^edit = gcnew EditWares(m_pPackages);
2495
 
2496
		if ( edit->ShowDialog(this) == Windows::Forms::DialogResult::OK )
2497
		{
2498
		}
2499
	}
2500
 
1 cycrow 2501
	void MainGui::EditGlobalsDialog()
2502
	{
2503
		if ( m_pPackages->IsVanilla() ) {
2504
			this->DisplayMessageBox(false, "Edit Globals", "Currently in Vanilla Mode, Cant change globals without being modified\n\nSwitch to modified mode if you wish to edit globals", MessageBoxButtons::OK, MessageBoxIcon::Question);
2505
			return;
2506
		}
2507
		if ( m_bDirLocked ) {
2508
			this->DisplayLocked(false);
2509
			return;
2510
		}
2511
 
2512
		//load globals
2513
		CyStringList globals;
2514
		m_pPackages->ReadGlobals(globals);
2515
 
2516
		EditGlobals ^edit = gcnew EditGlobals(&globals);
2517
 
2518
		// make our saved changes
2519
		for ( SStringList *str = m_pPackages->GetGlobals()->Head(); str; str = str->next )
2520
			edit->SetEditedItem(SystemStringFromCyString(str->str), SystemStringFromCyString(str->data));
2521
 
2522
		if ( edit->ShowDialog(this) == Windows::Forms::DialogResult::OK )
2523
		{
2524
			// compare whats different and save
2525
			m_pPackages->GetGlobals()->Clear();
2526
			for ( SStringList *str = edit->GetSavedSettings()->Head(); str; str = str->next )
2527
				m_pPackages->GetGlobals()->PushBack(str->str, str->data);
2528
		}
2529
	}
2530
 
2531
	void MainGui::ViewFileLog()
2532
	{
2533
		if ( m_pFileErrors->Empty() )
2534
			MessageBox::Show(this, "No messages to view in file log", "Empty File Log", MessageBoxButtons::OK, MessageBoxIcon::Warning);
2535
		else
2536
		{
2537
			FileLog ^log = gcnew FileLog;
2538
			for ( SStringList *str = m_pFileErrors->Head(); str; str = str->next )
2539
			{
2540
				bool add = true;
2541
				String ^status = "Unknown Error";
2542
				switch(str->data.GetToken(" ", 1, 1).ToInt())
2543
				{
2544
					case SPKINSTALL_CREATEDIRECTORY:
2545
						status = "Created Directory";
2546
						break;
2547
					case SPKINSTALL_CREATEDIRECTORY_FAIL:
2548
						status = "Failed to create Directory";
2549
						break;
2550
					case SPKINSTALL_WRITEFILE:
2551
						status = "File Written";
2552
						break;
2553
					case SPKINSTALL_WRITEFILE_FAIL:
2554
						status = "Failed to Write File";
2555
						break;
2556
					case SPKINSTALL_DELETEFILE:
2557
						status = "Deleted File";
2558
						break;
2559
					case SPKINSTALL_DELETEFILE_FAIL:
2560
						status = "Failed to Delete File";
2561
						break;
2562
					case SPKINSTALL_SKIPFILE:
2563
						status = "File Skipped";
2564
						break;
2565
					case SPKINSTALL_REMOVEDIR:
2566
						status = "Removed Directory";
2567
						break;
2568
					case SPKINSTALL_ENABLEFILE:
2569
						status = "Enabled File";
2570
						break;
2571
					case SPKINSTALL_DISABLEFILE:
2572
						status = "Disabled File";
2573
						break;
2574
					case SPKINSTALL_ENABLEFILE_FAIL:
2575
						status = "Failed to Enable File";
2576
						break;
2577
					case SPKINSTALL_DISABLEFILE_FAIL:
2578
						status = "Failed to Disable File";
2579
						break;
2580
					case SPKINSTALL_UNINSTALL_MOVE:
2581
						status = "Moved Uninstall File";
2582
						break;
2583
					case SPKINSTALL_UNINSTALL_COPY:
2584
						status = "Copied Uninstall File";
2585
						break;
2586
					case SPKINSTALL_UNINSTALL_MOVE_FAIL:
2587
						status = "Failed to move uninstall file";
2588
						break;
2589
					case SPKINSTALL_UNINSTALL_COPY_FAIL:
2590
						status = "Failed to copy uninstall file";
2591
						break;
2592
					case SPKINSTALL_UNINSTALL_REMOVE:
2593
						status = "Removed uninstall file";
2594
						break;
2595
					case SPKINSTALL_UNINSTALL_REMOVE_FAIL:
2596
						status = "Failed to remove uninstall file";
2597
						break;
2598
					case SPKINSTALL_ORIGINAL_BACKUP:
2599
						status = "Backed up Original";
2600
						break;
2601
					case SPKINSTALL_ORIGINAL_RESTORE:
2602
						status = "Restored Original";
2603
						break;
2604
					case SPKINSTALL_ORIGINAL_BACKUP_FAIL:
2605
						status = "Failed to Backup Original";
2606
						break;
2607
					case SPKINSTALL_ORIGINAL_RESTORE_FAIL:
2608
						status = "Failed to restore Original";
2609
						break;
2610
					case SPKINSTALL_FAKEPATCH:
2611
						status = "Adjusting Fakepatch";
2612
						break;
2613
					case SPKINSTALL_FAKEPATCH_FAIL:
2614
						status = "Failed to adjust Fakepatch";
2615
						break;
2616
					case SPKINSTALL_AUTOTEXT:
2617
						status = "Adjusting Text File";
2618
						break;
2619
					case SPKINSTALL_AUTOTEXT_FAIL:
2620
						status = "Failed to adjust Text File";
2621
						break;
2622
					case SPKINSTALL_MISSINGFILE:
2623
						status = "Missing File";
2624
						break;
2625
					case SPKINSTALL_SHARED:
2626
						status = "Shared File";
2627
						break;
2628
					case SPKINSTALL_SHARED_FAIL:
2629
						status = "Shared File Failed";
2630
						break;
2631
					case SPKINSTALL_ORPHANED:
2632
						status = "File Orphaned";
2633
						break;
2634
					case SPKINSTALL_ORPHANED_FAIL:
2635
						status = "Failed to Orphan file";
2636
						break;
2637
					case SPKINSTALL_UNCOMPRESS_FAIL:
2638
						status = "Failed to Uncompress";
2639
						break;
2640
				}
2641
 
2642
				if ( add )
2643
				{
2644
					if ( str->data.NumToken(" ") > 1 )
2645
						log->AddItem(SystemStringFromCyString(str->str.findreplace("~", " => ")), status, SystemStringFromCyString(SPK::ConvertTimeString((long)str->data.GetToken(" ", 2, 2).ToLong())));
2646
					else
2647
						log->AddItem(SystemStringFromCyString(str->str.findreplace("~", " => ")), status, nullptr);
2648
				}
2649
			}
2650
			if ( log->ShowDialog(this) == Windows::Forms::DialogResult::Cancel )
2651
			{
2652
				if ( MessageBox::Show(this, "Are you sure you want to clear the file log?", "Clear File Log", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == Windows::Forms::DialogResult::Yes )
2653
				{
2654
					m_pFileErrors->Clear();
2655
					MessageBox::Show(this, "The file log has been cleared", "File Log Cleared", MessageBoxButtons::OK, MessageBoxIcon::Information);
2656
				}
2657
			}
2658
 
2659
		}
2660
	}
2661
 
2662
	void MainGui::VerifyInstalledFiles()
2663
	{
2664
		CyStringList missing;
2665
		int amount = m_pPackages->VerifyInstalledFiles(&missing);
2666
		if ( !amount )
2667
			MessageBox::Show(this, "All files are currently installed", "Verifying Installed Files", MessageBoxButtons::OK, MessageBoxIcon::Information);
2668
		else
2669
		{
2670
			String ^text;
2671
			for ( SStringList *str = missing.Head(); str; str = str->next )
2672
			{
2673
				text += SystemStringFromCyString(str->str);
2674
				text += "\n\t";
2675
				CyString data = str->data.findreplace("\n", "\t\n");
2676
				text += SystemStringFromCyString(data);
2677
				text += "\n\n";
2678
			}
2679
			MessageBoxDetails::Show(this, "Verifing Installed Files", "Missing files detected\nAmount = " + amount, text, false, 600);
2680
		}
2681
	}
2682
 
2683
	void MainGui::ExportPackageList()
2684
	{
2685
		bool enabled = false;
2686
		if ( MessageBox::Show(this, "Do you only want to export enabled packages?", "Only Enabled", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == Windows::Forms::DialogResult::Yes )
2687
			enabled =true;
2688
		SaveFileDialog ^ofd = gcnew SaveFileDialog();
2689
		ofd->Filter = "Log Files (*.log)|*.log";
2690
		ofd->FilterIndex = 1;
2691
		ofd->RestoreDirectory = true;
2692
		ofd->AddExtension =  true;
2693
		ofd->Title = "Select the file to save the package list to";
2694
		if ( ofd->ShowDialog(this) == Windows::Forms::DialogResult::OK )
2695
		{
2696
			if ( IO::File::Exists(ofd->FileName) )
2697
				IO::File::Delete(ofd->FileName);
2698
 
2699
			StreamWriter ^sw = File::CreateText(ofd->FileName);
2700
			try 
2701
			{
2702
				for ( CBaseFile *package = m_pPackages->FirstPackage(); package; package = m_pPackages->NextPackage() )
2703
				{
2704
					if ( enabled && !package->IsEnabled() ) continue;
50 cycrow 2705
					Utils::String line = package->name() + " :: " + package->author() + " :: " + package->version() + " :: " + package->creationDate() + " :: ";
1 cycrow 2706
 
2707
					if ( package->GetType() == TYPE_XSP )
2708
						line += "Ship :: ";
2709
					else if ( package->GetType() == TYPE_ARCHIVE )
2710
						line += "- Archive - :: ";
50 cycrow 2711
					else if ( package->GetType() == TYPE_SPK ) {
2712
						Utils::String type = ((CSpkFile *)package)->GetScriptTypeString(m_pPackages->GetLanguage());
2713
						if ( !type.empty() ) line += type + " :: ";
1 cycrow 2714
					}
2715
 
50 cycrow 2716
					line = line + ((package->IsEnabled()) ? "Yes" : "No") + " :: " + ((package->IsSigned()) ? "Yes" : "No");
2717
					sw->WriteLine(_US(line));
1 cycrow 2718
				}
2719
			}
2720
			finally
2721
			{
2722
				if ( sw )
2723
					delete (IDisposable ^)sw;
2724
			}				
2725
 
2726
			if ( IO::File::Exists(ofd->FileName) )
2727
			{
2728
				if ( enabled )
2729
					MessageBox::Show(this, "Enabled Packages have been saved to:\n" + ofd->FileName, "Package List Saved", MessageBoxButtons::OK, MessageBoxIcon::Information);
2730
				else
2731
					MessageBox::Show(this, "Complete Package List has been saved to:\n" + ofd->FileName, "Package List Saved", MessageBoxButtons::OK, MessageBoxIcon::Information);
2732
			}
2733
			else
2734
				MessageBox::Show(this, "There was an error writing file:\n" + ofd->FileName, "File Write Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
2735
		}
2736
	}
2737
}
2738