Subversion Repositories spk

Rev

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